org.archive.uid.UUIDGenerator Java Examples

The following examples show how to use org.archive.uid.UUIDGenerator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WARCWriterTest.java    From webarchive-commons with Apache License 2.0 6 votes vote down vote up
protected void writeBasicRecords(final WARCWriter writer)
throws IOException {
 WARCRecordInfo recordInfo = new WARCRecordInfo();
 recordInfo.setType(WARCRecordType.metadata);
 recordInfo.setUrl("http://www.archive.org/");
 recordInfo.setCreate14DigitDate(ArchiveUtils.get14DigitDate());
 recordInfo.setMimetype("no/type");
 recordInfo.setEnforceLength(true);
 
	ANVLRecord headerFields = new ANVLRecord();
	headerFields.addLabelValue("x", "y");
	headerFields.addLabelValue("a", "b");
	recordInfo.setExtraHeaders(headerFields);
	
	URI rid = (new UUIDGenerator()).getQualifiedRecordID(TYPE, WARCRecordType.metadata.toString());
	recordInfo.setRecordId(rid);
	
	final String content = "Any old content.";
	for (int i = 0; i < 10; i++) {
		String body = i + ". " + content;
		byte [] bodyBytes = body.getBytes(UTF8Bytes.UTF8);
		recordInfo.setContentStream(new ByteArrayInputStream(bodyBytes));
		recordInfo.setContentLength((long)bodyBytes.length);
        writer.writeRecord(recordInfo);
	}
}
 
Example #2
Source File: WARCWriterTest.java    From webarchive-commons with Apache License 2.0 6 votes vote down vote up
/**
 * Write an arc file for other tests to use.
 * @param arcdir Directory to write to.
 * @param compress True if file should be compressed.
 * @return ARC written.
 * @throws IOException 
 */
public static File createWARCFile(File arcdir, boolean compress)
throws IOException {
    File [] files = {arcdir};
    WARCWriter writer =
        new WARCWriter(SERIAL_NO, 
                new WARCWriterPoolSettingsData(
                        "", 
                        "test", 
                        DEFAULT_MAX_WARC_FILE_SIZE, 
                        compress, 
                        Arrays.asList(files), 
                        null, 
                        new UUIDGenerator()));
    String content = getContent();
    writeRecord(writer, SOME_URL, "text/html", content.length(),
        getBaos(content));
    writer.close();
    return writer.getFile();
}