本文整理汇总了Java中com.google.common.io.ByteSink.openBufferedStream方法的典型用法代码示例。如果您正苦于以下问题:Java ByteSink.openBufferedStream方法的具体用法?Java ByteSink.openBufferedStream怎么用?Java ByteSink.openBufferedStream使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.io.ByteSink
的用法示例。
在下文中一共展示了ByteSink.openBufferedStream方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeBinary
import com.google.common.io.ByteSink; //导入方法依赖的package包/类
public static void writeBinary(OffsetIndex offsetIndex, ByteSink sink) throws IOException {
final DataOutputStream out = new DataOutputStream(sink.openBufferedStream());
boolean threw = true;
try {
out.writeInt(offsetIndex.keySet().size());
// use a fixed key order to be diff-friendly.
final Iterable<Symbol> keyOrder =
Ordering.usingToString().immutableSortedCopy(offsetIndex.keySet());
for (final Symbol key : keyOrder) {
out.writeUTF(key.asString());
// get is safe because we are iterating over the mapping's key set
final OffsetRange<ByteOffset> range = offsetIndex.byteOffsetsOf(key).get();
out.writeInt(range.startInclusive().asInt());
out.writeInt(range.endInclusive().asInt());
}
threw = false;
} finally {
Closeables.close(out, threw);
}
}
示例2: stream
import com.google.common.io.ByteSink; //导入方法依赖的package包/类
final void stream(
ByteSource input, ByteSink output, ByteSink error)
throws IOException, MojoExecutionException {
try (InputStream in = input.openBufferedStream()) {
try (OutputStream out = output.openBufferedStream()) {
try (PrintStream pout = new PrintStream(out, true, "UTF-8")) {
try (OutputStream err = error.openBufferedStream()) {
try (PrintStream perr = new PrintStream(err, true, "UTF-8")) {
stream(in, pout, perr);
}
}
}
}
}
}
示例3: writeBinaryIntArray
import com.google.common.io.ByteSink; //导入方法依赖的package包/类
public static void writeBinaryIntArray(final int[] arr,
final ByteSink outSup) throws IOException {
try (OutputStream out = outSup.openBufferedStream()) {
try (DataOutputStream dos = new DataOutputStream(out)) {
dos.writeInt(arr.length);
for (final int x : arr) {
dos.writeInt(x);
}
}
}
}
示例4: serializeTo
import com.google.common.io.ByteSink; //导入方法依赖的package包/类
public void serializeTo(final Object o, final ByteSink out) throws IOException {
final RootObject rootObj = RootObject.forObject(o);
final OutputStream bufStream = out.openBufferedStream();
mapper.writeValue(bufStream, rootObj);
bufStream.close();
}
示例5: writeFstToBinaryFile
import com.google.common.io.ByteSink; //导入方法依赖的package包/类
public static void writeFstToBinaryFile(Fst fst, File file) throws IOException {
ByteSink bs = Files.asByteSink(file);
try (ObjectOutputStream oos = new ObjectOutputStream(new GZIPOutputStream(bs.openBufferedStream()))) {
writeFstToBinaryStream(fst, oos);
}
}
示例6: writeTo
import com.google.common.io.ByteSink; //导入方法依赖的package包/类
public static <T> void writeTo(T model, File outputFile) throws IOException {
ByteSink sink = Files.asByteSink(outputFile);
try (ObjectOutputStream oos = new ObjectOutputStream(sink.openBufferedStream())) {
oos.writeObject(model);
}
}