All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.adobe.internal.io.RangedInputStream Maven / Gradle / Ivy

There is a newer version: 2024.11.18751.20241128T090041Z-241100
Show newest version
/**
 * 
 */
package com.adobe.internal.io;

import java.io.IOException;
import java.io.InputStream;

/**
 * @author sgill
 *
 */
public class RangedInputStream extends CountingInputStream 
{
	private final long length;
	private boolean closed;
	
	/**
	 * @param in
	 */
	public RangedInputStream(InputStream in, long length) 
	{
		super(in);
		this.length = length;
	}

	public int read() throws IOException 
	{
		if (this.closed || this.getOffset() == this.length)
		{
			return -1;
		}
		return super.read();
	}

	public int read(byte[] b, int off, int len) throws IOException 
	{
		if (this.closed || this.getOffset() == this.length)
		{
			return -1;
		}
		len = (int) Math.min(this.length - this.getOffset(), len);
		return super.read(b, off, len);
	}

	public int read(byte[] b) throws IOException 
	{
		return this.read(b, 0, b.length);
	}

	public long skip(long n) throws IOException 
	{
		n = Math.min(this.length - this.getOffset(), n);
		return super.skip(n);
	}
	
	public void close() throws IOException 
	{
		this.closed = true;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy