List of usage examples for org.apache.commons.io FileUtils openOutputStream
public static FileOutputStream openOutputStream(File file) throws IOException
From source file:de.smartics.maven.plugin.jboss.modules.index.Indexer.java
/** * Writes the index./*from w w w .j ava 2 s .c o m*/ * * @throws MojoExecutionException on any problem writing the file. */ public void writeIndex() throws MojoExecutionException { final File indexFile = new File(outputDirectory, "META-INF/INDEX.LIST"); indexFile.getParentFile().mkdirs(); PrintWriter writer = null; try { writer = new PrintWriter(new OutputStreamWriter(FileUtils.openOutputStream(indexFile), "UTF-8")); for (final String fileName : fileNames) { writer.append(fileName).append('\n'); } } catch (final IOException e) { throw new MojoExecutionException( String.format("Cannot write index file '%s'.", indexFile.getAbsoluteFile()), e); } finally { IOUtils.closeQuietly(writer); } }
From source file:by.zuyeu.deyestracker.core.util.OpenCVLibraryLoader.java
private void loadLibrary() throws DEyesTrackerException { LOG.info("loadLibrary() - start;"); try {/*w w w . ja v a2s .co m*/ final Properties properties = loadProperties(); final String rootPath = getRootPath(); InputStream in = null; File fileOut = null; final String osName = System.getProperty("os.name"); LOG.info("rootPath = {}, osName = {}", rootPath, osName); if (osName.startsWith("Windows")) { int bitness = Integer.parseInt(System.getProperty("sun.arch.data.model")); if (bitness == 32) { LOG.info("bit = {}", "32 bit detected"); in = new FileInputStream(new File(rootPath + properties.getProperty(OPENCVX86_JAVADLL))); fileOut = File.createTempFile("lib", ".dll"); } else if (bitness == 64) { LOG.info("bit = {}", "64 bit detected"); in = new FileInputStream(new File(rootPath + properties.getProperty(OPENCVX64_JAVADLL))); fileOut = File.createTempFile("lib", ".dll"); } else { LOG.info("bit = {}", "Unknown bit detected - trying with 32 bit"); in = new FileInputStream(new File(rootPath + properties.getProperty(OPENCVX86_JAVADLL))); fileOut = File.createTempFile("lib", ".dll"); } } else if (osName.equals("Mac OS X")) { in = new FileInputStream(new File(rootPath + properties.getProperty(OPENCVMAC_JAVADYLIB))); fileOut = File.createTempFile("lib", ".dylib"); } OutputStream out = FileUtils.openOutputStream(fileOut); IOUtils.copy(in, out); in.close(); out.close(); System.load(fileOut.toString()); } catch (NumberFormatException | IOException e) { LOG.error("loadLibrary", e); throw new DEyesTrackerException(DEyesTrackerExceptionCode.CORE_INIT_FAILURE, "Failed to load opencv native library", e); } LOG.info("loadLibrary() - end;"); }
From source file:dotaSoundEditor.Helpers.PortraitFinder.java
private void buildItemPortraits(VPKArchive vpk) { BufferedImage image = null;/* w ww. ja va2 s .c o m*/ for (VPKEntry entry : vpk.getEntriesForDir("resource/flash3/images/items/")) { if (entry.getType().equals("png")) { File imageFile = new File(entry.getPath()); try (FileChannel fc = FileUtils.openOutputStream(imageFile).getChannel()) { fc.write(entry.getData()); image = ImageIO.read(imageFile); String item = entry.getName(); portraitMap.put(item, image); } catch (IOException ex) { System.err.println("Can't write " + entry.getPath() + ": " + ex.getMessage()); } } } }
From source file:com.buddycloud.mediaserver.download.DownloadImageTest.java
@Test public void downloadImage() throws Exception { ClientResource client = new ClientResource(URL); client.setChallengeResponse(ChallengeScheme.HTTP_BASIC, BASE_USER, BASE_TOKEN); File file = new File(TEST_OUTPUT_DIR + File.separator + "downloaded.jpg"); FileOutputStream outputStream = FileUtils.openOutputStream(file); client.get().write(outputStream);/*from www . ja v a 2 s . c om*/ Assert.assertTrue(file.exists()); // Delete downloaded file FileUtils.deleteDirectory(new File(TEST_OUTPUT_DIR)); outputStream.close(); }
From source file:com.buddycloud.mediaserver.download.DownloadVideoTest.java
@Test public void downloadVideo() throws Exception { ClientResource client = new ClientResource(URL); client.setChallengeResponse(ChallengeScheme.HTTP_BASIC, BASE_USER, BASE_TOKEN); File file = new File(TEST_OUTPUT_DIR + File.separator + "downloaded.avi"); FileOutputStream outputStream = FileUtils.openOutputStream(file); client.get().write(outputStream);//from w ww . j a v a 2 s .co m Assert.assertTrue(file.exists()); // Delete downloaded file FileUtils.deleteDirectory(new File(TEST_OUTPUT_DIR)); outputStream.close(); }
From source file:com.textocat.textokit.morph.ruscorpora.DictionaryAligningTagMapper.java
@Override public void initialize(UimaContext ctx) throws ResourceInitializationException { ExternalResourceInitializer.initialize(this, ctx); ConfigurationParameterInitializer.initialize(this, ctx); dict = dictHolder.getDictionary();//from ww w.ja v a 2 s. co m gm = dict.getGramModel(); try { FileOutputStream os = FileUtils.openOutputStream(outFile); Writer bw = new BufferedWriter(new OutputStreamWriter(os, "utf-8")); out = new PrintWriter(bw); } catch (IOException e) { throw new ResourceInitializationException(e); } }
From source file:de.pawlidi.openaletheia.license.LicenseGenerator.java
/** * Store properties to file with given file name and file description. * //from w ww .j av a2s . co m * @param fileName * @param description * @throws LicenseException */ public void storeLicense(final String fileName, final String description) throws LicenseException { if (properties.isEmpty()) { return; } OutputStream outputStream; try { outputStream = FileUtils.openOutputStream(new File(fileName)); } catch (IOException openOutputStreamException) { throw new LicenseException("Could not write license information to file " + fileName); } try { properties.store(outputStream, description); outputStream.flush(); } catch (IOException e) { e.printStackTrace(); } finally { if (outputStream != null) { try { outputStream.close(); } catch (IOException e) { e.printStackTrace(); } } } }
From source file:mpimp.assemblxweb.util.ProtocolWriter.java
public void writeProtocolToFile() throws IOException { String resultFileName = model_.getOperator().getLogin() + "_AssemblyProtocols.xlsx"; String resultDirectoryName = AssemblXWebProperties.getInstance().getProperty("resultDirectory"); String protocolFilePath = model_.getWorkingDirectory() + File.separator + resultDirectoryName + File.separator + resultFileName; OutputStream outputStream = FileUtils.openOutputStream(new File(protocolFilePath)); workbook_.write(outputStream);/*from w ww.ja v a 2 s . c om*/ }
From source file:com.buddycloud.mediaserver.download.DownloadAvatarTest.java
@Test public void anonymousSuccessfulDownload() throws Exception { ClientResource client = new ClientResource(URL); client.setChallengeResponse(ChallengeScheme.HTTP_BASIC, BASE_USER, BASE_TOKEN); File file = new File(TEST_OUTPUT_DIR + File.separator + "downloadedAvatar.jpg"); FileOutputStream outputStream = FileUtils.openOutputStream(file); client.get().write(outputStream);// w w w . jav a 2 s .c o m Assert.assertTrue(file.exists()); // Delete downloaded file FileUtils.deleteDirectory(new File(TEST_OUTPUT_DIR)); outputStream.close(); }
From source file:com.textocat.textokit.postagger.DictionaryComplianceChecker.java
@Override public void initialize(UimaContext ctx) throws ResourceInitializationException { super.initialize(ctx); dict = dictHolder.getDictionary();//from w ww . j a v a 2 s.c o m gramModel = dict.getGramModel(); posTrimmer = new PosTrimmer(dict.getGramModel(), targetPosCategories); try { FileOutputStream os = FileUtils.openOutputStream(outFile); out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(os, "utf-8")), true); // write header out.println("Word\tGrams_diff\tCorpus_grams\tDict_grams"); } catch (IOException e) { throw new ResourceInitializationException(e); } }