From commits-return-8551-apmail-sis-commits-archive=sis.apache.org@sis.apache.org Fri Dec 23 17:48:49 2016 Return-Path: X-Original-To: apmail-sis-commits-archive@www.apache.org Delivered-To: apmail-sis-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 92B7D190CC for ; Fri, 23 Dec 2016 17:48:49 +0000 (UTC) Received: (qmail 82856 invoked by uid 500); 23 Dec 2016 17:48:49 -0000 Delivered-To: apmail-sis-commits-archive@sis.apache.org Received: (qmail 82828 invoked by uid 500); 23 Dec 2016 17:48:49 -0000 Mailing-List: contact commits-help@sis.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: sis-dev@sis.apache.org Delivered-To: mailing list commits@sis.apache.org Received: (qmail 82819 invoked by uid 99); 23 Dec 2016 17:48:49 -0000 Received: from Unknown (HELO svn01-us-west.apache.org) (209.188.14.144) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 23 Dec 2016 17:48:49 +0000 Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id A3B5D3A0111 for ; Fri, 23 Dec 2016 17:48:48 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1775860 - in /sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis: internal/storage/ChannelData.java internal/storage/Trackable.java storage/InputStreamAdapter.java Date: Fri, 23 Dec 2016 17:48:47 -0000 To: commits@sis.apache.org From: desruisseaux@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20161223174848.A3B5D3A0111@svn01-us-west.apache.org> 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. *