当前位置: 首页>>代码示例>>Java>>正文


Java ByteSink.openStream方法代码示例

本文整理汇总了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();
	}
 
开发者ID:cheremin,项目名称:scalarization,代码行数:25,代码来源:ForkingMain.java

示例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()));
          }
        });
  }
}
 
开发者ID:google,项目名称:closure-templates,代码行数:35,代码来源:BytecodeCompiler.java

示例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));
      }
    }
  }
}
 
开发者ID:google,项目名称:closure-templates,代码行数:32,代码来源:BytecodeCompiler.java

示例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);
        }
    }
}
 
开发者ID:IntellectualSites,项目名称:PlotSquared,代码行数:29,代码来源:NbtFactory.java

示例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;
}
 
开发者ID:wildfly-extras,项目名称:creaper,代码行数:19,代码来源:KeyPairAndCertificate.java

示例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;
}
 
开发者ID:wildfly-extras,项目名称:creaper,代码行数:19,代码来源:KeyPairAndCertificate.java

示例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);
  }
}
 
开发者ID:scottTomaszewski,项目名称:tem,代码行数:6,代码来源:Processor.java

示例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);
  }
}
 
开发者ID:scottTomaszewski,项目名称:tem,代码行数:6,代码来源:Processor.java


注:本文中的com.google.common.io.ByteSink.openStream方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。