Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   * Copyright 2010-2014, Inc. or its affiliates. All Rights Reserved.
   * Licensed under the Apache License, Version 2.0 (the "License").
   * You may not use this file except in compliance with the License.
   * A copy of the License is located at
  * or in the "license" file accompanying this file. This file is distributed
  * express or implied. See the License for the specific language governing
  * permissions and limitations under the License.
Filtered input stream implementation that exposes a range of an input stream as a new input stream.
 public final class InputSubstream extends SdkFilterInputStream {
 	private long currentPosition;
 	private final long requestedOffset;
 	private final long requestedLength;
 	private final boolean closeSourceStream;
 	private long markedPosition = 0;

Constructs a new InputSubstream so that when callers start reading from this stream they'll start at the specified offset in the real stream and after they've read the specified length, this stream will look empty.

in The input stream to wrap.
offset The offset, in bytes, into the specified input stream at which to start reading data.
length The length, in bytes, of the specified input stream to return through this stream.
closeSourceStream True if the wrapped InputStream should be closed when this InputSubstream is closed.
     public InputSubstream(InputStream inlong offsetlong lengthboolean closeSourceStream) {
     	this. = 0;
     	this. = length;
     	this. = offset;
     	this. = closeSourceStream;
     public int read() throws IOException {
         byte[] b = new byte[1];
         int bytesRead = read(b, 0, 1);
         if (bytesRead == -1) return bytesRead;
         return b[0];
     public int read(byte[] bint offint lenthrows IOException {
         while ( < ) {
             long skippedBytes = super.skip(requestedOffset - );
              += skippedBytes;
         long bytesRemaining = ( + ) - ;
 		if (bytesRemaining <= 0) return -1;
         len = (int) Math.min(lenbytesRemaining);
         int bytesRead =;
          += bytesRead;
         return bytesRead;
 	public synchronized void mark(int readlimit) {
 	public synchronized void reset() throws IOException {
 	public void close() throws IOException {
 		// Only close the wrapped input stream if we're at the end of
		// the wrapped stream.  We don't want to close the wrapped input
		// stream just because we've reached the end of one subsection.
		if (super.close();
    public int available() throws IOException {
		long bytesRemaining;
		if ( < bytesRemaining = ;
		else bytesRemaining = ( + ) - ;
		return (int)Math.min(bytesRemainingsuper.available());
New to GrepCode? Check out our FAQ X