it.unimi.dsi.fastutil.io.FastBufferedOutputStream Java Examples

The following examples show how to use it.unimi.dsi.fastutil.io.FastBufferedOutputStream. 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: MercatorSieve.java    From BUbiNG with Apache License 2.0 5 votes vote down vote up
/** Creates a bucket.
 *
 * @param bucketSize the size (in items) of the bucket.
 * @param bufferSize the size (in bytes) of the buffer to be used for the output stream.
 * @param sieveDir the directory where the auxiliary file should be opened.
 * @param serializer the serializer to be used for storing the keys.
 * @throws IOException
 */
public Bucket(final int bucketSize, final int bufferSize, final File sieveDir, final ByteSerializerDeserializer<K> serializer) throws IOException {
	this.serializer = serializer;
	this.ioBuffer = new byte[bufferSize];
	// buffer
	items = 0;
	size = bucketSize;
	buffer = new long[bucketSize];
	// aux
	auxFile = new File(sieveDir, "aux");
	aux = new FastBufferedOutputStream(new FileOutputStream(auxFile), ioBuffer);
}
 
Example #2
Source File: RandomReadWritesTest.java    From BUbiNG with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("resource")
public static int[] writeRecords(final String path, final int numRecords, final WarcRecord[] randomRecords, final int parallel) throws IOException, InterruptedException {
	final ProgressLogger pl = new ProgressLogger(LOGGER, "records");
	if (parallel <= 1) pl.expectedUpdates = numRecords;
	final ProgressLogger plb = new ProgressLogger(LOGGER, "KB");
	final CountingOutputStream cos = new CountingOutputStream(new FastBufferedOutputStream(new FileOutputStream (path)));
	final WarcWriter ww;
	if (parallel == 0) {
		ww = new UncompressedWarcWriter(cos);
		pl.start("Writing records…");
	} else if (parallel == 1) {
		ww = new CompressedWarcWriter(cos);
		pl.start("Writing records (compressed)…");
	} else {
		ww = null;
		pl.start("SHOULD NOT HAPPEN");
		throw new IllegalStateException();
	}
	plb.start();
	long written = 0;
	final int[] position = new int[numRecords];
	for (int i = 0; i < numRecords; i++) {
		final int pos = RandomTestMocks.RNG.nextInt(randomRecords.length);
		position[i] = pos;
		ww.write(randomRecords[pos]);
		if (parallel <= 0) {
			pl.lightUpdate();
			plb.update((cos.getCount() - written) / 1024);
		}
		written = cos.getCount();
	}
	ww.close();
	pl.done(numRecords);
	plb.done(cos.getCount());
	return position;
}
 
Example #3
Source File: OfflineIterable.java    From database with GNU General Public License v2.0 5 votes vote down vote up
/** Creates an offline iterable with given serializer.
 * 
 * @param serializer the serializer to be used.
 * @param store an object that is (re)used by the iterator(s) iterating on this iterable.
 * @throws IOException 
 */
public OfflineIterable( final Serializer<? super T, U> serializer, final U store ) throws IOException {
	this.serializer = serializer;
	this.store = store;
	file = File.createTempFile( OfflineIterable.class.getSimpleName(), "elmts" );
	file.deleteOnExit();
	dos = new DataOutputStream( new FastBufferedOutputStream( new FileOutputStream( file ) ) );
}
 
Example #4
Source File: WriterPoolMember.java    From webarchive-commons with Apache License 2.0 5 votes vote down vote up
protected String createFile(final File file) throws IOException {
	close();
    this.f = file;
    FileOutputStream fos = new FileOutputStream(this.f);
    this.countOut = new MiserOutputStream(new FastBufferedOutputStream(fos),settings.getFrequentFlushes());
    this.out = this.countOut; 
    logger.fine("Opened " + this.f.getAbsolutePath());
    return this.f.getName();
}
 
Example #5
Source File: RecordingOutputStream.java    From webarchive-commons with Apache License 2.0 5 votes vote down vote up
protected OutputStream ensureDiskStream() throws FileNotFoundException {
    if (this.diskStream == null) {
        FileOutputStream fis = new FileOutputStream(this.backingFilename);
        this.diskStream = new FastBufferedOutputStream(fis);
    }
    return this.diskStream;
}
 
Example #6
Source File: WorkbenchVirtualizer.java    From BUbiNG with Apache License 2.0 4 votes vote down vote up
@Override
public void close() throws IOException {
	final ObjectOutputStream oos = new ObjectOutputStream(new FastBufferedOutputStream(new FileOutputStream(new File(directory, "metadata"))));
	byteArrayDiskQueues.close();
	writeMetadata(oos);
}
 
Example #7
Source File: AbstractSieve.java    From BUbiNG with Apache License 2.0 4 votes vote down vote up
@Override
public synchronized void prepareToAppend() throws IOException {
	if (closed) throw new IllegalStateException();
	appendSize = 0;
	output = new DataOutputStream(new FastBufferedOutputStream(new FileOutputStream(new File(baseName + outputIndex))));
}
 
