You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by cu...@apache.org on 2010/09/03 01:11:24 UTC
svn commit: r992149 - in /avro/trunk: CHANGES.txt
lang/java/src/java/org/apache/avro/file/DataFileReader.java
lang/java/src/test/java/org/apache/avro/TestDataFile.java
Author: cutting
Date: Thu Sep 2 23:11:24 2010
New Revision: 992149
URL: http://svn.apache.org/viewvc?rev=992149&view=rev
Log:
AVRO-652. Java: Expose sync points in DataFileReader. Contributed by Stu Hood.
Modified:
avro/trunk/CHANGES.txt
avro/trunk/lang/java/src/java/org/apache/avro/file/DataFileReader.java
avro/trunk/lang/java/src/test/java/org/apache/avro/TestDataFile.java
Modified: avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=992149&r1=992148&r2=992149&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Thu Sep 2 23:11:24 2010
@@ -174,6 +174,9 @@ Avro 1.4.0 (31 August 2010)
AVRO-644: PHP: Add requirements to README. (Michael Glaesemann via cutting)
+ AVRO-652. Java: Expose sync points in DataFileReader.
+ (Stu Hood via cutting)
+
BUG FIXES
AVRO-622. python avro.ipc doesn't work with python2.4 (philz)
Modified: avro/trunk/lang/java/src/java/org/apache/avro/file/DataFileReader.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/src/java/org/apache/avro/file/DataFileReader.java?rev=992149&r1=992148&r2=992149&view=diff
==============================================================================
--- avro/trunk/lang/java/src/java/org/apache/avro/file/DataFileReader.java (original)
+++ avro/trunk/lang/java/src/java/org/apache/avro/file/DataFileReader.java Thu Sep 2 23:11:24 2010
@@ -44,6 +44,7 @@ public class DataFileReader<D> extends D
super(reader);
this.sin = new SeekableInputStream(sin);
initialize(this.sin);
+ blockFinished();
}
/** Move to a specific, known synchronization point, one returned from {@link
@@ -52,6 +53,7 @@ public class DataFileReader<D> extends D
public void seek(long position) throws IOException {
sin.seek(position);
vin = DecoderFactory.defaultFactory().createBinaryDecoder(this.sin, vin);
+ datumIn = null;
blockRemaining = 0;
blockStart = position;
}
@@ -93,6 +95,11 @@ public class DataFileReader<D> extends D
blockStart = sin.tell() - vin.inputStream().available();
}
+ /** Return the last synchronization point before our current position. */
+ public long previousSync() {
+ return blockStart;
+ }
+
/** Return true if past the next synchronization point after a position. */
public boolean pastSync(long position) throws IOException {
return ((blockStart >= position+SYNC_SIZE)||(blockStart >= sin.length()));
Modified: avro/trunk/lang/java/src/test/java/org/apache/avro/TestDataFile.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/src/test/java/org/apache/avro/TestDataFile.java?rev=992149&r1=992148&r2=992149&view=diff
==============================================================================
--- avro/trunk/lang/java/src/test/java/org/apache/avro/TestDataFile.java (original)
+++ avro/trunk/lang/java/src/test/java/org/apache/avro/TestDataFile.java Thu Sep 2 23:11:24 2010
@@ -152,6 +152,35 @@ public class TestDataFile {
}
@Test
+ public void testSyncDiscovery() throws IOException {
+ File file = makeFile();
+ DataFileReader<Object> reader =
+ new DataFileReader<Object>(file, new GenericDatumReader<Object>());
+ try {
+ // discover the sync points
+ ArrayList<Long> syncs = new ArrayList<Long>();
+ long previousSync = -1;
+ while (reader.hasNext()) {
+ if (reader.previousSync() != previousSync) {
+ previousSync = reader.previousSync();
+ syncs.add(previousSync);
+ }
+ reader.next();
+ }
+ // confirm that the first point is the one reached by sync(0)
+ reader.sync(0);
+ assertEquals((long)reader.previousSync(), (long)syncs.get(0));
+ // and confirm that all points are reachable
+ for (Long sync : syncs) {
+ reader.seek(sync);
+ assertNotNull(reader.next());
+ }
+ } finally {
+ reader.close();
+ }
+ }
+
+ @Test
public void testGenericAppend() throws IOException {
File file = makeFile();
long start = file.length();