Package org.apache.commons.compress.archivers.tar

Examples of org.apache.commons.compress.archivers.tar.TarArchiveOutputStream


            byte ba_1k[] = new byte[(int) _1K];
            for(int i=0; i < ba_1k.length; i++){
                ba_1k[i]='a';
            }
            try {
                TarArchiveOutputStream outTarStream =
                    (TarArchiveOutputStream)new ArchiveStreamFactory()
                    .createArchiveOutputStream(ArchiveStreamFactory.TAR, outTarFileStream);
                // Create archive contents
                TarArchiveEntry tarArchiveEntry = new TarArchiveEntry(name + ".txt");
                tarArchiveEntry.setSize(fileSize);

                outTarStream.putArchiveEntry(tarArchiveEntry);
                for(long i = 0; i < fileSize; i+= ba_1k.length) {
                    outTarStream.write(ba_1k);
                }
                outTarStream.closeArchiveEntry();
                outTarStream.close();
                outTarFileStream.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
View Full Code Here


  ** OutputStream os will be close()d if this method returns successfully.
  */
  private String createTarBucket(OutputStream os) throws IOException {
    if(logMINOR) Logger.minor(this, "Create a TAR Bucket");
   
    TarArchiveOutputStream tarOS = new TarArchiveOutputStream(os);
    try {
      tarOS.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
      TarArchiveEntry ze;

      for (ContainerElement ph : containerItems) {
        if (logMINOR)
          Logger.minor(this, "Putting into tar: " + ph + " data length " + ph.data.size() + " name " + ph.targetInArchive);
        ze = new TarArchiveEntry(ph.targetInArchive);
        ze.setModTime(0);
        long size = ph.data.size();
        ze.setSize(size);
        tarOS.putArchiveEntry(ze);
        BucketTools.copyTo(ph.data, tarOS, size);
        tarOS.closeArchiveEntry();
      }
    } finally {
      tarOS.close();
    }
   
    return ARCHIVE_TYPE.TAR.mimeTypes[0];
  }
View Full Code Here

   * archive successfully
   */
  public static void generateGZippedTar(final OutputStream outputStream, final File file) throws IOException {
    BufferedOutputStream bOut = null;
    GzipCompressorOutputStream gzOut = null;
    TarArchiveOutputStream tOut = null;
    try {
      bOut = new BufferedOutputStream(outputStream);
      gzOut = new GzipCompressorOutputStream(bOut);
      tOut = new TarArchiveOutputStream(gzOut);
      if (file.isDirectory()) {
        addFileToTar(tOut, file, "/");
      } else {
        addFileToTar(tOut, file, file.getName());
      }
    } finally {
      if (tOut != null) {
        tOut.finish();
        tOut.close();
      }
      if (gzOut != null) {
        gzOut.close();
      }
      if (bOut != null) {
View Full Code Here

    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);
                    }
                    return o;
                }
            });
        setEntryBuilder(
View Full Code Here

     * @param encoding the encoding of the entry names
     */
    public ArchiveOutputStream getArchiveStream(OutputStream stream,
                                                String encoding)
        throws IOException {
        return new TarArchiveOutputStream(stream, encoding);
    }
View Full Code Here

    byte[] bytes = new byte[len];
    r.nextBytes(bytes);

    File archiveFile = new File(p.toUri().getPath() + ".tar");
    archiveFile.createNewFile();
    TarArchiveOutputStream out = new TarArchiveOutputStream(
        new FileOutputStream(archiveFile));
    TarArchiveEntry entry = new TarArchiveEntry(p.getName());
    entry.setSize(bytes.length);
    out.putArchiveEntry(entry);
    out.write(bytes);
    out.closeArchiveEntry();
    out.close();

    LocalResource ret = recordFactory.newRecordInstance(LocalResource.class);
    ret.setResource(ConverterUtils.getYarnUrlFromPath(new Path(p.toString()
        + ".tar")));
    ret.setSize(len);
View Full Code Here

    byte[] bytes = new byte[len];
    r.nextBytes(bytes);

    File gzipFile = new File(p.toUri().getPath() + ".tar.gz");
    gzipFile.createNewFile();
    TarArchiveOutputStream out = new TarArchiveOutputStream(
        new GZIPOutputStream(new FileOutputStream(gzipFile)));
    TarArchiveEntry entry = new TarArchiveEntry(p.getName());
    entry.setSize(bytes.length);
    out.putArchiveEntry(entry);
    out.write(bytes);
    out.closeArchiveEntry();
    out.close();

    LocalResource ret = recordFactory.newRecordInstance(LocalResource.class);
    ret.setResource(ConverterUtils.getYarnUrlFromPath(new Path(p.toString()
        + ".tar.gz")));
    ret.setSize(len);
View Full Code Here

    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);
                    }
                    return o;
                }
            });
        setEntryBuilder(
View Full Code Here

   */
  public static void createFromDirectory(String sourceDirectory, String targetName) throws IOException {
    FileOutputStream fileOutputStream = null;
    BufferedOutputStream bufferedOutputStream = null;
    GzipCompressorOutputStream gzipOutputStream = null;
    TarArchiveOutputStream tarArchiveOutputStream = null;

    try {
      fileOutputStream = new FileOutputStream(new File(targetName));
      bufferedOutputStream = new BufferedOutputStream(fileOutputStream);
      gzipOutputStream = new GzipCompressorOutputStream(bufferedOutputStream);
      tarArchiveOutputStream = new TarArchiveOutputStream(gzipOutputStream);

      addFilesInDirectory(tarArchiveOutputStream, sourceDirectory);
    } finally {
      if (tarArchiveOutputStream != null) {
        tarArchiveOutputStream.finish();
      }
      if (tarArchiveOutputStream != null) {
        tarArchiveOutputStream.close();
      }
      if (gzipOutputStream != null) {
        gzipOutputStream.close();
      }
      if (bufferedOutputStream != null) {
View Full Code Here

            }
            return zip;
        }
        if (TAR.equalsIgnoreCase(archiverName)) {
            if (entryEncoding != null) {
                return new TarArchiveOutputStream(out, entryEncoding);
            } else {
                return new TarArchiveOutputStream(out);
            }
        }
        if (JAR.equalsIgnoreCase(archiverName)) {
            return new JarArchiveOutputStream(out);
        }
View Full Code Here

TOP

Related Classes of org.apache.commons.compress.archivers.tar.TarArchiveOutputStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.