// Path: core/src/main/java/net/vhati/openuhs/core/ByteReference.java
// public interface ByteReference {
// 	public long length();
// 
// 	public InputStream getInputStream() throws IOException;
// }
// 
// Path: core/src/main/java/net/vhati/openuhs/core/RangeInputStream.java
// public class RangeInputStream extends FilterInputStream {
// 	private long remaining;
// 
// 
// 	public RangeInputStream( InputStream in, long offset, long length ) throws IOException {
// 		super( in );
// 		if ( super.skip( offset ) < offset ) {
// 			throw new IOException( "Unable to skip leading bytes" );
// 		}
// 
// 		remaining = length;
// 	}
// 
// 
// 	@Override
// 	public boolean markSupported() {
// 		return false;
// 	}
// 
// 	@Override
// 	public int read() throws IOException {
// 		return --remaining >= 0 ? super.read() : -1;
// 	}
// 
// 	@Override
// 	public int read( byte[] b, int off, int len ) throws IOException {
// 		if ( remaining <= 0 ) return -1;
// 
// 		len = (int)Math.min( (long)len, remaining );
// 
// 		int result = super.read( b, off, len );
// 		if ( result > 0 ) {
// 			remaining -= result;
// 		}
// 		return result;
// 	}
// }


import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.IOException;
import net.vhati.openuhs.core.ByteReference;
import net.vhati.openuhs.core.RangeInputStream;
package net.vhati.openuhs.core;




public class FileRegionByteReference implements ByteReference {
	protected final File f;
	protected final long offset;
	protected final long length;


	public FileRegionByteReference( File f, long offset, long length ) {
		this.f = f;
		this.offset = offset;
		this.length = length;
	}


	@Override
	public long length() {
		return length;
	}

	@Override
	public InputStream getInputStream() throws IOException {
		FileInputStream fis = null;
		try {
// Path: core/src/main/java/net/vhati/openuhs/core/ByteReference.java
// public interface ByteReference {
// 	public long length();
// 
// 	public InputStream getInputStream() throws IOException;
// }
// 
// Path: core/src/main/java/net/vhati/openuhs/core/RangeInputStream.java
// public class RangeInputStream extends FilterInputStream {
// 	private long remaining;
// 
// 
// 	public RangeInputStream( InputStream in, long offset, long length ) throws IOException {
// 		super( in );
// 		if ( super.skip( offset ) < offset ) {
// 			throw new IOException( "Unable to skip leading bytes" );
// 		}
// 
// 		remaining = length;
// 	}
// 
// 
// 	@Override
// 	public boolean markSupported() {
// 		return false;
// 	}
// 
// 	@Override
// 	public int read() throws IOException {
// 		return --remaining >= 0 ? super.read() : -1;
// 	}
// 
// 	@Override
// 	public int read( byte[] b, int off, int len ) throws IOException {
// 		if ( remaining <= 0 ) return -1;
// 
// 		len = (int)Math.min( (long)len, remaining );
// 
// 		int result = super.read( b, off, len );
// 		if ( result > 0 ) {
// 			remaining -= result;
// 		}
// 		return result;
// 	}
// }


// Path: core/src/main/java/net/vhati/openuhs/core/FileRegionByteReference.java
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.IOException;
import net.vhati.openuhs.core.ByteReference;
import net.vhati.openuhs.core.RangeInputStream;

package net.vhati.openuhs.core;




public class FileRegionByteReference implements ByteReference {
	protected final File f;
	protected final long offset;
	protected final long length;


	public FileRegionByteReference( File f, long offset, long length ) {
		this.f = f;
		this.offset = offset;
		this.length = length;
	}


	@Override
	public long length() {
		return length;
	}

	@Override
	public InputStream getInputStream() throws IOException {
		FileInputStream fis = null;
		try {
			return new RangeInputStream( new BufferedInputStream( new FileInputStream( f ) ), offset, length );