本文整理汇总了Java中it.unimi.dsi.fastutil.io.FastBufferedOutputStream类的典型用法代码示例。如果您正苦于以下问题:Java FastBufferedOutputStream类的具体用法?Java FastBufferedOutputStream怎么用?Java FastBufferedOutputStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FastBufferedOutputStream类属于it.unimi.dsi.fastutil.io包,在下文中一共展示了FastBufferedOutputStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import it.unimi.dsi.fastutil.io.FastBufferedOutputStream; //导入依赖的package包/类
public void run() {
while (isRunning) {
try {
if (sock == null || !sock.isBound()) {
System.out.println("Creating new server socket...");
sock = new ServerSocket(masterToSlavePort);
}
Socket s = sock.accept();
OutputStream os = new FastBufferedOutputStream(s.getOutputStream());
while(isRunning) {
ServiceMessage m = queue.take();
os.write(m.serializedTransaction);
}
} catch(Exception e) {
System.err.println(e);
}
}
}
示例2: sendToMaster
import it.unimi.dsi.fastutil.io.FastBufferedOutputStream; //导入依赖的package包/类
protected void sendToMaster(Transaction t) throws Exception {
if(sock == null || !sock.isConnected()) {
sock = new Socket(serverHost, serverPort);
//oos = new ObjectOutputStream(sock.getOutputStream());
//o = new Output(new BufferedOutputStream(sock.getOutputStream()));
p = mp.createPacker(new FastBufferedOutputStream(sock.getOutputStream()));
}
p.write(t);
//oos.writeObject(t);
//k.writeObject(o, t);
p.
p.write(t);
}
示例3: SequentialHyperBall
import it.unimi.dsi.fastutil.io.FastBufferedOutputStream; //导入依赖的package包/类
/** Creates a new approximator for the neighbourhood function.
*
* @param g the graph whosee neighbourhood function you want to compute.
* @param log2m the logarithm of the number of registers per counter.
* @param pl a progress logger, or <code>null</code>.
*/
public SequentialHyperBall( final ImmutableGraph g, final int log2m, final ProgressLogger pl, final long seed ) throws IOException {
super( g.numNodes(), g.numNodes(), ensureEnoughRegisters( log2m ), seed );
if ( pl != null ) pl.logger().info( "Precision: " + Util.format( 100 * HyperLogLogCounterArray.relativeStandardDeviation( log2m ) ) + "% (" + m + " registers/counter, " + registerSize + " bits/counter)" );
this.g = g;
this.pl = pl;
numNodes = g.numNodes();
squareNumNodes = (double)numNodes * numNodes;
tempFile = File.createTempFile( SequentialHyperBall.class.getName(), "temp" );
tempFile.deleteOnExit();
dos = new DataOutputStream( new FastBufferedOutputStream( fos = new FileOutputStream( tempFile ) ) );
fbis = new FastBufferedInputStream( new FileInputStream( tempFile ) );
accumulator = new long[ counterLongwords ];
mask = new long[ counterLongwords ];
}
示例4: Bucket
import it.unimi.dsi.fastutil.io.FastBufferedOutputStream; //导入依赖的package包/类
/** 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);
}
示例5: writeRecords
import it.unimi.dsi.fastutil.io.FastBufferedOutputStream; //导入依赖的package包/类
@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;
}
示例6: delegateOutputFormat
import it.unimi.dsi.fastutil.io.FastBufferedOutputStream; //导入依赖的package包/类
@Provides
@Named("delegate")
@Singleton
OutputFormat delegateOutputFormat() throws IOException {
if (options.predictions() == null) {
return new NullOutputFormat();
} else if (options.predictions().equals("/dev/stdout")) {
return new PrintStreamOutputFormat().outputStream(System.out);
}
return new PrintStreamOutputFormat()
.outputStream(new PrintStream(new FastBufferedOutputStream(
Files.newOutputStream(Paths.get(options.predictions())))));
}
示例7: onStart
import it.unimi.dsi.fastutil.io.FastBufferedOutputStream; //导入依赖的package包/类
@Override
public void onStart()
{
System.out.println("starting...");
try {
if (sock == null || !sock.isBound()) {
System.out.println("Creating new server socket...");
sock = new ServerSocket(masterToSlavePort);
}
Socket s = sock.accept();
os = new FastBufferedOutputStream(s.getOutputStream());
mp = new MessagePack();
} catch (Exception e ) {
e.printStackTrace();
}
}
示例8: store
import it.unimi.dsi.fastutil.io.FastBufferedOutputStream; //导入依赖的package包/类
/** Stores an arc-list ASCII graph with a given shift.
*
* @param graph a graph to be stored.
* @param basename the name of the output file.
* @param shift a shift that will be added to each node; note that is the <em>opposite</em> of the shift that will
* have to be used to load the generated file.
*/
public static void store( final ImmutableGraph graph, final CharSequence basename, final int shift ) throws IOException {
final PrintStream ps = new PrintStream( new FastBufferedOutputStream( new FileOutputStream( basename.toString() ) ), false, Charsets.US_ASCII.toString() );
int d, s;
int[] successor;
for ( NodeIterator nodeIterator = graph.nodeIterator(); nodeIterator.hasNext(); ) {
s = nodeIterator.nextInt();
d = nodeIterator.outdegree();
successor = nodeIterator.successorArray();
for( int i = 0; i < d; i++ ) ps.println( ( s + shift ) + "\t" + ( successor[ i ] + shift ) );
}
ps.close();
}
示例9: store
import it.unimi.dsi.fastutil.io.FastBufferedOutputStream; //导入依赖的package包/类
public static void store( ImmutableGraph graph, final int shift, CharSequence basename ) throws IOException {
final PrintStream ps = new PrintStream( new FastBufferedOutputStream( new FileOutputStream( basename + ASCII_GRAPH_EXTENSION ) ), false, Charsets.US_ASCII.toString() );
int n = graph.numNodes();
LazyIntIterator successors;
ps.println( n );
for ( NodeIterator nodeIterator = graph.nodeIterator(); nodeIterator.hasNext(); ) {
nodeIterator.nextInt();
int d = nodeIterator.outdegree();
successors = nodeIterator.successors();
while ( d-- != 0 ) ps.print( ( successors.nextInt() + shift ) + " " );
ps.println();
}
ps.close();
}
示例10: createFile
import it.unimi.dsi.fastutil.io.FastBufferedOutputStream; //导入依赖的package包/类
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();
}
示例11: ensureDiskStream
import it.unimi.dsi.fastutil.io.FastBufferedOutputStream; //导入依赖的package包/类
protected OutputStream ensureDiskStream() throws FileNotFoundException {
if (this.diskStream == null) {
FileOutputStream fis = new FileOutputStream(this.backingFilename);
this.diskStream = new FastBufferedOutputStream(fis);
}
return this.diskStream;
}
示例12: close
import it.unimi.dsi.fastutil.io.FastBufferedOutputStream; //导入依赖的package包/类
@Override
public void close() throws IOException {
final ObjectOutputStream oos = new ObjectOutputStream(new FastBufferedOutputStream(new FileOutputStream(new File(directory, "metadata"))));
byteArrayDiskQueues.close();
writeMetadata(oos);
}
示例13: prepareToAppend
import it.unimi.dsi.fastutil.io.FastBufferedOutputStream; //导入依赖的package包/类
@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))));
}
示例14: main
import it.unimi.dsi.fastutil.io.FastBufferedOutputStream; //导入依赖的package包/类
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();
}
示例15: main
import it.unimi.dsi.fastutil.io.FastBufferedOutputStream; //导入依赖的package包/类
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();
}