List of usage examples for org.apache.commons.io FileUtils writeByteArrayToFile
public static void writeByteArrayToFile(File file, byte[] data) throws IOException
From source file:com.mvdb.etl.dao.impl.JdbcGenericDAO.java
private boolean writeDataHeader(DataHeader dataHeader, String objectName, File snapshotDirectory) { try {/*from www .j a va 2 s. c o m*/ snapshotDirectory.mkdirs(); String headerFileName = "header-" + objectName + ".dat"; File headerFile = new File(snapshotDirectory, headerFileName); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(dataHeader); FileUtils.writeByteArrayToFile(headerFile, baos.toByteArray()); return true; } catch (Throwable t) { t.printStackTrace(); return false; } }
From source file:com.cprassoc.solr.auth.model.HistoryVersion.java
public String saveVersion(String title, String description, SecurityJson json) { String uuid = UUID.randomUUID().toString(); try {/* w ww . j ava2s .c o m*/ JSONObject obj = new JSONObject(); obj.put("key", uuid); obj.put("title", title); obj.put("description", description); obj.put("data", json.export()); obj.put("date", new Date().toString()); File file = new File(historyDir.getAbsolutePath() + File.separator + uuid + ".json"); FileUtils.writeByteArrayToFile(file, obj.toString().getBytes()); } catch (Exception e) { e.printStackTrace(); uuid = null; } return uuid; }
From source file:info.joseluismartin.gtc.AbstractTileCache.java
/** * Write tile to disk cache// w ww . j a v a 2 s .c o m * @param tile tile to store * @throws IOException on write faliure */ public void storeTile(Tile tile) throws IOException { if (tile.isEmpty()) { log.info("Avoid to store empty tile on chache: " + tile.toString()); return; } File file = new File(getCachePath(tile)); FileUtils.writeByteArrayToFile(file, tile.getImage()); tileMap.put(tile.getKey(), tile); }
From source file:com.sap.hana.cloud.samples.jenkins.storage.FileStorageTest.java
private void makeConfigurationExisting(final byte[] data) throws IOException { final File configFile = tempDir.newFile("configuration.zip"); FileUtils.writeByteArrayToFile(configFile, data); }
From source file:com.joyent.manta.client.crypto.SecretKeyUtilsTest.java
public void canLoadKeyFromFilePath() throws IOException { File file = File.createTempFile("ciphertext-", ".data"); FileUtils.forceDeleteOnExit(file);//from w w w . j a v a2 s . c om FileUtils.writeByteArrayToFile(file, keyBytes); Path path = file.toPath(); SecretKey expected = SecretKeyUtils.loadKey(keyBytes, AesGcmCipherDetails.INSTANCE_128_BIT); SecretKey actual = SecretKeyUtils.loadKeyFromPath(path, AesGcmCipherDetails.INSTANCE_128_BIT); Assert.assertEquals(actual.getAlgorithm(), expected.getAlgorithm()); Assert.assertTrue(Arrays.equals(expected.getEncoded(), actual.getEncoded()), "Secret key loaded from URI doesn't match"); }
From source file:backtype.storm.utils.LocalState.java
private void persist(Map<Object, Object> val, boolean cleanup) throws IOException { byte[] toWrite = Utils.serialize(val); String newPath = _vs.createVersion(); FileUtils.writeByteArrayToFile(new File(newPath), toWrite); _vs.succeedVersion(newPath);/*from ww w . j a v a2 s . c o m*/ if (cleanup) _vs.cleanup(4); }
From source file:com.casker.portfolio.service.PortfolioServiceImpl.java
/** * @param portfolio/*from w w w . j a v a 2s . com*/ */ private void saveImageFile(String fileName, MultipartFile multipartFile) { File file = new File(filePath + File.separator + fileName); if (multipartFile == null || file.isDirectory()) { return; } try { FileUtils.writeByteArrayToFile(file, multipartFile.getBytes()); } catch (IOException e) { throw new RuntimeException("Unable to save image", e); } }
From source file:cpcc.core.utils.PngImageStreamResponseTest.java
@Test public void shouldStreamGivenFile() throws IOException { byte[] imageData = new byte[] { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 }; File file = File.createTempFile("random", "png"); FileUtils.writeByteArrayToFile(file, imageData); PngImageStreamResponse response = new PngImageStreamResponse(file); assertThat(response.getStream()).isNotNull(); byte[] actual = IOUtils.toByteArray(response.getStream()); assertThat(actual).isEqualTo(imageData); assertThat(response.getStream().read()).isEqualTo(-1); response.getStream().close();/*from w w w .ja va 2 s. co m*/ file.delete(); }
From source file:net.rptools.lib.image.ThumbnailManager.java
private Image createThumbnail(File file) throws IOException { // Gather info File thumbnailFile = getThumbnailFile(file); if (thumbnailFile.exists()) { return ImageUtil.getImage(thumbnailFile); }//from ww w .j a v a 2s .c o m Image image = ImageUtil.getImage(file); Dimension imgSize = new Dimension(image.getWidth(null), image.getHeight(null)); // Test if we Should we bother making a thumbnail ? // Jamz: New size 100k (was 30k) and put in check so we're not creating thumbnails LARGER than the original... if (file.length() < 102400 || (imgSize.width <= thumbnailSize.width && imgSize.height <= thumbnailSize.height)) { return image; } // Transform the image SwingUtil.constrainTo(imgSize, Math.min(image.getWidth(null), thumbnailSize.width), Math.min(image.getHeight(null), thumbnailSize.height)); BufferedImage thumbnailImage = new BufferedImage(imgSize.width, imgSize.height, ImageUtil.pickBestTransparency(image)); Graphics2D g = thumbnailImage.createGraphics(); g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g.drawImage(image, 0, 0, imgSize.width, imgSize.height, null); g.dispose(); // Use png to preserve transparency FileUtils.writeByteArrayToFile(thumbnailFile, ImageUtil.imageToBytes(thumbnailImage, "png")); return thumbnailImage; }
From source file:net.ripe.rpki.validator.output.ValidatedObjectWriter.java
@Override public void afterFetchSuccess(URI uri, CertificateRepositoryObject object, ValidationResult result) { File destinationFile = uriToFileMapper.map(uri, result); Validate.notNull(destinationFile, "uri could not be mapped to file"); try {/*from www . java 2 s .c o m*/ if (destinationFile.exists()) { LOG.error("destination file '" + destinationFile.getAbsolutePath() + "' already exists, validated object not stored"); } else { FileUtils.writeByteArrayToFile(destinationFile, object.getEncoded()); } } catch (IOException e) { LOG.error("error writing validated object to file '" + destinationFile.getAbsolutePath() + "'"); } }