Author: desruisseaux
Date: Fri Dec 23 17:48:47 2016
New Revision: 1775860
URL: http://svn.apache.org/viewvc?rev=1775860&view=rev
Log:
Add mark() and reset() methods in Trackable internal interface.
Modified:
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ChannelData.java
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/Trackable.java
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/InputStreamAdapter.java
Modified: sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ChannelData.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ChannelData.java?rev=1775860&r1=1775859&r2=1775860&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ChannelData.java [UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ChannelData.java [UTF-8] Fri Dec 23 17:48:47 2016
@@ -262,6 +262,7 @@ public abstract class ChannelData implem
* Note that {@code ChannelData} maintains its own marks - the buffer's
* mark is left unchanged.
*/
+ @Override
public final void mark() {
mark = new Mark(getStreamPosition(), (byte) getBitOffset(), mark);
}
@@ -281,6 +282,7 @@ public abstract class ChannelData implem
*
* @throws IOException if an I/O error occurs.
*/
+ @Override
public final void reset() throws IOException {
final Mark m = mark;
if (m == null) {
Modified: sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/Trackable.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/Trackable.java?rev=1775860&r1=1775859&r2=1775860&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/Trackable.java [UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/Trackable.java [UTF-8] Fri Dec 23 17:48:47 2016
@@ -17,11 +17,24 @@
package org.apache.sis.internal.storage;
import java.io.IOException;
+import java.nio.InvalidMarkException;
/**
* Stream reader or writer capable to keep trace of its position.
- * The stream does not need to be able to seekable.
+ * The stream does not need to be able to seek at arbitrary positions.
+ * However it may support nested marks.
+ *
+ *
Use case:
+ * this interface can be used when we need to move to a previously marked position, but we do not know how many nested
+ * {@code mark()} method calls may have been performed (typically because the stream has been used by arbitrary code).
+ * We can compare {@link #getStreamPosition()} value after {@link #reset()} method calls with the expected position.
+ *
+ *
+ * Design note:
+ * an alternative could be to support the {@code seek(long)} method. But using marks instead allows the stream
+ * to invalidate the marks if needed (for example when {@link ChannelData#setStreamPosition(long)} is invoked).
+ *
*
* @author Martin Desruisseaux (Geomatys)
* @since 0.8
@@ -36,4 +49,24 @@ public interface Trackable {
* @throws IOException if the position can not be obtained.
*/
long getStreamPosition() throws IOException;
+
+ /**
+ * Pushes the current stream position onto a stack of marked positions.
+ * A subsequent call to the {@link #reset()} method repositions this stream
+ * at the last marked position so that subsequent reads re-read the same bytes.
+ * Calls to {@code mark()} and {@code reset()} can be nested arbitrarily.
+ *
+ * @throws IOException if this stream can not mark the current position.
+ */
+ void mark() throws IOException;
+
+ /**
+ * Resets the current stream byte and bit positions from the stack of marked positions.
+ * An {@code IOException} may be be thrown if the previous marked position lies in the
+ * discarded portion of the stream.
+ *
+ * @throws InvalidMarkException if there is no mark.
+ * @throws IOException if a mark was defined but this stream can not move to that position.
+ */
+ void reset() throws IOException;
}
Modified: sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/InputStreamAdapter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/InputStreamAdapter.java?rev=1775860&r1=1775859&r2=1775860&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/InputStreamAdapter.java [UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/InputStreamAdapter.java [UTF-8] Fri Dec 23 17:48:47 2016
@@ -96,6 +96,7 @@ final class InputStreamAdapter extends I
/**
* Marks the current position in this input stream.
*
+ * @param readlimit ignored.
* @throws IOException if an I/O error occurs.
*/
@Override
@@ -103,6 +104,16 @@ final class InputStreamAdapter extends I
input.mark();
}
+ /**
+ * Marks the current position in this input stream.
+ *
+ * @throws IOException if an I/O error occurs.
+ */
+ @Override
+ public void mark() {
+ input.mark();
+ }
+
/**
* Repositions this stream to the position at the time the {@code mark} method was last called.
*