19 package org.sleuthkit.datamodel;
21 import java.io.IOException;
22 import java.io.InputStream;
23 import java.util.logging.Level;
24 import java.util.logging.Logger;
38 this.currentOffset = 0;
39 this.contentSize = content.
getSize();
43 public int read() throws IOException {
44 byte[] buff =
new byte[1];
45 return (
read(buff) != -1) ? buff[0] : -1;
49 public int read(byte[] b)
throws IOException {
50 return read(b, 0, b.length);
54 public int read(byte[] b,
int off,
int len)
throws IOException {
56 final int buffLen = b.length;
58 if (buffLen == 0 || len == 0) {
63 if (contentSize == 0) {
68 if (off < 0 || off >= buffLen) {
73 if (currentOffset >= contentSize) {
78 int lenToRead = (int) Math.min(contentSize - currentOffset, len);
81 lenToRead = Math.min(lenToRead, buffLen - off);
89 retBuf =
new byte[lenToRead];
92 final int lenRead = content.
read(retBuf, currentOffset, lenToRead);
94 if (lenRead == 0 || lenRead == -1) {
98 currentOffset += lenRead;
102 System.arraycopy(retBuf, 0, b, off, lenRead);
108 logger.log(Level.WARNING, (
"Error reading content into stream: "
110 +
", at offset " + currentOffset +
", length to read: " + lenToRead, ex);
111 throw new IOException(ex);
126 public long skip(
long n)
throws IOException {
129 long toSkip = Math.min(n, contentSize - currentOffset);
130 currentOffset += toSkip;
136 public void close() throws IOException {
173 public long seek(
long newPosition) {
174 if (newPosition < 0) {
175 throw new IllegalArgumentException(
"Illegal negative new position in the stream");
178 currentOffset = Math.min(newPosition, contentSize);
static final Logger logger
long seek(long newPosition)
int read(byte[] b, int off, int len)
int read(byte[] buf, long offset, long len)
ReadContentInputStream(Content content)
long getLength()
additional methods to facilitate stream seeking