static String readFile(final File file) { try { final BufferedInputStream bin = new BufferedInputStream(new FileInputStream(file)); try { return IOUtils.toString(bin); } finally { bin.close(); } } catch (final IOException e) { throw new RuntimeException("Could not read file " + file, e); } }
@Override public void close() throws IOException { IOUtils.closeQuietly(inputStream); } }
/** * Get the contents of an <code>InputStream</code> as a character array using the default * character encoding of the platform. * <p> * This method buffers the input internally, so there is no need to use a * <code>BufferedInputStream</code>. * * @param is * the <code>InputStream</code> to read from * @return the requested character array * @throws NullPointerException * if the input is null * @throws IOException * if an I/O error occurs */ public static char[] toCharArray(InputStream is) throws IOException { CharArrayWriter output = new CharArrayWriter(); copy(is, output); return output.toCharArray(); }
@Override public String asText() { InputStream stream = null; try { stream = getInputStream(); return IOUtils.toString(stream, Bootstrap.getSettings(Application.get()).getBootstrapLessCompilerSettings().getCharset().name()); } catch (IOException e) { throw new WicketRuntimeException(e); } finally { IOUtils.closeQuietly(stream); } }
try byte[] bytes = IOUtils.toByteArray(inputStream); String base64EncodedImage = Base64.getEncoder().encodeToString(bytes); return "data:" + resourceStream.getContentType() + ";base64," + IOUtils.closeQuietly(inputStream);
IOUtils.closeQuietly(boundedInputStream); IOUtils.close(inputStream);
@Override public void close() throws IOException { // getInputStream() is not always called (WICKET-790) IOUtils.close(in); }
write(data, output);
bytes = IOUtils.toByteArray(inputStream); resourceResponse.setContentLength(bytes.length); IOUtils.close(resourceStream);
@Override protected byte[] getImageData() { try { return IOUtils.toByteArray(new FileInputStream(file)); } catch (Exception e) { throw new RuntimeException(e); } } });
try byte[] bytes = IOUtils.toByteArray(inputStream); String base64EncodedImage = Base64.getEncoder().encodeToString(bytes); return "data:" + resourceStream.getContentType() + ";base64," + IOUtils.closeQuietly(inputStream);
IOUtils.closeQuietly(boundedInputStream); IOUtils.close(inputStream);
@Override public void close() throws IOException { // getInputStream() is not always called (WICKET-790) IOUtils.close(in); }
bytes = IOUtils.toByteArray(inputStream); resourceResponse.setContentLength(bytes.length); IOUtils.close(resourceStream);
/** * read binary file fully * * @param file * file to read * @return byte array representing the content of the file * @throws IOException * is something went wrong */ public static byte[] readBytes(final File file) throws IOException { FileInputStream stream = new FileInputStream(file); try { return IOUtils.toByteArray(stream); } finally { stream.close(); } }
protected void outputAs(String id, String ext) { String url = url(id, ext); File file = new File(StringUtils.substringAfter(url, "file:")); String content; try { content = IOUtils.toString(new FileInputStream(file)); } catch (IOException e) { content = e.getMessage(); } MultiLineLabel output = (MultiLineLabel) get("output"); output.setDefaultModelObject(content); }
@Override public void close() throws IOException { IOUtils.closeQuietly(inputStream); } }
/** * Get the contents of an <code>InputStream</code> as a character array using the default * character encoding of the platform. * <p> * This method buffers the input internally, so there is no need to use a * <code>BufferedInputStream</code>. * * @param is * the <code>InputStream</code> to read from * @return the requested character array * @throws NullPointerException * if the input is null * @throws IOException * if an I/O error occurs */ public static char[] toCharArray(InputStream is) throws IOException { CharArrayWriter output = new CharArrayWriter(); copy(is, output); return output.toCharArray(); }