From 124f869faae3a0f75a3825e6a8e195c17f3c626a Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Thu, 16 Oct 2014 23:34:20 +0400 Subject: initial for idea --- .../junrar/io/InputStreamReadOnlyAccessFile.java | 59 ++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 org.fox.ttcomics/src/main/java/com/github/junrar/io/InputStreamReadOnlyAccessFile.java (limited to 'org.fox.ttcomics/src/main/java/com/github/junrar/io/InputStreamReadOnlyAccessFile.java') diff --git a/org.fox.ttcomics/src/main/java/com/github/junrar/io/InputStreamReadOnlyAccessFile.java b/org.fox.ttcomics/src/main/java/com/github/junrar/io/InputStreamReadOnlyAccessFile.java new file mode 100644 index 0000000..3c7eedd --- /dev/null +++ b/org.fox.ttcomics/src/main/java/com/github/junrar/io/InputStreamReadOnlyAccessFile.java @@ -0,0 +1,59 @@ +package com.github.junrar.io; + +import java.io.BufferedInputStream; +import java.io.IOException; +import java.io.InputStream; + + + + +/** + * InputStream based implementation of the IReadOnlyAccess interface. + * + * @see http://rsbweb.nih.gov/ij/ + * @author martinr + */ +public class InputStreamReadOnlyAccessFile implements IReadOnlyAccess { + private RandomAccessStream is; + + /** + * Create new instance. + * + * @param is The input stream to wrap. + */ + public InputStreamReadOnlyAccessFile(final InputStream is) { + this.is = new RandomAccessStream(new BufferedInputStream(is)); + } + + @Override + public long getPosition() throws IOException { + return is.getLongFilePointer(); + } + + @Override + public void setPosition(long pos) throws IOException { + is.seek(pos); + } + + @Override + public int read() throws IOException { + return is.read(); + } + + @Override + public int read(byte[] buffer, int off, int count) throws IOException { + return is.read(buffer, off, count); + } + + @Override + public int readFully(byte[] buffer, int count) throws IOException { + is.readFully(buffer, count); + return count; + } + + @Override + public void close() throws IOException { + is.close(); + } + +} -- cgit v1.2.3