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


Java Files.newInputStream方法代码示例

本文整理汇总了Java中java.nio.file.Files.newInputStream方法的典型用法代码示例。如果您正苦于以下问题:Java Files.newInputStream方法的具体用法?Java Files.newInputStream怎么用?Java Files.newInputStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.nio.file.Files的用法示例。


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

示例1: read

import java.nio.file.Files; //导入方法依赖的package包/类
public static LoadFlowResult read(Path jsonFile) {
    Objects.requireNonNull(jsonFile);
    try (InputStream is = Files.newInputStream(jsonFile)) {
        return read(is);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
开发者ID:powsybl,项目名称:powsybl-core,代码行数:9,代码来源:LoadFlowResultDeserializer.java

示例2: main

import java.nio.file.Files; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    // create a zip file, and read it in as a byte array
    Path path = Files.createTempFile("bad", ".zip");
    try (OutputStream os = Files.newOutputStream(path);
            ZipOutputStream zos = new ZipOutputStream(os)) {
        ZipEntry e = new ZipEntry("x");
        zos.putNextEntry(e);
        zos.write((int) 'x');
    }
    int len = (int) Files.size(path);
    byte[] data = new byte[len];
    try (InputStream is = Files.newInputStream(path)) {
        is.read(data);
    }
    Files.delete(path);

    // year, month, day are zero
    testDate(data.clone(), 0, LocalDate.of(1979, 11, 30));
    // only year is zero
    testDate(data.clone(), 0 << 25 | 4 << 21 | 5 << 16, LocalDate.of(1980, 4, 5));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:ZeroDate.java

示例3: loadCredentials

import java.nio.file.Files; //导入方法依赖的package包/类
/**
 * HTTP request initializer that loads credentials from the service account file
 * and manages authentication for HTTP requests
 */
private GoogleCredential loadCredentials(String serviceAccount) throws IOException {
    if (serviceAccount == null) {
        throw new ElasticsearchException("Cannot load Google Cloud Storage service account file from a null path");
    }

    Path account = environment.configFile().resolve(serviceAccount);
    if (Files.exists(account) == false) {
        throw new ElasticsearchException("Unable to find service account file [" + serviceAccount
                + "] defined for repository");
    }

    try (InputStream is = Files.newInputStream(account)) {
        GoogleCredential credential = GoogleCredential.fromStream(is);
        if (credential.createScopedRequired()) {
            credential = credential.createScoped(Collections.singleton(StorageScopes.DEVSTORAGE_FULL_CONTROL));
        }
        return credential;
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:GoogleCloudStorageService.java

示例4: readFromLocationFile

import java.nio.file.Files; //导入方法依赖的package包/类
/**
 * Reads the path to the project from the Eclipse' .location meta data file.
 * This file can be found in
 * 'workspace\.metadata\.plugins\org.eclipse.core.resources\.projects\
 * PROJECTNAME\.lo c a t i o n ' .<br />
 * The .location files is written with a special Outpustream and read with
 * an special InputStream implementation. You can find them in the eclipse
 * project org.eclipse.core.resource. The class names are<br />
 * org.eclipse.core.internal.localstore.SafeChunkyInputStream and <br />
 * org.eclipse.core.internal.localstore.SafeChunkyOutputStream.
 * <p>
 * The eclipse implementation which reads the .location file can be found in
 * the same project, the class name is
 * org.eclipse.core.internal.resources.LocalMetaArea, refer to method
 * readPrivateDescription.
 * <p>
 * Basically the first 16 bytes of the .location file are for consistency
 * reason there, the next bytes are the path to the project source. Those
 * bytes must be read via DataInputStream.readUTF.
 */
private String readFromLocationFile(File project) throws IOException {
    String result = "";
    Path location = Paths.get(project.getAbsolutePath())
            .resolve(".location");
    InputStream inputStream = Files.newInputStream(location);
    try (DataInputStream dataStream = new DataInputStream(inputStream);) {
        byte[] begin_chunk = new byte[16];
        dataStream.read(begin_chunk, 0, 16);
        result = dataStream.readUTF();

        String uriPrefix = "URI//file:";
        if (System.getProperty("os.name").startsWith("Windows")) {
            uriPrefix = uriPrefix.concat("/");
        }

        if (result.startsWith(uriPrefix)) {
            result = result.substring(uriPrefix.length());
        }
    }
    return result;
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:42,代码来源:EclipseProjectReader.java

示例5: getInputStream

import java.nio.file.Files; //导入方法依赖的package包/类
public InputStream getInputStream() throws IOException {
    this.connect();
    if (iStream == null) {
        try {
            iStream = Files.newInputStream(f.toPath());
        } catch (InvalidPathException ex) {
            throw new IOException(ex);
        }
    }
    return iStream;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:NbinstURLStreamHandler.java

示例6: testCheckXPath36

import java.nio.file.Files; //导入方法依赖的package包/类
/**
 * XPath.evaluate(java.lang.String expression, InputSource source,
 * QName returnType) return correct number value if return type is Number.
 *
 * @throws Exception If any errors occur.
 */
@Test
public void testCheckXPath36() throws Exception {
    try (InputStream is = Files.newInputStream(XML_PATH)) {
        assertEquals(xpath.evaluate(EXPRESSION_NAME_A, new InputSource(is),
            NUMBER), 6d);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:XPathTest.java

示例7: unzip

import java.nio.file.Files; //导入方法依赖的package包/类
/**
 * Unzip a zip file to a destination directory.  If the zip file does not exist, an IOException is thrown.
 * If the destination directory does not exist, it will be created.
 *
 * @param zip      zip file to unzip
 * @param destDir  directory to unzip the file to
 * @param prefixToRemove  the (optional) prefix in the zip file path to remove when writing to the destination directory
 * @throws IOException if zip file does not exist, or there was an error reading from the zip file or
 *                     writing to the destination directory
 */
public static void unzip(final Path zip, final Path destDir, @Nullable final String prefixToRemove) throws IOException {
    if (Files.notExists(zip)) {
        throw new IOException("[" + zip + "] zip file must exist");
    }
    Files.createDirectories(destDir);

    try (ZipInputStream zipInput = new ZipInputStream(Files.newInputStream(zip))) {
        ZipEntry entry;
        while ((entry = zipInput.getNextEntry()) != null) {
            final String entryPath;
            if (prefixToRemove != null) {
                if (entry.getName().startsWith(prefixToRemove)) {
                    entryPath = entry.getName().substring(prefixToRemove.length());
                } else {
                    throw new IOException("prefix not found: " + prefixToRemove);
                }
            } else {
                entryPath = entry.getName();
            }
            final Path path = Paths.get(destDir.toString(), entryPath);
            if (entry.isDirectory()) {
                Files.createDirectories(path);
            } else {
                Files.copy(zipInput, path);
            }
            zipInput.closeEntry();
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:40,代码来源:FileTestUtils.java

示例8: initialize

import java.nio.file.Files; //导入方法依赖的package包/类
private static Properties initialize() {
    final Properties retval = new Properties();
    final Path path = Paths.get("config.properties");
    try(InputStream in = Files.newInputStream(path)){
        retval.load(in);
    } catch (IOException ex) {
        Logger.getLogger(App.class.getName()).log(Level.SEVERE, "Unable to read config", ex);
    }
    return retval;
}
 
开发者ID:erikcostlow,项目名称:PiCameraProject,代码行数:11,代码来源:App.java

示例9: validate

import java.nio.file.Files; //导入方法依赖的package包/类
static void validate(Path file) {
    try (InputStream is = Files.newInputStream(file)) {
        validate(is);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
开发者ID:powsybl,项目名称:powsybl-core,代码行数:8,代码来源:NetworkXml.java

示例10: getInstance

import java.nio.file.Files; //导入方法依赖的package包/类
public static XTFKeyStore getInstance() {
	if (instance == null) {
		Path defaultKeystore = findDefaultKeyStore();
		try (InputStream is = Files.newInputStream(defaultKeystore)) {
			instance = newInstance(is, "");
		} catch (IOException ex) {
			throw new RuntimeException("Couldn't load default keystore: " + defaultKeystore, ex);
		}
	}

	return instance;
}
 
开发者ID:xtf-cz,项目名称:xtf,代码行数:13,代码来源:XTFKeyStore.java

示例11: newInputStreamSupplierFor

import java.nio.file.Files; //导入方法依赖的package包/类
private Supplier<InputStream> newInputStreamSupplierFor(final Path file) {
    return new InputStreamSupplier() {
        @Override
        InputStream getInputStream() throws IOException {
            return Files.newInputStream(file);
        }
    };
}
 
开发者ID:TNG,项目名称:ArchUnit,代码行数:9,代码来源:ClassFileSource.java

示例12: addPackagesAttribute

import java.nio.file.Files; //导入方法依赖的package包/类
static void addPackagesAttribute(Path mi, Set<String> packages) throws IOException {
    byte[] bytes;
    try (InputStream in = Files.newInputStream(mi)) {
        ModuleInfoExtender extender = ModuleInfoExtender.newExtender(in);
        extender.packages(packages);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        extender.write(baos);
        bytes = baos.toByteArray();
    }

    Files.write(mi, bytes);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:AddPackagesAttribute.java

示例13: update

import java.nio.file.Files; //导入方法依赖的package包/类
public static void update(Network network, Path xmlFile) {
    try (InputStream is = Files.newInputStream(xmlFile)) {
        update(network, is);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
开发者ID:powsybl,项目名称:powsybl-core,代码行数:8,代码来源:NetworkXml.java

示例14: read

import java.nio.file.Files; //导入方法依赖的package包/类
public static DataCollection read(Path file) throws IOException {
	if (!Files.exists(file))
		throw new FileNotFoundException(file.getFileName().toString());

	try (DataInputStream in = new DataInputStream(Files.newInputStream(file))) {
		return read(in);
	}
}
 
开发者ID:Yeregorix,项目名称:EpiStats,代码行数:9,代码来源:DataCollection.java

示例15: toList

import java.nio.file.Files; //导入方法依赖的package包/类
@SneakyThrows(IOException.class)
public static List<String[]> toList(Path file) {
    try (InputStream is = Files.newInputStream(file, READ)) {
        CsvParserSettings settings = Csv.parseExcel();
        settings.setHeaderExtractionEnabled(true);
        CsvParser parser = new CsvParser(settings);
        return parser.parseAll(is);
    }
}
 
开发者ID:drtrang,项目名称:maven-archetype-springboot,代码行数:10,代码来源:CsvUtils.java


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