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


Java OutputSupplier类代码示例

本文整理汇总了Java中com.google.common.io.OutputSupplier的典型用法代码示例。如果您正苦于以下问题:Java OutputSupplier类的具体用法?Java OutputSupplier怎么用?Java OutputSupplier使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


OutputSupplier类属于com.google.common.io包,在下文中一共展示了OutputSupplier类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: saveStream

import com.google.common.io.OutputSupplier; //导入依赖的package包/类
/**
 * Save the content of a NBT compound to a stream.
 * <p>
 * Use {@link Files#newOutputStreamSupplier(java.io.File)} to provide a stream supplier to a file.
 * @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, OutputSupplier<? extends OutputStream> stream, StreamOptions option) throws IOException {
    OutputStream output = null;
    DataOutputStream data = null;
    boolean suppress = true;
    
    try {
        output = stream.getOutput();
        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:Mayomi,项目名称:PlotSquared-Chinese,代码行数:31,代码来源:NbtFactory.java

示例2: saveJvmOptions

import com.google.common.io.OutputSupplier; //导入依赖的package包/类
private void saveJvmOptions(Map<String, LocalFile> localFiles) throws IOException {
  if ((extraOptions == null || extraOptions.isEmpty()) &&
    JvmOptions.DebugOptions.NO_DEBUG.equals(debugOptions)) {
    // If no vm options, no need to localize the file.
    return;
  }
  LOG.debug("Create and copy {}", Constants.Files.JVM_OPTIONS);
  final Location location = createTempLocation(Constants.Files.JVM_OPTIONS);
  JvmOptionsCodec.encode(new JvmOptions(extraOptions, debugOptions), new OutputSupplier<Writer>() {
    @Override
    public Writer getOutput() throws IOException {
      return new OutputStreamWriter(location.getOutputStream(), Charsets.UTF_8);
    }
  });
  LOG.debug("Done {}", Constants.Files.JVM_OPTIONS);

  localFiles.put(Constants.Files.JVM_OPTIONS, createLocalFile(Constants.Files.JVM_OPTIONS, location));
}
 
开发者ID:chtyim,项目名称:incubator-twill,代码行数:19,代码来源:YarnTwillPreparer.java

示例3: testNoNulls

import com.google.common.io.OutputSupplier; //导入依赖的package包/类
@Test
public void testNoNulls() throws Exception {
  JvmOptions options = new JvmOptions("-version",
                                      new JvmOptions.DebugOptions(true, false, ImmutableSet.of("one", "two")));
  final StringWriter writer = new StringWriter();
  JvmOptionsCodec.encode(options, new OutputSupplier<Writer>() {
    @Override
    public Writer getOutput() throws IOException {
      return writer;
    }
  });
  JvmOptions options1 = JvmOptionsCodec.decode(new InputSupplier<Reader>() {
    @Override
    public Reader getInput() throws IOException {
      return new StringReader(writer.toString());
    }
  });
  Assert.assertEquals(options.getExtraOptions(), options1.getExtraOptions());
  Assert.assertEquals(options.getDebugOptions().doDebug(), options1.getDebugOptions().doDebug());
  Assert.assertEquals(options.getDebugOptions().doSuspend(), options1.getDebugOptions().doSuspend());
  Assert.assertEquals(options.getDebugOptions().getRunnables(), options1.getDebugOptions().getRunnables());
}
 
开发者ID:chtyim,项目名称:incubator-twill,代码行数:23,代码来源:JvmOptionsCodecTest.java

示例4: testSomeNulls

import com.google.common.io.OutputSupplier; //导入依赖的package包/类
@Test
public void testSomeNulls() throws Exception {
  JvmOptions options = new JvmOptions(null, new JvmOptions.DebugOptions(false, false, null));
  final StringWriter writer = new StringWriter();
  JvmOptionsCodec.encode(options, new OutputSupplier<Writer>() {
    @Override
    public Writer getOutput() throws IOException {
      return writer;
    }
  });
  JvmOptions options1 = JvmOptionsCodec.decode(new InputSupplier<Reader>() {
    @Override
    public Reader getInput() throws IOException {
      return new StringReader(writer.toString());
    }
  });
  Assert.assertEquals(options.getExtraOptions(), options1.getExtraOptions());
  Assert.assertEquals(options.getDebugOptions().doDebug(), options1.getDebugOptions().doDebug());
  Assert.assertEquals(options.getDebugOptions().doSuspend(), options1.getDebugOptions().doSuspend());
  Assert.assertEquals(options.getDebugOptions().getRunnables(), options1.getDebugOptions().getRunnables());
}
 
开发者ID:chtyim,项目名称:incubator-twill,代码行数:22,代码来源:JvmOptionsCodecTest.java

示例5: testNoRunnables

import com.google.common.io.OutputSupplier; //导入依赖的package包/类
@Test
public void testNoRunnables() throws Exception {
  List<String> noRunnables = Collections.emptyList();
  JvmOptions options = new JvmOptions(null, new JvmOptions.DebugOptions(true, false, noRunnables));
  final StringWriter writer = new StringWriter();
  JvmOptionsCodec.encode(options, new OutputSupplier<Writer>() {
    @Override
    public Writer getOutput() throws IOException {
      return writer;
    }
  });
  JvmOptions options1 = JvmOptionsCodec.decode(new InputSupplier<Reader>() {
    @Override
    public Reader getInput() throws IOException {
      return new StringReader(writer.toString());
    }
  });
  Assert.assertEquals(options.getExtraOptions(), options1.getExtraOptions());
  Assert.assertEquals(options.getDebugOptions().doDebug(), options1.getDebugOptions().doDebug());
  Assert.assertEquals(options.getDebugOptions().doSuspend(), options1.getDebugOptions().doSuspend());
  Assert.assertEquals(options.getDebugOptions().getRunnables(), options1.getDebugOptions().getRunnables());
}
 
开发者ID:chtyim,项目名称:incubator-twill,代码行数:23,代码来源:JvmOptionsCodecTest.java

示例6: saveStream

import com.google.common.io.OutputSupplier; //导入依赖的package包/类
/**
 * Save the content of a NBT compound to a stream.
 * <p>
 * Use {@link Files#newOutputStreamSupplier(java.io.File)} to provide a stream supplier to a file.
 * @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, OutputSupplier<? extends OutputStream> stream, StreamOptions option) throws IOException {
    OutputStream output = null;
    DataOutputStream data = null;
    boolean suppress = true;

    try {
        output = stream.getOutput();
        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:Kingdoms-of-Arden-Development,项目名称:Crafty,代码行数:31,代码来源:NbtFactory.java

示例7: saveStream

import com.google.common.io.OutputSupplier; //导入依赖的package包/类
/**
 * Save the content of a NBT compound to a stream.
 * <p>
 * Use {@link Files#newOutputStreamSupplier(java.io.File)} to provide a stream supplier to a file.
 *
 * @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, OutputSupplier<? extends OutputStream> stream, StreamOptions option) throws IOException {
	OutputStream output = null;
	DataOutputStream data = null;
	boolean suppress = true;

	try {
		output = stream.getOutput();
		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:KingFaris10,项目名称:KingKits,代码行数:32,代码来源:NbtFactory.java

示例8: createArchive

import com.google.common.io.OutputSupplier; //导入依赖的package包/类
private void createArchive(URI baseDir) throws IOException {
	File directory = new File(java.net.URI.create(baseDir.toString()));
	File lib = new File(directory, "lib");
	assertTrue(lib.mkdir());
	File nfar = new File(lib, host.archiveProjectId + ".nfar");
	final ZipOutputStream zipOutputStream = new ZipOutputStream(new FileOutputStream(nfar));
	zipOutputStream.putNextEntry(new ZipEntry("src/A.js"));
	zipOutputStream.putNextEntry(new ZipEntry("src/B.js"));
	zipOutputStream.putNextEntry(new ZipEntry("src/sub/B.js"));
	zipOutputStream.putNextEntry(new ZipEntry("src/sub/C.js"));
	zipOutputStream.putNextEntry(new ZipEntry("src/sub/leaf/D.js"));

	zipOutputStream.putNextEntry(new ZipEntry(IN4JSProject.N4MF_MANIFEST));
	// this will close the stream
	CharStreams.write("ProjectId: " + host.archiveProjectId + "\n" +
			"ProjectType: library\n" +
			"ProjectVersion: 0.0.1-SNAPSHOT\n" +
			"VendorId: org.eclipse.n4js\n" +
			"VendorName: \"Eclipse N4JS Project\"\n" +
			"Output: \"src-gen\"\n" +
			"Sources {\n" +
			"	source {" +
			"		\"src\"\n" +
			"	}\n" +
			"}",
			CharStreams.newWriterSupplier(new OutputSupplier<ZipOutputStream>() {
				@Override
				public ZipOutputStream getOutput() throws IOException {
					return zipOutputStream;
				}
			}, Charsets.UTF_8));
	host.setArchiveFileURI(URI.createURI(nfar.toURI().toString()));
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:34,代码来源:FileBasedProjectModelSetup.java

示例9: createArchive

import com.google.common.io.OutputSupplier; //导入依赖的package包/类
private void createArchive(String projectName) throws CoreException, IOException {
	IProject project = workspace.getProject(projectName);
	IFolder libFolder = project.getFolder(LIB_FOLDER_NAME);
	libFolder.create(false, true, null);

	IFile archiveFile = libFolder.getFile(host.archiveProjectId + ".nfar");
	ByteArrayOutputStream byteArrayOutputSteam = new ByteArrayOutputStream();
	final ZipOutputStream zipOutputStream = new ZipOutputStream(byteArrayOutputSteam);
	zipOutputStream.putNextEntry(new ZipEntry("src/A.js"));
	zipOutputStream.putNextEntry(new ZipEntry("src/B.js"));
	zipOutputStream.putNextEntry(new ZipEntry("src/sub/B.js"));
	zipOutputStream.putNextEntry(new ZipEntry("src/sub/C.js"));
	zipOutputStream.putNextEntry(new ZipEntry("src/sub/leaf/D.js"));

	zipOutputStream.putNextEntry(new ZipEntry(IN4JSProject.N4MF_MANIFEST));
	// this will close the stream
	CharStreams.write("ProjectId: " + host.archiveProjectId + "\n" +
			"ProjectType: library\n" +
			"ProjectVersion: 0.0.1-SNAPSHOT\n" +
			"VendorId: org.eclipse.n4js\n" +
			"VendorName: \"Eclipse N4JS Project\"\n" +
			"Libraries { \"" + LIB_FOLDER_NAME + "\"\n }\n" +
			"Output: \"src-gen\"" +
			"Sources {\n" +
			"	source { " +
			"		\"src\"\n" +
			"	}\n" +
			"}\n", CharStreams.newWriterSupplier(new OutputSupplier<ZipOutputStream>() {
				@Override
				public ZipOutputStream getOutput() throws IOException {
					return zipOutputStream;
				}
			}, Charsets.UTF_8));

	archiveFile.create(new ByteArrayInputStream(byteArrayOutputSteam.toByteArray()), false, null);

	host.setArchiveFileURI(URI.createPlatformResourceURI(archiveFile.getFullPath().toString(), true));
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:39,代码来源:EclipseBasedProjectModelSetup.java

示例10: saveArguments

import com.google.common.io.OutputSupplier; //导入依赖的package包/类
private void saveArguments(Arguments arguments, final Path targetPath) throws IOException {
  LOG.debug("Creating {}", targetPath);
  ArgumentsCodec.encode(arguments, new OutputSupplier<Writer>() {
    @Override
    public Writer getOutput() throws IOException {
      return Files.newBufferedWriter(targetPath, StandardCharsets.UTF_8);
    }
  });
  LOG.debug("Done {}", targetPath);
}
 
开发者ID:apache,项目名称:twill,代码行数:11,代码来源:YarnTwillPreparer.java

示例11: serialize

import com.google.common.io.OutputSupplier; //导入依赖的package包/类
public static void serialize(final Persister persister, final Object object, final OutputSupplier<? extends OutputStream> outputSupplier) throws IOException {
    final OutputStream output = outputSupplier.getOutput();
    boolean threw = true;
    try {
        persister.serialize(object, output);
        threw = false;
    } finally {
        Closeables.close(output, threw);
    }
}
 
开发者ID:asoem,项目名称:greyfish,代码行数:11,代码来源:Persisters.java

示例12: doFileExtract

import com.google.common.io.OutputSupplier; //导入依赖的package包/类
private void doFileExtract(File path) throws IOException
{
    InputStream inputStream = getClass().getResourceAsStream("/"+getContainedFile());
    OutputSupplier<FileOutputStream> outputSupplier = Files.newOutputStreamSupplier(path);
    System.out.println("doFileExtract path = " + path.getAbsolutePath() + ", inputStream = " + inputStream + ", outputSupplier = " + outputSupplier);
    ByteStreams.copy(inputStream, outputSupplier);
}
 
开发者ID:alexandrage,项目名称:CauldronGit,代码行数:8,代码来源:VersionInfo.java

示例13: saveArguments

import com.google.common.io.OutputSupplier; //导入依赖的package包/类
private void saveArguments(Arguments arguments, Map<String, LocalFile> localFiles) throws IOException {
  LOG.debug("Create and copy {}", Constants.Files.ARGUMENTS);
  final Location location = createTempLocation(Constants.Files.ARGUMENTS);
  ArgumentsCodec.encode(arguments, new OutputSupplier<Writer>() {
    @Override
    public Writer getOutput() throws IOException {
      return new OutputStreamWriter(location.getOutputStream(), Charsets.UTF_8);
    }
  });
  LOG.debug("Done {}", Constants.Files.ARGUMENTS);

  localFiles.put(Constants.Files.ARGUMENTS, createLocalFile(Constants.Files.ARGUMENTS, location));
}
 
开发者ID:chtyim,项目名称:incubator-twill,代码行数:14,代码来源:YarnTwillPreparer.java

示例14: encode

import com.google.common.io.OutputSupplier; //导入依赖的package包/类
public static void encode(JvmOptions jvmOptions, OutputSupplier<? extends Writer> writerSupplier) throws IOException {
  Writer writer = writerSupplier.getOutput();
  try {
    GSON.toJson(jvmOptions, writer);
  } finally {
    writer.close();
  }
}
 
开发者ID:chtyim,项目名称:incubator-twill,代码行数:9,代码来源:JvmOptionsCodec.java

示例15: encode

import com.google.common.io.OutputSupplier; //导入依赖的package包/类
public static void encode(Arguments arguments, OutputSupplier<? extends Writer> writerSupplier) throws IOException {
  Writer writer = writerSupplier.getOutput();
  try {
    GSON.toJson(arguments, writer);
  } finally {
    writer.close();
  }
}
 
开发者ID:chtyim,项目名称:incubator-twill,代码行数:9,代码来源:ArgumentsCodec.java


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