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

uk.bl.wa.nanite.droid.InputStreamIdentificationRequest Maven / Gradle / Ivy

There is a newer version: 1.5.0-111
Show newest version
/**
 * 
 */
package uk.bl.wa.nanite.droid;

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

import net.domesdaybook.reader.ByteReader;
import uk.gov.nationalarchives.droid.core.interfaces.RequestIdentifier;
import uk.gov.nationalarchives.droid.core.interfaces.resource.RequestMetaData;

/**
 * @author Andrew Jackson 
 *
 */
public class InputStreamIdentificationRequest extends ByteArrayIdentificationRequest {

	private InputStreamByteReader isReader;
	
	public InputStreamIdentificationRequest(RequestMetaData metaData,
			RequestIdentifier identifier, InputStream in) {
		this.metaData = metaData;
		this.identifier = identifier;
		try {
			this.size = in.available();
		} catch (IOException e) {
			e.printStackTrace();
		}
		// Init the reader:
		this.isReader = new InputStreamByteReader(in);
	}

	/* (non-Javadoc)
	 * @see uk.gov.nationalarchives.droid.core.interfaces.IdentificationRequest#getByte(long)
	 */
	@Override
	public byte getByte(long position) {
		return this.isReader.readByte(position);
	}

	/* (non-Javadoc)
	 * @see uk.gov.nationalarchives.droid.core.interfaces.IdentificationRequest#getReader()
	 */
	@Override
	public ByteReader getReader() {
		return this.isReader;
	}

	/* (non-Javadoc)
	 * @see uk.gov.nationalarchives.droid.core.interfaces.IdentificationRequest#close()
	 */
	@Override
	public void close() throws IOException {
		InputStream in = this.isReader.getInputStream();
		in.close();
	}

	/* (non-Javadoc)
	 * @see uk.gov.nationalarchives.droid.core.interfaces.IdentificationRequest#getSourceInputStream()
	 */
	@Override
	public InputStream getSourceInputStream() throws IOException {
		InputStream in = this.isReader.getInputStream();
	    in.reset();
		return in;
	}


}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy