Skip to content

Commit b45ea54

Browse files
committed
Added potential test case and lots of debug logging.
1 parent 399c58e commit b45ea54

5 files changed

Lines changed: 1077 additions & 1 deletion

File tree

src/main/java/org/archive/io/ArchiveRecord.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,13 @@ public String getDigestStr() {
292292
}
293293

294294
protected void incrementPosition() {
295+
System.err.println("incrementPostion()");
295296
this.position++;
296297
}
297298

298299
protected void incrementPosition(final long incr) {
300+
new Exception().printStackTrace();
301+
System.err.println("incrementPostion("+incr+")");
299302
this.position += incr;
300303
}
301304

@@ -404,6 +407,8 @@ public boolean hasContentHeaders() {
404407
}
405408

406409
protected void setBodyOffset(int bodyOffset) {
410+
new Exception().printStackTrace();
411+
System.err.println("setBodyOffset("+bodyOffset+")");
407412
this.position = bodyOffset;
408413
}
409414
}

src/main/java/org/archive/io/arc/ARCReaderFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ protected ArchiveReader getArchiveReader(final String arc,
147147
possiblyWrapped.mark(100);
148148
boolean compressed = testCompressedARCStream(possiblyWrapped);
149149
possiblyWrapped.reset();
150-
150+
151151
if (compressed) {
152152
return new CompressedARCReader(arc, possiblyWrapped, atFirstRecord);
153153
} else {

src/main/java/org/archive/io/arc/ARCRecord.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,8 @@ private int getTokenizedHeaderLine(final InputStream stream,
344344
// save verbatim header String
345345
this.headerString = StringUtils.join(list," ");
346346

347+
System.err.println("This "+this.headerString);
348+
347349
return read;
348350
}
349351

@@ -589,6 +591,7 @@ private InputStream readHttpHeader() throws IOException {
589591

590592
statusLine = EncodingUtil.getString(statusBytes, 0,
591593
statusBytes.length - eolCharCount, ARCConstants.DEFAULT_ENCODING);
594+
System.err.println("statusLine: "+statusLine);
592595

593596
// If a null or DELETED break immediately
594597
if ((statusLine == null) || statusLine.startsWith("DELETED")) {
@@ -602,6 +605,7 @@ private InputStream readHttpHeader() throws IOException {
602605
}
603606

604607
// Add bytes read to error "offset" to add to position
608+
System.err.println("BYTES: "+new String(statusBytes));
605609
errOffset += statusBytes.length;
606610
}
607611

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package org.archive.io.arc;
2+
3+
import java.io.File;
4+
import java.io.FileInputStream;
5+
import java.io.FileNotFoundException;
6+
import java.io.InputStream;
7+
import java.io.RandomAccessFile;
8+
9+
import org.archive.io.ArchiveReader;
10+
import org.archive.io.ArchiveRecord;
11+
12+
import junit.framework.TestCase;
13+
14+
/**
15+
*
16+
* Based on https://github.com/iipc/openwayback/pull/104/files
17+
*
18+
* @author csr@statsbiblioteket.dk (Colin Rosenthal)
19+
*
20+
*/
21+
public class ARCReaderFactoryTest extends TestCase {
22+
23+
private File testfile1 = new File("src/test/resources/org/archive/format/arc/IAH-20080430204825-00000-blackbook-truncated.arc");
24+
25+
/**
26+
* Test reading uncompressed arcfile for issue
27+
* https://github.com/iipc/openwayback/issues/101
28+
* @throws Exception
29+
*/
30+
public void testGetResource() throws Exception {
31+
this.offsetResourceTest(testfile1, 1515, "archive.org/robots.txt" );
32+
this.offsetResourceTest(testfile1, 36420, "archive.org/services/collection-rss.php" );
33+
}
34+
35+
private void offsetResourceTest( File testfile, long offset, String uri ) throws Exception {
36+
RandomAccessFile raf = new RandomAccessFile(testfile, "r");
37+
raf.seek(offset);
38+
InputStream is = new FileInputStream(raf.getFD());
39+
String fPath = testfile.getAbsolutePath();
40+
ArchiveReader reader = ARCReaderFactory.get(fPath, is, false);
41+
// This one works:
42+
//ArchiveReader reader = ARCReaderFactory.get(testfile, offset);
43+
ArchiveRecord record = reader.get();
44+
System.out.println("Position:"+record.getPosition());
45+
46+
final String url = record.getHeader().getUrl();
47+
System.out.println("Got URL: "+url);
48+
assertEquals("URL of record is not as expected.", uri, url);
49+
50+
final long position = record.getPosition();
51+
final long recordLength = record.getHeader().getLength();
52+
System.out.println("Position:"+position);
53+
System.out.println("Length:"+recordLength);
54+
assertTrue("Position " + position + " is after end of record " + recordLength, position <= recordLength);
55+
56+
// Clean up:
57+
if( raf != null )
58+
raf.close();
59+
}
60+
61+
}

0 commit comments

Comments
 (0)