/** * Attempts to load a resource from the file system, from a URL, or from the * classpath, in that order. * * @param resourceName The name of the resource to load * @param callingClass The Class object of the calling object * @return an InputStream to the resource or null if resource not found * @throws java.io.IOException IO error */ public static InputStream getResourceAsStream(final String resourceName, final Class callingClass) throws IOException { return getResourceAsStream(resourceName, callingClass, true, true); }
public CachedResource(Reader reader, String encoding) throws IOException { this(IOUtils.toByteArray(reader, encoding), DEFAULT_DESCRIPTION); }
public Object getObject() throws Exception { if(data!=null) { return data; } if(file!=null) { if(binary) { data = IOUtils.toByteArray(IOUtils.getResourceAsStream(file, getClass())); } else { data = IOUtils.getResourceAsString(file, getClass()); } } else if(ref!=null) { data = context.getBean(ref); } if(data==null) { throw new IllegalArgumentException("Data is null was not found"); } return data; }
protected String createStringFromInputStream(InputStream input) { try { return IOUtils.toString(input); } finally { IOUtils.closeQuietly(input); } }
public static synchronized void copyStreamToFile(InputStream input, File destination) throws IOException { if (destination.exists() && !destination.canWrite()) { throw new IOException("Destination file does not exist or is not writeable"); } try { FileOutputStream output = new FileOutputStream(destination); try { IOUtils.copy(input, output); } finally { IOUtils.closeQuietly(output); } } finally { IOUtils.closeQuietly(input); } }
/** * Attempts to load a resource from the file system, from a URL, or from the * classpath, in that order. * * @param resourceName The name of the resource to load * @param callingClass The Class object of the calling object * @return the requested resource as a string * @throws java.io.IOException IO error */ public static String getResourceAsString(final String resourceName, final Class callingClass) throws IOException { try (InputStream is = getResourceAsStream(resourceName, callingClass)) { if (is != null) { return toString(is); } else { throw new IOException("Unable to load resource " + resourceName); } } }
@Override public String getResourceAsString(String resourceName) throws IOException { return IOUtils.getResourceAsString(resourceName, getClass()); } }
InputStream in = IOUtils.getResourceAsStream(file, getClass(), false, false); if (in == null) IOUtils.copyLarge(in, baos); byte[] buffer = baos.toByteArray();
private void updateTextFile() { Properties props = getStoreAsProperties(); try { if (output != null) { closeQuietly(output); } output = new FileOutputStream(fileStore, false); props.store(output, StringUtils.EMPTY); } catch (IOException e) { logger.error(e.getMessage(), e); } }
try bytes = IOUtils.toByteArray(input); IOUtils.closeQuietly(input);
/** * Attempts to load a resource from the file system or from the classpath, in * that order. * * @param resourceName The name of the resource to load * @param callingClass The Class object of the calling object * @return an URL to the resource or null if resource not found */ public static URL getResourceAsUrl(final String resourceName, final Class callingClass) { return getResourceAsUrl(resourceName, callingClass, true, true); }
parts[i] = new CustomStringPart(ds.getName(), IOUtils.toString(ds.getInputStream()), mimeType.getParameter(CHARSET_PARAM_NAME), mimeType.getBaseType()); IOUtils.toByteArray(dh.getInputStream())), dh.getContentType(), null);
@Override public Object doTransform(Object src, String encoding) throws TransformerException { try { String data; if (src instanceof byte[]) { data = new String((byte[]) src, encoding); } else if (src instanceof InputStream) { data = IOUtils.toString((InputStream)src); } else { data = (String) src; } return XMLEntityCodec.decodeString(data); } catch (Exception ex) { throw new TransformerException( CoreMessages.transformFailed(src.getClass().getName(), "XML"), this, ex); } }
IOUtils.copyLarge(in, baos); IOUtils.closeQuietly(in);
public void write(MuleEvent event, OutputStream out) throws IOException { InputStream is = (InputStream) src; try { IOUtils.copyLarge(is, out); } finally { is.close(); } } };
protected String createStringFromInputStream(InputStream input, String outputEncoding) throws TransformerException { try { ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); IOUtils.copy(input, byteOut); return byteOut.toString(outputEncoding); } catch (IOException e) { throw new TransformerException(CoreMessages.errorReadingStream(), e); } finally { try { input.close(); } catch (IOException e) { logger.warn("Could not close stream", e); } } }
public static synchronized void copyStreamToFile(InputStream input, File destination) throws IOException { if (destination.exists() && !destination.canWrite()) { throw new IOException("Destination file does not exist or is not writeable"); } try { FileOutputStream output = new FileOutputStream(destination); try { IOUtils.copy(input, output); } finally { IOUtils.closeQuietly(output); } } finally { IOUtils.closeQuietly(input); } }
private void loadLicense(String licenseFile) throws IOException { license = IOUtils.getResourceAsString(licenseFile, getClass()); license = StringMessageUtils.getBoilerPlate(license, ' ', 80); }
@Override public synchronized void dispose() { Properties props = getStoreAsProperties(); if (output == null) { try { output = new FileOutputStream(fileStore, false); props.store(output, StringUtils.EMPTY); closeQuietly(output); } catch (IOException e) { logger.error(e.getMessage(), e); } } else { closeQuietly(output); } super.dispose(); }
@Override protected Object doTransform(Object src, String encoding) throws TransformerException { String string; if (src instanceof byte[]) { string = new String((byte[]) src); } else if (src instanceof InputStream) { InputStream input = (InputStream) src; try { string = IOUtils.toString(input); } finally { IOUtils.closeQuietly(input); } } else { string = (String) src; } return append(message, string); }