List of usage examples for org.apache.commons.io FileUtils writeByteArrayToFile
public static void writeByteArrayToFile(File file, byte[] data) throws IOException
From source file:org.geoserver.wps.gs.download.DownloadAnimationProcessTest.java
@Test public void testAnimateTimestamped() throws Exception { String xml = IOUtils.toString(getClass().getResourceAsStream("animateBlueMarbleTimestamped.xml")); MockHttpServletResponse response = postAsServletResponse("wps", xml); assertEquals("video/mp4", response.getContentType()); // JCodec API works off files only... File testFile = new File("target/animateTimestamped.mp4"); FileUtils.writeByteArrayToFile(testFile, response.getContentAsByteArray()); // check frames and duration Format f = JCodecUtil.detectFormat(testFile); Demuxer d = JCodecUtil.createDemuxer(f, testFile); DemuxerTrack vt = d.getVideoTracks().get(0); DemuxerTrackMeta dtm = vt.getMeta(); assertEquals(4, dtm.getTotalFrames()); assertEquals(8, dtm.getTotalDuration(), 0d); // grab first frame for test FrameGrab grabber = FrameGrab.createFrameGrab(NIOUtils.readableChannel(testFile)); BufferedImage frame1 = AWTUtil.toBufferedImage(grabber.getNativeFrame()); ImageAssert.assertEquals(new File(SAMPLES + "animateBlueMarbleTimestampedFrame1.png"), frame1, 100); }
From source file:org.getspout.spout.packet.PacketCacheFile.java
public void run(int playerId) { this.fileName = FileUtil.getFileName(this.fileName); if (!FileUtil.canCache(fileName)) { System.out.println("WARNING, " + plugin + " tried to cache an invalid file type: " + fileName); return;//from w w w. j a va2s .co m } File directory = new File(FileUtil.getCacheDirectory(), plugin); if (!directory.exists()) { directory.mkdir(); } File cache = new File(directory, fileName); try { FileUtils.writeByteArrayToFile(cache, fileData); } catch (IOException e) { e.printStackTrace(); } long expectedCRC = CRCManager.getCRC(fileName); long calculatedCRC = FileUtil.getCRC(cache, new byte[16384]); if (expectedCRC != calculatedCRC) { System.out.println("WARNING, Downloaded File " + fileName + "'s CRC " + calculatedCRC + " did not match the expected CRC: " + expectedCRC); SpoutClient.getInstance().getPacketManager() .sendSpoutPacket(new PacketPreCacheFile(plugin, fileName, expectedCRC, false)); System.out.println("Requesting re-downloaded of File " + fileName); } else if (cache.exists() && FileUtil.isImageFile(fileName)) { CustomTextureManager.getTextureFromUrl(plugin, fileName); } ((EntityClientPlayerMP) Minecraft.theMinecraft.thePlayer).sendQueue.addToSendQueue(new Packet0KeepAlive()); }
From source file:org.gluu.oxtrust.ldap.service.ImageRepository.java
/** * Creates image in repository// w ww .j a v a 2 s . c om * * @param image * image file * @return true if image was added successfully, false otherwise * @throws Exception */ public boolean createRepositoryImageFiles(GluuImage image, int thumbWidth, int thumbHeight) throws Exception { if (image.getSourceContentType().equals("application/octet-stream")) { image.setSourceContentType(fileTypeMap.getContentType(image.getSourceName())); } if (!addThumbnail(image, thumbWidth, thumbHeight)) { return false; } // Generate paths setGeneratedImagePathes(image, Type.IMAGE_JPEG.getExtension()); // Create folders tree createImagePathes(image); // Save thumb image FileUtils.writeByteArrayToFile(getThumbFile(image), image.getThumbData()); // Save source image FileUtils.writeByteArrayToFile(getSourceFile(image), image.getData()); return true; }
From source file:org.gluu.oxtrust.ldap.service.ImageRepository.java
public boolean createRepositoryFaviconImageFiles(GluuImage image) throws Exception { if (!isIconImage(image)) { return false; }/*from w w w . j a v a 2 s . c o m*/ // Generate paths setGeneratedImagePathes(image, null); // Create folders tree createImagePathes(image); // Set source image size image.setWidth(16); image.setHeight(16); byte[] data = image.getData(); FileUtils.writeByteArrayToFile(getThumbFile(image), data); // Save source image FileUtils.writeByteArrayToFile(getSourceFile(image), data); return true; }
From source file:org.hobbit.spatiotemporalbenchmark.platformConnection.systems.LogMapSystemAdapter.java
@Override public void receiveGeneratedData(byte[] data) { LOGGER.info("Starting receiveGeneratedData.."); ByteBuffer dataBuffer = ByteBuffer.wrap(data); // read the file path dataFormat = RabbitMQUtils.readString(dataBuffer); receivedGeneratedDataFilePath = RabbitMQUtils.readString(dataBuffer); byte[] receivedGeneratedData = RabbitMQUtils.readByteArray(dataBuffer); try {/*from w w w .j a va2 s . com*/ FileUtils.writeByteArrayToFile(new File(receivedGeneratedDataFilePath), receivedGeneratedData); } catch (IOException ex) { java.util.logging.Logger.getLogger(LogMapSystemAdapter.class.getName()).log(Level.SEVERE, null, ex); } LOGGER.info("Received data from receiveGeneratedData.."); }
From source file:org.hobbit.spatiotemporalbenchmark.platformConnection.systems.LogMapSystemAdapter.java
@Override public void receiveGeneratedTask(String taskId, byte[] data) { LOGGER.info("Starting receiveGeneratedTask.."); LOGGER.info("Task " + taskId + " received from task generator"); try {/*from ww w . j ava2s . co m*/ ByteBuffer taskBuffer = ByteBuffer.wrap(data); // // read the relation // String taskRelation = RabbitMQUtils.readString(taskBuffer); // LOGGER.info("taskRelation " + taskRelation); // read the file path taskFormat = RabbitMQUtils.readString(taskBuffer); String receivedGeneratedTaskFilePath = RabbitMQUtils.readString(taskBuffer); byte[] receivedGeneratedTask = RabbitMQUtils.readByteArray(taskBuffer); FileUtils.writeByteArrayToFile(new File(receivedGeneratedTaskFilePath), receivedGeneratedTask); LOGGER.info("Received task from receiveGeneratedTask.."); linkingController(receivedGeneratedDataFilePath, receivedGeneratedTaskFilePath); byte[][] resultsArray = new byte[1][]; resultsArray[0] = FileUtils.readFileToByteArray(resultsFile); byte[] results = RabbitMQUtils.writeByteArrays(resultsArray); try { sendResultToEvalStorage(taskId, results); LOGGER.info("Results sent to evaluation storage."); } catch (IOException e) { LOGGER.error("Exception while sending storage space cost to evaluation storage.", e); } } catch (IOException ex) { java.util.logging.Logger.getLogger(LogMapSystemAdapter.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:org.ikasan.component.endpoint.filesystem.producer.FileProducer.java
/** * Write the payload to the file based on the incoming payload type. * @param file/* w w w . j a v a2s. co m*/ * @param payload * @throws IOException */ protected void writeFile(File file, Object payload) throws IOException { if (payload instanceof String) { FileUtils.writeStringToFile(file, (String) payload, configuration.getEncoding()); } else if (payload instanceof byte[]) { FileUtils.writeByteArrayToFile(file, (byte[]) payload); } if (payload instanceof Collection) { if (configuration.getLineEnding() != null) { FileUtils.writeLines(file, (Collection) payload, configuration.getLineEnding()); } else { FileUtils.writeLines(file, (Collection) payload); } } }
From source file:org.iso.mpeg.dash.crypto.ContentProtectionMpegDashSea.java
/** * This constructor is used to generate a new instance of baseline content protection * TODO clean up this function, 'cause, damn * // w w w .j av a 2 s. c o m * @param contentProtectionNode * @throws DashCryptoException */ ContentProtectionMpegDashSea(RepresentationType representation, long segmentStartNum) throws DashCryptoException { super(CONTENT_PROTECTION_SCHEME_ID_URI, segmentStartNum, representation); KeySystem baselineKeySys = new KeySystemBaselineHttp(this); keySystems.add(baselineKeySys); segmentEncryption = new SegmentEncryptionAES128CBC(); // generate a random key to /tmp/key????????.bin SecureRandom secRnd = new SecureRandom(); String keyPath = "/tmp/key" + Integer.toString(10000000 + secRnd.nextInt(90000000)) + ".bin"; File keyFile = new File(keyPath); if (keyFile.exists()) throw new DashCryptoException("Error - key file " + keyPath + " already exists"); byte[] keyBytes = new byte[16]; secRnd.nextBytes(keyBytes); try { FileUtils.writeByteArrayToFile(keyFile, keyBytes); } catch (IOException e) { throw new DashCryptoException(e); } // // generate a random IV // byte[] ivBytes = new byte[16]; // secRnd.nextBytes(ivBytes); // create a single CryptoTimeline, covering all segments, including path to random key and implicit IV int numCryptoPeriods = representation.getSegmentList().getSegmentURLs().size(), numSegmentsPerCryptoPeriod = 1; if (numCryptoPeriods % 2 == 0) { // if even number of segments, have 2-seg cryptoperiods numCryptoPeriods /= 2; numSegmentsPerCryptoPeriod *= 2; } CryptoTimeline cryptoTimeline = new CryptoTimeline(keyPath, this, numCryptoPeriods); cryptoTimeline.setNumSegments(numSegmentsPerCryptoPeriod); // one or two segments per cryptoperiod // cryptoTimeline.setIV(ivBytes); cryptoPeriods.add(cryptoTimeline); preAssignSegmentsToCryptoPeriods(); // parse internal structure to descriptor (or should we do so lazily?) contentProtectionDescriptor = generateContentProtectionDescriptor(); }
From source file:org.jacorb.test.orb.AnyTest.java
@Test public void test_float_stream_serialize() throws Exception { File target = folder.newFile("foo"); short testValue = (short) 4711; Any outAny = setup.getClientOrb().create_any(); outAny.insert_short(testValue); assertEquals(testValue, outAny.extract_short()); TypeCode t1 = outAny.type();// w ww .ja va2s .c om OutputStream s = setup.getClientOrb().create_output_stream(); s.write_any(outAny); InputStream i = s.create_input_stream(); Any inAny = i.read_any(); assertEquals(testValue, inAny.extract_short()); assertTrue(outAny.equal(inAny)); FileUtils.writeByteArrayToFile(target, ((CDROutputStream) s).getBufferCopy()); assertTrue(FileUtils.sizeOf(target) > 0); byte[] messageByte = FileUtils.readFileToByteArray(target); i = new org.jacorb.orb.CDRInputStream(setup.getClientOrb(), messageByte); inAny = i.read_any(); assertEquals(testValue, inAny.extract_short()); assertTrue(outAny.equal(inAny)); }
From source file:org.jboss.arquillian.drone.webdriver.factory.remote.reusable.ReusedSessionPermanentFileStorage.java
private void writeStore(File file, byte[] data) throws IOException { if (Validate.writeable(file)) { FileUtils.writeByteArrayToFile(file, data); return;//from w w w . j a v a 2 s .c o m } log.severe("Reused session store cannot be persisted to file, session reuse will not work"); }