當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。