本文整理汇总了Java中com.google.common.io.ByteSink.openStream方法的典型用法代码示例。如果您正苦于以下问题:Java ByteSink.openStream方法的具体用法?Java ByteSink.openStream怎么用?Java ByteSink.openStream使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.io.ByteSink
的用法示例。
在下文中一共展示了ByteSink.openStream方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: runScenario
import com.google.common.io.ByteSink; //导入方法依赖的package包/类
private static void runScenario( final Class<? extends Scenario> scenarioClass ) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException, IOException, InterruptedException, ExecutionException {
final File scenarioOutputFile = new File(
TARGET_DIRECTORY,
scenarioClass.getCanonicalName()
);
final ScenarioRunner scenarioRunner = new ScenarioRunner(
scenarioClass,
new ByteSink() {
@Override
public OutputStream openStream() throws IOException {
final ByteSink fileSink = Files.asByteSink( scenarioOutputFile );
return new MultiplexingOutputStream(
System.out,
fileSink.openStream()
);
}
},
EXTENDED_RUN_PARAMETERS
);
scenarioRunner.run();
}
示例2: compileToJar
import com.google.common.io.ByteSink; //导入方法依赖的package包/类
/**
* Compiles all the templates in the given registry to a jar file written to the given output
* stream.
*
* <p>If errors are encountered, the error reporter will be updated and we will return. The
* contents of any data written to the sink at that point are undefined.
*
* @param registry All the templates to compile
* @param reporter The error reporter
* @param sink The output sink to write the JAR to.
*/
public static void compileToJar(TemplateRegistry registry, ErrorReporter reporter, ByteSink sink)
throws IOException {
ErrorReporter.Checkpoint checkpoint = reporter.checkpoint();
if (reporter.errorsSince(checkpoint)) {
return;
}
CompiledTemplateRegistry compilerRegistry = new CompiledTemplateRegistry(registry);
if (reporter.errorsSince(checkpoint)) {
return;
}
try (final SoyJarFileWriter writer = new SoyJarFileWriter(sink.openStream())) {
compileTemplates(
compilerRegistry,
reporter,
new CompilerListener<Void>() {
@Override
void onCompile(ClassData clazz) throws IOException {
writer.writeEntry(
clazz.type().internalName() + ".class", ByteSource.wrap(clazz.data()));
}
});
}
}
示例3: writeSrcJar
import com.google.common.io.ByteSink; //导入方法依赖的package包/类
/**
* Writes the source files out to a {@code -src.jar}. This places the soy files at the same
* classpath relative location as their generated classes. Ultimately this can be used by
* debuggers for source level debugging.
*
* <p>It is a little weird that the relative locations of the generated classes are not identical
* to the input source files. This is due to the disconnect between java packages and soy
* namespaces. We should consider using the soy namespace directly as a java package in the
* future.
*
* @param registry All the templates in the current compilation unit
* @param files The source files by file path
* @param sink The source to write the jar file
*/
public static void writeSrcJar(
TemplateRegistry registry, ImmutableMap<String, SoyFileSupplier> files, ByteSink sink)
throws IOException {
Set<SoyFileNode> seenFiles = new HashSet<>();
try (SoyJarFileWriter writer = new SoyJarFileWriter(sink.openStream())) {
for (TemplateNode template : registry.getAllTemplates()) {
SoyFileNode file = template.getParent();
if (file.getSoyFileKind() == SoyFileKind.SRC && seenFiles.add(file)) {
String namespace = file.getNamespace();
String fileName = file.getFileName();
writer.writeEntry(
Names.javaFileName(namespace, fileName),
files.get(file.getFilePath()).asCharSource().asByteSource(UTF_8));
}
}
}
}
示例4: saveStream
import com.google.common.io.ByteSink; //导入方法依赖的package包/类
/**
* Save the content of a NBT compound to a stream.
*
* @param source - the NBT compound to save.
* @param stream - the stream.
* @param option - whether or not to compress the output.
* @throws IOException If anything went wrong.
*/
public static void saveStream(NbtCompound source, ByteSink stream, StreamOptions option) throws IOException {
OutputStream output = null;
DataOutputStream data = null;
boolean suppress = true;
try {
output = stream.openStream();
data = new DataOutputStream(option == StreamOptions.GZIP_COMPRESSION ? new GZIPOutputStream(output) : output);
invokeMethod(get().SAVE_COMPOUND, null, source.getHandle(), data);
suppress = false;
} finally {
if (data != null) {
Closeables.close(data, suppress);
} else if (output != null) {
Closeables.close(output, suppress);
}
}
}
示例5: toTmpKeyStoreFile
import com.google.common.io.ByteSink; //导入方法依赖的package包/类
/**
* Creates a new keystore that will contain a single entry with given {@code entryAlias} and {@code entryPassword}
* and stores it to a temporary file. The entry will contain the private key and the certificate.
*/
public File toTmpKeyStoreFile(String entryAlias, String password) throws IOException, GeneralSecurityException {
KeyStore keyStore = toKeyStore(entryAlias, password);
File keyStoreFile = File.createTempFile("key-" + entryAlias, ".keystore", new File("target"));
ByteSink keyStoreSink = Files.asByteSink(keyStoreFile);
OutputStream keyStoreStream = keyStoreSink.openStream();
try {
keyStore.store(keyStoreStream, password.toCharArray());
} finally {
Closeables.close(keyStoreStream, true);
}
return keyStoreFile;
}
示例6: toTmpTrustStoreFile
import com.google.common.io.ByteSink; //导入方法依赖的package包/类
/**
* Creates a new truststore that will contain a single entry with given {@code entryAlias} and stores it
* to a temporary file. The entry will contain the certificate.
*/
public File toTmpTrustStoreFile(String entryAlias, String password) throws IOException, GeneralSecurityException {
KeyStore trustStore = toTrustStore(entryAlias);
File trustStoreFile = File.createTempFile("trust-" + entryAlias, ".truststore", new File("target"));
ByteSink trustStoreSink = Files.asByteSink(trustStoreFile);
OutputStream trustStoreStream = trustStoreSink.openStream();
try {
trustStore.store(trustStoreStream, password.toCharArray());
} finally {
Closeables.close(trustStoreStream, true);
}
return trustStoreFile;
}
示例7: run
import com.google.common.io.ByteSink; //导入方法依赖的package包/类
static void run(ByteSource from, ByteSink to) throws IOException {
try (OutputStream out = to.openStream()) {
run(from, out);
}
}
示例8: duplicateInput
import com.google.common.io.ByteSink; //导入方法依赖的package包/类
static void duplicateInput(ByteSource from, ByteSink to) throws IOException {
try (OutputStream out = to.openStream()) {
ByteSource.concat(from, from).copyTo(out);
}
}