public static String toString(InputStream inputStream) throws IOException { return toString(inputStream,"UTF-8"); }
public static byte[] toByteArray(File file) throws IOException { FileInputStream is = new FileInputStream(file); try { return toByteArray(is); } finally { close(is); } }
/** * 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); } }
public static long copy(final InputStream inputStream, final OutputStream outputStream) throws IOException { return copy(inputStream, outputStream, DEF_BUFF_SIZE); }
@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); } } }
protected byte[] load() throws IOException { return IOUtils.toByteArray(in); }
/** * 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); } }
public static long copy(final Reader reader, final Writer writer) throws IOException { return copy(reader, writer, DEF_CHAR_BUFF_SIZE); }
public static byte[] gunzip(byte[] gzippedData) throws IOException { GZIPInputStream is = new GZIPInputStream(new ByteArrayInputStream(gzippedData)); byte[] data = IOUtils.toByteArray(is); is.close(); return data; } }
public static String toString(InputStream inputStream) throws IOException { return toString(inputStream,"UTF-8"); }
/** * 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 long copy(final Reader reader, final Writer writer) throws IOException { return copy(reader, writer, DEF_CHAR_BUFF_SIZE); }
public static byte[] toByteArray(File file) throws IOException { FileInputStream is = new FileInputStream(file); try { return IOUtils.toByteArray(is); } finally { IOUtils.close(is); } }
public static byte[] gunzip(byte[] gzippedData) throws IOException { GZIPInputStream is = new GZIPInputStream(new ByteArrayInputStream(gzippedData)); byte[] data = IOUtils.toByteArray(is); is.close(); return data; } }
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(InputStream inputStream) throws IOException { return toString(new InputStreamReader(inputStream)); }
/** * 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 long copy(final InputStream inputStream, final OutputStream outputStream) throws IOException { return copy(inputStream, outputStream, DEF_BUFF_SIZE); }