sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1775688 - in /sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis: internal/storage/ChannelData.java internal/storage/ChannelDataOutput.java internal/storage/Trackable.java storage/InputStreamAdapter.java
Date Thu, 22 Dec 2016 17:47:00 GMT
Author: desruisseaux
Date: Thu Dec 22 17:47:00 2016
New Revision: 1775688

URL: http://svn.apache.org/viewvc?rev=1775688&view=rev
Log:
Add a 'Trackable' interface (internal API only for now) for querying the position of a source
(typically an InputStream).
It is like 'Seekable' but without the need to seek position.

Added:
    sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/Trackable.java
  (with props)
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/ChannelDataOutput.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=1775688&r1=1775687&r2=1775688&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] Thu Dec 22 17:47:00 2016
@@ -20,14 +20,12 @@ import java.io.IOException;
 import java.nio.ByteBuffer;
 import java.nio.InvalidMarkException;
 import java.nio.channels.Channel;
+import java.nio.channels.SeekableByteChannel;
 import org.apache.sis.util.Debug;
 import org.apache.sis.util.resources.Errors;
 
 import static org.apache.sis.util.ArgumentChecks.ensureBetween;
 
-// Branch-dependent imports
-import java.nio.channels.SeekableByteChannel;
-
 
 /**
  * Properties common to {@link ChannelDataInput} and {@link ChannelDataOutput}.
@@ -39,7 +37,7 @@ import java.nio.channels.SeekableByteCha
  * @version 0.5
  * @module
  */
