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


Java Files.newOutputStream方法代码示例

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

示例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);
}
 
开发者ID:Loara,项目名称:Meucci,代码行数:23,代码来源:ModLoader.java

示例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);
    }
}
 
开发者ID:powsybl,项目名称:powsybl-core,代码行数:17,代码来源:ContingencyJsonTest.java

示例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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:27,代码来源:SJFM_TestBase.java

示例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;
}
 
开发者ID:Dytanic,项目名称:CloudNet,代码行数:13,代码来源:Document.java

示例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);
    }
}
 
开发者ID:powsybl,项目名称:powsybl-core,代码行数:16,代码来源:LoadFlowResultSerializer.java

示例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);
    }
}
 
开发者ID:JavaSaBr,项目名称:jmonkeybuilder,代码行数:13,代码来源:CodeAreaFileEditor.java

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

示例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);
		}
	}
}
 
开发者ID:Yeregorix,项目名称:EpiStats,代码行数:14,代码来源:RankingList.java

示例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);
    }

}
 
开发者ID:MinBZK,项目名称:OperatieBRP,代码行数:18,代码来源:SelectieResultaatBerichtWriter.java

示例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);
        }
    }
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:16,代码来源:VMUtils.java

示例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;
}
 
开发者ID:inferjay,项目名称:r8,代码行数:16,代码来源:FileUtils.java

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

示例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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:28,代码来源:JImageGenerator.java

示例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
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:9,代码来源:InstallPluginCommandTests.java


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