本文整理汇总了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);
}
}
示例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));
}
示例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());
}
示例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());
}
示例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());
}
示例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);
}
}
示例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);
}
}
示例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()));
}
示例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));
}
示例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);
}
示例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);
}
}
示例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);
}
示例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));
}
示例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();
}
}
示例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();
}
}