Refine search
public InputStream getInputStream() throws IOException { try { return Files.newInputStream(file.toPath()); } catch (InvalidPathException e) { throw new IOException(e); } }
/** * 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; }
public byte[] get() { try { try (InputStream inputStream = Files.newInputStream(file.toPath())) { return IOUtils.toByteArray(inputStream); } } catch (IOException | InvalidPathException e) { throw new Error(e); } }
/** 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; } }
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); } }
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 } } }
/** * 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())); }
@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))); } }
/** * 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())); }
/** * 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); } }
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); } }
/** * 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); } }
/** * 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); } }
@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); } }
/** * This implementation opens a FileInputStream for the underlying file. * * @see java.io.FileInputStream */ @Override public InputStream getInputStream() throws IOException { return Files.newInputStream(file.toPath()); }
@ExpectWarning("OS_OPEN_STREAM") void test1(File f, byte b) throws IOException { InputStream stream = Files.newInputStream(Paths.get("")); stream.read(); }
@Override public InputStream getInputStream() throws IOException { return Files.newInputStream(file.toPath()); }
/** * 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); } }
@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); } }
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); }