List of usage examples for org.apache.commons.io FileUtils openOutputStream
public static FileOutputStream openOutputStream(File file) throws IOException
From source file:org.coode.html.OntologyExporter.java
private static PrintWriter createPrintWriter(File file) throws IOException { return new PrintWriter(FileUtils.openOutputStream(file)); }
From source file:org.craftercms.commons.crypto.impl.SecretKeyRepositoryImpl.java
protected void storeKeyStore() throws CryptoException { try {/*from w w w . j av a 2s. co m*/ try (OutputStream out = FileUtils.openOutputStream(keyStoreFile)) { keyStore.store(out, keyStorePassword); } logger.debug(LOG_KEY_KEY_STORE_STORED, keyStoreFile); } catch (GeneralSecurityException | IOException e) { throw new CryptoException(ERROR_KEY_KEY_STORE_STORE_ERROR, e); } }
From source file:org.craftercms.commons.zip.ZipUtils.java
/** * Unzips a zip from an input stream into an output folder. * * @param inputStream the zip input stream * @param outputFolder the output folder where the files * @throws IOException/*w w w .j av a2 s . com*/ */ public static void unZipFiles(InputStream inputStream, File outputFolder) throws IOException { ZipInputStream zis = new ZipInputStream(inputStream); ZipEntry ze = zis.getNextEntry(); while (ze != null) { File file = new File(outputFolder, ze.getName()); OutputStream os = new BufferedOutputStream(FileUtils.openOutputStream(file)); try { IOUtils.copy(zis, os); } finally { IOUtils.closeQuietly(os); } zis.closeEntry(); ze = zis.getNextEntry(); } }
From source file:org.craftercms.cstudio.alfresco.preview.PreviewDeployer.java
protected void fileSystemDeploy(String path, InputStream content, Properties metaData) throws IOException { File file = new File(deployRoot, path); FileUtils.copyInputStreamToFile(content, file); if (metaData != null) { File metaDataFile = new File(metaDataRoot, path + METADATA_EXTENSION); OutputStream metaDataOutput = new BufferedOutputStream(FileUtils.openOutputStream(metaDataFile)); try {/*from w w w . ja v a 2s. com*/ metaData.store(metaDataOutput, null); } finally { try { metaDataOutput.close(); } catch (IOException e) { } } cachedMetaData.put(path, metaData); } }
From source file:org.craftercms.security.utils.crypto.KeyFile.java
/** * Writes the given key to the files through an {@link ObjectOutputStream}. *///from ww w . ja v a 2 s. c o m public void writeKey(Key key) throws IOException { ObjectOutputStream out = new ObjectOutputStream(FileUtils.openOutputStream(file)); try { out.writeObject(key); out.flush(); } finally { IOUtils.closeQuietly(out); } }
From source file:org.cubictest.ui.utils.WizardUtils.java
private static void copyFile(File destinationFolder, String fileName, String destFileName) throws IOException { File destFile = new File(destinationFolder.getAbsolutePath() + "/" + destFileName); InputStream in = WizardUtils.class.getResourceAsStream(fileName); OutputStream out = FileUtils.openOutputStream(destFile); IOUtils.copy(in, out);/*from w ww. ja v a 2 s . c om*/ IOUtils.closeQuietly(out); }
From source file:org.dataconservancy.archive.impl.elm.fs.FsEntityStore.java
public void put(String entityId, InputStream stream) { OutputStream out = null;/*from w w w . ja v a2s. c o m*/ try { out = FileUtils.openOutputStream(getFile(entityId)); IOUtils.copy(stream, out); } catch (Exception e) { throw new RuntimeException(e); } finally { try { out.close(); } catch (IOException e) { } try { stream.close(); } catch (IOException e) { } System.gc(); } }
From source file:org.dataconservancy.archive.impl.elm.fs.FsMetadata.java
public FsMetadata(File file, String id, String type, String src) { mdFile = file;/* ww w .j a v a 2 s . co m*/ OutputStream out = null; try { out = FileUtils.openOutputStream(mdFile); write(out, REL_SELF, type, id); if (src != null) { write(out, REL_SRC, "", src); } } catch (Exception e) { throw new RuntimeException("Error writing metadata file", e); } finally { if (out != null) { try { out.close(); } catch (IOException e) { } } } }
From source file:org.dataconservancy.dcs.access.server.MediciServiceImpl.java
@Override public int splitSip(String sipFilePath) { ResearchObject masterSip = null;/*from w w w . ja va 2 s .c o m*/ try { masterSip = new SeadXstreamStaxModelBuilder().buildSip(new FileInputStream(sipFilePath + ".xml")); } catch (InvalidXmlException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (FileNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } int i = 0; Collection<DcsFile> files = masterSip.getFiles(); fileNos = files.size(); if (fileNos > Constants.MAX) { if (i == 0) { //#1 Make a SIP out of all DUs sipNew.setDeliverableUnits(masterSip.getDeliverableUnits()); String sipFileName = sipFilePath + "_" + i + ".xml"; File sipFile = new File(sipFileName); OutputStream out; try { out = FileUtils.openOutputStream(sipFile); new DcsXstreamStaxModelBuilder().buildSip(sipNew, out); out.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } sipNew = new ResearchObject(); i++; } int fileCount = 0; // int totalMans =0 ; Map<String, DcsFile> idFileMap = new HashMap<String, DcsFile>(); for (DcsFile file : masterSip.getFiles()) { idFileMap.put(file.getId(), file); } for (DcsManifestation manifestation : masterSip.getManifestations()) { //If a manifestation contains more than the allowed maximum, we make an exception and allow all the files in the same package for the sake of simplicity if (manifestation.getManifestationFiles().size() > Constants.MAX) { ResearchObject sipTemp = new ResearchObject(); sipTemp.addManifestation(manifestation); for (DcsManifestationFile mFile : manifestation.getManifestationFiles()) sipTemp.addFile(idFileMap.get(mFile.getRef().getRef())); String sipFileName = sipFilePath + "_" + i + ".xml"; File sipFile = new File(sipFileName); OutputStream out; try { out = FileUtils.openOutputStream(sipFile); new SeadXstreamStaxModelBuilder().buildSip(sipTemp, out); out.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } i++; } else { //Otherwise we limit the number of files in a package to less than/equal to the MAX if (fileCount + manifestation.getManifestationFiles().size() > Constants.MAX) { String sipFileName = sipFilePath + "_" + i + ".xml"; File sipFile = new File(sipFileName); OutputStream out; try { out = FileUtils.openOutputStream(sipFile); new DcsXstreamStaxModelBuilder().buildSip(sipNew, out); out.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } sipNew = new ResearchObject(); fileCount = 0; i++; } sipNew.addManifestation(manifestation); for (DcsManifestationFile mFile : manifestation.getManifestationFiles()) sipNew.addFile(idFileMap.get(mFile.getRef().getRef())); fileCount += manifestation.getManifestationFiles().size(); } } String sipFileName = sipFilePath + "_" + i + ".xml"; File sipFile = new File(sipFileName); OutputStream out; try { out = FileUtils.openOutputStream(sipFile); new SeadXstreamStaxModelBuilder().buildSip(sipNew, out); out.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { String sipFileName = sipFilePath + "_" + i + ".xml"; File sipFile = new File(sipFileName); OutputStream out; try { out = FileUtils.openOutputStream(sipFile); new SeadXstreamStaxModelBuilder().buildSip(masterSip, out); out.close(); } catch (IOException e) { e.printStackTrace(); } } return i; }
From source file:org.dataconservancy.dcs.index.dcpsolr.SolrService.java
/** * Create a local Solr install in the given directory. * * @throws IOException/* www . ja v a 2 s . co m*/ */ public static void createSolrInstall(File solrhome) throws IOException { // Cannot list resources so have keep names here String[] filenames = new String[] { "elevate.xml", "mapping-ISOLatin1Accent.txt", "protwords.txt", "solrconfig.xml", "spellings.txt", "stopwords.txt", "synonyms.txt", "schema.xml" }; File confdir = new File(solrhome, "default/conf"); confdir.mkdirs(); for (String name : filenames) { OutputStream os = new FileOutputStream(new File(confdir, name)); InputStream is = SolrService.class.getResourceAsStream("default/conf/" + name); FileUtil.copy(is, os); is.close(); os.close(); } OutputStream os = FileUtils.openOutputStream(new File(solrhome, "solr.xml")); InputStream is = SolrService.class.getResourceAsStream("solr.xml"); FileUtil.copy(is, os); is.close(); os.close(); }