Example usage for org.apache.commons.compress.archivers.ar ArArchiveEntry ArArchiveEntry

List of usage examples for org.apache.commons.compress.archivers.ar ArArchiveEntry ArArchiveEntry

Introduction

In this page you can find the example usage for org.apache.commons.compress.archivers.ar ArArchiveEntry ArArchiveEntry.

Prototype

public ArArchiveEntry(String name, long length, int userId, int groupId, int mode, long lastModified) 

Source Link

Document

Create a new instance.

Usage

From source file:com.moss.simpledeb.core.DebWriter.java

public void write(OutputStream out) throws Exception {

    if (out == null) {
        throw new NullPointerException();
    }// w w w .  j  a  v a2s  .  c om

    DebState state = new DebState();

    for (DebAction action : pkg.actions()) {
        action.run(state);
    }

    ArArchiveOutputStream ar = new ArArchiveOutputStream(out);

    /*
     * Version
     */

    byte[] versionData = "2.0\n".getBytes();

    ArArchiveEntry versionEntry = new ArArchiveEntry("debian-binary", versionData.length, 0, 0, 0664,
            System.currentTimeMillis());

    ar.putArchiveEntry(versionEntry);
    ar.write(versionData);
    ar.closeArchiveEntry();

    /*
     * Control
     */

    byte[] controlFileData = buildGzipTar(state.controlPaths);

    ArArchiveEntry controlEntry = new ArArchiveEntry("control.tar.gz", controlFileData.length, 0, 0, 0664,
            System.currentTimeMillis());

    ar.putArchiveEntry(controlEntry);
    ar.write(controlFileData);
    ar.closeArchiveEntry();

    /*
     * Data
     */

    byte[] contentData = buildGzipTar(state.contentPaths);

    ArArchiveEntry contentEntry = new ArArchiveEntry("data.tar.gz", contentData.length, 0, 0, 0664,
            System.currentTimeMillis());

    ar.putArchiveEntry(contentEntry);
    ar.write(contentData);
    ar.closeArchiveEntry();

    ar.close();
}

From source file:com.mobilesorcery.sdk.builder.linux.deb.DebBuilder.java

/**
 * Create debian package/*from  w ww . j a  v a  2  s.  c o  m*/
 *
 * @param p Path to write to
 */
public String build(File p) throws Exception, IOException, FileNotFoundException {
    File ftemp;
    String fileName = m_packName + ".deb";
    File filePack = new File(p, fileName);
    long sysTime = System.currentTimeMillis();
    FileOutputStream fos = new FileOutputStream(filePack);
    BufferedOutputStream bos = new BufferedOutputStream(fos);
    ArArchiveOutputStream aros = new ArArchiveOutputStream(bos);
    byte[] debBin = { (byte) '2', (byte) '.', (byte) '0', (byte) 0x0a };

    // Write the file 'debian-binary'
    aros.putArchiveEntry(new ArArchiveEntry("debian-binary", 4, 0, 0, 0x81a4, sysTime));
    aros.write(debBin);
    aros.closeArchiveEntry();

    // Create control.tar.gz
    ftemp = File.createTempFile(sysTime + "", "control.tar.gz");
    doCreateControlTarGZip(ftemp);
    aros.putArchiveEntry(new ArArchiveEntry("control.tar.gz", ftemp.length(), 0, 0, 0x81a4, sysTime));
    BuilderUtil.getInstance().copyFileToOutputStream(aros, ftemp);
    aros.closeArchiveEntry();
    ftemp.delete();

    // Create data.tar.gz
    ftemp = File.createTempFile(sysTime + "", "data.tar.gz");
    doAddFilesToTarGZip(ftemp);
    aros.putArchiveEntry(new ArArchiveEntry("data.tar.gz", ftemp.length(), 0, 0, 0x81a4, sysTime));
    BuilderUtil.getInstance().copyFileToOutputStream(aros, ftemp);
    aros.closeArchiveEntry();
    ftemp.delete();

    // Done
    aros.close();
    bos.close();
    fos.close();

    // Return absolute path
    return filePack.getName();
}

