本文整理匯總了Java中java.nio.file.Files.newOutputStream方法的典型用法代碼示例。如果您正苦於以下問題:Java Files.newOutputStream方法的具體用法?Java Files.newOutputStream怎麽用?Java Files.newOutputStream使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.nio.file.Files
的用法示例。
在下文中一共展示了Files.newOutputStream方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: writeToZip
import java.nio.file.Files; //導入方法依賴的package包/類
/**
* Write the dex program resources to @code{archive} and the proguard resource as its sibling.
*/
public void writeToZip(Path archive, OutputMode outputMode) throws IOException {
OpenOption[] options =
new OpenOption[] {StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING};
try (Closer closer = Closer.create()) {
try (ZipOutputStream out = new ZipOutputStream(Files.newOutputStream(archive, options))) {
List<Resource> dexProgramSources = getDexProgramResources();
for (int i = 0; i < dexProgramSources.size(); i++) {
ZipEntry zipEntry = new ZipEntry(outputMode.getOutputPath(dexProgramSources.get(i), i));
byte[] bytes =
ByteStreams.toByteArray(closer.register(dexProgramSources.get(i).getStream()));
zipEntry.setSize(bytes.length);
out.putNextEntry(zipEntry);
out.write(bytes);
out.closeEntry();
}
}
}
}
示例2: exportModulo
import java.nio.file.Files; //導入方法依賴的package包/類
public void exportModulo(Modulo mod)throws IOException, CodeException{//attenzione:non esportare funzioni shadow
Path na=Paths.get(mod.nome+".in");
try(ObjectOutputStream out=new ObjectOutputStream(new BufferedOutputStream
(Files.newOutputStream(na, StandardOpenOption.WRITE, StandardOpenOption.CREATE,
StandardOpenOption.TRUNCATE_EXISTING)))){
//out.writeUTF(mod.nome);non interessa il nome
out.writeInt(mod.deps.length);
for(String i:mod.deps)
out.writeUTF(i);
for(Boolean b:mod.publ)
out.writeBoolean(b);
out.writeInt(mod.type.length);
for(TypeDef td:mod.type){
exportType(td, out);
}
out.writeInt(mod.ca.length);
for(Callable c:mod.ca){
exportCall(c, out);
}
}
writeTemplates(mod);
}
示例3: write
import java.nio.file.Files; //導入方法依賴的package包/類
private static void write(Contingency object, Path jsonFile) {
Objects.requireNonNull(object);
Objects.requireNonNull(jsonFile);
try (OutputStream os = Files.newOutputStream(jsonFile)) {
ObjectMapper mapper = new ObjectMapper();
SimpleModule module = new SimpleModule();
module.addSerializer(ContingencyElement.class, new ContingencyElementSerializer());
mapper.registerModule(module);
ObjectWriter writer = mapper.writerWithDefaultPrettyPrinter();
writer.writeValue(os, object);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
示例4: createSourceZip
import java.nio.file.Files; //導入方法依賴的package包/類
/**
* Create a zip file containing the contents of the test.src directory.
*
* @return a path for the zip file.
* @throws IOException if there is a problem creating the file
*/
private Path createSourceZip() throws IOException {
Path testSrc = Paths.get(System.getProperty("test.src"));
Path testZip = Paths.get("test.zip");
try (OutputStream os = Files.newOutputStream(testZip)) {
try (ZipOutputStream zos = new ZipOutputStream(os)) {
Files.list(testSrc)
.filter(p -> p.getFileName().toString().endsWith(".java"))
.forEach(p -> {
try {
zos.putNextEntry(new ZipEntry(p.getFileName().toString()));
zos.write(Files.readAllBytes(p));
zos.closeEntry();
} catch (IOException ex) {
throw new UncheckedIOException(ex);
}
});
}
}
return testZip;
}
示例5: saveAsConfig
import java.nio.file.Files; //導入方法依賴的package包/類
public boolean saveAsConfig(Path path)
{
try(OutputStreamWriter outputStreamWriter = new OutputStreamWriter(Files.newOutputStream(path), "UTF-8"))
{
GSON.toJson(dataCatcher, outputStreamWriter);
return true;
} catch (IOException e)
{
e.printStackTrace();
}
return false;
}
示例6: write
import java.nio.file.Files; //導入方法依賴的package包/類
public static void write(LoadFlowResult result, Path jsonFile) {
Objects.requireNonNull(result);
Objects.requireNonNull(jsonFile);
try (OutputStream os = Files.newOutputStream(jsonFile)) {
ObjectMapper objectMapper = new ObjectMapper();
SimpleModule module = new SimpleModule();
module.addSerializer(LoadFlowResult.class, new LoadFlowResultSerializer());
objectMapper.registerModule(module);
ObjectWriter writer = objectMapper.writerWithDefaultPrettyPrinter();
writer.writeValue(os, result);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
示例7: doSave
import java.nio.file.Files; //導入方法依賴的package包/類
@Override
@BackgroundThread
public void doSave(@NotNull final Path toStore) throws IOException {
super.doSave(toStore);
final CodeArea codeArea = getCodeArea();
final String newContent = codeArea.getText();
try (final PrintWriter out = new PrintWriter(Files.newOutputStream(toStore))) {
out.print(newContent);
}
}
示例8: testClientWithMutualAuthentication
import java.nio.file.Files; //導入方法依賴的package包/類
@Test
public void testClientWithMutualAuthentication() throws Exception {
Path tempFile = Files.createTempFile("keystore", ".jks");
try {
// ARRANGE
final String keystorePassword = "password";
connector = ImmutableConnector.builder().from(connector)
.keystorePath(tempFile.toString())
.keystorePassword(keystorePassword.getBytes(Charset.defaultCharset()))
.build();
// create a keystore
KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
keystore.load(null, keystorePassword.toCharArray());
// export the keystore to the temp file
OutputStream os = Files.newOutputStream(tempFile);
keystore.store(os, keystorePassword.toCharArray());
os.close();
// ACT
client = new AbstractRemoteClientImpl(connector, AbstractRemoteClientImpl.RetroService.class);
} finally {
Files.delete(tempFile);
}
}
示例9: save
import java.nio.file.Files; //導入方法依賴的package包/類
public void save(Path file) throws IOException {
String fn = file.getFileName().toString();
if (fn.endsWith(".csv")) {
try (BufferedWriter out = Files.newBufferedWriter(file)) {
saveCSV(out);
}
} else {
try (DataOutputStream out = new DataOutputStream(Files.newOutputStream(file))) {
save(out);
}
}
}
示例10: SelectieResultaatBerichtWriter
import java.nio.file.Files; //導入方法依賴的package包/類
/**
* @param path path
* @throws IOException io fout
*/
private SelectieResultaatBerichtWriter(final Path path, final SelectieResultaatBericht bericht) throws IOException {
final OpenOption[] openOptions = {StandardOpenOption.CREATE, StandardOpenOption.APPEND};
out = new BufferedOutputStream(Files.newOutputStream(path, openOptions));
outputStreamWriter = new OutputStreamWriter(out, StandardCharsets.UTF_8);
try {
writer = new BerichtWriter(outputStreamWriter);
doStart(bericht);
} catch (BerichtException e) {
// Misschien een specifieke Exception.
throw new IOException(e);
}
}
示例11: saveProgramTraceFile
import java.nio.file.Files; //導入方法依賴的package包/類
public static void saveProgramTraceFile(Path basePath, String txHash, boolean compress, ProgramTrace trace) throws IOException {
if (compress) {
try(final FileOutputStream fos = new FileOutputStream(basePath.resolve(txHash + ".zip").toFile());
final ZipOutputStream zos = new ZipOutputStream(fos)
) {
ZipEntry zipEntry = new ZipEntry(txHash + ".json");
zos.putNextEntry(zipEntry);
Serializers.serializeFieldsOnly(trace, true, zos);
}
} else {
try (final OutputStream out = Files.newOutputStream(basePath.resolve(txHash + ".json"))) {
Serializers.serializeFieldsOnly(trace, true, out);
}
}
}
示例12: openPathWithDefault
import java.nio.file.Files; //導入方法依賴的package包/類
public static OutputStream openPathWithDefault(
Closer closer,
Path file,
PrintStream defaultOutput,
OpenOption... openOptions)
throws IOException {
OutputStream mapOut;
if (file == null) {
mapOut = defaultOutput;
} else {
mapOut = Files.newOutputStream(file, openOptions);
closer.register(mapOut);
}
return mapOut;
}
示例13: initialize
import java.nio.file.Files; //導入方法依賴的package包/類
void initialize(String[] args) {
this.args = args;
Path logFile = getDataDirPath().resolve("DeskChan.log");
try {
logFile.toFile().createNewFile();
logStream = Files.newOutputStream(logFile);
} catch (IOException e) {
log(e);
}
CoreInfo.printInfo();
tryLoadPluginByClass(CorePlugin.class);
loadPluginsBlacklist();
getCorePath();
}
示例14: createJarFile
import java.nio.file.Files; //導入方法依賴的package包/類
public static Path createJarFile(Path jarfile, Path dir, Path file) throws IOException {
// create the target directory
Path parent = jarfile.getParent();
if (parent != null)
Files.createDirectories(parent);
List<Path> entries = Files.find(dir.resolve(file), Integer.MAX_VALUE,
(p, attrs) -> attrs.isRegularFile())
.map(dir::relativize)
.collect(Collectors.toList());
try (OutputStream out = Files.newOutputStream(jarfile);
JarOutputStream jos = new JarOutputStream(out)) {
for (Path entry : entries) {
// map the file path to a name in the JAR file
Path normalized = entry.normalize();
String name = normalized
.subpath(0, normalized.getNameCount()) // drop root
.toString()
.replace(File.separatorChar, '/');
jos.putNextEntry(new JarEntry(name));
Files.copy(dir.resolve(entry), jos);
}
}
return jarfile;
}
示例15: writeJar
import java.nio.file.Files; //導入方法依賴的package包/類
/** creates a fake jar file with empty class files */
static void writeJar(Path jar, String... classes) throws IOException {
try (ZipOutputStream stream = new ZipOutputStream(Files.newOutputStream(jar))) {
for (String clazz : classes) {
stream.putNextEntry(new ZipEntry(clazz + ".class")); // no package names, just support simple classes
}
}
}