use of java.lang.IllegalArgumentException in project commoncrawl-examples by commoncrawl.
the class ArcRecord method setArcRecordHeader.
/**
* <p>Parses and sets the ARC record header fields.</p>
* <p>Currently, this method expects the ARC record header string to contain
* the following fields, in order, separated by space:
* <ul>
* <li>URL</li>
* <li>IP Address</li>
* <li>Archive Date</li>
* <li>Content Type</li>
* <li>Content Length</li>
* </ul>
* </p>
* <p>For more information on the arc file format, see
* {@link http://www.archive.org/web/researcher/ArcFileFormat.php}.</p>
*
* @param arcRecordHeader The first line of an ARC file entry - the header
* line for an ARC file item.
*/
public void setArcRecordHeader(String arcRecordHeader) throws IllegalArgumentException, ParseException {
if (arcRecordHeader == null || arcRecordHeader.equals(""))
throw new IllegalArgumentException("ARC v1 record header string is empty.");
String[] metadata = arcRecordHeader.split(" ");
if (metadata.length != 5) {
LOG.info(" [ " + arcRecordHeader + " ] ");
throw new IllegalArgumentException("ARC v1 record header must be 5 fields.");
}
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
this._url = metadata[0];
this._ipAddress = metadata[1];
this._archiveDate = format.parse(metadata[2]);
this._contentType = metadata[3];
this._contentLength = (new Integer(metadata[4])).intValue();
}
use of java.lang.IllegalArgumentException in project commoncrawl-examples by commoncrawl.
the class ArcRecord method setPayload.
/**
* <p>Reads and sets the ARC record payload from an input stream.</p>
*
* @param in An input stream positioned at the start of the ARC record payload.
*/
public void setPayload(InputStream in) throws IllegalArgumentException, ParseException, IOException {
if (in == null)
throw new IllegalArgumentException("ArcRecord cannot be created from NULL/missing input stream.");
int bufferSize = this._contentLength;
this._payload = new byte[bufferSize];
int n = in.read(this._payload, 0, this._payload.length);
if (n < this._payload.length) {
LOG.warn("Expecting " + bufferSize + " bytes in ARC record payload, found " + n + " bytes. Performing array copy.");
this._payload = Arrays.copyOf(this._payload, n);
}
// After this, we should be at the end of this GZIP member. Let the
// calling function verify the position of the stream.
}
use of java.lang.IllegalArgumentException in project translationstudio8 by heartsome.
the class FastIntBuffer method getIntArray.
/**
* Returns a single int array representing every int in this buffer instance
* @return int[] (null if there isn't anything left in the buffer
* @param startingOffset int
* @param len int
* @return int[]
*/
public int[] getIntArray(int startingOffset, int len) {
if (size <= 0 || startingOffset < 0) {
throw (new IllegalArgumentException());
}
if ((startingOffset + len) > size()) {
throw (new IndexOutOfBoundsException());
}
// allocate result array
int[] result = new int[len];
// int first_index = (int) (startingOffset / pageSize);
// int last_index = (int) ((startingOffset + len) / pageSize);
// if ((startingOffset + len) % pageSize == 0) {
// last_index--;
// }
int first_index = startingOffset >> exp;
int last_index = (startingOffset + len) >> exp;
if (((startingOffset + len) & r) == 0) {
last_index--;
}
if (first_index == last_index) {
// to see if there is a need to go across buffer boundry
System.arraycopy((int[]) (bufferArrayList.get(first_index)), // startingOffset % pageSize,
startingOffset & r, result, 0, len);
} else {
int int_array_offset = 0;
for (int i = first_index; i <= last_index; i++) {
int[] currentChunk = (int[]) bufferArrayList.get(i);
if (// first section
i == first_index) {
System.arraycopy(currentChunk, // startingOffset % pageSize,
startingOffset & r, result, 0, // pageSize - (startingOffset % pageSize));
pageSize - (startingOffset & r));
// int_array_offset += pageSize - (startingOffset) % pageSize;
int_array_offset += pageSize - (startingOffset & r);
} else if (// last sections
i == last_index) {
System.arraycopy(currentChunk, 0, result, int_array_offset, len - int_array_offset);
} else {
System.arraycopy(currentChunk, 0, result, int_array_offset, pageSize);
int_array_offset += pageSize;
}
}
}
return result;
}
use of java.lang.IllegalArgumentException in project robovm by robovm.
the class IvParameterSpecTest method testIvParameterSpec2.
/**
* IvParameterSpec(byte[] iv) constructor testing. Checks that
* NullPointerException is thrown in the case of null input
* array and that input array is copied during initialization.
*/
public void testIvParameterSpec2() {
try {
new IvParameterSpec(null, 1, 1);
fail("Should raise an IllegalArgumentException " + "in the case of null byte array.");
} catch (ArrayIndexOutOfBoundsException e) {
fail("Unexpected ArrayIndexOutOfBoundsException was thrown");
} catch (IllegalArgumentException e) {
} catch (NullPointerException e) {
fail("Unexpected NullPointerException was thrown");
}
try {
new IvParameterSpec(new byte[] { 1, 2, 3 }, 2, 2);
fail("Should raise an IllegalArgumentException " + "if (iv.length - offset < len).");
} catch (ArrayIndexOutOfBoundsException e) {
fail("Unexpected ArrayIndexOutOfBoundsException was thrown");
} catch (IllegalArgumentException e) {
} catch (NullPointerException e) {
fail("Unexpected NullPointerException was thrown");
}
try {
new IvParameterSpec(new byte[] { 1, 2, 3 }, -1, 1);
fail("Should raise an ArrayIndexOutOfBoundsException " + "if offset index bytes outside the iv.");
} catch (ArrayIndexOutOfBoundsException e) {
} catch (IllegalArgumentException e) {
fail("Unexpected IllegalArgumentException was thrown");
} catch (NullPointerException e) {
fail("Unexpected NullPointerException was thrown");
}
/* TODO: DRL fail with java.lang.NegativeArraySizeException
try {
new IvParameterSpec(new byte[] {1, 2, 3}, 1, -2);
fail("Should raise an ArrayIndexOutOfBoundsException "
+ "if len index bytes outside the iv.");
} catch(ArrayIndexOutOfBoundsException e) {
} catch(IllegalArgumentException e) {
fail("Unexpected IllegalArgumentException was thrown");
} catch(NullPointerException e) {
fail("Unexpected NullPointerException was thrown");
}
*/
byte[] iv = new byte[] { 1, 2, 3, 4, 5 };
IvParameterSpec ivps = new IvParameterSpec(iv, 0, iv.length);
iv[0]++;
assertFalse("The change of input array's content should not cause " + "the change of internal array", iv[0] == ivps.getIV()[0]);
//Regression for HARMONY-1089
try {
new IvParameterSpec(new byte[2], 2, -1);
fail("ArrayIndexOutOfBoundsException expected");
} catch (ArrayIndexOutOfBoundsException e) {
//expected
}
}
use of java.lang.IllegalArgumentException in project robovm by robovm.
the class RC2ParameterSpecTest method testRC2ParameterSpec2.
/**
* RC2ParameterSpec(int effectiveKeyBits, byte[] iv, int offset) method
* testing. Tests that IllegalArgumentException is thrown in the case of
* inappropriate constructor parameters and that input iv array is
* copied to protect against subsequent modification.
*/
public void testRC2ParameterSpec2() {
int effectiveKeyBits = 10;
byte[] iv = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
int offset = 2;
try {
new RC2ParameterSpec(effectiveKeyBits, null, offset);
fail("An IllegalArgumentException should be thrown " + "in the case of null iv.");
} catch (IllegalArgumentException e) {
}
try {
new RC2ParameterSpec(effectiveKeyBits, iv, 4);
fail("An IllegalArgumentException should be thrown " + "in the case of short iv.");
} catch (IllegalArgumentException e) {
}
RC2ParameterSpec ps = new RC2ParameterSpec(effectiveKeyBits, iv, offset);
iv[offset]++;
assertFalse("The change of iv specified in the constructor " + "should not cause the change of internal array.", iv[offset] == ps.getIV()[0]);
}
Aggregations