-public abstract class ChannelData {
+public abstract class ChannelData implements Trackable {
     /**
      * Number of bits needed for storing the bit offset in {@link #bitPosition}.
      * The following condition must hold:
@@ -113,10 +111,10 @@ public abstract class ChannelData {
      * Creates a new instance for the given channel and using the given buffer.
      * The channel is not stored by this class - it shall be stored by the subclass.
      *
-     * @param  filename A file identifier used only for formatting error message.
-     * @param  channel  The channel from where data are read or where to wrote.
-     * @param  buffer   The buffer where to store the data.
-     * @throws IOException If an error occurred while reading the channel.
+     * @param  filename  a file identifier used only for formatting error message.
+     * @param  channel   the channel from where data are read or where to wrote.
+     * @param  buffer    the buffer where to store the data.
+     * @throws IOException if an error occurred while reading the channel.
      */
     ChannelData(final String filename, final Channel channel, final ByteBuffer buffer) throws
IOException {
         this.filename      = filename;
@@ -131,7 +129,7 @@ public abstract class ChannelData {
      * by every call to any {@code read} or {@code write} method except {@code readBit()},
{@code readBits(int)},
      * {@code writeBit(int)} and {@code writeBits(long, int)}.</p>
      *
-     * @return The bit offset of the stream.
+     * @return the bit offset of the stream.
      */
     public final int getBitOffset() {
         final long position = bufferOffset + buffer.position();
@@ -144,7 +142,7 @@ public abstract class ChannelData {
     /**
      * Sets the bit offset to the given value.
      *
-     * @param bitOffset The new bit offset of the stream.
+     * @param  bitOffset  the new bit offset of the stream.
      */
     public final void setBitOffset(final int bitOffset) {
         ensureBetween("bitOffset", 0, Byte.SIZE - 1, bitOffset);
@@ -162,8 +160,9 @@ public abstract class ChannelData {
     /**
      * Returns the current byte position of the stream.
      *
-     * @return The position of the stream.
+     * @return the position of the stream.
      */
+    @Override
     public long getStreamPosition() {
         return bufferOffset + buffer.position();
     }
@@ -182,7 +181,7 @@ public abstract class ChannelData {
      *       has changed.</li>
      * </ul>
      *
-     * @param position The new position of the stream.
+     * @param position the new position of the stream.
      */
     public final void setStreamPosition(final long position) {
         bufferOffset = position - buffer.position();
@@ -193,8 +192,7 @@ public abstract class ChannelData {
     }
 
     /**
-     * Returns the earliest position in the stream to which {@linkplain #seek(long) seeking}
-     * may be performed.
+     * Returns the earliest position in the stream to which {@linkplain #seek(long) seeking}
may be performed.
      *
      * @return the earliest legal position for seeking.
      */
@@ -210,8 +208,8 @@ public abstract class ChannelData {
      * <p>This method moves the data starting at the given position to the beginning
of the {@link #buffer},
      * thus making more room for new data before the data at the given position is discarded.</p>
      *
-     * @param  position The length of the stream prefix that may be flushed.
-     * @throws IOException If an I/O error occurred.
+     * @param  position  the length of the stream prefix that may be flushed.
+     * @throws IOException if an I/O error occurred.
      */
     public final void flushBefore(final long position) throws IOException {
         final long currentPosition = getStreamPosition();
@@ -254,8 +252,8 @@ public abstract class ChannelData {
     /**
      * Moves to the given position in the stream, relative to the stream position at construction
time.
      *
-     * @param  position The position where to move.
-     * @throws IOException If the stream can not be moved to the given position.
+     * @param  position  the position where to move.
+     * @throws IOException if the stream can not be moved to the given position.
      */
     public abstract void seek(final long position) throws IOException;
 
@@ -281,7 +279,7 @@ public abstract class ChannelData {
      *       doing nothing. Doing nothing is considered a too high risk of error.</li>
      * </ul>
      *
-     * @throws IOException If an I/O error occurs.
+     * @throws IOException if an I/O error occurs.
      */
     public final void reset() throws IOException {
         final Mark m = mark;
@@ -303,7 +301,7 @@ public abstract class ChannelData {
      * We do that in order to avoid high CPU consumption when data are expected to take more
than
      * a few nanoseconds to arrive.</p>
      *
-     * @throws IOException If the implementation chooses to stop the process.
+     * @throws IOException if the implementation chooses to stop the process.
      */
     protected void onEmptyTransfer() throws IOException {
         try {
@@ -322,7 +320,7 @@ public abstract class ChannelData {
     /**
      * Returns a string representation of this object for debugging purpose.
      *
-     * @return A string representation of this object.
+     * @return a string representation of this object.
      */
     @Debug
     @Override

Modified: sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ChannelDataOutput.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ChannelDataOutput.java?rev=1775688&r1=1775687&r2=1775688&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ChannelDataOutput.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ChannelDataOutput.java
[UTF-8] Thu Dec 22 17:47:00 2016
@@ -27,13 +27,11 @@ import java.nio.FloatBuffer;
 import java.nio.IntBuffer;
 import java.nio.LongBuffer;
 import java.nio.ShortBuffer;
+import java.nio.channels.SeekableByteChannel;
 import java.nio.channels.WritableByteChannel;
 
 import static org.apache.sis.util.ArgumentChecks.ensureBetween;
 
-// Branch-dependent imports
-import java.nio.channels.SeekableByteChannel;
-
 
 /**
  * Provides convenience methods for working with a ({@link WritableByteChannel}, {@link ByteBuffer})
pair.
@@ -74,10 +72,10 @@ public class ChannelDataOutput extends C
     /**
      * Creates a new data output for the given channel and using the given buffer.
      *
-     * @param  filename A file identifier used only for formatting error message.
-     * @param  channel  The channel where data are written.
-     * @param  buffer   The buffer where to put the data.
-     * @throws IOException If an error occurred while creating the data output.
+     * @param  filename  a file identifier used only for formatting error message.
+     * @param  channel   the channel where data are written.
+     * @param  buffer    the buffer where to put the data.
+     * @throws IOException if an error occurred while creating the data output.
      */
     public ChannelDataOutput(final String filename, final WritableByteChannel channel, final
ByteBuffer buffer)
             throws IOException
@@ -95,8 +93,8 @@ public class ChannelDataOutput extends C
      * <p>After this method call, the buffer {@linkplain ByteBuffer#limit() limit}
      * will be equal or greater than {@code position + n}.</p>
      *
-     * @param  n The minimal number of additional bytes that the {@linkplain #buffer buffer}
shall accept.
-     * @throws IOException If an error occurred while writing to the channel.
+     * @param  n  the minimal number of additional bytes that the {@linkplain #buffer buffer}
shall accept.
+     * @throws IOException if an error occurred while writing to the channel.
      */
     private void ensureBufferAccepts(final int n) throws IOException {
         final int capacity = buffer.capacity();
@@ -132,7 +130,7 @@ public class ChannelDataOutput extends C
     /**
      * Returns the current byte position of the stream.
      *
-     * @return The position of the stream.
+     * @return the position of the stream.
      */
     @Override
     public long getStreamPosition() {
@@ -152,8 +150,8 @@ public class ChannelDataOutput extends C
      * Writes a single bit. This method uses only the rightmost bit of the given argument;
      * the upper 31 bits are ignored.
      *
-     * @param bit The bit to write (rightmost bit).
-     * @throws IOException If an error occurred while creating the data output.
+     * @param  bit  the bit to write (rightmost bit).
+     * @throws IOException if an error occurred while creating the data output.
      */
     public final void writeBit(final int bit) throws IOException {
         writeBits(bit, 1);
@@ -163,9 +161,9 @@ public class ChannelDataOutput extends C
      * Writes a sequence of bits. This method uses only the <code>numBits</code>
rightmost bits;
      * other bits are ignored.
      *
-     * @param  bits The bits to write (rightmost bits).
-     * @param  numBits The number of bits to write.
-     * @throws IOException If an error occurred while creating the data output.
+     * @param  bits     the bits to write (rightmost bits).
+     * @param  numBits  the number of bits to write.
+     * @throws IOException if an error occurred while creating the data output.
      */
     public final void writeBits(long bits, int numBits) throws IOException {
         ensureBetween("numBits", 0, Long.SIZE, numBits);
@@ -216,12 +214,12 @@ public class ChannelDataOutput extends C
      * This method ensures that there is space for at least 1 byte in the buffer,
      * (writing previous bytes into the channel if necessary), then delegates to {@link ByteBuffer#put(byte)}.
      *
-     * @param  v byte to be written.
+     * @param  value  byte to be written.
      * @throws IOException if some I/O exception occurs during writing.
      */
-    public final void writeByte(final int v) throws IOException {
+    public final void writeByte(final int value) throws IOException {
         ensureBufferAccepts(Byte.BYTES);
-        buffer.put((byte) v);
+        buffer.put((byte) value);
     }
 
     /**
@@ -230,12 +228,12 @@ public class ChannelDataOutput extends C
      * This method ensures that there is space for at least 2 bytes in the buffer,
      * (writing previous bytes into the channel if necessary), then delegates to {@link ByteBuffer#put(short)}.
      *
-     * @param  v short to be written.
+     * @param  value  short integer to be written.
      * @throws IOException if some I/O exception occurs during writing.
      */
-    public final void writeShort(final int v) throws IOException {
+    public final void writeShort(final int value) throws IOException {
         ensureBufferAccepts(Short.BYTES);
-        buffer.putShort((short) v);
+        buffer.putShort((short) value);
     }
 
     /**
@@ -243,12 +241,12 @@ public class ChannelDataOutput extends C
      * This method ensures that there is space for at least 2 bytes in the buffer,
      * (writing previous bytes into the channel if necessary), then delegates to {@link ByteBuffer#put(char)}.
      *
-     * @param  v char to be written.
+     * @param  value  character to be written.
      * @throws IOException if some I/O exception occurs during writing.
      */
-    public final void writeChar(final int v) throws IOException {
+    public final void writeChar(final int value) throws IOException {
         ensureBufferAccepts(Character.BYTES);
-        buffer.putChar((char) v);
+        buffer.putChar((char) value);
     }
 
     /**
@@ -256,12 +254,12 @@ public class ChannelDataOutput extends C
      * This method ensures that there is space for at least 4 bytes in the buffer,
      * (writing previous bytes into the channel if necessary), then delegates to {@link ByteBuffer#put(int)}.
      *
-     * @param  v Integer to be written.
+     * @param  value  integer to be written.
      * @throws IOException if some I/O exception occurs during writing.
      */
-    public final void writeInt(final int v) throws IOException {
+    public final void writeInt(final int value) throws IOException {
         ensureBufferAccepts(Integer.BYTES);
-        buffer.putInt(v);
+        buffer.putInt(value);
     }
 
     /**
@@ -269,12 +267,12 @@ public class ChannelDataOutput extends C
      * This method ensures that there is space for at least 4 bytes in the buffer,
      * (writing previous bytes into the channel if necessary), then delegates to {@link ByteBuffer#put(long)}.
      *
-     * @param  v Long to be written.
+     * @param  value  long integer to be written.
      * @throws IOException if some I/O exception occurs during writing.
      */
-    public final void writeLong(final long v) throws IOException {
+    public final void writeLong(final long value) throws IOException {
         ensureBufferAccepts(Long.BYTES);
-        buffer.putLong(v);
+        buffer.putLong(value);
     }
 
     /**
@@ -282,12 +280,12 @@ public class ChannelDataOutput extends C
      * This method ensures that there is space for at least 4 bytes in the buffer,
      * (writing previous bytes into the channel if necessary), then delegates to {@link ByteBuffer#put(float)}.
      *
-     * @param  v Float to be written.
+     * @param  value floating point value to be written.
      * @throws IOException if some I/O exception occurs during writing.
      */
-    public final void writeFloat(final float v) throws IOException {
+    public final void writeFloat(final float value) throws IOException {
         ensureBufferAccepts(Float.BYTES);
-        buffer.putFloat(v);
+        buffer.putFloat(value);
     }
 
     /**
@@ -295,12 +293,12 @@ public class ChannelDataOutput extends C
      * This method ensures that there is space for at least 8 bytes in the buffer,
      * (writing previous bytes into the channel if necessary), then delegates to {@link ByteBuffer#put(double)}.
      *
-     * @param  v Double to be written.
+     * @param  value  double precision floating point value to be written.
      * @throws IOException if some I/O exception occurs during writing.
      */
-    public final void writeDouble(final double v) throws IOException {
+    public final void writeDouble(final double value) throws IOException {
         ensureBufferAccepts(Double.BYTES);
-        buffer.putDouble(v);
+        buffer.putDouble(value);
     }
 
     /**
@@ -311,8 +309,8 @@ public class ChannelDataOutput extends C
      *     return write(src, 0, src.length);
      * }
      *
-     * @param  src An array of bytes to be written into stream.
-     * @throws IOException If an error occurred while writing the stream.
+     * @param  src  an array of bytes to be written into stream.
+     * @throws IOException if an error occurred while writing the stream.
      */
     public final void write(final byte[] src) throws IOException {
         write(src, 0, src.length);
@@ -326,8 +324,8 @@ public class ChannelDataOutput extends C
      *     return writeShorts(src, 0, src.length);
      * }
      *
-     * @param  src An array of shorts to be written into stream.
-     * @throws IOException If an error occurred while writing the stream.
+     * @param  src  an array of shorts to be written into stream.
+     * @throws IOException if an error occurred while writing the stream.
      */
     public final void writeShorts(final short[] src) throws IOException {
         writeShorts(src, 0, src.length);
@@ -341,8 +339,8 @@ public class ChannelDataOutput extends C
      *     return writeChars(src, 0, src.length);
      * }
      *
-     * @param  src An array of characters to be written into stream.
-     * @throws IOException If an error occurred while writing the stream.
+     * @param  src  an array of characters to be written into stream.
+     * @throws IOException if an error occurred while writing the stream.
      */
     public final void writeChars(final char[] src) throws IOException {
         writeChars(src, 0, src.length);
@@ -356,8 +354,8 @@ public class ChannelDataOutput extends C
      *     return writeInts(src, 0, src.length);
      * }
      *
-     * @param  src An array of integers to be written into stream.
-     * @throws IOException If an error occurred while writing the stream.
+     * @param  src  an array of integers to be written into stream.
+     * @throws IOException if an error occurred while writing the stream.
      */
     public final void writeInts(final int[] src) throws IOException {
         writeInts(src, 0, src.length);
@@ -371,8 +369,8 @@ public class ChannelDataOutput extends C
      *     return writeLongs(src, 0, src.length);
      * }
      *
-     * @param  src An array of longs to be written into stream.
-     * @throws IOException If an error occurred while writing the stream.
+     * @param  src  an array of longs to be written into stream.
+     * @throws IOException if an error occurred while writing the stream.
      */
     public final void writeLongs(final long[] src) throws IOException {
         writeLongs(src, 0, src.length);
@@ -386,8 +384,8 @@ public class ChannelDataOutput extends C
      *     return writeFloats(src, 0, src.length);
      * }
      *
-     * @param  src An array of floats to be written into stream.
-     * @throws IOException If an error occurred while writing the stream.
+     * @param  src  an array of floats to be written into stream.
+     * @throws IOException if an error occurred while writing the stream.
      */
     public final void writeFloats(final float[] src) throws IOException {
         writeFloats(src, 0, src.length);
@@ -401,8 +399,8 @@ public class ChannelDataOutput extends C
      *     return writeDoubles(src, 0, src.length);
      * }
      *
-     * @param  src An array of doubles to be written into stream.
-     * @throws IOException If an error occurred while writing the stream.
+     * @param  src  an array of doubles to be written into stream.
+     * @throws IOException if an error occurred while writing the stream.
      */
     public final void writeDoubles(final double[] src) throws IOException {
         writeDoubles(src, 0, src.length);
@@ -411,10 +409,10 @@ public class ChannelDataOutput extends C
     /**
      * Writes {@code length} bytes starting at index {@code offset} from the given array.
      *
-     * @param  src    An array containing the bytes to write.
-     * @param  offset Index within {@code src} of the first byte to write.
-     * @param  length The number of bytes to write.
-     * @throws IOException If an error occurred while writing the stream.
+     * @param  src     an array containing the bytes to write.
+     * @param  offset  index within {@code src} of the first byte to write.
+     * @param  length  the number of bytes to write.
+     * @throws IOException if an error occurred while writing the stream.
      */
     public final void write(final byte[] src, int offset, int length) throws IOException
{
         if (length != 0) {
@@ -455,7 +453,7 @@ public class ChannelDataOutput extends C
          * Skips the given amount of bytes in the buffer. It is caller responsibility to
ensure
          * that there is enough bytes remaining in the buffer.
          *
-         * @param nByte byte shift of buffer position.
+         * @param  nByte  byte shift of buffer position.
          */
         private void skipInBuffer(int nByte) {
             buffer.position(buffer.position() + nByte);
@@ -464,10 +462,10 @@ public class ChannelDataOutput extends C
         /**
          * Writes {@code length} characters from the array to the stream.
          *
-         * @param  dataSize The size of the Java primitive type which is the element of the
array.
-         * @param  offset   The starting position within {@code src} to write.
-         * @param  length   The number of characters to write.
-         * @throws IOException If an error occurred while writing the stream.
+         * @param  dataSize  the size of the Java primitive type which is the element of
the array.
+         * @param  offset    the starting position within {@code src} to write.
+         * @param  length    the number of characters to write.
+         * @throws IOException if an error occurred while writing the stream.
          */
         final void writeFully(final int dataSize, int offset, int length) throws IOException
{
             clearBitOffset(); // Actually needed only if length == 0.
@@ -489,10 +487,10 @@ public class ChannelDataOutput extends C
     /**
      * Writes {@code length} chars starting at index {@code offset} from the given array.
      *
-     * @param  src    An array containing the characters to write.
-     * @param  offset Index within {@code src} of the first char to write.
-     * @param  length The number of chars to write.
-     * @throws IOException If an error occurred while writing the stream.
+     * @param  src     an array containing the characters to write.
+     * @param  offset  index within {@code src} of the first char to write.
+     * @param  length  the number of chars to write.
+     * @throws IOException if an error occurred while writing the stream.
      */
     public final void writeChars(final char[] src, int offset, int length) throws IOException
{
         new ArrayWriter() {
@@ -505,10 +503,10 @@ public class ChannelDataOutput extends C
     /**
      * Writes {@code length} shorts starting at index {@code offset} from the given array.
      *
-     * @param  src    An array containing the shorts to write.
-     * @param  offset Index within {@code src} of the first short to write.
-     * @param  length The number of shorts to write.
-     * @throws IOException If an error occurred while writing the stream.
+     * @param  src     an array containing the shorts to write.
+     * @param  offset  index within {@code src} of the first short to write.
+     * @param  length  the number of shorts to write.
+     * @throws IOException if an error occurred while writing the stream.
      */
     public final void writeShorts(final short[] src, int offset, int length) throws IOException
{
         new ArrayWriter() {
@@ -521,10 +519,10 @@ public class ChannelDataOutput extends C
     /**
      * Writes {@code length} integers starting at index {@code offset} from the given array.
      *
-     * @param  src    An array containing the integers to write.
-     * @param  offset Index within {@code src} of the first integer to write.
-     * @param  length The number of integers to write.
-     * @throws IOException If an error occurred while writing the stream.
+     * @param  src     an array containing the integers to write.
+     * @param  offset  index within {@code src} of the first integer to write.
+     * @param  length  the number of integers to write.
+     * @throws IOException if an error occurred while writing the stream.
      */
     public final void writeInts(final int[] src, int offset, int length) throws IOException
{
         new ArrayWriter() {
@@ -537,10 +535,10 @@ public class ChannelDataOutput extends C
     /**
      * Writes {@code length} longs starting at index {@code offset} from the given array.
      *
-     * @param  src    An array containing the longs to write.
-     * @param  offset Index within {@code src} of the first long to write.
-     * @param  length The number of longs to write.
-     * @throws IOException If an error occurred while writing the stream.
+     * @param  src     an array containing the longs to write.
+     * @param  offset  index within {@code src} of the first long to write.
+     * @param  length  the number of longs to write.
+     * @throws IOException if an error occurred while writing the stream.
      */
     public final void writeLongs(final long[] src, int offset, int length) throws IOException
{
         new ArrayWriter() {
@@ -553,10 +551,10 @@ public class ChannelDataOutput extends C
     /**
      * Writes {@code length} floats starting at index {@code offset} from the given array.
      *
-     * @param  src    An array containing the floats to write.
-     * @param  offset Index within {@code src} of the first float to write.
-     * @param  length The number of floats to write.
-     * @throws IOException If an error occurred while writing the stream.
+     * @param  src     an array containing the floats to write.
+     * @param  offset  index within {@code src} of the first float to write.
+     * @param  length  the number of floats to write.
+     * @throws IOException if an error occurred while writing the stream.
      */
     public final void writeFloats(final float[] src, int offset, int length) throws IOException
{
         new ArrayWriter() {
@@ -569,10 +567,10 @@ public class ChannelDataOutput extends C
     /**
      * Writes {@code length} doubles starting at index {@code offset} from the given array.
      *
-     * @param  src    An array containing the doubles to write.
-     * @param  offset Index within {@code src} of the first double to write.
-     * @param  length The number of doubles to write.
-     * @throws IOException If an error occurred while writing the stream.
+     * @param  src     an array containing the doubles to write.
+     * @param  offset  index within {@code src} of the first double to write.
+     * @param  length  the number of doubles to write.
+     * @throws IOException if an error occurred while writing the stream.
      */
     public final void writeDoubles(final double[] src, int offset, int length) throws IOException
{
         new ArrayWriter() {
@@ -603,8 +601,8 @@ public class ChannelDataOutput extends C
      * If the given position is greater than the stream length, then the values of bytes
between the
      * previous stream length and the given position are unspecified. The limit is unchanged.
      *
-     * @param  position The position where to move.
-     * @throws IOException If the stream can not be moved to the given position.
+     * @param  position  the position where to move.
+     * @throws IOException if the stream can not be moved to the given position.
      */
     @Override
     public final void seek(final long position) throws IOException {
@@ -657,7 +655,7 @@ public class ChannelDataOutput extends C
      * Flushes the {@link #buffer buffer} content to the channel.
      * This method does <strong>not</strong> flush the channel itself.
      *
-     * @throws IOException If an error occurred while writing to the channel.
+     * @throws IOException if an error occurred while writing to the channel.
      */
     @Override
     public final void flush() throws IOException {
@@ -684,7 +682,7 @@ public class ChannelDataOutput extends C
      * Writes fully the buffer content from its position to its limit.
      * After this method call, the buffer position is equals to its limit.
      *
-     * @throws IOException If an error occurred while writing to the channel.
+     * @throws IOException if an error occurred while writing to the channel.
      */
     private void writeFully() throws IOException {
         int n = buffer.remaining();

Added: 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=1775688&view=auto
==============================================================================
--- sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/Trackable.java
(added)
+++ sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/Trackable.java
[UTF-8] Thu Dec 22 17:47:00 2016
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.internal.storage;
+
+import java.io.IOException;
+
+
+/**
+ * Stream reader or writer capable to keep trace of its position.
+ * The stream does not need to be able to seekable.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.8
+ * @version 0.8
+ * @module
+ */
+public interface Trackable {
+    /**
+     * Returns the current byte position of the stream.
+     *
+     * @return the position of the stream.
+     * @throws IOException if the position can not be obtained.
+     */
+    long getStreamPosition() throws IOException;
+}

Propchange: sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/Trackable.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/Trackable.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

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=1775688&r1=1775687&r2=1775688&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] Thu Dec 22 17:47:00 2016
@@ -19,6 +19,7 @@ package org.apache.sis.storage;
 import java.io.InputStream;
 import java.io.IOException;
 import javax.imageio.stream.ImageInputStream;
+import org.apache.sis.internal.storage.Trackable;
 
 
 /**
@@ -26,10 +27,10 @@ import javax.imageio.stream.ImageInputSt
  *
  * @author  Martin Desruisseaux (IRD)
  * @since   0.4
- * @version 0.4
+ * @version 0.8
  * @module
  */
-final class InputStreamAdapter extends InputStream {
+final class InputStreamAdapter extends InputStream implements Trackable {
     /**
      * The data input stream.
      */
@@ -113,6 +114,17 @@ final class InputStreamAdapter extends I
     }
 
     /**
+     * Returns the current byte position of the stream.
+     *
+     * @return the position of the stream.
+     * @throws IOException if the position can not be obtained.
+     */
+    @Override
+    public long getStreamPosition() throws IOException {
+        return input.getStreamPosition();
+    }
+
+    /**
      * Closes this input stream.
      *
      * @throws IOException if an I/O error occurs.



Mime
View raw message