summaryrefslogtreecommitdiff
path: root/org.fox.ttcomics/src/main/java/com/github/junrar/io/InputStreamReadOnlyAccessFile.java
blob: 3c7eedd07739517d8a8cc81000b80e2b986ed94b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package com.github.junrar.io;

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




/**
 * InputStream based implementation of the <code>IReadOnlyAccess</code> 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();
	}

}