/** * Write data to a file * * @param file File to write data to * @param data Data to write */ public static void write(File file, byte[] data) throws IOException { FileOutputStream fos = new FileOutputStream(file); try { fos.write(data); } finally { IOUtils.close(fos); } }
/** * Write data to a file * * @param file File to write data to * @param data Data to write */ public static void write(File file, byte[] data) throws IOException { FileOutputStream fos = new FileOutputStream(file); try { fos.write(data); } finally { IOUtils.close(fos); } }
/** * Write data to a file * * @param file File to write data to * @param data Data to write */ public static void write(File file, byte[] data) throws IOException { FileOutputStream fos = new FileOutputStream(file); try { fos.write(data); } finally { close(fos); } } }
/** * Write string to a file * * @param file File to write text to * @param text Text to write * @param encoding Character encoding */ public static void write(File file, String text, String encoding) throws IOException { FileOutputStream fos = new FileOutputStream(file); try { fos.write(text.getBytes(encoding)); } finally { IOUtils.close(fos); } }
/** * Write string to a file * * @param file File to write text to * @param text Text to write * @param encoding Character encoding */ public static void write(File file, String text, String encoding) throws IOException { FileOutputStream fos = new FileOutputStream(file); try { fos.write(text.getBytes(encoding)); } finally { IOUtils.close(fos); } }
public static String toString(File file, String encoding) throws IOException { StringWriter buffer = new StringWriter(); InputStreamReader fileReader = null; try { fileReader = new InputStreamReader(new FileInputStream(file), encoding); IOUtils.copy(fileReader, buffer); return buffer.toString(); } finally { IOUtils.close(buffer); IOUtils.close(fileReader); } }
public static String toString(File file, String encoding) throws IOException { StringWriter buffer = new StringWriter(); InputStreamReader fileReader = null; try { fileReader = new InputStreamReader(new FileInputStream(file), encoding); IOUtils.copy(fileReader, buffer); return buffer.toString(); } finally { IOUtils.close(buffer); IOUtils.close(fileReader); } }
public synchronized void unsetProxy() { if (httpClient != null) { IOUtils.close(httpClient); } httpClient = HttpClients.createMinimal(); }
public static byte[] toByteArray(File file) throws IOException { FileInputStream is = new FileInputStream(file); try { return toByteArray(is); } finally { close(is); } }
public static void copy( File src, File dst ) throws IOException { FileInputStream is = null; FileOutputStream os = null; try { is = new FileInputStream(src); os = new FileOutputStream(dst); IOUtils.copy(is,os); } finally { IOUtils.close(is,os); } }
public byte[] closeAndReturnData() { ByteArrayDataOutputStream buffer = (ByteArrayDataOutputStream) this.out; IOUtils.close(buffer); return buffer.toByteArray(); } }
public static byte[] toByteArray(File file) throws IOException { FileInputStream is = new FileInputStream(file); try { return IOUtils.toByteArray(is); } finally { IOUtils.close(is); } }
public static void copy( File src, File dst ) throws IOException { FileInputStream is = null; FileOutputStream os = null; try { is = new FileInputStream(src); os = new FileOutputStream(dst); IOUtils.copy(is,os); } finally { IOUtils.close(is,os); } }
public static byte[] toByteArray(File file) throws IOException { FileInputStream is = new FileInputStream(file); try { return IOUtils.toByteArray(is); } finally { IOUtils.close(is); } }
public synchronized void setProxy(@NotNull String scheme, @NotNull String host, int port, @Nullable String username, @Nullable String password) { if (httpClient != null) { IOUtils.close(httpClient); } HttpClientBuilder builder = HttpClients.custom(); HttpHost proxyHost = new HttpHost(host, port, scheme); DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxyHost); builder = builder.setRoutePlanner(routePlanner); if (username != null && password != null) { CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope(proxyHost), new UsernamePasswordCredentials(username, password)); builder = builder.setDefaultCredentialsProvider(credsProvider); } httpClient = builder.build(); }
@Override public long getTimeDifferential(HttpRequest request, HttpContext context) throws IOException { CloseableHttpClient httpClient = HttpClientBuilder.create().build(); try { CloseableHttpResponse response = httpClient.execute(new HttpGet(url)); if (response.getStatusLine().getStatusCode() != 200) { throw new IOException("Unable to sync time, server returned error code " + response.getStatusLine().getStatusCode() + " : " + response.getStatusLine().getReasonPhrase()); } long now = System.currentTimeMillis(); String serverTimestamp = IOUtils.toString(response.getEntity().getContent()); try { return now - TimeUtils.parseISOUTCDateTime(serverTimestamp).getTime(); } catch (ParseException e) { throw new IOException("Unable to sync time, invalid time returned by server: " + serverTimestamp); } } finally { IOUtils.close(httpClient); } } }
public static byte[] toByteArray(DataGenerator dataGenerator) throws IOException { ByteArrayDataOutputStream buffer = new ByteArrayDataOutputStream(); dataGenerator.generateData(buffer); close(buffer); return buffer.toByteArray(); }
} finally { if (tmpFile) { IOUtils.close((TempFile) source.getLocalFile());