0N/A/*
3261N/A * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage sun.net.httpserver;
0N/A
0N/Aimport java.io.*;
0N/Aimport java.net.*;
0N/Aimport com.sun.net.httpserver.*;
0N/Aimport com.sun.net.httpserver.spi.*;
0N/A
0N/A/**
0N/A * a class which allows the caller to read up to a defined
0N/A * number of bytes off an underlying stream
0N/A * close() does not close the underlying stream
0N/A */
0N/A
0N/Aclass FixedLengthInputStream extends LeftOverInputStream {
687N/A private long remaining;
0N/A
687N/A FixedLengthInputStream (ExchangeImpl t, InputStream src, long len) {
0N/A super (t, src);
0N/A this.remaining = len;
0N/A }
0N/A
0N/A protected int readImpl (byte[]b, int off, int len) throws IOException {
0N/A
687N/A eof = (remaining == 0L);
0N/A if (eof) {
0N/A return -1;
0N/A }
0N/A if (len > remaining) {
687N/A len = (int)remaining;
0N/A }
0N/A int n = in.read(b, off, len);
0N/A if (n > -1) {
0N/A remaining -= n;
3105N/A if (remaining == 0) {
3105N/A t.getServerImpl().requestCompleted (t.getConnection());
3105N/A }
0N/A }
0N/A return n;
0N/A }
0N/A
0N/A public int available () throws IOException {
0N/A if (eof) {
0N/A return 0;
0N/A }
0N/A int n = in.available();
687N/A return n < remaining? n: (int)remaining;
0N/A }
0N/A
0N/A public boolean markSupported () {return false;}
0N/A
0N/A public void mark (int l) {
0N/A }
0N/A
0N/A public void reset () throws IOException {
0N/A throw new IOException ("mark/reset not supported");
0N/A }
0N/A}