/** * Reads file into a byte array. * * @param file file to read. * @return content of file. * @throws java.io.IOException */ public static byte[] read(File file) throws IOException { FileInputStream is = new FileInputStream(file); try { return bytes(is); } finally { closeQuietly(is); } }
/** * Reads contents of resource fully into a byte array. * * @param resourceName resource name. * @return entire contents of resource as byte array. */ public static byte[] readResourceBytes(String resourceName) { InputStream is = Util.class.getResourceAsStream(resourceName); try { return bytes(is); } catch (IOException e) { throw new RuntimeException(e); } finally { closeQuietly(is); } }
/** * Converts <code>java.sql.Blob</code> to bytes array. * * @param blob Blob to be converted * @return blob converted to byte array */ public static byte[] toBytes(Blob blob) { InputStream is = null; try { is = blob.getBinaryStream(); return bytes(is); } catch (Exception e) { throw new ConversionException(e); } finally { closeQuietly(is); } }
/** * Constructor to be used in tests, field name and file name are set to File name. * Content type set to "text/plain". * * @param file file to send. * @throws IOException */ public FileItem(File file) throws IOException { super(file.getName(), file.getName(), true, "text/plain", Util.bytes(new FileInputStream(file))); }
/** * Reads entire request data as byte array. Do not use for large data sets to avoid * memory issues. * * @return data sent by client as string. * @throws IOException */ protected byte[] getRequestBytes() throws IOException { return Util.bytes(RequestContext.getHttpRequest().getInputStream()); }
/** * Reads file into a byte array. * * @param file file to read. * @return content of file. * @throws java.io.IOException */ public static byte[] read(File file) throws IOException { FileInputStream is = new FileInputStream(file); try { return bytes(is); } finally { closeQuietly(is); } }
/** * Reads contents of resource fully into a byte array. * * @param resourceName resource name. * @return entire contents of resource as byte array. */ public static byte[] readResourceBytes(String resourceName) { InputStream is = Util.class.getResourceAsStream(resourceName); try { return bytes(is); } catch (IOException e) { throw new RuntimeException(e); } finally { closeQuietly(is); } }
/** * Reads file into a byte array. * * @param file file to read. * @return content of file. * @throws java.io.IOException */ public static byte[] read(File file) throws IOException { FileInputStream is = new FileInputStream(file); try { return bytes(is); } finally { closeQuietly(is); } }
/** * Reads contents of resource fully into a byte array. * * @param resourceName resource name. * @return entire contents of resource as byte array. */ public static byte[] readResourceBytes(String resourceName) { InputStream is = Util.class.getResourceAsStream(resourceName); try { return bytes(is); } catch (IOException e) { throw new RuntimeException(e); } finally { closeQuietly(is); } }
/** * Reads contents of a file into a byte array at once. * * @return contents of a file as byte array. */ public byte[] getBytes() { try { return Util.bytes(fileItemStream.openStream()); } catch (Exception e) { throw new ControllerException(e); } }
/** * Converts <code>java.sql.Blob</code> to bytes array. * * @param blob Blob to be converted * @return blob converted to byte array */ public static byte[] toBytes(Blob blob) { InputStream is = null; try { is = blob.getBinaryStream(); return bytes(is); } catch (Exception e) { throw new ConversionException(e); } finally { closeQuietly(is); } }
/** * Converts <code>java.sql.Blob</code> to bytes array. * * @param blob Blob to be converted * @return blob converted to byte array */ public static byte[] toBytes(Blob blob) { InputStream is = null; try { is = blob.getBinaryStream(); return bytes(is); } catch (Exception e) { throw new ConversionException(e); } finally { closeQuietly(is); } }
@Override public Class<?> loadClass(String name) throws ClassNotFoundException { try{ if (name.startsWith("org.javalite.activeweb")) { return loadByParent(name); } if(name.endsWith("Controller") || name.contains("Controller$") || name.equals(Configuration.getRouteConfigClassName())){ String pathToClassFile = name.replace('.', '/') + ".class"; byte[] classBytes = bytes(getResourceAsStream(pathToClassFile)); Class<?> daClass = defineClass(name, classBytes, 0, classBytes.length); LOGGER.debug("Loaded class: " + name); return daClass; }else{ return loadByParent(name); } } catch(Exception e){ LOGGER.debug("Failed to dynamically load class: " + name + ". Loading by parent class loader."); return loadByParent(name); } }