|
@@ -330,8 +330,8 @@ public class CryptoInputStream extends FilterInputStream implements
|
|
throws IOException {
|
|
throws IOException {
|
|
checkStream();
|
|
checkStream();
|
|
if (!(in instanceof PositionedReadable)) {
|
|
if (!(in instanceof PositionedReadable)) {
|
|
- throw new UnsupportedOperationException("This stream does not support " +
|
|
|
|
- "positioned read.");
|
|
|
|
|
|
+ throw new UnsupportedOperationException(in.getClass().getCanonicalName()
|
|
|
|
+ + " does not support positioned read.");
|
|
}
|
|
}
|
|
final int n = ((PositionedReadable) in).read(position, buffer, offset,
|
|
final int n = ((PositionedReadable) in).read(position, buffer, offset,
|
|
length);
|
|
length);
|
|
@@ -351,8 +351,8 @@ public class CryptoInputStream extends FilterInputStream implements
|
|
throws IOException {
|
|
throws IOException {
|
|
checkStream();
|
|
checkStream();
|
|
if (!(in instanceof ByteBufferPositionedReadable)) {
|
|
if (!(in instanceof ByteBufferPositionedReadable)) {
|
|
- throw new UnsupportedOperationException("This stream does not support " +
|
|
|
|
- "positioned reads with byte buffers.");
|
|
|
|
|
|
+ throw new UnsupportedOperationException(in.getClass().getCanonicalName()
|
|
|
|
+ + " does not support positioned reads with byte buffers.");
|
|
}
|
|
}
|
|
int bufPos = buf.position();
|
|
int bufPos = buf.position();
|
|
final int n = ((ByteBufferPositionedReadable) in).read(position, buf);
|
|
final int n = ((ByteBufferPositionedReadable) in).read(position, buf);
|
|
@@ -363,7 +363,27 @@ public class CryptoInputStream extends FilterInputStream implements
|
|
|
|
|
|
return n;
|
|
return n;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Positioned readFully using {@link ByteBuffer}s. This method is thread-safe.
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public void readFully(long position, final ByteBuffer buf)
|
|
|
|
+ throws IOException {
|
|
|
|
+ checkStream();
|
|
|
|
+ if (!(in instanceof ByteBufferPositionedReadable)) {
|
|
|
|
+ throw new UnsupportedOperationException(in.getClass().getCanonicalName()
|
|
|
|
+ + " does not support positioned reads with byte buffers.");
|
|
|
|
+ }
|
|
|
|
+ int bufPos = buf.position();
|
|
|
|
+ ((ByteBufferPositionedReadable) in).readFully(position, buf);
|
|
|
|
+ final int n = buf.position() - bufPos;
|
|
|
|
+ if (n > 0) {
|
|
|
|
+ // This operation does not change the current offset of the file
|
|
|
|
+ decrypt(position, buf, n, bufPos);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Decrypt length bytes in buffer starting at offset. Output is also put
|
|
* Decrypt length bytes in buffer starting at offset. Output is also put
|
|
* into buffer starting at offset. It is thread-safe.
|
|
* into buffer starting at offset. It is thread-safe.
|
|
@@ -480,8 +500,8 @@ public class CryptoInputStream extends FilterInputStream implements
|
|
throws IOException {
|
|
throws IOException {
|
|
checkStream();
|
|
checkStream();
|
|
if (!(in instanceof PositionedReadable)) {
|
|
if (!(in instanceof PositionedReadable)) {
|
|
- throw new UnsupportedOperationException("This stream does not support " +
|
|
|
|
- "positioned readFully.");
|
|
|
|
|
|
+ throw new UnsupportedOperationException(in.getClass().getCanonicalName()
|
|
|
|
+ + " does not support positioned readFully.");
|
|
}
|
|
}
|
|
((PositionedReadable) in).readFully(position, buffer, offset, length);
|
|
((PositionedReadable) in).readFully(position, buffer, offset, length);
|
|
if (length > 0) {
|
|
if (length > 0) {
|
|
@@ -513,8 +533,8 @@ public class CryptoInputStream extends FilterInputStream implements
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
if (!(in instanceof Seekable)) {
|
|
if (!(in instanceof Seekable)) {
|
|
- throw new UnsupportedOperationException("This stream does not " +
|
|
|
|
- "support seek.");
|
|
|
|
|
|
+ throw new UnsupportedOperationException(in.getClass().getCanonicalName()
|
|
|
|
+ + " does not support seek.");
|
|
}
|
|
}
|
|
((Seekable) in).seek(pos);
|
|
((Seekable) in).seek(pos);
|
|
resetStreamOffset(pos);
|
|
resetStreamOffset(pos);
|
|
@@ -672,8 +692,8 @@ public class CryptoInputStream extends FilterInputStream implements
|
|
"Cannot seek to negative offset.");
|
|
"Cannot seek to negative offset.");
|
|
checkStream();
|
|
checkStream();
|
|
if (!(in instanceof Seekable)) {
|
|
if (!(in instanceof Seekable)) {
|
|
- throw new UnsupportedOperationException("This stream does not support " +
|
|
|
|
- "seekToNewSource.");
|
|
|
|
|
|
+ throw new UnsupportedOperationException(in.getClass().getCanonicalName()
|
|
|
|
+ + " does not support seekToNewSource.");
|
|
}
|
|
}
|
|
boolean result = ((Seekable) in).seekToNewSource(targetPos);
|
|
boolean result = ((Seekable) in).seekToNewSource(targetPos);
|
|
resetStreamOffset(targetPos);
|
|
resetStreamOffset(targetPos);
|
|
@@ -687,16 +707,16 @@ public class CryptoInputStream extends FilterInputStream implements
|
|
checkStream();
|
|
checkStream();
|
|
if (outBuffer.remaining() > 0) {
|
|
if (outBuffer.remaining() > 0) {
|
|
if (!(in instanceof Seekable)) {
|
|
if (!(in instanceof Seekable)) {
|
|
- throw new UnsupportedOperationException("This stream does not " +
|
|
|
|
- "support seek.");
|
|
|
|
|
|
+ throw new UnsupportedOperationException(in.getClass().getCanonicalName()
|
|
|
|
+ + " does not support seek.");
|
|
}
|
|
}
|
|
// Have some decrypted data unread, need to reset.
|
|
// Have some decrypted data unread, need to reset.
|
|
((Seekable) in).seek(getPos());
|
|
((Seekable) in).seek(getPos());
|
|
resetStreamOffset(getPos());
|
|
resetStreamOffset(getPos());
|
|
}
|
|
}
|
|
if (!(in instanceof HasEnhancedByteBufferAccess)) {
|
|
if (!(in instanceof HasEnhancedByteBufferAccess)) {
|
|
- throw new UnsupportedOperationException("This stream does not support " +
|
|
|
|
- "enhanced byte buffer access.");
|
|
|
|
|
|
+ throw new UnsupportedOperationException(in.getClass().getCanonicalName()
|
|
|
|
+ + " does not support enhanced byte buffer access.");
|
|
}
|
|
}
|
|
final ByteBuffer buffer = ((HasEnhancedByteBufferAccess) in).
|
|
final ByteBuffer buffer = ((HasEnhancedByteBufferAccess) in).
|
|
read(bufferPool, maxLength, opts);
|
|
read(bufferPool, maxLength, opts);
|
|
@@ -714,8 +734,8 @@ public class CryptoInputStream extends FilterInputStream implements
|
|
@Override
|
|
@Override
|
|
public void releaseBuffer(ByteBuffer buffer) {
|
|
public void releaseBuffer(ByteBuffer buffer) {
|
|
if (!(in instanceof HasEnhancedByteBufferAccess)) {
|
|
if (!(in instanceof HasEnhancedByteBufferAccess)) {
|
|
- throw new UnsupportedOperationException("This stream does not support " +
|
|
|
|
- "release buffer.");
|
|
|
|
|
|
+ throw new UnsupportedOperationException(in.getClass().getCanonicalName()
|
|
|
|
+ + " does not support release buffer.");
|
|
}
|
|
}
|
|
((HasEnhancedByteBufferAccess) in).releaseBuffer(buffer);
|
|
((HasEnhancedByteBufferAccess) in).releaseBuffer(buffer);
|
|
}
|
|
}
|
|
@@ -724,8 +744,8 @@ public class CryptoInputStream extends FilterInputStream implements
|
|
public void setReadahead(Long readahead) throws IOException,
|
|
public void setReadahead(Long readahead) throws IOException,
|
|
UnsupportedOperationException {
|
|
UnsupportedOperationException {
|
|
if (!(in instanceof CanSetReadahead)) {
|
|
if (!(in instanceof CanSetReadahead)) {
|
|
- throw new UnsupportedOperationException("This stream does not support " +
|
|
|
|
- "setting the readahead caching strategy.");
|
|
|
|
|
|
+ throw new UnsupportedOperationException(in.getClass().getCanonicalName()
|
|
|
|
+ + " does not support setting the readahead caching strategy.");
|
|
}
|
|
}
|
|
((CanSetReadahead) in).setReadahead(readahead);
|
|
((CanSetReadahead) in).setReadahead(readahead);
|
|
}
|
|
}
|
|
@@ -734,8 +754,9 @@ public class CryptoInputStream extends FilterInputStream implements
|
|
public void setDropBehind(Boolean dropCache) throws IOException,
|
|
public void setDropBehind(Boolean dropCache) throws IOException,
|
|
UnsupportedOperationException {
|
|
UnsupportedOperationException {
|
|
if (!(in instanceof CanSetReadahead)) {
|
|
if (!(in instanceof CanSetReadahead)) {
|
|
- throw new UnsupportedOperationException("This stream does not " +
|
|
|
|
- "support setting the drop-behind caching setting.");
|
|
|
|
|
|
+ throw new UnsupportedOperationException(in.getClass().getCanonicalName()
|
|
|
|
+ + " stream does not support setting the drop-behind caching"
|
|
|
|
+ + " setting.");
|
|
}
|
|
}
|
|
((CanSetDropBehind) in).setDropBehind(dropCache);
|
|
((CanSetDropBehind) in).setDropBehind(dropCache);
|
|
}
|
|
}
|
|
@@ -842,8 +863,8 @@ public class CryptoInputStream extends FilterInputStream implements
|
|
case StreamCapabilities.READBYTEBUFFER:
|
|
case StreamCapabilities.READBYTEBUFFER:
|
|
case StreamCapabilities.PREADBYTEBUFFER:
|
|
case StreamCapabilities.PREADBYTEBUFFER:
|
|
if (!(in instanceof StreamCapabilities)) {
|
|
if (!(in instanceof StreamCapabilities)) {
|
|
- throw new UnsupportedOperationException("This stream does not expose " +
|
|
|
|
- "its stream capabilities.");
|
|
|
|
|
|
+ throw new UnsupportedOperationException(in.getClass().getCanonicalName()
|
|
|
|
+ + " does not expose its stream capabilities.");
|
|
}
|
|
}
|
|
return ((StreamCapabilities) in).hasCapability(capability);
|
|
return ((StreamCapabilities) in).hasCapability(capability);
|
|
default:
|
|
default:
|