本文整理了Java中java.nio.file.Files.newInputStream()
方法的一些代码示例,展示了Files.newInputStream()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Files.newInputStream()
方法的具体详情如下:
包路径:java.nio.file.Files
类名称:Files
方法名:newInputStream
暂无
代码示例来源:origin: jenkinsci/jenkins
public InputStream getInputStream() throws IOException {
try {
return Files.newInputStream(file.toPath());
} catch (InvalidPathException e) {
throw new IOException(e);
}
}
代码示例来源:origin: apache/kafka
/**
* Read a properties file from the given path
* @param filename The path of the file to read
*/
public static Properties loadProps(String filename) throws IOException {
Properties props = new Properties();
if (filename != null) {
try (InputStream propStream = Files.newInputStream(Paths.get(filename))) {
props.load(propStream);
}
} else {
System.out.println("Did not load any properties since the property file is not specified");
}
return props;
}
代码示例来源:origin: jenkinsci/jenkins
public byte[] get() {
try {
try (InputStream inputStream = Files.newInputStream(file.toPath())) {
return IOUtils.toByteArray(inputStream);
}
} catch (IOException | InvalidPathException e) {
throw new Error(e);
}
}
代码示例来源:origin: ben-manes/caffeine
/** Returns the input stream for the raw file. */
private InputStream openFile(String filePath) throws IOException {
Path file = Paths.get(filePath);
if (Files.exists(file)) {
return Files.newInputStream(file);
}
InputStream input = getClass().getResourceAsStream(filePath);
checkArgument(input != null, "Could not find file: " + filePath);
return input;
}
}
代码示例来源:origin: jenkinsci/jenkins
public static void copy(File src, OutputStream out) throws IOException {
try (InputStream in = Files.newInputStream(src.toPath())) {
org.apache.commons.io.IOUtils.copy(in, out);
} catch (InvalidPathException e) {
throw new IOException(e);
}
}
代码示例来源:origin: googleapis/google-cloud-java
public static void main(String... args) throws IOException {
Path path = Paths.get(URI.create("gs://bucket/lolcat.csv"));
try (InputStream input = Files.newInputStream(path)) {
// use input stream
}
}
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Copy the contents of the given input File into a new byte array.
* @param in the file to copy from
* @return the new byte array that has been copied to
* @throws IOException in case of I/O errors
*/
public static byte[] copyToByteArray(File in) throws IOException {
Assert.notNull(in, "No input File specified");
return copyToByteArray(Files.newInputStream(in.toPath()));
}
代码示例来源:origin: apache/nifi
@Override
protected InputStream getServiceAccountJson(Map<PropertyDescriptor, String> properties) throws IOException {
String serviceAccountFile = properties.get(CredentialPropertyDescriptors.SERVICE_ACCOUNT_JSON_FILE);
return new BufferedInputStream(Files.newInputStream(Paths.get(serviceAccountFile)));
}
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Copy the contents of the given input File to the given output File.
* @param in the file to copy from
* @param out the file to copy to
* @return the number of bytes copied
* @throws IOException in case of I/O errors
*/
public static int copy(File in, File out) throws IOException {
Assert.notNull(in, "No input File specified");
Assert.notNull(out, "No output File specified");
return copy(Files.newInputStream(in.toPath()), Files.newOutputStream(out.toPath()));
}
代码示例来源:origin: lets-blade/blade
/**
* Load environment by file
*
* @param file environment file
* @return return Environment instance
*/
public static Environment of(@NonNull File file) {
try {
return of(Files.newInputStream(Paths.get(file.getPath())));
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
代码示例来源:origin: jenkinsci/jenkins
private static String readPemFile(File f) throws IOException{
try (InputStream is = Files.newInputStream(f.toPath());
DataInputStream dis = new DataInputStream(is)) {
byte[] bytes = new byte[(int) f.length()];
dis.readFully(bytes);
return new String(bytes);
} catch (InvalidPathException e) {
throw new IOException(e);
}
}
代码示例来源:origin: lets-blade/blade
/**
* Load environment by file
*
* @param file environment file
* @return return Environment instance
*/
public static Environment of(@NonNull File file) {
try {
return of(Files.newInputStream(Paths.get(file.getPath())));
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
代码示例来源:origin: jenkinsci/jenkins
/**
* Loads the contents of this file into a new object.
*/
public Object read() throws IOException {
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine("Reading "+file);
}
try (InputStream in = new BufferedInputStream(Files.newInputStream(file.toPath()))) {
return xs.fromXML(in);
} catch (RuntimeException | Error e) {
throw new IOException("Unable to read "+file,e);
}
}
代码示例来源:origin: apache/incubator-druid
@Override
public void refresh()
{
try {
Properties props = new Properties();
try (InputStream is = Files.newInputStream(Paths.get(sessionCredentialsFile))) {
props.load(is);
}
String sessionToken = props.getProperty("sessionToken");
String accessKey = props.getProperty("accessKey");
String secretKey = props.getProperty("secretKey");
awsSessionCredentials = new Credentials(sessionToken, accessKey, secretKey);
}
catch (IOException e) {
throw new RuntimeException("cannot refresh AWS credentials", e);
}
}
代码示例来源:origin: micronaut-projects/micronaut-core
/**
* This implementation opens a FileInputStream for the underlying file.
*
* @see java.io.FileInputStream
*/
@Override
public InputStream getInputStream() throws IOException {
return Files.newInputStream(file.toPath());
}
代码示例来源:origin: spotbugs/spotbugs
@ExpectWarning("OS_OPEN_STREAM")
void test1(File f, byte b) throws IOException {
InputStream stream = Files.newInputStream(Paths.get(""));
stream.read();
}
代码示例来源:origin: pmd/pmd
@Override
public InputStream getInputStream() throws IOException {
return Files.newInputStream(file.toPath());
}
代码示例来源:origin: apache/kafka
/**
* Loads this keystore
* @return the keystore
* @throws KafkaException if the file could not be read or if the keystore could not be loaded
* using the specified configs (e.g. if the password or keystore type is invalid)
*/
KeyStore load() {
try (InputStream in = Files.newInputStream(Paths.get(path))) {
KeyStore ks = KeyStore.getInstance(type);
// If a password is not set access to the truststore is still available, but integrity checking is disabled.
char[] passwordChars = password != null ? password.value().toCharArray() : null;
ks.load(in, passwordChars);
fileLastModifiedMs = lastModifiedMs(path);
log.debug("Loaded key store with path {} modification time {}", path,
fileLastModifiedMs == null ? null : new Date(fileLastModifiedMs));
return ks;
} catch (GeneralSecurityException | IOException e) {
throw new KafkaException("Failed to load SSL keystore " + path + " of type " + type, e);
}
}
代码示例来源:origin: jenkinsci/jenkins
@Override public InputStream open() throws IOException {
if (isIllegalSymlink()) {
throw new FileNotFoundException(f.getPath());
}
try {
return Files.newInputStream(f.toPath());
} catch (InvalidPathException e) {
throw new IOException(e);
}
}
代码示例来源:origin: apache/kafka
public static <T extends Certificate> void createTrustStore(
String filename, Password password, Map<String, T> certs) throws GeneralSecurityException, IOException {
KeyStore ks = KeyStore.getInstance("JKS");
try (InputStream in = Files.newInputStream(Paths.get(filename))) {
ks.load(in, password.value().toCharArray());
} catch (EOFException e) {
ks = createEmptyKeyStore();
}
for (Map.Entry<String, T> cert : certs.entrySet()) {
ks.setCertificateEntry(cert.getKey(), cert.getValue());
}
saveKeyStore(ks, filename, password);
}
内容来源于网络,如有侵权,请联系作者删除!