List of usage examples for org.apache.commons.io IOUtils toByteArray
public static byte[] toByteArray(String input) throws IOException
String
as a byte[]
using the default character encoding of the platform. From source file:com.imag.nespros.network.devices.SacomutDevice.java
public SacomutDevice(String name) { super(name);//from ww w. j a v a 2 s . c o m this.setCpuSpeed(350); this.setTotalMemory(1024); this.setDeviceType(DeviceType.SACOMUT); this.setDeviceName(name); try { byte[] imageInByte; imageInByte = IOUtils.toByteArray(getClass().getClassLoader().getResourceAsStream("image/sacomut.jpg")); icon = new MyLayeredIcon(new ImageIcon(imageInByte).getImage()); } catch (IOException ex) { Logger.getLogger(AMIDevice.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:invio.util.ArquivoUtil.java
public static void exportaPDF(String path) { FacesContext facesContext = FacesContext.getCurrentInstance(); ExternalContext externalContext = facesContext.getExternalContext(); HttpServletResponse response = (HttpServletResponse) externalContext.getResponse(); response.setContentType("application/pdf"); try {/*from ww w . j ava 2 s . c om*/ FileInputStream input = new FileInputStream(path); byte[] bytes = IOUtils.toByteArray(input); OutputStream output = response.getOutputStream(); output.write(bytes); IOUtils.closeQuietly(input); IOUtils.closeQuietly(output); } catch (IOException e) { } }
From source file:gui.CompressDecompress.java
public static byte[] compressBuffer(List<List<BigInteger>> encBuffer) { try {/*ww w. j a v a 2 s.c o m*/ File loc = new File("temp.dat"); if (loc.exists()) { Files.delete(loc.toPath()); } byte[] byteArray = serialize(encBuffer); AdaptiveArithmeticCompress.encoder(byteArray, loc.getAbsolutePath()); InputStream is = new FileInputStream(loc); byte[] bytes = IOUtils.toByteArray(is); is.close(); return bytes; } catch (IOException ex) { Logger.getLogger(CompressDecompress.class.getName()).log(Level.SEVERE, null, ex); } return null; }
From source file:de.mas.telegramircbot.utils.images.ImgurUploader.java
public static String uploadImageAndGetLink(InputStream is) throws IOException { return uploadImageAndGetLink(IOUtils.toByteArray(is)); }
From source file:com.imag.nespros.network.devices.HTACoordDevice.java
public HTACoordDevice(String name) { super(name);/*from w w w .j av a 2 s . c o m*/ this.setCpuSpeed(500); this.setTotalMemory(16000); this.setDeviceType(DeviceType.HTA_COORD); this.setDeviceName(name); try { byte[] imageInByte; imageInByte = IOUtils .toByteArray(getClass().getClassLoader().getResourceAsStream("image/htaCoord.jpg")); icon = new MyLayeredIcon(new ImageIcon(imageInByte).getImage()); } catch (IOException ex) { Logger.getLogger(AMIDevice.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.pullup.app.util.ImageUtils.java
public String saveImage(InputStream stream, String token) { byte[] bytes = null; String path = "C:\\pullup\\profile\\" + token + ".png"; try {/*from www.j a v a 2s .c om*/ bytes = IOUtils.toByteArray(stream); log.info("Saving image"); IOUtils.write(token, new FileWriter(new File(path))); } catch (IOException ex) { log.severe("Could not write image: " + ex.getMessage()); } return path; }
From source file:blue.lapis.pore.vault.PoreVaultInjector.java
public static void inject() throws Exception { Plugin vault = Pore.getServer().getPluginManager().getPlugin("Vault"); if (vault == null) return;// ww w. j a v a 2 s . co m ClassLoader loader = vault.getClass().getClassLoader(); LocalClassLoader injector = new LocalReflectClassLoader(loader); for (String addition : new String[] { "Hook", "Chat", "Economy", "Permissions" }) { String name = START + addition; URL url = Pore.class.getClassLoader().getResource(name.replace('.', '/') + ".class"); byte[] clazz = IOUtils.toByteArray(url); injector.defineClass(name, clazz); } Class.forName(HOOK, true, loader).getMethod("hook").invoke(null); }
From source file:com.mobius.software.mqtt.parser.test.StaticData.java
public static byte[] loadBytesFromResource(String resource) throws IOException { InputStream is = StaticData.class.getClassLoader().getResourceAsStream(resource); byte[] result; result = IOUtils.toByteArray(is); // result = hexStringToByteArray(IOUtils.toString(is)); is.close();/*from w w w . j av a 2s.co m*/ return result; }
From source file:com.mitrapps.mocaFileTransfer.FileUploader.java
public static void transferFile(MocaConnection conn, String inputFileName, String outputPath) { try {/*from w w w .j a v a2s.co m*/ // get pointer to the file and print ack message to user File file = new File(inputFileName); //System.out.println("File is size " + file.length()); // Convert contents to byte array and print ack message to user InputStream in = new FileInputStream(file); byte[] fileContents = IOUtils.toByteArray(in); in.close(); //System.out.println("Byte array size is " + fileContents.length); String command = String.format( "decode from base64" + " where str = '%s'" + " | " + "write stream to file " + " where dataStream = @base64_decoded" + " and filePath = '%s'", com.redprairie.util.Base64.encode(fileContents), outputPath); conn.executeCommand(command); } catch (MocaException e) { e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.github.ctrimble.chlorine.asm.ClassByteLoader.java
public byte[] getBytes(String name) throws ClassInspectionException { try {//from w ww . j av a 2 s . c o m return IOUtils.toByteArray(source.getResourceAsStream(name + ".class")); } catch (IOException ioe) { throw new ClassInspectionException("Could not load bytes for class " + name, ioe); } }