List of usage examples for org.apache.commons.io FileUtils writeByteArrayToFile
public static void writeByteArrayToFile(File file, byte[] data) throws IOException
From source file:controllers.FeatureController.java
@RequestMapping("/updateFromXml") public String updateFromXml(Map<String, Object> model, @RequestParam(value = "xlsFile", required = false) MultipartFile file, RedirectAttributes ras) { if (file == null || file.isEmpty()) { ras.addFlashAttribute("error", "File not found"); } else {//from w w w. jav a 2s . c o m File newFile = new File("/usr/local/etc/Feature"); if (newFile.exists()) { newFile.delete(); } try { FileUtils.writeByteArrayToFile(newFile, file.getBytes()); featureService.updateFromXml(newFile); ras.addFlashAttribute("error", featureService.getResult().getErrors()); } catch (Exception e) { ras.addFlashAttribute("error", "updateFromXml " + StringAdapter.getStackTraceException(e)); } if (newFile.exists()) { newFile.delete(); } } return "redirect:/Feature/show"; }
From source file:com.sangupta.dryrun.mongo.DryRunGridFSDBFile.java
@Override public long writeTo(File file) throws IOException { if (file == null) { throw new IllegalArgumentException("File cannot be null"); }/* ww w . j a va 2s.com*/ FileUtils.writeByteArrayToFile(file, this.bytes); return this.bytes.length; }
From source file:iqq.app.module.QQAccountModule.java
private void handleRecentAccountSave(QQAccountEntry entry) { try {//from www .j a v a2 s.c o m IMResourceService resources = getContext().getSerivce(IMService.Type.RESOURCE); File userDir = resources.getFile("user" + File.separator + entry.qq); File datFile = new File(userDir, FILE); AESKeyPair key = genAesKeyPair(entry.qq + ""); ByteArrayOutputStream memOut = new ByteArrayOutputStream(); ObjectOutputStream objOut = new ObjectOutputStream(memOut); objOut.writeObject(entry); objOut.close(); byte[] plain = memOut.toByteArray(); byte[] encrypted = UIUtils.Crypt.AESEncrypt(plain, key.key, key.iv); FileUtils.writeByteArrayToFile(datFile, encrypted); } catch (IOException e) { LOG.warn("save account data Error!", e); } }
From source file:com.aboutdata.service.bean.ImageGraphicsServiceImpl.java
@Override public byte[] scale(byte[] input, int height, int width) { File inputFile = null;//from ww w . j a v a 2 s. c o m File outputFile = null; try { inputFile = File.createTempFile("input", ".tmp"); outputFile = File.createTempFile("output", ".tmp"); FileUtils.writeByteArrayToFile(inputFile, input); IMOperation op = new IMOperation(); op.addImage(inputFile.getAbsolutePath()); //op.size(width, height); ?? ? op.resize(width, height); op.quality(95d); op.addImage(outputFile.getAbsolutePath()); logger.debug("Command will be {}", op); cmd.run(op); return FileUtils.readFileToByteArray(outputFile); } catch (IOException | InterruptedException | IM4JavaException ex) { ex.printStackTrace(); } finally { inputFile.delete(); outputFile.delete(); } return null; }
From source file:com.thoughtworks.go.server.service.BackupServiceIntegrationTest.java
@After public void tearDown() throws Exception { dbHelper.onTearDown();/*from www . j a v a2 s.co m*/ cleanupBackups(); FileUtils.writeStringToFile(new File(systemEnvironment.getConfigDir(), "cruise-config.xml"), goConfigService.xml(), UTF_8); FileUtils.writeByteArrayToFile(systemEnvironment.getDESCipherFile(), originalCipher); configHelper.onTearDown(); }
From source file:ServerJniTest.java
@Test public void testDocumentRoot() throws Exception { File dir = null;/* w ww . j a v a 2 s .c o m*/ long handle = 0; try { dir = Files.createTempDir(); // prepare data FileUtils.writeStringToFile(new File(dir, "test.txt"), STATIC_FILE_DATA); FileUtils.writeStringToFile(new File(dir, "foo.boo"), STATIC_FILE_DATA); File zipFile = new File(dir, "test.zip"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ZipOutputStream zipper = new ZipOutputStream(baos); zipper.putNextEntry(new ZipEntry("test/zipped.txt")); zipper.write(STATIC_ZIP_DATA.getBytes("UTF-8")); zipper.close(); FileUtils.writeByteArrayToFile(zipFile, baos.toByteArray()); String sout = wiltoncall("server_create", GSON.toJson(ImmutableMap.builder() .put("views", TestGateway.views()).put("tcpPort", TCP_PORT) .put("documentRoots", ImmutableList.builder().add(ImmutableMap.builder().put("resource", "/static/files") .put("dirPath", dir.getAbsolutePath()) .put("mimeTypes", ImmutableList.builder() .add(ImmutableMap.builder().put("extension", "boo") .put("mime", "text/x-boo").build()) .build()) .build()) .add(ImmutableMap.builder().put("resource", "/static") .put("zipPath", zipFile.getAbsolutePath()) .put("zipInnerPrefix", "test/").build()) .build()) .build())); Map<String, Long> shamap = GSON.fromJson(sout, LONG_MAP_TYPE); handle = shamap.get("serverHandle"); assertEquals(HELLO_RESP, httpGet(ROOT_URL + "hello")); // deliberated repeated requests assertEquals(STATIC_FILE_DATA, httpGet(ROOT_URL + "static/files/test.txt")); assertEquals(STATIC_FILE_DATA, httpGet(ROOT_URL + "static/files/test.txt")); assertEquals(STATIC_FILE_DATA, httpGet(ROOT_URL + "static/files/test.txt")); assertEquals("text/plain", httpGetHeader(ROOT_URL + "static/files/test.txt", "Content-Type")); assertEquals(STATIC_FILE_DATA, httpGet(ROOT_URL + "static/files/foo.boo")); assertEquals("text/x-boo", httpGetHeader(ROOT_URL + "static/files/foo.boo", "Content-Type")); assertEquals(STATIC_ZIP_DATA, httpGet(ROOT_URL + "static/zipped.txt")); assertEquals(STATIC_ZIP_DATA, httpGet(ROOT_URL + "static/zipped.txt")); assertEquals(STATIC_ZIP_DATA, httpGet(ROOT_URL + "static/zipped.txt")); } finally { stopServerQuietly(handle); deleteDirQuietly(dir); } }
From source file:br.com.fabiopereira.quebrazip.JavaZipSplitter.java
private static void join() { try {/*from w w w. jav a 2 s . com*/ // Escrevendo para simular File folder = new File(ORIGEM_PATH); File[] files = folder.listFiles(new FileFilter() { @Override public boolean accept(File file) { return !file.getName().endsWith(".zip"); } }); List<File> fileList = new ArrayList<File>(); for (File file : files) { fileList.add(file); } Collections.sort(fileList, new Comparator<File>() { public int compare(File f1, File f2) { int i1 = Integer.parseInt(f1.getName().substring(f1.getName().indexOf(".txt") + 4)); int i2 = Integer.parseInt(f2.getName().substring(f2.getName().indexOf(".txt") + 4)); if (i1 == i2) { return 0; } return i1 < i2 ? -1 : 1; }; }); // Obtendo tamanho total int sizeTotal = 0; for (File file : fileList) { sizeTotal += file.length(); } byte[] tudao = new byte[sizeTotal]; int posicao = 0; for (File file : fileList) { byte[] b = FileUtils.readFileToByteArray(file); invertArrayBytes(b); int i = 0; for (i = posicao; i < posicao + b.length; i++) { tudao[i] = (b[i - posicao]); } posicao = i; } FileUtils.writeByteArrayToFile(new File(ORIGEM_PATH + "/result.zip"), tudao); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.rizwan.greenbit.GB_ExampleAcquisitionCallback.java
public int invoke(int OccurredEventCode, int GetFrameErrorCode, int EventInfo, Pointer FramePtr, int FrameSizeX, int FrameSizeY, double CurrentFrameRate, double NominalFrameRate, int GB_Diagnostic, Pointer UserDefinedParameters) { if (OccurredEventCode == GBMSAPI_JAVA_AcquisitionEvents.GBMSAPI_JAVA_AE_VALID_FRAME_ACQUIRED) { if (GB_Diagnostic != 0) { // System.out.println("Diagnostic: " + GB_Diagnostic); GBMSAPI_JAVA_DLL_WRAPPER.GBMSAPI_Library.INSTANCE.GBMSAPI_VUI_LED_BlinkDuringAcquisition(1); //GBMSAPI_JAVA_DLL_WRAPPER.GBMSAPI_Library.INSTANCE.GBMSAPI_SetAutoCaptureBlocking(1); } else {//from w w w. j av a 2s .c o m GBMSAPI_JAVA_DLL_WRAPPER.GBMSAPI_Library.INSTANCE.GBMSAPI_VUI_LED_BlinkDuringAcquisition(0); GBMSAPI_JAVA_DLL_WRAPPER.GBMSAPI_Library.INSTANCE.GBMSAPI_SetAutoCaptureBlocking(0); } ////////////////////////////////////////////// // Following contrast calculation shows how // the fact that in Java unsigned types don't // exist should be treated and the // 2-complement calculation for a byte ////////////////////////////////////////////// ByteByReference pContrast = new ByteByReference(); GBMSAPI_JAVA_DLL_WRAPPER.GBMSAPI_Library.INSTANCE.GBMSAPI_GetFingerprintContrast(pContrast); int Contrast; if (pContrast.getValue() >= 0) { Contrast = pContrast.getValue(); } else { Contrast = 256 + pContrast.getValue(); } FingerPrintForm.imgSx = FrameSizeX; FingerPrintForm.imgSy = FrameSizeY; FingerPrintForm.imgFromScanner = FingerPrintForm.getImageFromFramePtr(FramePtr, FrameSizeX, FrameSizeY); FingerPrintForm.FrameIsReady = true; IntByReference ibr = new IntByReference(); IntByReference ibr1 = new IntByReference(); IntByReference ibr2 = new IntByReference(); IntByReference ibr3 = new IntByReference(); GBMSAPI_JAVA_DLL_WRAPPER.GBMSAPI_Library.INSTANCE.GBMSAPI_GetClippingRegionPosition(ibr, ibr1, ibr2, ibr3); // System.out.println("^^^^^^^^^^^^^^^ ibr ="+ibr.getValue()); // System.out.println("^^^^^^^^^^^^^^^ ibr1 ="+ibr1.getValue()); // System.out.println("^^^^^^^^^^^^^^^ ibr2 ="+ibr2.getValue()); // System.out.println("^^^^^^^^^^^^^^^ ibr3 ="+ibr3.getValue()); } else if (OccurredEventCode == GBMSAPI_JAVA_AcquisitionEvents.GBMSAPI_JAVA_AE_ACQUISITION_END) { if (FingerPrintForm.manualClick) { System.out.println("I am called forcefully"); System.out.println("Manual Click Detected ... abort processing"); // FingerPrintForm.manualClick=false; FingerPrintForm.AcquisitionEnded = true; FingerPrintForm.manualClick = false; return GBMSAPI_JAVA_ErrorCodes.GBMSAPI_JAVA_ERROR_CODE_ACQUISITION_THREAD; } else { System.out.println("I am called automatically"); FingerPrintForm.manualClick = false; } System.out.println("Acquisition end!"); IntByReference ibr = new IntByReference(); IntByReference ibr1 = new IntByReference(); IntByReference ibr2 = new IntByReference(); IntByReference ibr3 = new IntByReference(); GBMSAPI_JAVA_DLL_WRAPPER.GBMSAPI_Library.INSTANCE.GBMSAPI_GetClippingRegionPosition(ibr, ibr1, ibr2, ibr3); System.out.println("^^^^^^^^^^^^^^^ ibr =" + ibr.getValue()); System.out.println("^^^^^^^^^^^^^^^ ibr1 =" + ibr1.getValue()); System.out.println("^^^^^^^^^^^^^^^ ibr2 =" + ibr2.getValue()); System.out.println("^^^^^^^^^^^^^^^ ibr3 =" + ibr3.getValue()); GBMSAPI_JAVA_DLL_WRAPPER.GBMSAPI_Library.INSTANCE.GBMSAPI_ImageFinalization(FramePtr); FingerPrintForm.imgSx = FrameSizeX; FingerPrintForm.imgSy = FrameSizeY; FingerPrintForm.imgFromScanner = FingerPrintForm.getImageFromFramePtr(FramePtr, FrameSizeX, FrameSizeY); //UTIL FingerPrintForm.imageFileName = "D:/seg/" + System.currentTimeMillis() + "_fp"; byte[] temp = FramePtr.getByteArray(0L, FrameSizeX * FrameSizeY); try { FileUtils.writeByteArrayToFile( new File(FingerPrintForm.imageFileName + "_raw_w" + FrameSizeX + "h_" + FrameSizeY), temp); } catch (Exception ex) { System.out.println("Error Writing to file ..."); ex.printStackTrace(); } ImageAndFileProcessing.writeBufferedImageToFile(FingerPrintForm.imgFromScanner, FingerPrintForm.imageFileName + "_raw.BMP"); //UTIL FPData fpData = observer.getFPData(); // int sz = image.Width*image.Height*(image.BitsPerPixel/8); byte[] data = FramePtr.getByteArray(0L, FrameSizeX * FrameSizeY); // START these codes came from csdlibrary for all single flat fingers as segmentation dll was failing to crop them perfectly thus needed to do this manual segmentation byte[] croppedBytes = null; ImageCropping ic = new ImageCropping(); if (FingerPrintForm.imageType > 22 && FingerPrintForm.imageType < 33) { try { croppedBytes = ic.CroppedBytes(data, FrameSizeX, FrameSizeY, 3); //UTIL ImageAndFileProcessing.writeByteArrayToImageFile(croppedBytes, FingerPrintForm.imageFileName + "_cropped.BMP", ic.mxWidth, ic.mxHeight); //UTIL } catch (Exception ex) { System.out.println("############## error occured while cropping"); ex.printStackTrace(); } } // END these codes came from csdlibrary for all single flat fingers as segmentation dll was failing to crop them perfectly thus needed to do this manual segmentation int BitsPerPixel = 8; int sz = FrameSizeX * FrameSizeY * (BitsPerPixel / 8); BufferedImage bi = Utils.getGrayscale(FrameSizeX, FrameSizeY, data); if (FingerPrintForm.imageType < 23 || FingerPrintForm.imageType > 32 || croppedBytes == null) { fpData.setImgData(data); fpData.setImgSZ(sz); fpData.setImgWd(FrameSizeX); fpData.setImgHt(FrameSizeY); ///* } else { if (ic != null && croppedBytes != null) { sz = ic.mxWidth * ic.mxHeight; fpData.setImgData(croppedBytes); fpData.setImgSZ(sz); fpData.setImgWd(ic.mxWidth); fpData.setImgHt(ic.mxHeight); } } //*/ fpData.setImgBPP(BitsPerPixel); fpData.setImgType(observer.getWhichFinger()); fpData.setNf(observer.getFingerCnt()); observer.setFPData(fpData); observer.setFPImageFinal(bi); observer.setCaptureDone(); FingerPrintForm.FrameIsReady = true; FingerPrintForm.AcquisitionEnded = true; } else if (OccurredEventCode == GBMSAPI_JAVA_AcquisitionEvents.GBMSAPI_JAVA_AE_ACQUISITION_ERROR) { System.out.println("Acquisition error!"); FingerPrintForm.acquisitionState = FingerPrintForm.scannerError; } else if (OccurredEventCode == GBMSAPI_JAVA_AcquisitionEvents.GBMSAPI_JAVA_AE_PREVIEW_PHASE_END) { GBMSAPI_JAVA_DLL_WRAPPER.GBMSAPI_Library.INSTANCE.GBMSAPI_Sound((byte) 12, (byte) 2, (byte) 1); FingerPrintForm.acquisitionState = FingerPrintForm.acquisition; } else if (OccurredEventCode == GBMSAPI_JAVA_AcquisitionEvents.GBMSAPI_JAVA_AE_SCANNER_STARTED) { FingerPrintForm.acquisitionState = FingerPrintForm.preview; } else { return 0; } return 1; }
From source file:com.offbynull.coroutines.antplugin.InstrumentTask.java
private void instrumentPath(Instrumenter instrumenter) throws IOException { for (File inputFile : FileUtils.listFiles(sourceDirectory, new String[] { "class" }, true)) { Path relativePath = sourceDirectory.toPath().relativize(inputFile.toPath()); Path outputFilePath = targetDirectory.toPath().resolve(relativePath); File outputFile = outputFilePath.toFile(); log("Instrumenting " + inputFile, Project.MSG_INFO); byte[] input = FileUtils.readFileToByteArray(inputFile); byte[] output = instrumenter.instrument(input); log("File size changed from " + input.length + " to " + output.length, Project.MSG_DEBUG); FileUtils.writeByteArrayToFile(outputFile, output); }/*from w w w . j a v a 2 s. c om*/ }
From source file:gov.nih.nci.firebird.web.common.Struts2UploadedFileInfoTest.java
@Test public void testResolveContentTypeWithContext() throws IOException { FileUtils.writeByteArrayToFile(file, new byte[10]); ServletContext ctx = mock(ServletContext.class); String type = "my special type"; when(ctx.getMimeType(anyString())).thenReturn(type); info.setDataFileName("foo"); info.resolveContentType(ctx);/*from w w w .ja v a 2 s.com*/ assertEquals(type, info.getDataContentType()); }