diff --git a/src/main/java/org/archive/io/arc/ARCReaderFactory.java b/src/main/java/org/archive/io/arc/ARCReaderFactory.java
index e7dc1625..44437ed7 100644
--- a/src/main/java/org/archive/io/arc/ARCReaderFactory.java
+++ b/src/main/java/org/archive/io/arc/ARCReaderFactory.java
@@ -147,11 +147,11 @@ protected ArchiveReader getArchiveReader(final String arc,
possiblyWrapped.mark(100);
boolean compressed = testCompressedARCStream(possiblyWrapped);
possiblyWrapped.reset();
-
+
if (compressed) {
return new CompressedARCReader(arc, possiblyWrapped, atFirstRecord);
} else {
- return new UncompressedARCReader(arc, possiblyWrapped);
+ return new UncompressedARCReader(arc, possiblyWrapped, atFirstRecord);
}
}
@@ -330,10 +330,11 @@ public UncompressedARCReader(final File f, final long offset)
* @param f Uncompressed arc to read.
* @param is InputStream.
*/
- public UncompressedARCReader(final String f, final InputStream is) {
+ public UncompressedARCReader(final String f, final InputStream is, boolean atFirstRecord) {
// Arc file has been tested for existence by time it has come
// to here.
setIn(new CountingInputStream(is));
+ setAlignedOnFirstRecord(atFirstRecord);
initialize(f);
}
}
diff --git a/src/test/java/org/archive/io/arc/ARCReaderFactoryTest.java b/src/test/java/org/archive/io/arc/ARCReaderFactoryTest.java
new file mode 100644
index 00000000..0721f795
--- /dev/null
+++ b/src/test/java/org/archive/io/arc/ARCReaderFactoryTest.java
@@ -0,0 +1,57 @@
+package org.archive.io.arc;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.io.RandomAccessFile;
+
+import org.archive.io.ArchiveReader;
+import org.archive.io.ArchiveRecord;
+
+import junit.framework.TestCase;
+
+/**
+ *
+ * Based on https://github.com/iipc/openwayback/pull/104/files
+ *
+ * @author csr@statsbiblioteket.dk (Colin Rosenthal)
+ *
+ */
+public class ARCReaderFactoryTest extends TestCase {
+
+ private File testfile1 = new File("src/test/resources/org/archive/format/arc/IAH-20080430204825-00000-blackbook-truncated.arc");
+
+ /**
+ * Test reading uncompressed arcfile for issue
+ * https://github.com/iipc/openwayback/issues/101
+ * @throws Exception
+ */
+ public void testGetResource() throws Exception {
+ this.offsetResourceTest(testfile1, 1515, "http://www.archive.org/robots.txt" );
+ this.offsetResourceTest(testfile1, 36420, "http://www.archive.org/services/collection-rss.php" );
+ }
+
+ private void offsetResourceTest( File testfile, long offset, String uri ) throws Exception {
+ RandomAccessFile raf = new RandomAccessFile(testfile, "r");
+ raf.seek(offset);
+ InputStream is = new FileInputStream(raf.getFD());
+ String fPath = testfile.getAbsolutePath();
+ ArchiveReader reader = ARCReaderFactory.get(fPath, is, false);
+ // This one works:
+ //ArchiveReader reader = ARCReaderFactory.get(testfile, offset);
+ ArchiveRecord record = reader.get();
+
+ final String url = record.getHeader().getUrl();
+ assertEquals("URL of record is not as expected.", uri, url);
+
+ final long position = record.getPosition();
+ final long recordLength = record.getHeader().getLength();
+ assertTrue("Position " + position + " is after end of record " + recordLength, position <= recordLength);
+
+ // Clean up:
+ if( raf != null )
+ raf.close();
+ }
+
+}
diff --git a/src/test/resources/org/archive/format/arc/IAH-20080430204825-00000-blackbook-truncated.arc b/src/test/resources/org/archive/format/arc/IAH-20080430204825-00000-blackbook-truncated.arc
new file mode 100644
index 00000000..3cbffb81
--- /dev/null
+++ b/src/test/resources/org/archive/format/arc/IAH-20080430204825-00000-blackbook-truncated.arc
@@ -0,0 +1,1006 @@
+filedesc://IAH-20080430204825-00000-blackbook-truncated.arc 0.0.0.0 20080430204825 text/plain 1300
+1 1 InternetArchive
+URL IP-address Archive-date Content-type Archive-length
+
+

+
+ |
+
+
|
+
+ |
+
| UploadAnonymous User (login or join us) | ||||||||
|
+ Announcements (more)
+ |
++ + |
+
+
+
+ |
++ + |
+
+
+The Internet Archive is building a digital library of Internet
+ sites and other cultural artifacts in digital form. Like a paper
+ library, we provide free access to researchers, historians,
+ scholars, and the general public.
+ |
++ + + + | |||
| + + + |
+
+
+ |
++ + |
+
|
++ + |
+
+
+ |
++ + |
+
+
+ |
++ + | ||||||||
|
+ Curator's Choice (more)
+ A Few Good G-Men
+Randall Glass, the maker of "Warthog Jump," re-creates in "A Few Good G-Men" an entire scene from... |
++ + |
+ Curator's Choice (more)
+ Grateful Dead Live at Nashville Municipal...
+Set 1 Sugaree Beat It On Down The Line Candyman Me And My Uncle -> Big River Stagger Lee Looks Like... |
++ + |
+ Curator's Choice (more)
+ Zanstones - Slaakhuis: Live in Rotterdam, Holland
+Zanstones confuses the dutch masses with this live display of wacked rhythms, whacked vocals, and... |
++ + |
+ Curator's Choice (more)
+ |
++ + | |||||||||
|
+ Recent Reviews
+Code4Lib 2008: Can Resource Description become Rigorous Data?
+Average rating: ![]() ![]() ![]() ![]() ![]() +Madonna adopts African baby. Average rating: ![]() ![]() ![]() ![]() ![]() + |
++ + |
+ Recent Reviews
+Carolina Chocolate Drops Live at MerleFest on 2007-04-27
+Average rating: ![]() ![]() ![]() ![]() ![]() +Grateful Dead Live at Oakland-Alameda County Coliseum on 1988-12-28 Average rating: ![]() ![]() ![]() ![]() ![]() + |
++ + |
+ Recent Reviews
+No Thoroughfare
+Average rating: ![]() ![]() ![]() ![]() ![]() +JAHTARI RIDDIM FORCE - Farmer In The Sky / Depth Charge Average rating: ![]() ![]() ![]() ![]() ![]() + |
++ + |
+ Recent Reviews
+A manual of chemical analysis, qualitative and quantitative
+Average rating: ![]() ![]() ![]() ![]() ![]() +Chemical lecture experiments; non-metallic elements Average rating: ![]() ![]() ![]() ![]() ![]() + |
++ + |
|
+
+
+
|
++ + | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Institutional Support
|