From source file:org.apache.ant.compress.taskdefs.Ar.java

public Ar() {
    setFactory(new ArStreamFactory() {
        public ArchiveOutputStream getArchiveStream(OutputStream stream, String encoding) throws IOException {
            ArArchiveOutputStream o = (ArArchiveOutputStream) super.getArchiveStream(stream, encoding);
            if (format.equals(Format.BSD)) {
                o.setLongFileMode(ArArchiveOutputStream.LONGFILE_BSD);
            }//from  ww w.j  av a  2 s .c  o m
            return o;
        }
    });
    setEntryBuilder(new ArchiveBase.EntryBuilder() {
        public ArchiveEntry buildEntry(ArchiveBase.ResourceWithFlags r) {
            boolean isDir = r.getResource().isDirectory();
            if (isDir) {
                throw new BuildException(NO_DIRS_MESSAGE);
            }

            int mode = ArchiveFileSet.DEFAULT_FILE_MODE;
            if (r.getCollectionFlags().hasModeBeenSet()) {
                mode = r.getCollectionFlags().getMode();
            } else if (r.getResourceFlags().hasModeBeenSet()) {
                mode = r.getResourceFlags().getMode();
            }

            int uid = 0;
            if (r.getResourceFlags().hasUserIdBeenSet()) {
                uid = r.getResourceFlags().getUserId();
            } else if (r.getCollectionFlags().hasUserIdBeenSet()) {
                uid = r.getCollectionFlags().getUserId();
            }

            int gid = 0;
            if (r.getResourceFlags().hasGroupIdBeenSet()) {
                gid = r.getResourceFlags().getGroupId();
            } else if (r.getCollectionFlags().hasGroupIdBeenSet()) {
                gid = r.getCollectionFlags().getGroupId();
            }

            return new ArArchiveEntry(r.getName(), r.getResource().getSize(), uid, gid, mode,
                    round(r.getResource().getLastModified(), 1000) / 1000);
        }
    });
    setFileSetBuilder(new ArchiveBase.FileSetBuilder() {
        public ArchiveFileSet buildFileSet(Resource dest) {
            ArchiveFileSet afs = new ArFileSet();
            afs.setSrcResource(dest);
            return afs;
        }
    });
}

From source file:org.eclipse.scada.utils.pkg.deb.DebianPackageWriter.java

public DebianPackageWriter(final OutputStream stream, final GenericControlFile packageControlFile,
        final TimestampProvider timestampProvider) throws IOException {
    this.packageControlFile = packageControlFile;
    this.timestampProvider = timestampProvider;
    if (getTimestampProvider() == null) {
        throw new IllegalArgumentException("'timestampProvider' must not be null");
    }/*  w  w  w  .  ja v a2s. co  m*/
    BinaryPackageControlFile.validate(packageControlFile);

    this.ar = new ArArchiveOutputStream(stream);

    this.ar.putArchiveEntry(new ArArchiveEntry("debian-binary", this.binaryHeader.length, 0, 0,
            AR_ARCHIVE_DEFAULT_MODE, getTimestampProvider().getModTime() / 1000));
    this.ar.write(this.binaryHeader);
    this.ar.closeArchiveEntry();

    this.dataTemp = File.createTempFile("data", null);

    this.dataStream = new TarArchiveOutputStream(new GZIPOutputStream(new FileOutputStream(this.dataTemp)));
    this.dataStream.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
}

From source file:org.eclipse.scada.utils.pkg.deb.DebianPackageWriter.java

private void addArFile(final File file, final String entryName) throws IOException {
    final ArArchiveEntry entry = new ArArchiveEntry(entryName, file.length(), 0, 0, AR_ARCHIVE_DEFAULT_MODE,
            timestampProvider.getModTime() / 1000);
    this.ar.putArchiveEntry(entry);

    ByteStreams.copy(new FileInputStream(file), this.ar);

    this.ar.closeArchiveEntry();
}