/** * Read an input stream and return the content as string assuming UTF8. * @param in The input stream * @return The read String * @return The content * @throws IOException e */ public static String readInput(InputStream in) throws IOException { byte[] content = readInputStream(in); return Utf8.toString(content); }
/** * Read an input stream and return the content as string assuming UTF8. * @param in The input stream * @return The read String * @return The content * @throws IOException e */ public static String readInput(InputStream in) throws IOException { byte[] content = readInputStream(in); return Utf8.toString(content); }
/** * Read a file and return the content as string assuming UTF8. * @param file The file to read * @return The content as a UTF-8 String * @throws IOException If an error occurred */ public static String readFile(File file) throws IOException { long len = 0; if (file.length() >= Integer.MAX_VALUE) { throw new IOException("Too large file, unexpected!"); } else { len = file.length(); } byte[] buf = new byte[(int) len]; InputStream is = Files.newInputStream(file.toPath()); readInputStream(is, buf); return Utf8.toString(buf); }
/** * Read a file and return the content as string assuming UTF8. * @param file The file to read * @return The content as a UTF-8 String * @throws IOException If an error occurred */ public static String readFile(File file) throws IOException { long len = 0; if (file.length() >= Integer.MAX_VALUE) { throw new IOException("Too large file, unexpected!"); } else { len = file.length(); } byte[] buf = new byte[(int) len]; InputStream is = Files.newInputStream(file.toPath()); readInputStream(is, buf); return Utf8.toString(buf); }