List of usage examples for org.apache.commons.io FileUtils writeByteArrayToFile
public static void writeByteArrayToFile(File file, byte[] data) throws IOException
From source file:files.FileStorage.java
public void saveFile(Long id, MultipartFile file) throws IOException { File newFile = new File(filePath + id); FileUtils.writeByteArrayToFile(newFile, file.getBytes()); }
From source file:edu.american.student.util.CloudGenerator.java
/** * Generate a Tag Cloud//w w w .ja v a 2 s .c o m * @param cloud * @param saveLocation * @throws IOException */ public static void generateCloud(Cloud cloud, String saveLocation) throws IOException { List<Tag> tags = cloud.allTags(); String html = ""; int i = 0; int tagsPerLine = 30; for (Tag tag : tags) { int score = tag.getScoreInt(); html += "<a href=" + tag.getLink() + " style=font-size:" + (score * 7) + "px;>" + tag.getName() + "</a> "; if (i % tagsPerLine == 0) { html += "<br>"; } i++; } FileUtils.writeByteArrayToFile(new File(saveLocation), html.getBytes()); }
From source file:net.darkmist.alib.io.Spew.java
public static void spew(String filename, byte[] data) throws IOException { FileUtils.writeByteArrayToFile(new File(filename), data); //spew(new File(filename), data); }
From source file:net.nicholaswilliams.java.licensing.encryption.KeyFileUtilities.java
protected static void writeEncryptedPrivateKey(PrivateKey privateKey, File file, char[] passphrase) throws IOException { FileUtils.writeByteArrayToFile(file, KeyFileUtilities.writeEncryptedPrivateKey(privateKey, passphrase)); }
From source file:edu.illinois.cs.cogcomp.core.utilities.SerializationHelper.java
/** * Serialize a TextAnnotation and then write to file. If forceOverwrite_ is set to false and * file already exists, this method throws an exception. * * @param ta The text annotation to be serialized * @param fileName Name of file to write to * @param forceOverwrite Whether or not to overwrite existing file. */// w ww .j av a2 s.c om public static void serializeTextAnnotationToFile(TextAnnotation ta, String fileName, boolean forceOverwrite) throws IOException { File outFile = new File(fileName); if (outFile.exists() && !forceOverwrite) throw new IOException( "ERROR: " + NAME + ".serializeTextAnnotationToFile(): file '" + fileName + "' already exists."); FileUtils.writeByteArrayToFile(outFile, serializeTextAnnotationToBytes(ta)); }
From source file:com.bookselling.util.FileUtilities.java
public void write(UploadedFile multipartFiles[], String path) { if (multipartFiles != null && multipartFiles.length != 0) { for (UploadedFile multipartFile : multipartFiles) { String fileWithFullPath = path + "/" + multipartFile.getName(); File file = new File(fileWithFullPath); try { FileUtils.writeByteArrayToFile(file, multipartFile.getData()); } catch (IOException ex) { Logger.getLogger(FileUtilities.class.getName()).log(Level.SEVERE, null, ex); }// ww w . j a va 2 s . c om } } }
From source file:com.qubit.terra.docs.util.helpers.OpenofficeInProcessConverter.java
public static synchronized byte[] convert(final byte[] odtContent, final String tempDirFullPath, final String mimeTypeAbbreviation) { try {/*from ww w.j a va 2s. c o m*/ long currentTimeMillis = System.currentTimeMillis(); if (System.getProperty("os.name").startsWith("Windows")) { final String odtFilename = tempDirFullPath + "openofficeConversion-" + currentTimeMillis + ".odt"; FileUtils.writeByteArrayToFile(new File(odtFilename), odtContent); final Process process = Runtime.getRuntime() .exec(String.format("soffice --headless --convert-to %s --outdir %s %s", mimeTypeAbbreviation, tempDirFullPath.subSequence(0, tempDirFullPath.length() - 1), odtFilename)); try { process.waitFor(); } catch (InterruptedException e) { } process.destroy(); final String outputFilename = tempDirFullPath + "openofficeConversion-" + currentTimeMillis + "." + mimeTypeAbbreviation; final byte[] output = FileUtils.readFileToByteArray(new File(outputFilename)); FileUtils.deleteQuietly(new File(odtFilename)); FileUtils.deleteQuietly(new File(outputFilename)); return output; } else { final String odtFilename = tempDirFullPath + "/openofficeConversion-" + currentTimeMillis + ".odt"; FileUtils.writeByteArrayToFile(new File(odtFilename), odtContent); final Process process = Runtime.getRuntime() .exec(String.format( "soffice --headless --convert-to %s -env:UserInstallation=file://%s --outdir %s %s", mimeTypeAbbreviation, tempDirFullPath, tempDirFullPath, odtFilename)); try { process.waitFor(); } catch (InterruptedException e) { } process.destroy(); final String outputFilename = tempDirFullPath + "/openofficeConversion-" + currentTimeMillis + "." + mimeTypeAbbreviation; final byte[] output = FileUtils.readFileToByteArray(new File(outputFilename)); FileUtils.deleteQuietly(new File(odtFilename)); FileUtils.deleteQuietly(new File(outputFilename)); return output; } } catch (final Throwable e) { throw new OpenofficeInProcessConversionException(e); } }
From source file:net.nicholaswilliams.java.licensing.encryption.KeyFileUtilities.java
protected static void writeEncryptedPublicKey(PublicKey publicKey, File file, char[] passphrase) throws IOException { FileUtils.writeByteArrayToFile(file, KeyFileUtilities.writeEncryptedPublicKey(publicKey, passphrase)); }
From source file:files.FileStorage.java
public void saveFile(Long id, byte[] bytes) throws IOException { File newFile = new File(filePath + id); FileUtils.writeByteArrayToFile(newFile, bytes); }
From source file:fi.helsinki.opintoni.service.storage.FileService.java
public void writeByteArrayToFile(File file, byte[] bytes) throws IOException { FileUtils.writeByteArrayToFile(file, bytes); }