summaryrefslogtreecommitdiff
path: root/platform/java/src/com/artifex/mupdf/fitz/BufferInputStream.java
diff options
context:
space:
mode:
Diffstat (limited to 'platform/java/src/com/artifex/mupdf/fitz/BufferInputStream.java')
-rw-r--r--platform/java/src/com/artifex/mupdf/fitz/BufferInputStream.java55
1 files changed, 55 insertions, 0 deletions
diff --git a/platform/java/src/com/artifex/mupdf/fitz/BufferInputStream.java b/platform/java/src/com/artifex/mupdf/fitz/BufferInputStream.java
new file mode 100644
index 00000000..6a03dc00
--- /dev/null
+++ b/platform/java/src/com/artifex/mupdf/fitz/BufferInputStream.java
@@ -0,0 +1,55 @@
+package com.artifex.mupdf.fitz;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+public class BufferInputStream extends InputStream
+{
+ protected Buffer buffer;
+ protected int position;
+ protected int resetPosition;
+
+ public BufferInputStream(Buffer buffer) {
+ super();
+ this.buffer = buffer;
+ this.position = 0;
+ this.resetPosition = -1;
+ }
+
+ public int available() {
+ return buffer.getLength();
+ }
+
+ public void mark(int readlimit) {
+ resetPosition = position;
+ }
+
+ public boolean markSupported() {
+ return true;
+ }
+
+ public int read() {
+ return buffer.readByte(position++);
+ }
+
+ public int read(byte[] b) {
+ int n = buffer.readBytes(position, b);
+ position += n;
+ return n;
+ }
+
+ public int read(byte[] b, int off, int len) {
+ int n = buffer.readBytesInto(position, b, off, len);
+ position += n;
+ return n;
+ }
+
+ public void reset() throws IOException {
+ if (resetPosition < 0)
+ throw new IOException("cannot reset because mark never set");
+ if (resetPosition >= buffer.getLength())
+ throw new IOException("cannot reset because mark set outside of buffer");
+
+ position = resetPosition;
+ }
+}