commons-compress-1.0

16:34:42.166 INFO  jd.cli.Main - Decompiling commons-compress-1.0.jar
package org.apache.commons.compress.archivers.ar;

import java.io.File;
import org.apache.commons.compress.archivers.ArchiveEntry;

public class ArArchiveEntry
  implements ArchiveEntry
{
  public static final String HEADER = "!<arch>\n";
  public static final String TRAILER = "`\n";
  private final String name;
  private final int userId;
  private final int groupId;
  private final int mode;
  private static final int DEFAULT_MODE = 33188;
  private final long lastModified;
  private final long length;
  
  public ArArchiveEntry(String name, long length)
  {
    this(name, length, 0, 0, 33188, System.currentTimeMillis());
  }
  
  public ArArchiveEntry(String name, long length, int userId, int groupId, int mode, long lastModified)
  {
    this.name = name;
    this.length = length;
    this.userId = userId;
    this.groupId = groupId;
    this.mode = mode;
    this.lastModified = lastModified;
  }
  
  public ArArchiveEntry(File inputFile, String entryName)
  {
    this(entryName, inputFile.isFile() ? inputFile.length() : 0L, 0, 0, 0, inputFile.lastModified());
  }
  
  public long getSize()
  {
    return getLength();
  }
  
  public String getName()
  {
    return name;
  }
  
  public int getUserId()
  {
    return userId;
  }
  
  public int getGroupId()
  {
    return groupId;
  }
  
  public int getMode()
  {
    return mode;
  }
  
  public long getLastModified()
  {
    return lastModified;
  }
  
  public long getLength()
  {
    return length;
  }
  
  public boolean isDirectory()
  {
    return false;
  }
  
  public int hashCode()
  {
    int prime = 31;
    int result = 1;
    result = 31 * result + (name == null ? 0 : name.hashCode());
    return result;
  }
  
  public boolean equals(Object obj)
  {
    if (this == obj) {
      return true;
    }
    if ((obj == null) || (getClass() != obj.getClass())) {
      return false;
    }
    ArArchiveEntry other = (ArArchiveEntry)obj;
    if (name == null)
    {
      if (name != null) {
        return false;
      }
    }
    else if (!name.equals(name)) {
      return false;
    }
    return true;
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.compress.archivers.ar.ArArchiveEntry
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.compress.archivers.ar;

import java.io.IOException;
import java.io.InputStream;
import org.apache.commons.compress.archivers.ArchiveEntry;
import org.apache.commons.compress.archivers.ArchiveInputStream;
import org.apache.commons.compress.utils.ArchiveUtils;

public class ArArchiveInputStream
  extends ArchiveInputStream
{
  private final InputStream input;
  private long offset = 0L;
  private boolean closed;
  private ArArchiveEntry currentEntry = null;
  private long entryOffset = -1L;
  
  public ArArchiveInputStream(InputStream pInput)
  {
    input = pInput;
    closed = false;
  }
  
  public ArArchiveEntry getNextArEntry()
    throws IOException
  {
    if (currentEntry != null)
    {
      long entryEnd = entryOffset + currentEntry.getLength();
      while (offset < entryEnd)
      {
        int x = read();
        if (x == -1) {
          return null;
        }
      }
      currentEntry = null;
    }
    if (offset == 0L)
    {
      byte[] expected = ArchiveUtils.toAsciiBytes("!<arch>\n");
      byte[] realized = new byte[expected.length];
      int read = read(realized);
      if (read != expected.length) {
        throw new IOException("failed to read header. Occured at byte: " + getCount());
      }
      for (int i = 0; i < expected.length; i++) {
        if (expected[i] != realized[i]) {
          throw new IOException("invalid header " + ArchiveUtils.toAsciiString(realized));
        }
      }
    }
    if ((offset % 2L != 0L) && 
      (read() < 0)) {
      return null;
    }
    if (input.available() == 0) {
      return null;
    }
    byte[] name = new byte[16];
    byte[] lastmodified = new byte[12];
    byte[] userid = new byte[6];
    byte[] groupid = new byte[6];
    byte[] filemode = new byte[8];
    byte[] length = new byte[10];
    
    read(name);
    read(lastmodified);
    read(userid);
    read(groupid);
    read(filemode);
    read(length);
    
    byte[] expected = ArchiveUtils.toAsciiBytes("`\n");
    byte[] realized = new byte[expected.length];
    int read = read(realized);
    if (read != expected.length) {
      throw new IOException("failed to read entry header. Occured at byte: " + getCount());
    }
    for (int i = 0; i < expected.length; i++) {
      if (expected[i] != realized[i]) {
        throw new IOException("invalid entry header. not read the content? Occured at byte: " + getCount());
      }
    }
    entryOffset = offset;
    
    String temp = ArchiveUtils.toAsciiString(name).trim();
    if (temp.endsWith("/")) {
      temp = temp.substring(0, temp.length() - 1);
    }
    currentEntry = new ArArchiveEntry(temp, Long.parseLong(new String(length).trim()));
    return currentEntry;
  }
  
  public ArchiveEntry getNextEntry()
    throws IOException
  {
    return getNextArEntry();
  }
  
  public void close()
    throws IOException
  {
    if (!closed)
    {
      closed = true;
      input.close();
    }
    currentEntry = null;
  }
  
  public int read(byte[] b, int off, int len)
    throws IOException
  {
    int toRead = len;
    if (currentEntry != null)
    {
      long entryEnd = entryOffset + currentEntry.getLength();
      if ((len > 0) && (entryEnd > offset)) {
        toRead = (int)Math.min(len, entryEnd - offset);
      } else {
        return -1;
      }
    }
    int ret = input.read(b, off, toRead);
    count(ret);
    offset += (ret > 0 ? ret : 0);
    return ret;
  }
  
  public static boolean matches(byte[] signature, int length)
  {
    if (length < 8) {
      return false;
    }
    if (signature[0] != 33) {
      return false;
    }
    if (signature[1] != 60) {
      return false;
    }
    if (signature[2] != 97) {
      return false;
    }
    if (signature[3] != 114) {
      return false;
    }
    if (signature[4] != 99) {
      return false;
    }
    if (signature[5] != 104) {
      return false;
    }
    if (signature[6] != 62) {
      return false;
    }
    if (signature[7] != 10) {
      return false;
    }
    return true;
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.compress.archivers.ar.ArArchiveInputStream
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.compress.archivers.ar;

import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import org.apache.commons.compress.archivers.ArchiveEntry;
import org.apache.commons.compress.archivers.ArchiveOutputStream;
import org.apache.commons.compress.utils.ArchiveUtils;

public class ArArchiveOutputStream
  extends ArchiveOutputStream
{
  private final OutputStream out;
  private long archiveOffset = 0L;
  private long entryOffset = 0L;
  private ArArchiveEntry prevEntry;
  private boolean haveUnclosedEntry = false;
  private boolean finished = false;
  
  public ArArchiveOutputStream(OutputStream pOut)
  {
    out = pOut;
  }
  
  private long writeArchiveHeader()
    throws IOException
  {
    byte[] header = ArchiveUtils.toAsciiBytes("!<arch>\n");
    out.write(header);
    return header.length;
  }
  
  public void closeArchiveEntry()
    throws IOException
  {
    if (finished) {
      throw new IOException("Stream has already been finished");
    }
    if ((prevEntry == null) || (!haveUnclosedEntry)) {
      throw new IOException("No current entry to close");
    }
    if (entryOffset % 2L != 0L)
    {
      out.write(10);
      archiveOffset += 1L;
    }
    haveUnclosedEntry = false;
  }
  
  public void putArchiveEntry(ArchiveEntry pEntry)
    throws IOException
  {
    if (finished) {
      throw new IOException("Stream has already been finished");
    }
    ArArchiveEntry pArEntry = (ArArchiveEntry)pEntry;
    if (prevEntry == null)
    {
      archiveOffset += writeArchiveHeader();
    }
    else
    {
      if (prevEntry.getLength() != entryOffset) {
        throw new IOException("length does not match entry (" + prevEntry.getLength() + " != " + entryOffset);
      }
      if (haveUnclosedEntry) {
        closeArchiveEntry();
      }
    }
    prevEntry = pArEntry;
    
    archiveOffset += writeEntryHeader(pArEntry);
    
    entryOffset = 0L;
    haveUnclosedEntry = true;
  }
  
  private long fill(long pOffset, long pNewOffset, char pFill)
    throws IOException
  {
    long diff = pNewOffset - pOffset;
    if (diff > 0L) {
      for (int i = 0; i < diff; i++) {
        write(pFill);
      }
    }
    return pNewOffset;
  }
  
  private long write(String data)
    throws IOException
  {
    byte[] bytes = data.getBytes("ascii");
    write(bytes);
    return bytes.length;
  }
  
  private long writeEntryHeader(ArArchiveEntry pEntry)
    throws IOException
  {
    long offset = 0L;
    
    String n = pEntry.getName();
    if (n.length() > 16) {
      throw new IOException("filename too long, > 16 chars: " + n);
    }
    offset += write(n);
    
    offset = fill(offset, 16L, ' ');
    String m = "" + pEntry.getLastModified() / 1000L;
    if (m.length() > 12) {
      throw new IOException("modified too long");
    }
    offset += write(m);
    
    offset = fill(offset, 28L, ' ');
    String u = "" + pEntry.getUserId();
    if (u.length() > 6) {
      throw new IOException("userid too long");
    }
    offset += write(u);
    
    offset = fill(offset, 34L, ' ');
    String g = "" + pEntry.getGroupId();
    if (g.length() > 6) {
      throw new IOException("groupid too long");
    }
    offset += write(g);
    
    offset = fill(offset, 40L, ' ');
    String fm = "" + Integer.toString(pEntry.getMode(), 8);
    if (fm.length() > 8) {
      throw new IOException("filemode too long");
    }
    offset += write(fm);
    
    offset = fill(offset, 48L, ' ');
    String s = "" + pEntry.getLength();
    if (s.length() > 10) {
      throw new IOException("size too long");
    }
    offset += write(s);
    
    offset = fill(offset, 58L, ' ');
    
    offset += write("`\n");
    
    return offset;
  }
  
  public void write(byte[] b, int off, int len)
    throws IOException
  {
    out.write(b, off, len);
    count(len);
    entryOffset += len;
  }
  
  public void close()
    throws IOException
  {
    if (!finished) {
      finish();
    }
    out.close();
    prevEntry = null;
  }
  
  public ArchiveEntry createArchiveEntry(File inputFile, String entryName)
    throws IOException
  {
    if (finished) {
      throw new IOException("Stream has already been finished");
    }
    return new ArArchiveEntry(inputFile, entryName);
  }
  
  public void finish()
    throws IOException
  {
    if (haveUnclosedEntry) {
      throw new IOException("This archive contains unclosed entries.");
    }
    if (finished) {
      throw new IOException("This archive has already been finished");
    }
    finished = true;
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.compress.archivers.ar.ArArchiveOutputStream
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.compress.archivers;

public abstract interface ArchiveEntry
{
  public static final long SIZE_UNKNOWN = -1L;
  
  public abstract String getName();
  
  public abstract long getSize();
  
  public abstract boolean isDirectory();
}

/* Location:
 * Qualified Name:     org.apache.commons.compress.archivers.ArchiveEntry
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.compress.archivers;

public class ArchiveException
  extends Exception
{
  private static final long serialVersionUID = 2772690708123267100L;
  
  public ArchiveException(String message)
  {
    super(message);
  }
  
  public ArchiveException(String message, Exception cause)
  {
    super(message);
    initCause(cause);
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.compress.archivers.ArchiveException
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.compress.archivers;

import java.io.IOException;
import java.io.InputStream;

public abstract class ArchiveInputStream
  extends InputStream
{
  private byte[] SINGLE = new byte[1];
  private static final int BYTE_MASK = 255;
  private int bytesRead = 0;
  
  public abstract ArchiveEntry getNextEntry()
    throws IOException;
  
  public int read()
    throws IOException
  {
    int num = read(SINGLE, 0, 1);
    return num == -1 ? -1 : SINGLE[0] & 0xFF;
  }
  
  protected void count(int read)
  {
    if (read != -1) {
      bytesRead += read;
    }
  }
  
  public int getCount()
  {
    return bytesRead;
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.compress.archivers.ArchiveInputStream
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.compress.archivers;

import java.io.File;
import java.io.IOException;
import java.io.OutputStream;

public abstract class ArchiveOutputStream
  extends OutputStream
{
  private final byte[] oneByte = new byte[1];
  static final int BYTE_MASK = 255;
  private int bytesRead = 0;
  
  public abstract void putArchiveEntry(ArchiveEntry paramArchiveEntry)
    throws IOException;
  
  public abstract void closeArchiveEntry()
    throws IOException;
  
  public abstract void finish()
    throws IOException;
  
  public abstract ArchiveEntry createArchiveEntry(File paramFile, String paramString)
    throws IOException;
  
  public void write(int b)
    throws IOException
  {
    oneByte[0] = ((byte)(b & 0xFF));
    write(oneByte, 0, 1);
  }
  
  protected void count(int read)
  {
    if (read != -1) {
      bytesRead += read;
    }
  }
  
  public int getCount()
  {
    return bytesRead;
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.compress.archivers.ArchiveOutputStream
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.compress.archivers;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.apache.commons.compress.archivers.ar.ArArchiveInputStream;
import org.apache.commons.compress.archivers.ar.ArArchiveOutputStream;
import org.apache.commons.compress.archivers.cpio.CpioArchiveInputStream;
import org.apache.commons.compress.archivers.cpio.CpioArchiveOutputStream;
import org.apache.commons.compress.archivers.jar.JarArchiveInputStream;
import org.apache.commons.compress.archivers.jar.JarArchiveOutputStream;
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;

public class ArchiveStreamFactory
{
  public ArchiveInputStream createArchiveInputStream(String archiverName, InputStream in)
    throws ArchiveException
  {
    if ((archiverName == null) || (in == null)) {
      throw new IllegalArgumentException("Archivername must not be null.");
    }
    if ("ar".equalsIgnoreCase(archiverName)) {
      return new ArArchiveInputStream(in);
    }
    if ("zip".equalsIgnoreCase(archiverName)) {
      return new ZipArchiveInputStream(in);
    }
    if ("tar".equalsIgnoreCase(archiverName)) {
      return new TarArchiveInputStream(in);
    }
    if ("jar".equalsIgnoreCase(archiverName)) {
      return new JarArchiveInputStream(in);
    }
    if ("cpio".equalsIgnoreCase(archiverName)) {
      return new CpioArchiveInputStream(in);
    }
    throw new ArchiveException("Archiver: " + archiverName + " not found.");
  }
  
  public ArchiveOutputStream createArchiveOutputStream(String archiverName, OutputStream out)
    throws ArchiveException
  {
    if ((archiverName == null) || (out == null)) {
      throw new IllegalArgumentException("Archivername and stream must not be null.");
    }
    if ("ar".equalsIgnoreCase(archiverName)) {
      return new ArArchiveOutputStream(out);
    }
    if ("zip".equalsIgnoreCase(archiverName)) {
      return new ZipArchiveOutputStream(out);
    }
    if ("tar".equalsIgnoreCase(archiverName)) {
      return new TarArchiveOutputStream(out);
    }
    if ("jar".equalsIgnoreCase(archiverName)) {
      return new JarArchiveOutputStream(out);
    }
    if ("cpio".equalsIgnoreCase(archiverName)) {
      return new CpioArchiveOutputStream(out);
    }
    throw new ArchiveException("Archiver: " + archiverName + " not found.");
  }
  
  public ArchiveInputStream createArchiveInputStream(InputStream in)
    throws ArchiveException
  {
    if (in == null) {
      throw new IllegalArgumentException("Stream must not be null.");
    }
    if (!in.markSupported()) {
      throw new IllegalArgumentException("Mark is not supported.");
    }
    byte[] signature = new byte[12];
    in.mark(signature.length);
    try
    {
      int signatureLength = in.read(signature);
      in.reset();
      if (ZipArchiveInputStream.matches(signature, signatureLength)) {
        return new ZipArchiveInputStream(in);
      }
      if (JarArchiveInputStream.matches(signature, signatureLength)) {
        return new JarArchiveInputStream(in);
      }
      if (ArArchiveInputStream.matches(signature, signatureLength)) {
        return new ArArchiveInputStream(in);
      }
      if (CpioArchiveInputStream.matches(signature, signatureLength)) {
        return new CpioArchiveInputStream(in);
      }
      byte[] tarheader = new byte['?'];
      in.mark(tarheader.length);
      signatureLength = in.read(tarheader);
      in.reset();
      if (TarArchiveInputStream.matches(tarheader, signatureLength)) {
        return new TarArchiveInputStream(in);
      }
    }
    catch (IOException e)
    {
      throw new ArchiveException("Could not use reset and mark operations.", e);
    }
    throw new ArchiveException("No Archiver found for the stream signature");
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.compress.archivers.ArchiveStreamFactory
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.compress.archivers.cpio;

import java.io.File;
import org.apache.commons.compress.archivers.ArchiveEntry;

public class CpioArchiveEntry
  implements CpioConstants, ArchiveEntry
{
  private final short fileFormat;
  private final int headerSize;
  private final int alignmentBoundary;
  private long chksum = 0L;
  private long filesize = 0L;
  private long gid = 0L;
  private long inode = 0L;
  private long maj = 0L;
  private long min = 0L;
  private long mode = 0L;
  private long mtime = 0L;
  private String name;
  private long nlink = 0L;
  private long rmaj = 0L;
  private long rmin = 0L;
  private long uid = 0L;
  
  public CpioArchiveEntry(short format)
  {
    switch (format)
    {
    case 1: 
      headerSize = 110;
      alignmentBoundary = 4;
      break;
    case 2: 
      headerSize = 110;
      alignmentBoundary = 4;
      break;
    case 4: 
      headerSize = 76;
      alignmentBoundary = 0;
      break;
    case 8: 
      headerSize = 26;
      alignmentBoundary = 2;
      break;
    case 3: 
    case 5: 
    case 6: 
    case 7: 
    default: 
      throw new IllegalArgumentException("Unknown header type");
    }
    fileFormat = format;
  }
  
  public CpioArchiveEntry(String name)
  {
    this((short)1);
    this.name = name;
  }
  
  public CpioArchiveEntry(String name, long size)
  {
    this((short)1);
    this.name = name;
    setSize(size);
  }
  
  public CpioArchiveEntry(File inputFile, String entryName)
  {
    this(entryName, inputFile.isFile() ? inputFile.length() : 0L);
    long mode = 0L;
    if (inputFile.isDirectory()) {
      mode |= 0x4000;
    } else if (inputFile.isFile()) {
      mode |= 0x8000;
    } else {
      throw new IllegalArgumentException("Cannot determine type of file " + inputFile.getName());
    }
    setMode(mode);
  }
  
  private void checkNewFormat()
  {
    if ((fileFormat & 0x3) == 0) {
      throw new UnsupportedOperationException();
    }
  }
  
  private void checkOldFormat()
  {
    if ((fileFormat & 0xC) == 0) {
      throw new UnsupportedOperationException();
    }
  }
  
  public long getChksum()
  {
    checkNewFormat();
    return chksum;
  }
  
  public long getDevice()
  {
    checkOldFormat();
    return min;
  }
  
  public long getDeviceMaj()
  {
    checkNewFormat();
    return maj;
  }
  
  public long getDeviceMin()
  {
    checkNewFormat();
    return min;
  }
  
  public long getSize()
  {
    return filesize;
  }
  
  public short getFormat()
  {
    return fileFormat;
  }
  
  public long getGID()
  {
    return gid;
  }
  
  public int getHeaderSize()
  {
    return headerSize;
  }
  
  public int getAlignmentBoundary()
  {
    return alignmentBoundary;
  }
  
  public int getHeaderPadCount()
  {
    if (alignmentBoundary == 0) {
      return 0;
    }
    int size = headerSize + name.length() + 1;
    int remain = size % alignmentBoundary;
    if (remain > 0) {
      return alignmentBoundary - remain;
    }
    return 0;
  }
  
  public int getDataPadCount()
  {
    if (alignmentBoundary == 0) {
      return 0;
    }
    long size = filesize;
    int remain = (int)(size % alignmentBoundary);
    if (remain > 0) {
      return alignmentBoundary - remain;
    }
    return 0;
  }
  
  public long getInode()
  {
    return inode;
  }
  
  public long getMode()
  {
    return mode;
  }
  
  public String getName()
  {
    return name;
  }
  
  public long getNumberOfLinks()
  {
    return nlink;
  }
  
  public long getRemoteDevice()
  {
    checkOldFormat();
    return rmin;
  }
  
  public long getRemoteDeviceMaj()
  {
    checkNewFormat();
    return rmaj;
  }
  
  public long getRemoteDeviceMin()
  {
    checkNewFormat();
    return rmin;
  }
  
  public long getTime()
  {
    return mtime;
  }
  
  public long getUID()
  {
    return uid;
  }
  
  public boolean isBlockDevice()
  {
    return (mode & 0xF000) == 24576L;
  }
  
  public boolean isCharacterDevice()
  {
    return (mode & 0xF000) == 8192L;
  }
  
  public boolean isDirectory()
  {
    return (mode & 0xF000) == 16384L;
  }
  
  public boolean isNetwork()
  {
    return (mode & 0xF000) == 36864L;
  }
  
  public boolean isPipe()
  {
    return (mode & 0xF000) == 4096L;
  }
  
  public boolean isRegularFile()
  {
    return (mode & 0xF000) == 32768L;
  }
  
  public boolean isSocket()
  {
    return (mode & 0xF000) == 49152L;
  }
  
  public boolean isSymbolicLink()
  {
    return (mode & 0xF000) == 40960L;
  }
  
  public void setChksum(long chksum)
  {
    checkNewFormat();
    this.chksum = chksum;
  }
  
  public void setDevice(long device)
  {
    checkOldFormat();
    min = device;
  }
  
  public void setDeviceMaj(long maj)
  {
    checkNewFormat();
    this.maj = maj;
  }
  
  public void setDeviceMin(long min)
  {
    checkNewFormat();
    this.min = min;
  }
  
  public void setSize(long size)
  {
    if ((size < 0L) || (size > 4294967295L)) {
      throw new IllegalArgumentException("invalid entry size <" + size + ">");
    }
    filesize = size;
  }
  
  public void setGID(long gid)
  {
    this.gid = gid;
  }
  
  public void setInode(long inode)
  {
    this.inode = inode;
  }
  
  public void setMode(long mode)
  {
    long maskedMode = mode & 0xF000;
    switch ((int)maskedMode)
    {
    case 4096: 
    case 8192: 
    case 16384: 
    case 24576: 
    case 32768: 
    case 36864: 
    case 40960: 
    case 49152: 
      break;
    default: 
      throw new IllegalArgumentException("Unknown mode. Full: " + Long.toHexString(mode) + " Masked: " + Long.toHexString(maskedMode));
    }
    this.mode = mode;
  }
  
  public void setName(String name)
  {
    this.name = name;
  }
  
  public void setNumberOfLinks(long nlink)
  {
    this.nlink = nlink;
  }
  
  public void setRemoteDevice(long device)
  {
    checkOldFormat();
    rmin = device;
  }
  
  public void setRemoteDeviceMaj(long rmaj)
  {
    checkNewFormat();
    this.rmaj = rmaj;
  }
  
  public void setRemoteDeviceMin(long rmin)
  {
    checkNewFormat();
    this.rmin = rmin;
  }
  
  public void setTime(long time)
  {
    mtime = time;
  }
  
  public void setUID(long uid)
  {
    this.uid = uid;
  }
  
  public int hashCode()
  {
    int prime = 31;
    int result = 1;
    result = 31 * result + (name == null ? 0 : name.hashCode());
    return result;
  }
  
  public boolean equals(Object obj)
  {
    if (this == obj) {
      return true;
    }
    if ((obj == null) || (getClass() != obj.getClass())) {
      return false;
    }
    CpioArchiveEntry other = (CpioArchiveEntry)obj;
    if (name == null)
    {
      if (name != null) {
        return false;
      }
    }
    else if (!name.equals(name)) {
      return false;
    }
    return true;
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.compress.archivers.cpio.CpioArchiveEntry
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.compress.archivers.cpio;

import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import org.apache.commons.compress.archivers.ArchiveEntry;
import org.apache.commons.compress.archivers.ArchiveInputStream;
import org.apache.commons.compress.utils.ArchiveUtils;

public class CpioArchiveInputStream
  extends ArchiveInputStream
  implements CpioConstants
{
  private boolean closed = false;
  private CpioArchiveEntry entry;
  private long entryBytesRead = 0L;
  private boolean entryEOF = false;
  private final byte[] tmpbuf = new byte['?'];
  private long crc = 0L;
  private final InputStream in;
  
  public CpioArchiveInputStream(InputStream in)
  {
    this.in = in;
  }
  
  public int available()
    throws IOException
  {
    ensureOpen();
    if (entryEOF) {
      return 0;
    }
    return 1;
  }
  
  public void close()
    throws IOException
  {
    if (!closed)
    {
      in.close();
      closed = true;
    }
  }
  
  private void closeEntry()
    throws IOException
  {
    ensureOpen();
    while (read(tmpbuf, 0, tmpbuf.length) != -1) {}
    entryEOF = true;
  }
  
  private void ensureOpen()
    throws IOException
  {
    if (closed) {
      throw new IOException("Stream closed");
    }
  }
  
  public CpioArchiveEntry getNextCPIOEntry()
    throws IOException
  {
    ensureOpen();
    if (entry != null) {
      closeEntry();
    }
    byte[] magic = new byte[2];
    readFully(magic, 0, magic.length);
    if (CpioUtil.byteArray2long(magic, false) == 29127L)
    {
      entry = readOldBinaryEntry(false);
    }
    else if (CpioUtil.byteArray2long(magic, true) == 29127L)
    {
      entry = readOldBinaryEntry(true);
    }
    else
    {
      byte[] more_magic = new byte[4];
      readFully(more_magic, 0, more_magic.length);
      byte[] tmp = new byte[6];
      System.arraycopy(magic, 0, tmp, 0, magic.length);
      System.arraycopy(more_magic, 0, tmp, magic.length, more_magic.length);
      
      String magicString = ArchiveUtils.toAsciiString(tmp);
      if (magicString.equals("070701")) {
        entry = readNewEntry(false);
      } else if (magicString.equals("070702")) {
        entry = readNewEntry(true);
      } else if (magicString.equals("070707")) {
        entry = readOldAsciiEntry();
      } else {
        throw new IOException("Unknown magic [" + magicString + "]. Occured at byte: " + getCount());
      }
    }
    entryBytesRead = 0L;
    entryEOF = false;
    crc = 0L;
    if (entry.getName().equals("TRAILER!!!"))
    {
      entryEOF = true;
      return null;
    }
    return entry;
  }
  
  private void skip(int bytes)
    throws IOException
  {
    byte[] buff = new byte[4];
    if (bytes > 0) {
      readFully(buff, 0, bytes);
    }
  }
  
  public int read(byte[] b, int off, int len)
    throws IOException
  {
    ensureOpen();
    if ((off < 0) || (len < 0) || (off > b.length - len)) {
      throw new IndexOutOfBoundsException();
    }
    if (len == 0) {
      return 0;
    }
    if ((entry == null) || (entryEOF)) {
      return -1;
    }
    if (entryBytesRead == entry.getSize())
    {
      skip(entry.getDataPadCount());
      entryEOF = true;
      if ((entry.getFormat() == 2) && 
        (crc != entry.getChksum())) {
        throw new IOException("CRC Error. Occured at byte: " + getCount());
      }
      return -1;
    }
    int tmplength = (int)Math.min(len, entry.getSize() - entryBytesRead);
    if (tmplength < 0) {
      return -1;
    }
    int tmpread = readFully(b, off, tmplength);
    if (entry.getFormat() == 2) {
      for (int pos = 0; pos < tmpread; pos++) {
        crc += (b[pos] & 0xFF);
      }
    }
    entryBytesRead += tmpread;
    
    return tmpread;
  }
  
  private final int readFully(byte[] b, int off, int len)
    throws IOException
  {
    if (len < 0) {
      throw new IndexOutOfBoundsException();
    }
    int n = 0;
    while (n < len)
    {
      int count = in.read(b, off + n, len - n);
      count(count);
      if (count < 0) {
        throw new EOFException();
      }
      n += count;
    }
    return n;
  }
  
  private long readBinaryLong(int length, boolean swapHalfWord)
    throws IOException
  {
    byte[] tmp = new byte[length];
    readFully(tmp, 0, tmp.length);
    return CpioUtil.byteArray2long(tmp, swapHalfWord);
  }
  
  private long readAsciiLong(int length, int radix)
    throws IOException
  {
    byte[] tmpBuffer = new byte[length];
    readFully(tmpBuffer, 0, tmpBuffer.length);
    return Long.parseLong(ArchiveUtils.toAsciiString(tmpBuffer), radix);
  }
  
  private CpioArchiveEntry readNewEntry(boolean hasCrc)
    throws IOException
  {
    CpioArchiveEntry ret;
    CpioArchiveEntry ret;
    if (hasCrc) {
      ret = new CpioArchiveEntry((short)2);
    } else {
      ret = new CpioArchiveEntry((short)1);
    }
    ret.setInode(readAsciiLong(8, 16));
    long mode = readAsciiLong(8, 16);
    if (mode != 0L) {
      ret.setMode(mode);
    }
    ret.setUID(readAsciiLong(8, 16));
    ret.setGID(readAsciiLong(8, 16));
    ret.setNumberOfLinks(readAsciiLong(8, 16));
    ret.setTime(readAsciiLong(8, 16));
    ret.setSize(readAsciiLong(8, 16));
    ret.setDeviceMaj(readAsciiLong(8, 16));
    ret.setDeviceMin(readAsciiLong(8, 16));
    ret.setRemoteDeviceMaj(readAsciiLong(8, 16));
    ret.setRemoteDeviceMin(readAsciiLong(8, 16));
    long namesize = readAsciiLong(8, 16);
    ret.setChksum(readAsciiLong(8, 16));
    String name = readCString((int)namesize);
    ret.setName(name);
    if ((mode == 0L) && (!name.equals("TRAILER!!!"))) {
      throw new IOException("Mode 0 only allowed in the trailer. Found entry name: " + name + " Occured at byte: " + getCount());
    }
    skip(ret.getHeaderPadCount());
    
    return ret;
  }
  
  private CpioArchiveEntry readOldAsciiEntry()
    throws IOException
  {
    CpioArchiveEntry ret = new CpioArchiveEntry((short)4);
    
    ret.setDevice(readAsciiLong(6, 8));
    ret.setInode(readAsciiLong(6, 8));
    long mode = readAsciiLong(6, 8);
    if (mode != 0L) {
      ret.setMode(mode);
    }
    ret.setUID(readAsciiLong(6, 8));
    ret.setGID(readAsciiLong(6, 8));
    ret.setNumberOfLinks(readAsciiLong(6, 8));
    ret.setRemoteDevice(readAsciiLong(6, 8));
    ret.setTime(readAsciiLong(11, 8));
    long namesize = readAsciiLong(6, 8);
    ret.setSize(readAsciiLong(11, 8));
    String name = readCString((int)namesize);
    ret.setName(name);
    if ((mode == 0L) && (!name.equals("TRAILER!!!"))) {
      throw new IOException("Mode 0 only allowed in the trailer. Found entry: " + name + " Occured at byte: " + getCount());
    }
    return ret;
  }
  
  private CpioArchiveEntry readOldBinaryEntry(boolean swapHalfWord)
    throws IOException
  {
    CpioArchiveEntry ret = new CpioArchiveEntry((short)8);
    
    ret.setDevice(readBinaryLong(2, swapHalfWord));
    ret.setInode(readBinaryLong(2, swapHalfWord));
    long mode = readBinaryLong(2, swapHalfWord);
    if (mode != 0L) {
      ret.setMode(mode);
    }
    ret.setUID(readBinaryLong(2, swapHalfWord));
    ret.setGID(readBinaryLong(2, swapHalfWord));
    ret.setNumberOfLinks(readBinaryLong(2, swapHalfWord));
    ret.setRemoteDevice(readBinaryLong(2, swapHalfWord));
    ret.setTime(readBinaryLong(4, swapHalfWord));
    long namesize = readBinaryLong(2, swapHalfWord);
    ret.setSize(readBinaryLong(4, swapHalfWord));
    String name = readCString((int)namesize);
    ret.setName(name);
    if ((mode == 0L) && (!name.equals("TRAILER!!!"))) {
      throw new IOException("Mode 0 only allowed in the trailer. Found entry: " + name + "Occured at byte: " + getCount());
    }
    skip(ret.getHeaderPadCount());
    
    return ret;
  }
  
  private String readCString(int length)
    throws IOException
  {
    byte[] tmpBuffer = new byte[length];
    readFully(tmpBuffer, 0, tmpBuffer.length);
    return new String(tmpBuffer, 0, tmpBuffer.length - 1);
  }
  
  public long skip(long n)
    throws IOException
  {
    if (n < 0L) {
      throw new IllegalArgumentException("negative skip length");
    }
    ensureOpen();
    int max = (int)Math.min(n, 2147483647L);
    int total = 0;
    while (total < max)
    {
      int len = max - total;
      if (len > tmpbuf.length) {
        len = tmpbuf.length;
      }
      len = read(tmpbuf, 0, len);
      if (len == -1)
      {
        entryEOF = true;
        break;
      }
      total += len;
    }
    return total;
  }
  
  public ArchiveEntry getNextEntry()
    throws IOException
  {
    return getNextCPIOEntry();
  }
  
  public static boolean matches(byte[] signature, int length)
  {
    if (length < 6) {
      return false;
    }
    if ((signature[0] == 113) && ((signature[1] & 0xFF) == 199)) {
      return true;
    }
    if ((signature[1] == 113) && ((signature[0] & 0xFF) == 199)) {
      return true;
    }
    if (signature[0] != 48) {
      return false;
    }
    if (signature[1] != 55) {
      return false;
    }
    if (signature[2] != 48) {
      return false;
    }
    if (signature[3] != 55) {
      return false;
    }
    if (signature[4] != 48) {
      return false;
    }
    if (signature[5] == 49) {
      return true;
    }
    if (signature[5] == 50) {
      return true;
    }
    if (signature[5] == 55) {
      return true;
    }
    return false;
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.compress.archivers.cpio.CpioArchiveInputStream
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.compress.archivers.cpio;

import java.io.File;
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.HashMap;
import org.apache.commons.compress.archivers.ArchiveEntry;
import org.apache.commons.compress.archivers.ArchiveOutputStream;
import org.apache.commons.compress.utils.ArchiveUtils;

public class CpioArchiveOutputStream
  extends ArchiveOutputStream
  implements CpioConstants
{
  private CpioArchiveEntry entry;
  private boolean closed = false;
  private boolean finished;
  private final short entryFormat;
  private final HashMap names = new HashMap();
  private long crc = 0L;
  private long written;
  private final OutputStream out;
  
  public CpioArchiveOutputStream(OutputStream out, short format)
  {
    this.out = new FilterOutputStream(out);
    switch (format)
    {
    case 1: 
    case 2: 
    case 4: 
    case 8: 
      break;
    case 3: 
    case 5: 
    case 6: 
    case 7: 
    default: 
      throw new IllegalArgumentException("Unknown format: " + format);
    }
    entryFormat = format;
  }
  
  public CpioArchiveOutputStream(OutputStream out)
  {
    this(out, (short)1);
  }
  
  private void ensureOpen()
    throws IOException
  {
    if (closed) {
      throw new IOException("Stream closed");
    }
  }
  
  public void putArchiveEntry(ArchiveEntry entry)
    throws IOException
  {
    if (finished) {
      throw new IOException("Stream has already been finished");
    }
    CpioArchiveEntry e = (CpioArchiveEntry)entry;
    ensureOpen();
    if (this.entry != null) {
      closeArchiveEntry();
    }
    if (e.getTime() == -1L) {
      e.setTime(System.currentTimeMillis());
    }
    short format = e.getFormat();
    if (format != entryFormat) {
      throw new IOException("Header format: " + format + " does not match existing format: " + entryFormat);
    }
    if (names.put(e.getName(), e) != null) {
      throw new IOException("duplicate entry: " + e.getName());
    }
    writeHeader(e);
    this.entry = e;
    written = 0L;
  }
  
  private void writeHeader(CpioArchiveEntry e)
    throws IOException
  {
    switch (e.getFormat())
    {
    case 1: 
      out.write(ArchiveUtils.toAsciiBytes("070701"));
      writeNewEntry(e);
      break;
    case 2: 
      out.write(ArchiveUtils.toAsciiBytes("070702"));
      writeNewEntry(e);
      break;
    case 4: 
      out.write(ArchiveUtils.toAsciiBytes("070707"));
      writeOldAsciiEntry(e);
      break;
    case 8: 
      boolean swapHalfWord = true;
      writeBinaryLong(29127L, 2, swapHalfWord);
      writeOldBinaryEntry(e, swapHalfWord);
    }
  }
  
  private void writeNewEntry(CpioArchiveEntry entry)
    throws IOException
  {
    writeAsciiLong(entry.getInode(), 8, 16);
    writeAsciiLong(entry.getMode(), 8, 16);
    writeAsciiLong(entry.getUID(), 8, 16);
    writeAsciiLong(entry.getGID(), 8, 16);
    writeAsciiLong(entry.getNumberOfLinks(), 8, 16);
    writeAsciiLong(entry.getTime(), 8, 16);
    writeAsciiLong(entry.getSize(), 8, 16);
    writeAsciiLong(entry.getDeviceMaj(), 8, 16);
    writeAsciiLong(entry.getDeviceMin(), 8, 16);
    writeAsciiLong(entry.getRemoteDeviceMaj(), 8, 16);
    writeAsciiLong(entry.getRemoteDeviceMin(), 8, 16);
    writeAsciiLong(entry.getName().length() + 1, 8, 16);
    writeAsciiLong(entry.getChksum(), 8, 16);
    writeCString(entry.getName());
    pad(entry.getHeaderPadCount());
  }
  
  private void writeOldAsciiEntry(CpioArchiveEntry entry)
    throws IOException
  {
    writeAsciiLong(entry.getDevice(), 6, 8);
    writeAsciiLong(entry.getInode(), 6, 8);
    writeAsciiLong(entry.getMode(), 6, 8);
    writeAsciiLong(entry.getUID(), 6, 8);
    writeAsciiLong(entry.getGID(), 6, 8);
    writeAsciiLong(entry.getNumberOfLinks(), 6, 8);
    writeAsciiLong(entry.getRemoteDevice(), 6, 8);
    writeAsciiLong(entry.getTime(), 11, 8);
    writeAsciiLong(entry.getName().length() + 1, 6, 8);
    writeAsciiLong(entry.getSize(), 11, 8);
    writeCString(entry.getName());
  }
  
  private void writeOldBinaryEntry(CpioArchiveEntry entry, boolean swapHalfWord)
    throws IOException
  {
    writeBinaryLong(entry.getDevice(), 2, swapHalfWord);
    writeBinaryLong(entry.getInode(), 2, swapHalfWord);
    writeBinaryLong(entry.getMode(), 2, swapHalfWord);
    writeBinaryLong(entry.getUID(), 2, swapHalfWord);
    writeBinaryLong(entry.getGID(), 2, swapHalfWord);
    writeBinaryLong(entry.getNumberOfLinks(), 2, swapHalfWord);
    writeBinaryLong(entry.getRemoteDevice(), 2, swapHalfWord);
    writeBinaryLong(entry.getTime(), 4, swapHalfWord);
    writeBinaryLong(entry.getName().length() + 1, 2, swapHalfWord);
    writeBinaryLong(entry.getSize(), 4, swapHalfWord);
    writeCString(entry.getName());
    pad(entry.getHeaderPadCount());
  }
  
  public void closeArchiveEntry()
    throws IOException
  {
    if (finished) {
      throw new IOException("Stream has already been finished");
    }
    ensureOpen();
    if (entry == null) {
      throw new IOException("Trying to close non-existent entry");
    }
    if (entry.getSize() != written) {
      throw new IOException("invalid entry size (expected " + entry.getSize() + " but got " + written + " bytes)");
    }
    pad(entry.getDataPadCount());
    if ((entry.getFormat() == 2) && 
      (crc != entry.getChksum())) {
      throw new IOException("CRC Error");
    }
    entry = null;
    crc = 0L;
    written = 0L;
  }
  
  public
1 2 3 4 5 6 7

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd