List of usage examples for org.apache.commons.io FileUtils writeByteArrayToFile
public static void writeByteArrayToFile(File file, byte[] data) throws IOException
From source file:de.micromata.tpsb.doc.renderer.VelocityRenderer.java
public void save(byte[] data, ParserConfig cfg, String filename) { try {/*from w w w . j av a 2 s . c o m*/ String fName = new File(new File(cfg.getOutputDir()), filename).getAbsolutePath(); if (fName.endsWith(getFileExtension()) == false) { fName = fName + "." + getFileExtension(); } log.info("Schreibe Datei: " + fName); File file = new File(fName); FileUtils.writeByteArrayToFile(file, data); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.artglorin.web.utils.ResourcesHelper.java
/** * ? ?? ./*from ww w .j ava2 s . c o m*/ * ? * * @param data ?? , ?. * @param path ? . ??, . ? * ?, ? ? ? ?. ? ? ?? ? * ["data","file",".txt"], ? "/pathToResources/data/file.txt". * ? ?? ["data","file.txt"] ? "/data/file.txt", * ? "/pathToResources/data/file.txt" * @throws IOException */ public void saveData(byte[] data, String... path) throws IOException { if (path.length == 0) { throw new IOException("Path cannot be null"); } Path file = createRealPath(path); String[] filePath = null; if (file.toFile().exists()) { FileUtils.writeByteArrayToFile(file.toFile(), data); } else { if (path.length > 1) { if (path[path.length - 1].startsWith(".")) { filePath = Arrays.copyOf(path, path.length - 2); } } } if (filePath == null) { filePath = Arrays.copyOf(path, path.length - 1); } createResourcesDirectory(filePath); FileUtils.writeByteArrayToFile(file.toFile(), data); }
From source file:edu.umn.msi.tropix.common.io.FileUtilsImpl.java
public void writeByteArrayToFile(final File file, final byte[] contents) { try {/* w ww. j a va 2 s.c o m*/ FileUtils.writeByteArrayToFile(file, contents); } catch (final IOException e) { throw new IORuntimeException(e); } }
From source file:com.mvdb.etl.dao.impl.JdbcGenericDAO.java
private boolean writeMetadata(Metadata metadata, File snapshotDirectory) { try {/*w w w. j av a 2 s .com*/ String structFileName = "schema-" + metadata.getTableName() + ".dat"; snapshotDirectory.mkdirs(); File structFile = new File(snapshotDirectory, structFileName); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(metadata); oos.flush(); FileUtils.writeByteArrayToFile(structFile, baos.toByteArray()); return true; } catch (Throwable t) { t.printStackTrace(); return false; } }
From source file:com.thoughtworks.go.server.service.BackupServiceH2IntegrationTest.java
@After public void tearDown() throws Exception { dbHelper.onTearDown();/* w ww .jav a 2 s. co m*/ FileUtils.writeStringToFile(new File(systemEnvironment.getConfigDir(), "cruise-config.xml"), goConfigService.xml(), UTF_8); FileUtils.writeByteArrayToFile(systemEnvironment.getDESCipherFile(), originalCipher); configHelper.onTearDown(); FileUtils.deleteQuietly(backupsDirectory); }
From source file:glluch.com.ontotaxoseeker.TestsGen.java
public void testTermsResults() throws IOException, FileNotFoundException, ClassNotFoundException { Terms ts = (Terms) TestsGen.load("resources/test/Terms.ser"); ArrayList<Term> terms = ts.terms(); Iterator iter = terms.iterator(); ArrayList<String> lemas = new ArrayList<>(); while (iter.hasNext()) { Term next = (Term) iter.next();/* www . jav a 2s . c o m*/ lemas.add(next.getLema()); } File target = new File("resources/test/testTermsResults.bin"); byte[] vs = SerializationUtils.serialize(lemas); FileUtils.writeByteArrayToFile(target, vs); }
From source file:net.nicholaswilliams.java.licensing.encryption.TestFilePublicKeyDataProvider.java
@Test public void testGetEncryptedPublicKeyData03() throws IOException { final String fileName = "testGetEncryptedPublicKeyData03.key"; File file = new File(fileName); if (file.exists()) FileUtils.forceDelete(file);// ww w. j a v a2 s . c om byte[] data = new byte[] { 0x01, 0x71, 0x33 }; FileUtils.writeByteArrayToFile(file, data); try { FilePublicKeyDataProvider provider = new FilePublicKeyDataProvider(file); byte[] returnedData = provider.getEncryptedPublicKeyData(); assertNotNull("The data should not be null.", returnedData); assertArrayEquals("The data is not correct.", data, returnedData); } finally { FileUtils.forceDelete(file); } }
From source file:com.iyonger.apm.web.model.AgentManager.java
/** * Initialize agent manager./* www.j a v a2 s. c o m*/ */ @PostConstruct public void init() { int port = config.getControllerPort(); ConsoleCommunicationSetting consoleCommunicationSetting = ConsoleCommunicationSetting.asDefault(); if (config.getInactiveClientTimeOut() > 0) { consoleCommunicationSetting.setInactiveClientTimeOut(config.getInactiveClientTimeOut()); } agentControllerServerDaemon = new AgentControllerServerDaemon(config.getCurrentIP(), port, consoleCommunicationSetting); agentControllerServerDaemon.start(); agentControllerServerDaemon.setAgentDownloadRequestListener(this); agentControllerServerDaemon.addLogArrivedListener(new LogArrivedListener() { @Override public void logArrived(String testId, AgentAddress agentAddress, byte[] logs) { AgentControllerIdentityImplementation agentIdentity = convert(agentAddress.getIdentity()); if (ArrayUtils.isEmpty(logs)) { LOGGER.error("Log is arrived from {} but no log content", agentIdentity.getIp()); } File logFile = null; try { logFile = new File(config.getHome().getPerfTestLogDirectory(testId.replace("test_", "")), agentIdentity.getName() + "-" + agentIdentity.getRegion() + "-log.zip"); FileUtils.writeByteArrayToFile(logFile, logs); } catch (IOException e) { LOGGER.error("Error while write logs from {} to {}", agentAddress.getIdentity().getName(), logFile.getAbsolutePath()); LOGGER.error("Error is following", e); } } }); }
From source file:de.knurt.fam.test.unit.util.LetterTest.java
@Test public void writeTermsToFile() throws URIException { LetterGeneratorShowLetter genera = new LetterGeneratorShowLetter(); User target = UserFactory.getInstance().getJoeBloggs(); // TODO raus - mpi spezifisch target.addCustomField("principal_investigator_title_id_unknown", "Mr."); target.addCustomField("principal_investigator_fname_id_unknown", "Peter"); target.addCustomField("principal_investigator_sname_id_unknown", "Investigator"); target.addCustomField("taskdesc_id_unknown", "My task is to foo, but we need nearly 80 characters here, more foo to test and we have more then 80 - future save!"); target.setIntendedResearch(this.getIndendedResearchCharsLong(500)); target.addCustomField("hasRights", ""); target.addCustomField("trademarkrights_id_unknown", "My trademark is named foo, and we do not expect longer names here"); target.addCustomField("principal_investigator_issecret_id_unknown", "1"); target.addCustomField("partner_id_unknown", "Der Partner stellt zur Verfgung: Foo und Bar"); String customid = target.getUsername() + "-terms"; PostMethod post = new FamServicePDFResolver().process(genera.getTermsLetterStyle(target, customid)); assertEquals(post.getStatusCode() + "@" + post.getURI(), post.getStatusCode(), 200); String checkFileName = System.getProperty("java.io.tmpdir") + "/test-terms.pdf"; File checkFile = new File(checkFileName); if (checkFile.exists()) checkFile.delete();// w w w .j a va 2 s. co m try { checkFile.createNewFile(); FileUtils.writeByteArrayToFile(checkFile, post.getResponseBody()); assertTrue(checkFile.length() > 1042); System.out.println("find the result in " + checkFile); } catch (Exception e) { fail("should not throw " + e + ". file closed on idiot windows?"); } }
From source file:net.instantcom.mm7.DeliverReqTest.java
@Test public void readCaiXinDatafromHW() throws IOException, MM7Error { String ct = "multipart/related; boundary=\"--NextPart_0_9094_20600\"; type=text/xml"; InputStream in = DeliverReq.class.getResourceAsStream("caixin.txt"); DeliverReq req = (DeliverReq) MM7Response.load(in, ct, new MM7Context()); DefaultHttpClient httpclient = new DefaultHttpClient(); HttpPost post = null;//from w w w . j av a 2 s. c o m try { post = new HttpPost("http://127.0.0.1:8081/mm7serv/10085receiver"); //post = new HttpPost("http://42.96.185.95:8765"); post.addHeader("Content-Type", req.getSoapContentType()); post.addHeader("SOAPAction", ""); ByteArrayOutputStream byteos = new ByteArrayOutputStream(); MM7Message.save(req, byteos, new MM7Context()); post.setEntity(new ByteArrayEntity(byteos.toByteArray())); HttpResponse resp = httpclient.execute(post); HttpEntity entity = resp.getEntity(); String message = EntityUtils.toString(entity, "utf-8"); System.out.println(message); } catch (Exception e) { } finally { if (post != null) post.releaseConnection(); } for (Content c : req.getContent()) { ContentType ctype = new ContentType(c.getContentType()); if (ctype.getPrimaryType().equals("image")) { BinaryContent image = (BinaryContent) c; String fileName = DeliverReq.class.getResource("caixin.txt").getFile() + ".jpg"; System.out.println(fileName); Base64 base64 = new Base64(); FileUtils.writeByteArrayToFile(new File(fileName), base64.encode(image.getData())); } } ByteArrayOutputStream byteos = new ByteArrayOutputStream(); MM7Message.save(req, byteos, new MM7Context()); req = (DeliverReq) MM7Response.load(new ByteArrayInputStream(byteos.toByteArray()), req.getSoapContentType(), new MM7Context()); assertEquals("+8618703815655", req.getSender().toString()); }