List of usage examples for org.apache.commons.compress.archivers.tar TarArchiveOutputStream setLongFileMode
public void setLongFileMode(int longFileMode)
From source file:lk.score.androphsy.main.NewCase.java
private void compressFiles(ArrayList<File> list, File outFile) throws IOException { FileOutputStream fos = new FileOutputStream(outFile); BufferedOutputStream bos = new BufferedOutputStream(fos); GZIPOutputStream gos = new GZIPOutputStream(bos); TarArchiveOutputStream taos = new TarArchiveOutputStream(gos); taos.setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_STAR); taos.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU); for (File f : list) { addFileToCompression(taos, f, ""); }/*from www. ja v a2s . co m*/ taos.close(); fos.close(); // gos.close(); // bos.close(); }
From source file:gov.nih.nci.ncicb.tcga.dcc.dam.processors.FilePackager.java
TarArchiveOutputStream makeTarGzOutputStream(final File archiveFile) throws IOException { final TarArchiveOutputStream tarArchiveOutputStream = new TarArchiveOutputStream( new GZIPOutputStream(new FileOutputStream(archiveFile))); tarArchiveOutputStream.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU); tarArchiveOutputStream.setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_STAR); return tarArchiveOutputStream; }
From source file:gdt.data.entity.ArchiveHandler.java
/** * Compress the database into the tar archive file. * @param entigrator entigrator instance, * @param locator$ container of arguments * in the string form. //from w w w . j ava2s . co m * @return true if success false otherwise. */ public boolean compressDatabaseToTar(Entigrator entigrator, String locator$) { try { System.out.println("ArchiveHandler:compressDatabaseToTar:locator=" + locator$); Properties locator = Locator.toProperties(locator$); archiveType$ = locator.getProperty(ARCHIVE_TYPE); archiveFile$ = locator.getProperty(ARCHIVE_FILE); String tarfile$ = archiveFile$; File tarfile = new File(tarfile$); if (!tarfile.exists()) tarfile.createNewFile(); TarArchiveOutputStream aos = (TarArchiveOutputStream) new ArchiveStreamFactory() .createArchiveOutputStream("tar", new FileOutputStream(tarfile$)); aos.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU); String entihome$ = entigrator.getEntihome(); append(entigrator, entihome$, entihome$, aos); aos.close(); return true; } catch (Exception e) { Logger.getLogger(getClass().getName()).severe(e.toString()); return false; } }
From source file:gdt.data.entity.ArchiveHandler.java
/** * Compress the database into the tgz archive file. * @param entigrator entigrator instance * @param locator$ container of arguments in the string form. * @return true if success false otherwise. *//*from w w w.jav a2 s .c o m*/ public boolean compressDatabaseToTgz(Entigrator entigrator, String locator$) { try { Properties locator = Locator.toProperties(locator$); archiveType$ = locator.getProperty(ARCHIVE_TYPE); archiveFile$ = locator.getProperty(ARCHIVE_FILE); String tgzFile$ = archiveFile$; File tgzFile = new File(tgzFile$); if (!tgzFile.exists()) tgzFile.createNewFile(); // String userHome$=System.getProperty("user.home"); File tarFile = new File(tgzFile$.replace(".tgz", "") + ".tar"); if (!tarFile.exists()) tarFile.createNewFile(); TarArchiveOutputStream aos = (TarArchiveOutputStream) new ArchiveStreamFactory() .createArchiveOutputStream("tar", new FileOutputStream(tarFile)); aos.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU); String entihome$ = entigrator.getEntihome(); append(entigrator, entihome$, entihome$, aos); aos.close(); compressGzipFile(tarFile.getPath(), tgzFile.getPath()); tarFile.delete(); return true; } catch (Exception e) { Logger.getLogger(getClass().getName()).severe(e.toString()); return false; } }
From source file:gdt.data.entity.ArchiveHandler.java
/** * Compress the entities into the tar archive file. * @param entigrator entigrator instance * @param locator$ container of arguments in the string form. * @return true if success false otherwise. *///from ww w . j a v a 2s. c om public boolean compressEntitiesToTar(Entigrator entigrator, String locator$) { try { // System.out.println("ArchiveHandler:compressEntitiesToTar:locator="+locator$); Properties locator = Locator.toProperties(locator$); archiveType$ = locator.getProperty(ARCHIVE_TYPE); archiveFile$ = locator.getProperty(ARCHIVE_FILE); String entityList$ = locator.getProperty(EntityHandler.ENTITY_LIST); String[] sa = Locator.toArray(entityList$); System.out.println("ArchiveHandler:compressEntitiesToTar:sa=" + sa.length); String tarfile$ = archiveFile$; File tarfile = new File(tarfile$); if (!tarfile.exists()) tarfile.createNewFile(); String entityBody$ = null; String entityHome$ = null; TarArchiveOutputStream aos = (TarArchiveOutputStream) new ArchiveStreamFactory() .createArchiveOutputStream("tar", new FileOutputStream(tarfile$)); aos.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU); String entihome$ = entigrator.getEntihome(); String entitiesHome$ = entihome$ + "/" + Entigrator.ENTITY_BASE + "/data/"; // System.out.println("ArchiveHandler:append:entities home=" + entitiesHome$); String iconsHome$ = entihome$ + "/" + Entigrator.ICONS + "/"; String icon$; for (String aSa : sa) { entityBody$ = entitiesHome$ + aSa; append(entigrator, entigrator.getEntihome(), entityBody$, aos); entityHome$ = entigrator.ent_getHome(aSa); if (new File(entityHome$).exists()) { append(entigrator, entigrator.getEntihome(), entityHome$, aos); } icon$ = entigrator.indx_getIcon(aSa); if (icon$ != null) append(entigrator, entigrator.getEntihome(), iconsHome$ + icon$, aos); } aos.close(); return true; } catch (Exception e) { LOGGER.severe(e.toString()); return false; } }
From source file:gdt.data.entity.ArchiveHandler.java
/** * Compress the entities into the tgz archive file. * @param entigrator entigrator instance * @param locator$ container of arguments in the string form. * @return true if success false otherwise. *//*from ww w . jav a2 s . co m*/ public boolean compressEntitiesToTgz(Entigrator entigrator, String locator$) { try { Properties locator = Locator.toProperties(locator$); archiveType$ = locator.getProperty(ARCHIVE_TYPE); archiveFile$ = locator.getProperty(ARCHIVE_FILE); String entityList$ = locator.getProperty(EntityHandler.ENTITY_LIST); String[] sa = Locator.toArray(entityList$); String tgzFile$ = archiveFile$; File tgzFile = new File(tgzFile$); if (!tgzFile.exists()) tgzFile.createNewFile(); // String userHome$=System.getProperty("user.home"); File tarFile = new File(tgzFile$.replace(".tgz", "") + ".tar"); if (!tarFile.exists()) tarFile.createNewFile(); String entityBody$ = null; String entityHome$ = null; TarArchiveOutputStream aos = (TarArchiveOutputStream) new ArchiveStreamFactory() .createArchiveOutputStream("tar", new FileOutputStream(tarFile)); aos.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU); String entihome$ = entigrator.getEntihome(); String entitiesHome$ = entihome$ + "/" + Entigrator.ENTITY_BASE + "/data/"; String iconsHome$ = entihome$ + "/" + Entigrator.ICONS + "/"; String icon$; for (String aSa : sa) { entityBody$ = entitiesHome$ + aSa; append(entigrator, entigrator.getEntihome(), entityBody$, aos); entityHome$ = entigrator.ent_getHome(aSa); if (new File(entityHome$).exists()) append(entigrator, entigrator.getEntihome(), entityHome$, aos); icon$ = entigrator.indx_getIcon(aSa); if (icon$ != null) append(entigrator, entigrator.getEntihome(), iconsHome$ + icon$, aos); } aos.close(); compressGzipFile(tarFile.getPath(), tgzFile.getPath()); tarFile.delete(); return true; } catch (Exception e) { LOGGER.severe(e.toString()); return false; } }
From source file:com.linuxbox.enkive.workspace.searchFolder.SearchFolder.java
/** * Writes a tar.gz file to the provided outputstream * /* w ww . ja v a 2 s . c o m*/ * @param outputStream * @throws IOException */ public void exportSearchFolder(OutputStream outputStream) throws IOException { BufferedOutputStream out = new BufferedOutputStream(outputStream); GzipCompressorOutputStream gzOut = new GzipCompressorOutputStream(out); TarArchiveOutputStream tOut = new TarArchiveOutputStream(gzOut); File mboxFile = File.createTempFile("mbox-export", ".mbox"); BufferedWriter mboxWriter = new BufferedWriter(new FileWriter(mboxFile)); // Write mbox to tempfile? for (String messageId : getMessageIds()) { try { Message message = retrieverService.retrieve(messageId); mboxWriter.write("From " + message.getDateStr() + "\r\n"); BufferedReader reader = new BufferedReader(new StringReader(message.getReconstitutedEmail())); String tmpLine; while ((tmpLine = reader.readLine()) != null) { if (tmpLine.startsWith("From ")) mboxWriter.write(">" + tmpLine); else mboxWriter.write(tmpLine); mboxWriter.write("\r\n"); } } catch (CannotRetrieveException e) { // Add errors to report // if (LOGGER.isErrorEnabled()) // LOGGER.error("Could not retrieve message with id" // + messageId); } } mboxWriter.flush(); mboxWriter.close(); // Add mbox to tarfile TarArchiveEntry mboxEntry = new TarArchiveEntry(mboxFile, "filename.mbox"); tOut.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU); tOut.putArchiveEntry(mboxEntry); IOUtils.copy(new FileInputStream(mboxFile), tOut); tOut.flush(); tOut.closeArchiveEntry(); mboxWriter.close(); mboxFile.delete(); // Create report in tempfile? // Add report to tarfile // Close out stream tOut.finish(); outputStream.flush(); tOut.close(); outputStream.close(); }
From source file:org.apache.ant.compress.taskdefs.Tar.java
public Tar() { setFactory(new TarStreamFactory() { public ArchiveOutputStream getArchiveStream(OutputStream stream, String encoding) throws IOException { TarArchiveOutputStream o = (TarArchiveOutputStream) super.getArchiveStream(stream, encoding); if (format.equals(Format.OLDGNU)) { o.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU); } else if (format.equals(Format.GNU)) { o.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU); o.setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_STAR); } else if (format.equals(Format.STAR)) { o.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX); o.setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_STAR); } else if (format.equals(Format.PAX)) { o.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX); o.setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_POSIX); o.setAddPaxHeadersForNonAsciiNames(true); }//from w ww. j ava2 s. c o m return o; } }); setEntryBuilder(new ArchiveBase.EntryBuilder() { public ArchiveEntry buildEntry(ArchiveBase.ResourceWithFlags r) { boolean isDir = r.getResource().isDirectory(); String name = r.getName(); if (isDir && !name.endsWith("/")) { name += "/"; } else if (!isDir && name.endsWith("/")) { name = name.substring(0, name.length() - 1); } TarArchiveEntry ent = new TarArchiveEntry(name, getPreserveLeadingSlashes()); ent.setModTime(round(r.getResource().getLastModified(), 1000)); ent.setSize(isDir ? 0 : r.getResource().getSize()); if (!isDir && r.getCollectionFlags().hasModeBeenSet()) { ent.setMode(r.getCollectionFlags().getMode()); } else if (isDir && r.getCollectionFlags().hasDirModeBeenSet()) { ent.setMode(r.getCollectionFlags().getDirMode()); } else if (r.getResourceFlags().hasModeBeenSet()) { ent.setMode(r.getResourceFlags().getMode()); } else { ent.setMode(isDir ? ArchiveFileSet.DEFAULT_DIR_MODE : ArchiveFileSet.DEFAULT_FILE_MODE); } if (r.getResourceFlags().hasUserIdBeenSet()) { ent.setUserId(r.getResourceFlags().getUserId()); } else if (r.getCollectionFlags().hasUserIdBeenSet()) { ent.setUserId(r.getCollectionFlags().getUserId()); } if (r.getResourceFlags().hasGroupIdBeenSet()) { ent.setGroupId(r.getResourceFlags().getGroupId()); } else if (r.getCollectionFlags().hasGroupIdBeenSet()) { ent.setGroupId(r.getCollectionFlags().getGroupId()); } if (r.getResourceFlags().hasUserNameBeenSet()) { ent.setUserName(r.getResourceFlags().getUserName()); } else if (r.getCollectionFlags().hasUserNameBeenSet()) { ent.setUserName(r.getCollectionFlags().getUserName()); } if (r.getResourceFlags().hasGroupNameBeenSet()) { ent.setGroupName(r.getResourceFlags().getGroupName()); } else if (r.getCollectionFlags().hasGroupNameBeenSet()) { ent.setGroupName(r.getCollectionFlags().getGroupName()); } return ent; } }); setFileSetBuilder(new ArchiveBase.FileSetBuilder() { public ArchiveFileSet buildFileSet(Resource dest) { ArchiveFileSet afs = new TarFileSet(); afs.setSrcResource(dest); return afs; } }); }
From source file:org.apache.camel.dataformat.tarfile.TarFileDataFormat.java
@Override public void marshal(Exchange exchange, Object graph, OutputStream stream) throws Exception { String filename = exchange.getIn().getHeader(FILE_NAME, String.class); Long filelength = exchange.getIn().getHeader(FILE_LENGTH, Long.class); if (filename != null) { filename = new File(filename).getName(); // remove any path elements } else {/* w w w.j a v a2 s . co m*/ // generate the file name as the camel file component would do filename = StringHelper.sanitize(exchange.getIn().getMessageId()); } TarArchiveOutputStream tos = new TarArchiveOutputStream(stream); tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX); tos.setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_POSIX); InputStream is = exchange.getContext().getTypeConverter().mandatoryConvertTo(InputStream.class, graph); if (filelength == null) { filelength = new Long(is.available()); } TarArchiveEntry entry = new TarArchiveEntry(filename); entry.setSize(filelength); tos.putArchiveEntry(entry); try { IOHelper.copy(is, tos); } finally { tos.closeArchiveEntry(); IOHelper.close(is, tos); } String newFilename = filename + ".tar"; exchange.getOut().setHeader(FILE_NAME, newFilename); }
From source file:org.apache.camel.processor.aggregate.tarfile.TarAggregationStrategy.java
private static void addFileToTar(File source, File file, String fileName) throws IOException, ArchiveException { File tmpTar = File.createTempFile(source.getName(), null); tmpTar.delete();/*from w w w .j a va 2 s . c o m*/ if (!source.renameTo(tmpTar)) { throw new IOException("Could not make temp file (" + source.getName() + ")"); } TarArchiveInputStream tin = (TarArchiveInputStream) new ArchiveStreamFactory() .createArchiveInputStream(ArchiveStreamFactory.TAR, new FileInputStream(tmpTar)); TarArchiveOutputStream tos = new TarArchiveOutputStream(new FileOutputStream(source)); tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX); tos.setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_POSIX); InputStream in = new FileInputStream(file); // copy the existing entries ArchiveEntry nextEntry; while ((nextEntry = tin.getNextEntry()) != null) { tos.putArchiveEntry(nextEntry); IOUtils.copy(tin, tos); tos.closeArchiveEntry(); } // Add the new entry TarArchiveEntry entry = new TarArchiveEntry(fileName == null ? file.getName() : fileName); entry.setSize(file.length()); tos.putArchiveEntry(entry); IOUtils.copy(in, tos); tos.closeArchiveEntry(); IOHelper.close(in); IOHelper.close(tin); IOHelper.close(tos); }