Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transfer-encoding: chunked and stuff. #7

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion jwat-arc/src/main/java/org/jwat/arc/ArcRecordBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ public void payloadClosed() throws IOException {
/*
* Check payload digest.
*/
digest = payloadHeaderWrapped.getDigest();
digest = payloadHeaderWrapped.getPayloadDigest();
if (digest != null) {
computedPayloadDigest = new Digest();
computedPayloadDigest.digestBytes = digest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
*/
package org.jwat.arc;

import static org.mockito.Mockito.when;
import static org.mockito.Mockito.mock;
import static org.powermock.api.mockito.PowerMockito.mockStatic;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Date;
Expand All @@ -29,8 +25,6 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

@RunWith(JUnit4.class)
//@RunWith(PowerMockRunner.class)
Expand All @@ -41,16 +35,18 @@ public class TestArcFileNamingDefault {
public void test_arcfilenaming_default() {
ArcFileNamingDefault afn;

Date date = new Date();
String dateStr;
String hostname = null;
try {
// Get current date after this since this could maybe take several seconds in rare cases.
hostname = InetAddress.getLocalHost().getHostName().toLowerCase();
}
catch (UnknownHostException e) {
Assert.fail("Unexpected exception!");
}

Date date = new Date();
String dateStr;

afn = new ArcFileNamingDefault(null, null, null, null);
Assert.assertEquals("JWAT", afn.filePrefix);
Assert.assertEquals(true, (afn.date.getTime() - date.getTime()) >= 0);
Expand Down
12 changes: 6 additions & 6 deletions jwat-arc/src/test/java/org/jwat/arc/TestArcReader_Digest.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,15 @@ public void test_arcreader() {
payload_digest = md_payload.digest();
//System.out.println("p1: " + Base16.encodeArray(payload_digest));
//System.out.println("p2: " + Base16.encodeArray(payloadWithHeader.getDigest()));
Assert.assertArrayEquals(payload_digest, payloadWithHeader.getDigest());
Assert.assertArrayEquals(payload_digest, payloadWithHeader.getPayloadDigest());

Assert.assertEquals(payloadAlgo, record.computedPayloadDigest.algorithm);
if (!"base2".equals(payloadBase)) {
Assert.assertEquals(payloadBase, record.computedPayloadDigest.encoding);
} else {
Assert.assertNull(record.computedPayloadDigest.encoding);
}
Assert.assertArrayEquals(record.computedPayloadDigest.digestBytes, payloadWithHeader.getDigest());
Assert.assertArrayEquals(record.computedPayloadDigest.digestBytes, payloadWithHeader.getPayloadDigest());
} else {
Assert.assertNull(record.computedPayloadDigest);
}
Expand Down Expand Up @@ -308,15 +308,15 @@ public void test_arcreader() {
payload_digest = md_payload.digest();
//System.out.println("p1: " + Base16.encodeArray(payload_digest));
//System.out.println("p2: " + Base16.encodeArray(payloadWithHeader.getDigest()));
Assert.assertArrayEquals(payload_digest, payloadWithHeader.getDigest());
Assert.assertArrayEquals(payload_digest, payloadWithHeader.getPayloadDigest());

Assert.assertEquals(payloadAlgo, record.computedPayloadDigest.algorithm);
if (!"base2".equals(payloadBase)) {
Assert.assertEquals(payloadBase, record.computedPayloadDigest.encoding);
} else {
Assert.assertNull(record.computedPayloadDigest.encoding);
}
Assert.assertArrayEquals(record.computedPayloadDigest.digestBytes, payloadWithHeader.getDigest());
Assert.assertArrayEquals(record.computedPayloadDigest.digestBytes, payloadWithHeader.getPayloadDigest());
} else {
Assert.assertNull(record.computedPayloadDigest);
}
Expand Down Expand Up @@ -436,15 +436,15 @@ public void test_arcreader() {
payload_digest = md_payload.digest();
//System.out.println("p1: " + Base16.encodeArray(payload_digest));
//System.out.println("p2: " + Base16.encodeArray(payloadWithHeader.getDigest()));
Assert.assertArrayEquals(payload_digest, payloadWithHeader.getDigest());
Assert.assertArrayEquals(payload_digest, payloadWithHeader.getPayloadDigest());

Assert.assertEquals(payloadAlgo, record.computedPayloadDigest.algorithm);
if (!"base2".equals(payloadBase)) {
Assert.assertEquals(payloadBase, record.computedPayloadDigest.encoding);
} else {
Assert.assertNull(record.computedPayloadDigest.encoding);
}
Assert.assertArrayEquals(record.computedPayloadDigest.digestBytes, payloadWithHeader.getDigest());
Assert.assertArrayEquals(record.computedPayloadDigest.digestBytes, payloadWithHeader.getPayloadDigest());
} else {
Assert.assertNull(record.computedPayloadDigest);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,58 @@
*/
public interface ArchiveParserCallback {

/** Report the file and what it has been identified as. */
/**
* Report the file and what it has been identified as.
* @param file file object currently being parsed
* @param fileId type the file was identified as
*/
public void apcFileId(File file, int fileId);

/** Notity that a GZIP entry was encountered. */
/**
* Notity that a GZIP entry was encountered.
* @param gzipEntry gzip entry object
* @param startOffset start offset of gzip entry
*/
public void apcGzipEntryStart(GzipEntry gzipEntry, long startOffset);

/** Notity that an ARC record was encountered. */
/**
* Notity that an ARC record was encountered.
* @param arcRecord arc record object parsed
* @param startOffset start offset of record
* @param compressed was the record compressed or not
* @throws IOException if an I/O Exception occurs while parsing the ARC record
*/
public void apcArcRecordStart(ArcRecordBase arcRecord, long startOffset, boolean compressed) throws IOException;

/** Notity that a WARC record was encountered. */
/**
* Notity that a WARC record was encountered.
* @param warcRecord warc record object parsed
* @param startOffset start offset of record
* @param compressed was the record compressed or not
* @throws IOException if an I/O Exception occurs while parsing the WARC record
*/
public void apcWarcRecordStart(WarcRecord warcRecord, long startOffset, boolean compressed) throws IOException;

/** Report updated consumed bytes number. */
/**
* Report updated consumed bytes number.
* @param consumed bytes consumed by the parser so far
*/
public void apcUpdateConsumed(long consumed);

/** Report a runtime exception was encountered during the parsing of a file. (Should hopefully not happen!) */
/**
* Report a runtime exception was encountered during the parsing of a file. (Should hopefully not happen!)
* @param t throwable object
* @param offset throwable caught at this offset in the data
* @param consumed data consumed by the parser before the throwable
*/
public void apcRuntimeError(Throwable t, long offset, long consumed);

/** Parser done, no more records/entries. */
/**
* Parser done, no more records/entries.
* @param gzipReader gzip reader used for this file or null
* @param arcReader arc reader used for this file or null
* @param warcReader warc reader used for this file or null
*/
public void apcDone(GzipReader gzipReader, ArcReader arcReader, WarcReader warcReader);

}
10 changes: 5 additions & 5 deletions jwat-archive/src/main/java/org/jwat/archive/ManagedPayload.java
Original file line number Diff line number Diff line change
Expand Up @@ -314,11 +314,11 @@ public void managedHttp(byte[] bytes, boolean bDigest) throws IOException {
}

/**
* Closes the input stream after usage.
* @param in
* @param len
* @param bDigest
* @throws IOException
* Closes the input stream after usage. This method seems used though.
* @param in inputstream to mange
* @param len length of the inputstream
* @param bDigest optional switch to enable digest of inputstream data
* @throws IOException if an I/O Exception occurs while buffering inputstream data
*/
public void managePayloadInputStream(InputStream in, long len, boolean bDigest) throws IOException {
payloadLength = 0;
Expand Down
2 changes: 2 additions & 0 deletions jwat-common/src/main/java/org/jwat/common/ArrayUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public static boolean startsWithIgnoreCase(byte[] subArr, byte[] arr) {
* Check if a byte array matches a specified case sensitive sub byte array at a certain index.
* @param subArr case sensitive sub byte array to compare against
* @param arr byte array to look in
* @param fIdx index to start looking from in <code>arr</code>
* @return boolean indicating if there was a match
*/
public static boolean equalsAt(byte[] subArr, byte[] arr, int fIdx) {
Expand All @@ -147,6 +148,7 @@ public static boolean equalsAt(byte[] subArr, byte[] arr, int fIdx) {
* Check if a byte array matches a specified case insensitive sub byte array at a certain index.
* @param subArr case sensitive sub byte array to compare against
* @param arr byte array to look in
* @param fIdx index to start looking from in <code>arr</code>
* @return boolean indicating if there was a match
*/
public static boolean equalsAtIgnoreCase(byte[] subArr, byte[] arr, int fIdx) {
Expand Down
6 changes: 3 additions & 3 deletions jwat-common/src/main/java/org/jwat/common/Digest.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class Digest {
public String encoding;

/** Cache length of algorithm digest output. */
protected static Map<String, Integer> digestAlgoLengthache = new TreeMap<String, Integer>();
protected static Map<String, Integer> digestAlgoLengthCache = new TreeMap<String, Integer>();

/**
* Returns the length of an algorithms digest output or -1 if it is an
Expand All @@ -66,7 +66,7 @@ public static synchronized int digestAlgorithmLength(String digestAlgorithm) {
if (digestAlgorithm == null || digestAlgorithm.length() == 0) {
throw new IllegalArgumentException("'digestAlgorithm' is empty or null");
}
Integer cachedLen = digestAlgoLengthache.get(digestAlgorithm);
Integer cachedLen = digestAlgoLengthCache.get(digestAlgorithm);
if (cachedLen == null) {
try {
MessageDigest md = MessageDigest.getInstance(digestAlgorithm);
Expand All @@ -78,7 +78,7 @@ public static synchronized int digestAlgorithmLength(String digestAlgorithm) {
if (cachedLen == null) {
cachedLen = -1;
}
digestAlgoLengthache.put(digestAlgorithm, cachedLen);
digestAlgoLengthCache.put(digestAlgorithm, cachedLen);
}
return cachedLen;
}
Expand Down
Loading