Example #8
Source File: WarcCompressor.java    From BUbiNG with Apache License 2.0 4 votes vote down vote up
public static void main(String arg[]) throws IOException, InterruptedException, JSAPException {

	SimpleJSAP jsap = new SimpleJSAP(WarcCompressor.class.getName(),
		"Given a store uncompressed, write a compressed store.",
		new Parameter[] { new FlaggedOption("output", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, 'o', "output", "The output filename  (- for stdout)."),
		new UnflaggedOption("store", JSAP.STRING_PARSER, JSAP.NOT_REQUIRED, "The name of the store (if omitted, stdin)."),
	});

	JSAPResult jsapResult = jsap.parse(arg);
	if (jsap.messagePrinted()) return;

	final InputStream in = jsapResult.userSpecified("store") ? new FastBufferedInputStream(new FileInputStream(jsapResult.getString("store"))) : System.in;

	final WarcReader reader = new UncompressedWarcReader(in);
	final ProgressLogger pl = new ProgressLogger(LOGGER, 1, TimeUnit.MINUTES, "records");
	final String output = jsapResult.getString("output");

	PrintStream out = "-".equals(output) ? System.out : new PrintStream(new FastBufferedOutputStream(new FileOutputStream(output)), false, "UTF-8");
	final WarcWriter writer = new CompressedWarcWriter(out);

	pl.itemsName = "records";
	pl.displayFreeMemory = true;
	pl.displayLocalSpeed = true;
	pl.start("Scanning...");

	for (long storePosition = 0;; storePosition++) {
	    LOGGER.trace("STOREPOSITION " + storePosition);
	    WarcRecord record = null;
	    try {
		record = reader.read();
	    } catch (Exception e) {
		LOGGER.error("Exception while reading record " + storePosition + " ");
		LOGGER.error(e.getMessage());
		e.printStackTrace();
		continue;
	    }
	    if (record == null)
		break;
	    writer.write(record);
	    pl.lightUpdate();
	}
	pl.done();
	writer.close();
    }
 
Example #9
Source File: ParallelFilteredProcessorRunner.java    From BUbiNG with Apache License 2.0 4 votes vote down vote up
public static void main(final String[] arg) throws Exception {
	final SimpleJSAP jsap = new SimpleJSAP(ParallelFilteredProcessorRunner.class.getName(), "Processes a store.",
			new Parameter[] {
			new FlaggedOption("filter", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED, 'f', "filter", "A WarcRecord filter that recods must pass in order to be processed."),
	 		new FlaggedOption("processor", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, 'p', "processor", "A processor to be applied to data.").setAllowMultipleDeclarations(true),
		 	new FlaggedOption("writer", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, 'w', "writer", "A writer to be applied to the results.").setAllowMultipleDeclarations(true),
			new FlaggedOption("output", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED, 'o', "output", "The output filename  (- for stdout).").setAllowMultipleDeclarations(true),
			new FlaggedOption("threads", JSAP.INTSIZE_PARSER, Integer.toString(Runtime.getRuntime().availableProcessors()), JSAP.NOT_REQUIRED, 'T', "threads", "The number of threads to be used."),
			new Switch("sequential", 'S', "sequential"),
			new UnflaggedOption("store", JSAP.STRING_PARSER, JSAP.NOT_REQUIRED, "The name of the store (if omitted, stdin)."),
	});

	final JSAPResult jsapResult = jsap.parse(arg);
	if (jsap.messagePrinted()) return;

	final String filterSpec = jsapResult.getString("filter");
	final Filter<WarcRecord> filter;
	if (filterSpec != null) {
		final FilterParser<WarcRecord> parser = new FilterParser<>(WarcRecord.class);
		filter = parser.parse(filterSpec);
	} else
		filter = null;
	final InputStream in = jsapResult.userSpecified("store") ? new FastBufferedInputStream(new FileInputStream(jsapResult.getString("store"))) : System.in;
	final ParallelFilteredProcessorRunner parallelFilteredProcessorRunner = new ParallelFilteredProcessorRunner(in, filter);

	final String[] processor =  jsapResult.getStringArray("processor");
	final String[] writer =  jsapResult.getStringArray("writer");
	final String[] output =  jsapResult.getStringArray("output");
	if (processor.length != writer.length) throw new IllegalArgumentException("You must specify the same number or processors and writers");
	if (output.length != writer.length) throw new IllegalArgumentException("You must specify the same number or output specifications and writers");

	final String[] packages = new String[] { ParallelFilteredProcessorRunner.class.getPackage().getName() };
	final PrintStream[] ops = new PrintStream[processor.length];
	for (int i = 0; i < processor.length; i++) {
		ops[i] = "-".equals(output[i]) ? System.out : new PrintStream(new FastBufferedOutputStream(new FileOutputStream(output[i])), false, "UTF-8");
		// TODO: these casts to SOMETHING<Object> are necessary for compilation under Eclipse. Check in the future.
		parallelFilteredProcessorRunner.add((Processor<Object>)ObjectParser.fromSpec(processor[i], Processor.class, packages, new String[] { "getInstance" }),
				(Writer<Object>)ObjectParser.fromSpec(writer[i], Writer.class,  packages, new String[] { "getInstance" }),
				ops[i]);
	}

	if (jsapResult.userSpecified("sequential")) parallelFilteredProcessorRunner.runSequentially();
	else parallelFilteredProcessorRunner.run(jsapResult.getInt("threads"));

	for (int i = 0; i < processor.length; i++) ops[i].close();

}