link start!
This commit is contained in:
@@ -0,0 +1,196 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.ice.tar;
|
||||
|
||||
import com.ice.tar.InvalidHeaderException;
|
||||
import com.ice.tar.TarEntry;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
/*
|
||||
* Illegal identifiers - consider using --renameillegalidents true
|
||||
*/
|
||||
public class FastTarStream {
|
||||
private boolean debug;
|
||||
private boolean hasHitEOF;
|
||||
private TarEntry currEntry;
|
||||
private InputStream inStream;
|
||||
private int recordSize;
|
||||
|
||||
public void setDebug(boolean bl) {
|
||||
this.debug = bl;
|
||||
}
|
||||
|
||||
public TarEntry getNextEntry() throws IOException {
|
||||
int n;
|
||||
int n2;
|
||||
if (this.hasHitEOF) {
|
||||
return null;
|
||||
}
|
||||
if (this.currEntry != null && this.currEntry.getSize() > 0L && (n2 = ((int)this.currEntry.getSize() + (this.recordSize - 1)) / this.recordSize) > 0) {
|
||||
this.inStream.skip(n2 * this.recordSize);
|
||||
}
|
||||
byte[] byArray = new byte[this.recordSize];
|
||||
int n3 = 0;
|
||||
int n4 = this.recordSize;
|
||||
while (n4 > 0) {
|
||||
n = this.inStream.read(byArray, n3, n4);
|
||||
if (n == -1) {
|
||||
this.hasHitEOF = true;
|
||||
break;
|
||||
}
|
||||
n3 += n;
|
||||
n4 -= n;
|
||||
}
|
||||
if (!this.hasHitEOF) {
|
||||
this.hasHitEOF = true;
|
||||
n4 = 0;
|
||||
while (n4 < byArray.length) {
|
||||
if (byArray[n4] != 0) {
|
||||
this.hasHitEOF = false;
|
||||
break;
|
||||
}
|
||||
++n4;
|
||||
}
|
||||
}
|
||||
if (this.hasHitEOF) {
|
||||
this.currEntry = null;
|
||||
} else {
|
||||
try {
|
||||
this.currEntry = new TarEntry(byArray);
|
||||
if (this.debug) {
|
||||
byte[] byArray2 = new byte[byArray.length];
|
||||
n = 0;
|
||||
while (n < byArray.length) {
|
||||
byArray2[n] = byArray[n] == 0 ? 20 : byArray[n];
|
||||
++n;
|
||||
}
|
||||
String string = new String(byArray2);
|
||||
System.out.println("\n" + string);
|
||||
}
|
||||
if (byArray[257] != 117 || byArray[258] != 115 || byArray[259] != 116 || byArray[260] != 97 || byArray[261] != 114) {
|
||||
throw new InvalidHeaderException("header magic is not'ustar', but '" + byArray[257] + byArray[258] + byArray[259] + byArray[260] + byArray[261] + "', or (dec) " + byArray[257] + ", " + byArray[258] + ", " + byArray[259] + ", " + byArray[260] + ", " + byArray[261]);
|
||||
}
|
||||
}
|
||||
catch (InvalidHeaderException invalidHeaderException) {
|
||||
this.currEntry = null;
|
||||
throw invalidHeaderException;
|
||||
}
|
||||
}
|
||||
return this.currEntry;
|
||||
}
|
||||
|
||||
public static void main(String[] stringArray) {
|
||||
boolean bl = false;
|
||||
InputStream inputStream = null;
|
||||
try {
|
||||
TarEntry tarEntry;
|
||||
int n = 0;
|
||||
if (stringArray.length > 0) {
|
||||
if (stringArray[n].equals("-d")) {
|
||||
bl = true;
|
||||
++n;
|
||||
}
|
||||
inputStream = stringArray[n].endsWith(".gz") || stringArray[n].endsWith(".tgz") ? new GZIPInputStream(new FileInputStream(stringArray[n])) : new FileInputStream(stringArray[n]);
|
||||
} else {
|
||||
inputStream = System.in;
|
||||
}
|
||||
FastTarStream fastTarStream = new FastTarStream(inputStream);
|
||||
fastTarStream.setDebug(bl);
|
||||
int n2 = 56;
|
||||
int n3 = 9;
|
||||
int n4 = 8;
|
||||
StringBuffer stringBuffer = new StringBuffer(128);
|
||||
while ((tarEntry = fastTarStream.getNextEntry()) != null) {
|
||||
if (tarEntry.isDirectory()) {
|
||||
System.out.print("D ");
|
||||
stringBuffer.setLength(0);
|
||||
stringBuffer.append(tarEntry.getName());
|
||||
stringBuffer.setLength(stringBuffer.length() - 1);
|
||||
if (stringBuffer.length() > n2) {
|
||||
stringBuffer.setLength(n2);
|
||||
}
|
||||
while (stringBuffer.length() < n2) {
|
||||
stringBuffer.append('_');
|
||||
}
|
||||
stringBuffer.append('_');
|
||||
System.out.print(stringBuffer.toString());
|
||||
stringBuffer.setLength(0);
|
||||
while (stringBuffer.length() < n3) {
|
||||
stringBuffer.insert(0, '_');
|
||||
}
|
||||
stringBuffer.append(' ');
|
||||
System.out.print(stringBuffer.toString());
|
||||
stringBuffer.setLength(0);
|
||||
stringBuffer.append(tarEntry.getUserName());
|
||||
if (stringBuffer.length() > n4) {
|
||||
stringBuffer.setLength(n4);
|
||||
}
|
||||
while (stringBuffer.length() < n4) {
|
||||
stringBuffer.append(' ');
|
||||
}
|
||||
System.out.print(stringBuffer.toString());
|
||||
} else {
|
||||
System.out.print("F ");
|
||||
stringBuffer.setLength(0);
|
||||
stringBuffer.append(tarEntry.getName());
|
||||
if (stringBuffer.length() > n2) {
|
||||
stringBuffer.setLength(n2);
|
||||
}
|
||||
while (stringBuffer.length() < n2) {
|
||||
stringBuffer.append(' ');
|
||||
}
|
||||
stringBuffer.append(' ');
|
||||
System.out.print(stringBuffer.toString());
|
||||
stringBuffer.setLength(0);
|
||||
stringBuffer.append(tarEntry.getSize());
|
||||
if (stringBuffer.length() > n3) {
|
||||
stringBuffer.setLength(n3);
|
||||
}
|
||||
while (stringBuffer.length() < n3) {
|
||||
stringBuffer.insert(0, ' ');
|
||||
}
|
||||
stringBuffer.append(' ');
|
||||
System.out.print(stringBuffer.toString());
|
||||
stringBuffer.setLength(0);
|
||||
stringBuffer.append(tarEntry.getUserName());
|
||||
if (stringBuffer.length() > n4) {
|
||||
stringBuffer.setLength(n4);
|
||||
}
|
||||
while (stringBuffer.length() < n4) {
|
||||
stringBuffer.append(' ');
|
||||
}
|
||||
System.out.print(stringBuffer.toString());
|
||||
}
|
||||
System.out.println("");
|
||||
}
|
||||
}
|
||||
catch (IOException iOException) {
|
||||
iOException.printStackTrace(System.err);
|
||||
}
|
||||
}
|
||||
|
||||
private final /* synthetic */ void this() {
|
||||
this.debug = false;
|
||||
this.hasHitEOF = false;
|
||||
this.currEntry = null;
|
||||
this.inStream = null;
|
||||
this.recordSize = 512;
|
||||
}
|
||||
|
||||
public FastTarStream(InputStream inputStream) {
|
||||
this(inputStream, 512);
|
||||
}
|
||||
|
||||
public FastTarStream(InputStream inputStream, int n) {
|
||||
this.this();
|
||||
this.inStream = inputStream;
|
||||
this.hasHitEOF = false;
|
||||
this.currEntry = null;
|
||||
this.recordSize = n;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.ice.tar;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class InvalidHeaderException
|
||||
extends IOException {
|
||||
public InvalidHeaderException() {
|
||||
}
|
||||
|
||||
public InvalidHeaderException(String string) {
|
||||
super(string);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,285 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.ice.tar;
|
||||
|
||||
import com.ice.tar.InvalidHeaderException;
|
||||
import com.ice.tar.TarEntry;
|
||||
import com.ice.tar.TarInputStream;
|
||||
import com.ice.tar.TarOutputStream;
|
||||
import com.ice.tar.TarProgressDisplay;
|
||||
import com.ice.tar.TarTransFileTyper;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
public class TarArchive {
|
||||
protected boolean verbose;
|
||||
protected boolean debug;
|
||||
protected boolean keepOldFiles;
|
||||
protected boolean asciiTranslate;
|
||||
protected int userId;
|
||||
protected String userName;
|
||||
protected int groupId;
|
||||
protected String groupName;
|
||||
protected String rootPath;
|
||||
protected String tempPath;
|
||||
protected String pathPrefix;
|
||||
protected int recordSize;
|
||||
protected byte[] recordBuf;
|
||||
protected TarInputStream tarIn;
|
||||
protected TarOutputStream tarOut;
|
||||
protected TarTransFileTyper transTyper;
|
||||
protected TarProgressDisplay progressDisplay;
|
||||
|
||||
private final void initialize(int n) {
|
||||
this.recordSize = n;
|
||||
this.rootPath = null;
|
||||
this.pathPrefix = null;
|
||||
this.tempPath = System.getProperty("user.dir");
|
||||
this.userId = 0;
|
||||
this.userName = "";
|
||||
this.groupId = 0;
|
||||
this.groupName = "";
|
||||
this.debug = false;
|
||||
this.verbose = false;
|
||||
this.keepOldFiles = false;
|
||||
this.progressDisplay = null;
|
||||
this.recordBuf = new byte[this.getRecordSize()];
|
||||
}
|
||||
|
||||
public void setDebug(boolean bl) {
|
||||
this.debug = bl;
|
||||
if (this.tarIn != null) {
|
||||
this.tarIn.setDebug(bl);
|
||||
} else if (this.tarOut != null) {
|
||||
this.tarOut.setDebug(bl);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isVerbose() {
|
||||
return this.verbose;
|
||||
}
|
||||
|
||||
public void setVerbose(boolean bl) {
|
||||
this.verbose = bl;
|
||||
}
|
||||
|
||||
public void setTarProgressDisplay(TarProgressDisplay tarProgressDisplay) {
|
||||
this.progressDisplay = tarProgressDisplay;
|
||||
}
|
||||
|
||||
public void setKeepOldFiles(boolean bl) {
|
||||
this.keepOldFiles = bl;
|
||||
}
|
||||
|
||||
public void setAsciiTranslation(boolean bl) {
|
||||
this.asciiTranslate = bl;
|
||||
}
|
||||
|
||||
public void setTransFileTyper(TarTransFileTyper tarTransFileTyper) {
|
||||
this.transTyper = tarTransFileTyper;
|
||||
}
|
||||
|
||||
public void setUserInfo(int n, String string, int n2, String string2) {
|
||||
this.userId = n;
|
||||
this.userName = string;
|
||||
this.groupId = n2;
|
||||
this.groupName = string2;
|
||||
}
|
||||
|
||||
public int getUserId() {
|
||||
return this.userId;
|
||||
}
|
||||
|
||||
public String getUserName() {
|
||||
return this.userName;
|
||||
}
|
||||
|
||||
public int getGroupId() {
|
||||
return this.groupId;
|
||||
}
|
||||
|
||||
public String getGroupName() {
|
||||
return this.groupName;
|
||||
}
|
||||
|
||||
public String getTempDirectory() {
|
||||
return this.tempPath;
|
||||
}
|
||||
|
||||
public void setTempDirectory(String string) {
|
||||
this.tempPath = string;
|
||||
}
|
||||
|
||||
public int getRecordSize() {
|
||||
if (this.tarIn != null) {
|
||||
return this.tarIn.getRecordSize();
|
||||
}
|
||||
if (this.tarOut != null) {
|
||||
return this.tarOut.getRecordSize();
|
||||
}
|
||||
return 512;
|
||||
}
|
||||
|
||||
public void closeArchive() throws IOException {
|
||||
if (this.tarIn != null) {
|
||||
this.tarIn.close();
|
||||
} else if (this.tarOut != null) {
|
||||
this.tarOut.close();
|
||||
}
|
||||
}
|
||||
|
||||
public void listContents() throws IOException, InvalidHeaderException {
|
||||
while (true) {
|
||||
TarEntry tarEntry;
|
||||
if ((tarEntry = this.tarIn.getNextEntry()) == null) {
|
||||
if (!this.debug) break;
|
||||
System.err.println("READ EOF RECORD");
|
||||
break;
|
||||
}
|
||||
if (this.progressDisplay == null) continue;
|
||||
this.progressDisplay.showTarProgressMessage(tarEntry.getName());
|
||||
}
|
||||
}
|
||||
|
||||
public void extractContents(File file) throws IOException, InvalidHeaderException {
|
||||
while (true) {
|
||||
TarEntry tarEntry;
|
||||
if ((tarEntry = this.tarIn.getNextEntry()) == null) {
|
||||
if (!this.debug) break;
|
||||
System.err.println("READ EOF RECORD");
|
||||
break;
|
||||
}
|
||||
this.extractEntry(file, tarEntry);
|
||||
}
|
||||
}
|
||||
|
||||
private final void extractEntry(File file, TarEntry tarEntry) throws IOException {
|
||||
if (this.verbose && this.progressDisplay != null) {
|
||||
this.progressDisplay.showTarProgressMessage(tarEntry.getName());
|
||||
}
|
||||
String string = tarEntry.getName();
|
||||
string = string.replace('/', File.separatorChar);
|
||||
File file2 = new File(file, string);
|
||||
if (tarEntry.isDirectory()) {
|
||||
if (!file2.exists() && !file2.mkdirs()) {
|
||||
throw new IOException("error making directory path '" + file2.getPath() + '\'');
|
||||
}
|
||||
} else {
|
||||
File file3 = new File(file2.getParent());
|
||||
if (!file3.exists() && !file3.mkdirs()) {
|
||||
throw new IOException("error making directory path '" + file3.getPath() + '\'');
|
||||
}
|
||||
if (this.keepOldFiles && file2.exists()) {
|
||||
if (this.verbose && this.progressDisplay != null) {
|
||||
this.progressDisplay.showTarProgressMessage("not overwriting " + tarEntry.getName());
|
||||
}
|
||||
} else {
|
||||
int n;
|
||||
boolean bl = false;
|
||||
FileOutputStream fileOutputStream = new FileOutputStream(file2);
|
||||
PrintWriter printWriter = null;
|
||||
if (bl) {
|
||||
printWriter = new PrintWriter(fileOutputStream);
|
||||
}
|
||||
byte[] byArray = new byte[32768];
|
||||
while ((n = this.tarIn.read(byArray)) != -1) {
|
||||
if (bl && printWriter != null) {
|
||||
int n2 = 0;
|
||||
int n3 = 0;
|
||||
while (n3 < n) {
|
||||
if (byArray[n3] == 10) {
|
||||
String string2 = new String(byArray, n2, n3 - n2);
|
||||
printWriter.println(string2);
|
||||
n2 = n3 + 1;
|
||||
}
|
||||
++n3;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
fileOutputStream.write(byArray, 0, n);
|
||||
}
|
||||
if (bl && printWriter != null) {
|
||||
printWriter.close();
|
||||
} else {
|
||||
fileOutputStream.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void writeEntry(TarEntry tarEntry, boolean bl) throws IOException {
|
||||
boolean bl2 = tarEntry.isUnixTarFormat();
|
||||
File file = tarEntry.getFile();
|
||||
TarEntry tarEntry2 = (TarEntry)tarEntry.clone();
|
||||
if (this.verbose && this.progressDisplay != null) {
|
||||
this.progressDisplay.showTarProgressMessage(tarEntry2.getName());
|
||||
}
|
||||
String string = null;
|
||||
if (this.rootPath != null && tarEntry2.getName().startsWith(this.rootPath)) {
|
||||
string = tarEntry2.getName().substring(this.rootPath.length() + 1);
|
||||
}
|
||||
if (this.pathPrefix != null) {
|
||||
String string2 = string = string == null ? this.pathPrefix + '/' + tarEntry2.getName() : this.pathPrefix + '/' + string;
|
||||
}
|
||||
if (string != null) {
|
||||
tarEntry2.setName(string);
|
||||
}
|
||||
this.tarOut.putNextEntry(tarEntry2);
|
||||
if (tarEntry2.isDirectory()) {
|
||||
if (bl) {
|
||||
TarEntry[] tarEntryArray = tarEntry2.getDirectoryEntries();
|
||||
int n = 0;
|
||||
while (n < tarEntryArray.length) {
|
||||
TarEntry tarEntry3 = tarEntryArray[n];
|
||||
if (bl2) {
|
||||
tarEntry3.setUnixTarFormat();
|
||||
}
|
||||
this.writeEntry(tarEntry3, bl);
|
||||
++n;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
int n;
|
||||
FileInputStream fileInputStream = new FileInputStream(file);
|
||||
byte[] byArray = new byte[32768];
|
||||
while ((n = fileInputStream.read(byArray, 0, byArray.length)) != -1) {
|
||||
this.tarOut.write(byArray, 0, n);
|
||||
}
|
||||
fileInputStream.close();
|
||||
this.tarOut.closeEntry();
|
||||
}
|
||||
}
|
||||
|
||||
public TarArchive(InputStream inputStream) {
|
||||
this(inputStream, 10240);
|
||||
}
|
||||
|
||||
public TarArchive(InputStream inputStream, int n) {
|
||||
this(inputStream, n, 512);
|
||||
}
|
||||
|
||||
public TarArchive(InputStream inputStream, int n, int n2) {
|
||||
this.tarIn = new TarInputStream(inputStream, n, n2);
|
||||
this.initialize(n2);
|
||||
}
|
||||
|
||||
public TarArchive(OutputStream outputStream) {
|
||||
this(outputStream, 10240);
|
||||
}
|
||||
|
||||
public TarArchive(OutputStream outputStream, int n) {
|
||||
this(outputStream, n, 512);
|
||||
}
|
||||
|
||||
public TarArchive(OutputStream outputStream, int n, int n2) {
|
||||
this.tarOut = new TarOutputStream(outputStream, n, n2);
|
||||
this.initialize(n2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,227 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.ice.tar;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
public class TarBuffer {
|
||||
public static final int DEFAULT_RCDSIZE = 512;
|
||||
public static final int DEFAULT_BLKSIZE = 10240;
|
||||
private InputStream inStream;
|
||||
private OutputStream outStream;
|
||||
private byte[] blockBuffer;
|
||||
private int currBlkIdx;
|
||||
private int currRecIdx;
|
||||
private int blockSize;
|
||||
private int recordSize;
|
||||
private int recsPerBlock;
|
||||
private boolean debug;
|
||||
|
||||
private final void initialize(int n, int n2) {
|
||||
this.debug = false;
|
||||
this.blockSize = n;
|
||||
this.recordSize = n2;
|
||||
this.recsPerBlock = this.blockSize / this.recordSize;
|
||||
this.blockBuffer = new byte[this.blockSize];
|
||||
if (this.inStream != null) {
|
||||
this.currBlkIdx = -1;
|
||||
this.currRecIdx = this.recsPerBlock;
|
||||
} else {
|
||||
this.currBlkIdx = 0;
|
||||
this.currRecIdx = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public int getBlockSize() {
|
||||
return this.blockSize;
|
||||
}
|
||||
|
||||
public int getRecordSize() {
|
||||
return this.recordSize;
|
||||
}
|
||||
|
||||
public void setDebug(boolean bl) {
|
||||
this.debug = bl;
|
||||
}
|
||||
|
||||
public boolean isEOFRecord(byte[] byArray) {
|
||||
int n = 0;
|
||||
int n2 = this.getRecordSize();
|
||||
while (n < n2) {
|
||||
if (byArray[n] != 0) {
|
||||
return false;
|
||||
}
|
||||
++n;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void skipRecord() throws IOException {
|
||||
if (this.debug) {
|
||||
System.err.println("SkipRecord: recIdx = " + this.currRecIdx + " blkIdx = " + this.currBlkIdx);
|
||||
}
|
||||
if (this.inStream == null) {
|
||||
throw new IOException("reading (via skip) from an output buffer");
|
||||
}
|
||||
if (this.currRecIdx >= this.recsPerBlock && !this.readBlock()) {
|
||||
return;
|
||||
}
|
||||
++this.currRecIdx;
|
||||
}
|
||||
|
||||
public byte[] readRecord() throws IOException {
|
||||
if (this.debug) {
|
||||
System.err.println("ReadRecord: recIdx = " + this.currRecIdx + " blkIdx = " + this.currBlkIdx);
|
||||
}
|
||||
if (this.inStream == null) {
|
||||
throw new IOException("reading from an output buffer");
|
||||
}
|
||||
if (this.currRecIdx >= this.recsPerBlock && !this.readBlock()) {
|
||||
return null;
|
||||
}
|
||||
byte[] byArray = new byte[this.recordSize];
|
||||
System.arraycopy(this.blockBuffer, this.currRecIdx * this.recordSize, byArray, 0, this.recordSize);
|
||||
++this.currRecIdx;
|
||||
return byArray;
|
||||
}
|
||||
|
||||
private final boolean readBlock() throws IOException {
|
||||
if (this.debug) {
|
||||
System.err.println("ReadBlock: blkIdx = " + this.currBlkIdx);
|
||||
}
|
||||
if (this.inStream == null) {
|
||||
throw new IOException("reading from an output buffer");
|
||||
}
|
||||
this.currRecIdx = 0;
|
||||
int n = 0;
|
||||
int n2 = this.blockSize;
|
||||
while (n2 > 0) {
|
||||
long l = this.inStream.read(this.blockBuffer, n, n2);
|
||||
if (l == (long)-1) break;
|
||||
n = (int)((long)n + l);
|
||||
n2 = (int)((long)n2 - l);
|
||||
if (l == (long)this.blockSize || !this.debug) continue;
|
||||
System.err.println("ReadBlock: INCOMPLETE READ " + l + " of " + this.blockSize + " bytes read.");
|
||||
}
|
||||
++this.currBlkIdx;
|
||||
return true;
|
||||
}
|
||||
|
||||
public int getCurrentBlockNum() {
|
||||
return this.currBlkIdx;
|
||||
}
|
||||
|
||||
public int getCurrentRecordNum() {
|
||||
return this.currRecIdx - 1;
|
||||
}
|
||||
|
||||
public void writeRecord(byte[] byArray) throws IOException {
|
||||
if (this.debug) {
|
||||
System.err.println("WriteRecord: recIdx = " + this.currRecIdx + " blkIdx = " + this.currBlkIdx);
|
||||
}
|
||||
if (this.outStream == null) {
|
||||
throw new IOException("writing to an input buffer");
|
||||
}
|
||||
if (byArray.length != this.recordSize) {
|
||||
throw new IOException("record to write has length '" + byArray.length + "' which is not the record size of '" + this.recordSize + '\'');
|
||||
}
|
||||
if (this.currRecIdx >= this.recsPerBlock) {
|
||||
this.writeBlock();
|
||||
}
|
||||
System.arraycopy(byArray, 0, this.blockBuffer, this.currRecIdx * this.recordSize, this.recordSize);
|
||||
++this.currRecIdx;
|
||||
}
|
||||
|
||||
public void writeRecord(byte[] byArray, int n) throws IOException {
|
||||
if (this.debug) {
|
||||
System.err.println("WriteRecord: recIdx = " + this.currRecIdx + " blkIdx = " + this.currBlkIdx);
|
||||
}
|
||||
if (this.outStream == null) {
|
||||
throw new IOException("writing to an input buffer");
|
||||
}
|
||||
if (n + this.recordSize > byArray.length) {
|
||||
throw new IOException("record has length '" + byArray.length + "' with offset '" + n + "' which is less than the record size of '" + this.recordSize + '\'');
|
||||
}
|
||||
if (this.currRecIdx >= this.recsPerBlock) {
|
||||
this.writeBlock();
|
||||
}
|
||||
System.arraycopy(byArray, n, this.blockBuffer, this.currRecIdx * this.recordSize, this.recordSize);
|
||||
++this.currRecIdx;
|
||||
}
|
||||
|
||||
private final void writeBlock() throws IOException {
|
||||
if (this.debug) {
|
||||
System.err.println("WriteBlock: blkIdx = " + this.currBlkIdx);
|
||||
}
|
||||
if (this.outStream == null) {
|
||||
throw new IOException("writing to an input buffer");
|
||||
}
|
||||
this.outStream.write(this.blockBuffer, 0, this.blockSize);
|
||||
this.outStream.flush();
|
||||
this.currRecIdx = 0;
|
||||
++this.currBlkIdx;
|
||||
}
|
||||
|
||||
private final void flushBlock() throws IOException {
|
||||
if (this.debug) {
|
||||
System.err.println("TarBuffer.flushBlock() called.");
|
||||
}
|
||||
if (this.outStream == null) {
|
||||
throw new IOException("writing to an input buffer");
|
||||
}
|
||||
if (this.currRecIdx > 0) {
|
||||
int n = this.currRecIdx * this.recordSize;
|
||||
byte[] byArray = new byte[this.blockSize - n];
|
||||
System.arraycopy(byArray, 0, this.blockBuffer, n, byArray.length);
|
||||
this.writeBlock();
|
||||
}
|
||||
}
|
||||
|
||||
public void close() throws IOException {
|
||||
if (this.debug) {
|
||||
System.err.println("TarBuffer.closeBuffer().");
|
||||
}
|
||||
if (this.outStream != null) {
|
||||
this.flushBlock();
|
||||
if (this.outStream != System.out && this.outStream != System.err) {
|
||||
this.outStream.close();
|
||||
this.outStream = null;
|
||||
}
|
||||
} else if (this.inStream != null && this.inStream != System.in) {
|
||||
this.inStream.close();
|
||||
this.inStream = null;
|
||||
}
|
||||
}
|
||||
|
||||
public TarBuffer(InputStream inputStream) {
|
||||
this(inputStream, 10240);
|
||||
}
|
||||
|
||||
public TarBuffer(InputStream inputStream, int n) {
|
||||
this(inputStream, n, 512);
|
||||
}
|
||||
|
||||
public TarBuffer(InputStream inputStream, int n, int n2) {
|
||||
this.inStream = inputStream;
|
||||
this.outStream = null;
|
||||
this.initialize(n, n2);
|
||||
}
|
||||
|
||||
public TarBuffer(OutputStream outputStream) {
|
||||
this(outputStream, 10240);
|
||||
}
|
||||
|
||||
public TarBuffer(OutputStream outputStream, int n) {
|
||||
this(outputStream, n, 512);
|
||||
}
|
||||
|
||||
public TarBuffer(OutputStream outputStream, int n, int n2) {
|
||||
this.inStream = null;
|
||||
this.outStream = outputStream;
|
||||
this.initialize(n, n2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,389 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.ice.tar;
|
||||
|
||||
import com.ice.tar.InvalidHeaderException;
|
||||
import com.ice.tar.TarHeader;
|
||||
import java.io.File;
|
||||
import java.util.Date;
|
||||
|
||||
public class TarEntry
|
||||
implements Cloneable {
|
||||
protected File file;
|
||||
protected TarHeader header;
|
||||
protected boolean unixFormat;
|
||||
protected boolean ustarFormat;
|
||||
protected boolean gnuFormat;
|
||||
|
||||
private final void initialize() {
|
||||
this.file = null;
|
||||
this.header = new TarHeader();
|
||||
this.gnuFormat = false;
|
||||
this.ustarFormat = true;
|
||||
this.unixFormat = false;
|
||||
}
|
||||
|
||||
public Object clone() {
|
||||
TarEntry tarEntry = null;
|
||||
try {
|
||||
tarEntry = (TarEntry)super.clone();
|
||||
if (this.header != null) {
|
||||
tarEntry.header = (TarHeader)this.header.clone();
|
||||
}
|
||||
if (this.file != null) {
|
||||
tarEntry.file = new File(this.file.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
catch (CloneNotSupportedException cloneNotSupportedException) {
|
||||
cloneNotSupportedException.printStackTrace(System.err);
|
||||
}
|
||||
return tarEntry;
|
||||
}
|
||||
|
||||
public boolean isUSTarFormat() {
|
||||
return this.ustarFormat;
|
||||
}
|
||||
|
||||
public void setUSTarFormat() {
|
||||
this.ustarFormat = true;
|
||||
this.gnuFormat = false;
|
||||
this.unixFormat = false;
|
||||
}
|
||||
|
||||
public boolean isGNUTarFormat() {
|
||||
return this.gnuFormat;
|
||||
}
|
||||
|
||||
public void setGNUTarFormat() {
|
||||
this.gnuFormat = true;
|
||||
this.ustarFormat = false;
|
||||
this.unixFormat = false;
|
||||
}
|
||||
|
||||
public boolean isUnixTarFormat() {
|
||||
return this.unixFormat;
|
||||
}
|
||||
|
||||
public void setUnixTarFormat() {
|
||||
this.unixFormat = true;
|
||||
this.ustarFormat = false;
|
||||
this.gnuFormat = false;
|
||||
}
|
||||
|
||||
public boolean equals(TarEntry tarEntry) {
|
||||
return this.header.name.toString().equals(tarEntry.header.name.toString());
|
||||
}
|
||||
|
||||
public boolean isDescendent(TarEntry tarEntry) {
|
||||
return tarEntry.header.name.toString().startsWith(this.header.name.toString());
|
||||
}
|
||||
|
||||
public TarHeader getHeader() {
|
||||
return this.header;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.header.name.toString();
|
||||
}
|
||||
|
||||
public void setName(String string) {
|
||||
this.header.name = new StringBuffer(string);
|
||||
}
|
||||
|
||||
public int getUserId() {
|
||||
return this.header.userId;
|
||||
}
|
||||
|
||||
public void setUserId(int n) {
|
||||
this.header.userId = n;
|
||||
}
|
||||
|
||||
public int getGroupId() {
|
||||
return this.header.groupId;
|
||||
}
|
||||
|
||||
public void setGroupId(int n) {
|
||||
this.header.groupId = n;
|
||||
}
|
||||
|
||||
public String getUserName() {
|
||||
return this.header.userName.toString();
|
||||
}
|
||||
|
||||
public void setUserName(String string) {
|
||||
this.header.userName = new StringBuffer(string);
|
||||
}
|
||||
|
||||
public String getGroupName() {
|
||||
return this.header.groupName.toString();
|
||||
}
|
||||
|
||||
public void setGroupName(String string) {
|
||||
this.header.groupName = new StringBuffer(string);
|
||||
}
|
||||
|
||||
public void setIds(int n, int n2) {
|
||||
this.setUserId(n);
|
||||
this.setGroupId(n2);
|
||||
}
|
||||
|
||||
public void setNames(String string, String string2) {
|
||||
this.setUserName(string);
|
||||
this.setGroupName(string2);
|
||||
}
|
||||
|
||||
public void setModTime(long l) {
|
||||
this.header.modTime = l / 1000L;
|
||||
}
|
||||
|
||||
public void setModTime(Date date) {
|
||||
this.header.modTime = date.getTime() / 1000L;
|
||||
}
|
||||
|
||||
public Date getModTime() {
|
||||
return new Date(this.header.modTime * 1000L);
|
||||
}
|
||||
|
||||
public File getFile() {
|
||||
return this.file;
|
||||
}
|
||||
|
||||
public long getSize() {
|
||||
return this.header.size;
|
||||
}
|
||||
|
||||
public void setSize(long l) {
|
||||
this.header.size = l;
|
||||
}
|
||||
|
||||
public boolean isDirectory() {
|
||||
if (this.file != null) {
|
||||
return this.file.isDirectory();
|
||||
}
|
||||
if (this.header != null) {
|
||||
if (this.header.linkFlag == 53) {
|
||||
return true;
|
||||
}
|
||||
if (this.header.name.toString().endsWith("/")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void getFileTarHeader(TarHeader tarHeader, File file) throws InvalidHeaderException {
|
||||
this.file = file;
|
||||
String string = file.getPath();
|
||||
String string2 = System.getProperty("os.name");
|
||||
if (string2 != null) {
|
||||
String string3 = "windows";
|
||||
if (string2.toLowerCase().startsWith(string3) && string.length() > 2) {
|
||||
char c = string.charAt(0);
|
||||
char c2 = string.charAt(1);
|
||||
if (c2 == ':' && (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z')) {
|
||||
string = string.substring(2);
|
||||
}
|
||||
}
|
||||
}
|
||||
string = string.replace(File.separatorChar, '/');
|
||||
while (string.startsWith("/")) {
|
||||
string = string.substring(1);
|
||||
}
|
||||
tarHeader.linkName = new StringBuffer("");
|
||||
tarHeader.name = new StringBuffer(string);
|
||||
if (file.isDirectory()) {
|
||||
tarHeader.size = 0L;
|
||||
tarHeader.mode = 16877;
|
||||
tarHeader.linkFlag = (byte)53;
|
||||
if (tarHeader.name.charAt(tarHeader.name.length() - 1) != '/') {
|
||||
tarHeader.name.append("/");
|
||||
}
|
||||
} else {
|
||||
tarHeader.size = file.length();
|
||||
tarHeader.mode = 33188;
|
||||
tarHeader.linkFlag = (byte)48;
|
||||
}
|
||||
tarHeader.modTime = file.lastModified() / 1000L;
|
||||
tarHeader.checkSum = 0;
|
||||
tarHeader.devMajor = 0;
|
||||
tarHeader.devMinor = 0;
|
||||
}
|
||||
|
||||
public TarEntry[] getDirectoryEntries() throws InvalidHeaderException {
|
||||
if (this.file == null || !this.file.isDirectory()) {
|
||||
return new TarEntry[0];
|
||||
}
|
||||
String[] stringArray = this.file.list();
|
||||
TarEntry[] tarEntryArray = new TarEntry[stringArray.length];
|
||||
int n = 0;
|
||||
while (n < stringArray.length) {
|
||||
tarEntryArray[n] = new TarEntry(new File(this.file, stringArray[n]));
|
||||
++n;
|
||||
}
|
||||
return tarEntryArray;
|
||||
}
|
||||
|
||||
public long computeCheckSum(byte[] byArray) {
|
||||
long l = 0L;
|
||||
int n = 0;
|
||||
while (n < byArray.length) {
|
||||
l += (long)(0xFF & byArray[n]);
|
||||
++n;
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
public void writeEntryHeader(byte[] byArray) throws InvalidHeaderException {
|
||||
int n = 0;
|
||||
if (this.isUnixTarFormat() && this.header.name.length() > 100) {
|
||||
throw new InvalidHeaderException("file path is greater than 100 characters, " + this.header.name);
|
||||
}
|
||||
n = TarHeader.getFileNameBytes(this.header.name.toString(), byArray);
|
||||
n = TarHeader.getOctalBytes(this.header.mode, byArray, n, 8);
|
||||
n = TarHeader.getOctalBytes(this.header.userId, byArray, n, 8);
|
||||
n = TarHeader.getOctalBytes(this.header.groupId, byArray, n, 8);
|
||||
long l = this.header.size;
|
||||
n = TarHeader.getLongOctalBytes(l, byArray, n, 12);
|
||||
int n2 = n = TarHeader.getLongOctalBytes(this.header.modTime, byArray, n, 12);
|
||||
int n3 = 0;
|
||||
while (n3 < 8) {
|
||||
byArray[n++] = 32;
|
||||
++n3;
|
||||
}
|
||||
byArray[n++] = this.header.linkFlag;
|
||||
n = TarHeader.getNameBytes(this.header.linkName, byArray, n, 100);
|
||||
if (this.unixFormat) {
|
||||
n3 = 0;
|
||||
while (n3 < 8) {
|
||||
byArray[n++] = 0;
|
||||
++n3;
|
||||
}
|
||||
} else {
|
||||
n = TarHeader.getNameBytes(this.header.magic, byArray, n, 8);
|
||||
}
|
||||
n = TarHeader.getNameBytes(this.header.userName, byArray, n, 32);
|
||||
n = TarHeader.getNameBytes(this.header.groupName, byArray, n, 32);
|
||||
n = TarHeader.getOctalBytes(this.header.devMajor, byArray, n, 8);
|
||||
n = TarHeader.getOctalBytes(this.header.devMinor, byArray, n, 8);
|
||||
while (n < byArray.length) {
|
||||
byArray[n++] = 0;
|
||||
}
|
||||
long l2 = this.computeCheckSum(byArray);
|
||||
TarHeader.getCheckSumOctalBytes(l2, byArray, n2, 8);
|
||||
}
|
||||
|
||||
public void parseTarHeader(TarHeader tarHeader, byte[] byArray) throws InvalidHeaderException {
|
||||
int n = 0;
|
||||
if (byArray[257] == 0 && byArray[258] == 0 && byArray[259] == 0 && byArray[260] == 0 && byArray[261] == 0) {
|
||||
this.unixFormat = true;
|
||||
this.ustarFormat = false;
|
||||
this.gnuFormat = false;
|
||||
} else if (byArray[257] == 117 && byArray[258] == 115 && byArray[259] == 116 && byArray[260] == 97 && byArray[261] == 114 && byArray[262] == 0) {
|
||||
this.ustarFormat = true;
|
||||
this.gnuFormat = false;
|
||||
this.unixFormat = false;
|
||||
} else if (byArray[257] == 117 && byArray[258] == 115 && byArray[259] == 116 && byArray[260] == 97 && byArray[261] == 114 && byArray[262] != 0 && byArray[263] != 0) {
|
||||
this.gnuFormat = true;
|
||||
this.unixFormat = false;
|
||||
this.ustarFormat = false;
|
||||
} else {
|
||||
StringBuffer stringBuffer = new StringBuffer(128);
|
||||
stringBuffer.append("header magic is not 'ustar' or unix-style zeros, it is '");
|
||||
stringBuffer.append(byArray[257]);
|
||||
stringBuffer.append(byArray[258]);
|
||||
stringBuffer.append(byArray[259]);
|
||||
stringBuffer.append(byArray[260]);
|
||||
stringBuffer.append(byArray[261]);
|
||||
stringBuffer.append(byArray[262]);
|
||||
stringBuffer.append(byArray[263]);
|
||||
stringBuffer.append("', or (dec) ");
|
||||
stringBuffer.append(byArray[257]);
|
||||
stringBuffer.append(", ");
|
||||
stringBuffer.append(byArray[258]);
|
||||
stringBuffer.append(", ");
|
||||
stringBuffer.append(byArray[259]);
|
||||
stringBuffer.append(", ");
|
||||
stringBuffer.append(byArray[260]);
|
||||
stringBuffer.append(", ");
|
||||
stringBuffer.append(byArray[261]);
|
||||
stringBuffer.append(", ");
|
||||
stringBuffer.append(byArray[262]);
|
||||
stringBuffer.append(", ");
|
||||
stringBuffer.append(byArray[263]);
|
||||
throw new InvalidHeaderException(stringBuffer.toString());
|
||||
}
|
||||
tarHeader.name = TarHeader.parseFileName(byArray);
|
||||
n = 100;
|
||||
tarHeader.mode = (int)TarHeader.parseOctal(byArray, n, 8);
|
||||
tarHeader.userId = (int)TarHeader.parseOctal(byArray, n += 8, 8);
|
||||
tarHeader.groupId = (int)TarHeader.parseOctal(byArray, n += 8, 8);
|
||||
tarHeader.size = TarHeader.parseOctal(byArray, n += 8, 12);
|
||||
tarHeader.modTime = TarHeader.parseOctal(byArray, n += 12, 12);
|
||||
tarHeader.checkSum = (int)TarHeader.parseOctal(byArray, n += 12, 8);
|
||||
n += 8;
|
||||
tarHeader.linkFlag = byArray[n++];
|
||||
tarHeader.linkName = TarHeader.parseName(byArray, n, 100);
|
||||
n += 100;
|
||||
if (this.ustarFormat) {
|
||||
tarHeader.magic = TarHeader.parseName(byArray, n, 8);
|
||||
tarHeader.userName = TarHeader.parseName(byArray, n += 8, 32);
|
||||
tarHeader.groupName = TarHeader.parseName(byArray, n += 32, 32);
|
||||
tarHeader.devMajor = (int)TarHeader.parseOctal(byArray, n += 32, 8);
|
||||
tarHeader.devMinor = (int)TarHeader.parseOctal(byArray, n += 8, 8);
|
||||
} else {
|
||||
tarHeader.devMajor = 0;
|
||||
tarHeader.devMinor = 0;
|
||||
tarHeader.magic = new StringBuffer("");
|
||||
tarHeader.userName = new StringBuffer("");
|
||||
tarHeader.groupName = new StringBuffer("");
|
||||
}
|
||||
}
|
||||
|
||||
public void nameTarHeader(TarHeader tarHeader, String string) {
|
||||
boolean bl = string.endsWith("/");
|
||||
this.gnuFormat = false;
|
||||
this.ustarFormat = true;
|
||||
this.unixFormat = false;
|
||||
tarHeader.checkSum = 0;
|
||||
tarHeader.devMajor = 0;
|
||||
tarHeader.devMinor = 0;
|
||||
tarHeader.name = new StringBuffer(string);
|
||||
tarHeader.mode = bl ? 16877 : 33188;
|
||||
tarHeader.userId = 0;
|
||||
tarHeader.groupId = 0;
|
||||
tarHeader.size = 0L;
|
||||
tarHeader.checkSum = 0;
|
||||
tarHeader.modTime = new Date().getTime() / 1000L;
|
||||
tarHeader.linkFlag = (byte)(bl ? 53 : 48);
|
||||
tarHeader.linkName = new StringBuffer("");
|
||||
tarHeader.userName = new StringBuffer("");
|
||||
tarHeader.groupName = new StringBuffer("");
|
||||
tarHeader.devMajor = 0;
|
||||
tarHeader.devMinor = 0;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuffer stringBuffer = new StringBuffer(128);
|
||||
return stringBuffer.append("[TarEntry name=").append(this.getName()).append(", isDir=").append(this.isDirectory()).append(", size=").append(this.getSize()).append(", userId=").append(this.getUserId()).append(", user=").append(this.getUserName()).append(", groupId=").append(this.getGroupId()).append(", group=").append(this.getGroupName()).append("]").toString();
|
||||
}
|
||||
|
||||
protected TarEntry() {
|
||||
}
|
||||
|
||||
public TarEntry(String string) {
|
||||
this.initialize();
|
||||
this.nameTarHeader(this.header, string);
|
||||
}
|
||||
|
||||
public TarEntry(File file) throws InvalidHeaderException {
|
||||
this.initialize();
|
||||
this.getFileTarHeader(this.header, file);
|
||||
}
|
||||
|
||||
public TarEntry(byte[] byArray) throws InvalidHeaderException {
|
||||
this.initialize();
|
||||
this.parseTarHeader(this.header, byArray);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.ice.tar;
|
||||
|
||||
import com.ice.tar.TarEntry;
|
||||
import com.ice.tar.TarInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Enumeration;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
/*
|
||||
* Illegal identifiers - consider using --renameillegalidents true
|
||||
*/
|
||||
public class TarEntryEnumerator
|
||||
implements Enumeration {
|
||||
private TarInputStream tis;
|
||||
private boolean eof;
|
||||
private TarEntry readAhead;
|
||||
|
||||
public Object nextElement() throws NoSuchElementException {
|
||||
if (this.eof && this.readAhead == null) {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
TarEntry tarEntry = null;
|
||||
if (this.readAhead != null) {
|
||||
tarEntry = this.readAhead;
|
||||
this.readAhead = null;
|
||||
} else {
|
||||
tarEntry = this.getNext();
|
||||
}
|
||||
return tarEntry;
|
||||
}
|
||||
|
||||
public boolean hasMoreElements() {
|
||||
if (this.eof) {
|
||||
return false;
|
||||
}
|
||||
boolean bl = false;
|
||||
this.readAhead = this.getNext();
|
||||
if (this.readAhead != null) {
|
||||
bl = true;
|
||||
}
|
||||
return bl;
|
||||
}
|
||||
|
||||
private final TarEntry getNext() {
|
||||
TarEntry tarEntry = null;
|
||||
try {
|
||||
tarEntry = this.tis.getNextEntry();
|
||||
}
|
||||
catch (IOException iOException) {
|
||||
iOException.printStackTrace();
|
||||
}
|
||||
if (tarEntry == null) {
|
||||
this.eof = true;
|
||||
}
|
||||
return tarEntry;
|
||||
}
|
||||
|
||||
private final /* synthetic */ void this() {
|
||||
this.tis = null;
|
||||
this.eof = false;
|
||||
this.readAhead = null;
|
||||
}
|
||||
|
||||
public TarEntryEnumerator(TarInputStream tarInputStream) {
|
||||
this.this();
|
||||
this.tis = tarInputStream;
|
||||
this.eof = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.ice.tar;
|
||||
|
||||
import com.ice.tar.TarEntry;
|
||||
import com.ice.tar.TarOutputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
/*
|
||||
* Illegal identifiers - consider using --renameillegalidents true
|
||||
*/
|
||||
public class TarGzOutputStream
|
||||
extends TarOutputStream {
|
||||
private TarOutputStream tos;
|
||||
private GZIPOutputStream gzip;
|
||||
private ByteArrayOutputStream bos;
|
||||
private TarEntry currentEntry;
|
||||
|
||||
public void setDebug(boolean bl) {
|
||||
this.tos.setDebug(bl);
|
||||
}
|
||||
|
||||
public void setBufferDebug(boolean bl) {
|
||||
this.tos.setBufferDebug(bl);
|
||||
}
|
||||
|
||||
public void finish() throws IOException {
|
||||
if (this.currentEntry != null) {
|
||||
this.closeEntry();
|
||||
}
|
||||
this.tos.finish();
|
||||
}
|
||||
|
||||
public void close() throws IOException {
|
||||
this.tos.close();
|
||||
this.gzip.finish();
|
||||
}
|
||||
|
||||
public int getRecordSize() {
|
||||
return this.tos.getRecordSize();
|
||||
}
|
||||
|
||||
public void putNextEntry(TarEntry tarEntry) throws IOException {
|
||||
if (tarEntry.getSize() != 0L) {
|
||||
this.tos.putNextEntry(tarEntry);
|
||||
} else {
|
||||
this.currentEntry = tarEntry;
|
||||
}
|
||||
}
|
||||
|
||||
public void closeEntry() throws IOException {
|
||||
if (this.currentEntry == null) {
|
||||
this.tos.closeEntry();
|
||||
} else {
|
||||
this.currentEntry.setSize(this.bos.size());
|
||||
this.tos.putNextEntry(this.currentEntry);
|
||||
this.bos.writeTo(this.tos);
|
||||
this.tos.closeEntry();
|
||||
this.currentEntry = null;
|
||||
this.bos = new ByteArrayOutputStream();
|
||||
}
|
||||
}
|
||||
|
||||
public void write(int n) throws IOException {
|
||||
if (this.currentEntry == null) {
|
||||
this.tos.write(n);
|
||||
} else {
|
||||
this.bos.write(n);
|
||||
}
|
||||
}
|
||||
|
||||
public void write(byte[] byArray) throws IOException {
|
||||
if (this.currentEntry == null) {
|
||||
this.tos.write(byArray);
|
||||
} else {
|
||||
this.bos.write(byArray);
|
||||
}
|
||||
}
|
||||
|
||||
public void write(byte[] byArray, int n, int n2) throws IOException {
|
||||
if (this.currentEntry == null) {
|
||||
this.tos.write(byArray, n, n2);
|
||||
} else {
|
||||
this.bos.write(byArray, n, n2);
|
||||
}
|
||||
}
|
||||
|
||||
private final /* synthetic */ void this() {
|
||||
this.tos = null;
|
||||
this.gzip = null;
|
||||
this.bos = null;
|
||||
this.currentEntry = null;
|
||||
}
|
||||
|
||||
public TarGzOutputStream(OutputStream outputStream) throws IOException {
|
||||
super(null);
|
||||
this.this();
|
||||
this.gzip = new GZIPOutputStream(outputStream);
|
||||
this.tos = new TarOutputStream(this.gzip);
|
||||
this.bos = new ByteArrayOutputStream();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,212 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.ice.tar;
|
||||
|
||||
import com.ice.tar.InvalidHeaderException;
|
||||
|
||||
public class TarHeader
|
||||
implements Cloneable {
|
||||
public static final int NAMELEN = 100;
|
||||
public static final int NAMEOFFSET = 0;
|
||||
public static final int PREFIXLEN = 155;
|
||||
public static final int PREFIXOFFSET = 345;
|
||||
public static final int MODELEN = 8;
|
||||
public static final int UIDLEN = 8;
|
||||
public static final int GIDLEN = 8;
|
||||
public static final int CHKSUMLEN = 8;
|
||||
public static final int SIZELEN = 12;
|
||||
public static final int MAGICLEN = 8;
|
||||
public static final int MODTIMELEN = 12;
|
||||
public static final int UNAMELEN = 32;
|
||||
public static final int GNAMELEN = 32;
|
||||
public static final int DEVLEN = 8;
|
||||
public static final byte LF_OLDNORM = 0;
|
||||
public static final byte LF_NORMAL = 48;
|
||||
public static final byte LF_LINK = 49;
|
||||
public static final byte LF_SYMLINK = 50;
|
||||
public static final byte LF_CHR = 51;
|
||||
public static final byte LF_BLK = 52;
|
||||
public static final byte LF_DIR = 53;
|
||||
public static final byte LF_FIFO = 54;
|
||||
public static final byte LF_CONTIG = 55;
|
||||
public static final String TMAGIC = "ustar";
|
||||
public static final String GNU_TMAGIC = "ustar ";
|
||||
public StringBuffer name;
|
||||
public int mode;
|
||||
public int userId;
|
||||
public int groupId;
|
||||
public long size;
|
||||
public long modTime;
|
||||
public int checkSum;
|
||||
public byte linkFlag;
|
||||
public StringBuffer linkName;
|
||||
public StringBuffer magic = new StringBuffer("ustar");
|
||||
public StringBuffer userName;
|
||||
public StringBuffer groupName;
|
||||
public int devMajor;
|
||||
public int devMinor;
|
||||
|
||||
public Object clone() {
|
||||
TarHeader tarHeader = null;
|
||||
try {
|
||||
tarHeader = (TarHeader)super.clone();
|
||||
tarHeader.name = this.name == null ? null : new StringBuffer(this.name.toString());
|
||||
tarHeader.mode = this.mode;
|
||||
tarHeader.userId = this.userId;
|
||||
tarHeader.groupId = this.groupId;
|
||||
tarHeader.size = this.size;
|
||||
tarHeader.modTime = this.modTime;
|
||||
tarHeader.checkSum = this.checkSum;
|
||||
tarHeader.linkFlag = this.linkFlag;
|
||||
tarHeader.linkName = this.linkName == null ? null : new StringBuffer(this.linkName.toString());
|
||||
tarHeader.magic = this.magic == null ? null : new StringBuffer(this.magic.toString());
|
||||
tarHeader.userName = this.userName == null ? null : new StringBuffer(this.userName.toString());
|
||||
tarHeader.groupName = this.groupName == null ? null : new StringBuffer(this.groupName.toString());
|
||||
tarHeader.devMajor = this.devMajor;
|
||||
tarHeader.devMinor = this.devMinor;
|
||||
}
|
||||
catch (CloneNotSupportedException cloneNotSupportedException) {
|
||||
cloneNotSupportedException.printStackTrace(System.err);
|
||||
}
|
||||
return tarHeader;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name.toString();
|
||||
}
|
||||
|
||||
public static long parseOctal(byte[] byArray, int n, int n2) throws InvalidHeaderException {
|
||||
long l = 0L;
|
||||
boolean bl = true;
|
||||
int n3 = n + n2;
|
||||
int n4 = n;
|
||||
while (n4 < n3) {
|
||||
if (byArray[n4] == 0) break;
|
||||
if (byArray[n4] == 32 || byArray[n4] == 48) {
|
||||
if (!bl) {
|
||||
if (byArray[n4] == 32) break;
|
||||
}
|
||||
} else {
|
||||
bl = false;
|
||||
l = (l << 3) + (long)(byArray[n4] - 48);
|
||||
}
|
||||
++n4;
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
public static StringBuffer parseFileName(byte[] byArray) {
|
||||
int n;
|
||||
StringBuffer stringBuffer = new StringBuffer(256);
|
||||
if (byArray[345] != 0) {
|
||||
n = 345;
|
||||
while (n < 500 && byArray[n] != 0) {
|
||||
stringBuffer.append((char)byArray[n]);
|
||||
++n;
|
||||
}
|
||||
stringBuffer.append("/");
|
||||
}
|
||||
n = 0;
|
||||
while (n < 100 && byArray[n] != 0) {
|
||||
stringBuffer.append((char)byArray[n]);
|
||||
++n;
|
||||
}
|
||||
return stringBuffer;
|
||||
}
|
||||
|
||||
public static StringBuffer parseName(byte[] byArray, int n, int n2) throws InvalidHeaderException {
|
||||
StringBuffer stringBuffer = new StringBuffer(n2);
|
||||
int n3 = n + n2;
|
||||
int n4 = n;
|
||||
while (n4 < n3) {
|
||||
if (byArray[n4] == 0) break;
|
||||
stringBuffer.append((char)byArray[n4]);
|
||||
++n4;
|
||||
}
|
||||
return stringBuffer;
|
||||
}
|
||||
|
||||
public static int getFileNameBytes(String string, byte[] byArray) throws InvalidHeaderException {
|
||||
if (string.length() > 100) {
|
||||
int n = string.indexOf("/", string.length() - 100);
|
||||
if (n == -1) {
|
||||
throw new InvalidHeaderException("file name is greater than 100 characters, " + string);
|
||||
}
|
||||
String string2 = string.substring(n + 1);
|
||||
String string3 = string.substring(0, n);
|
||||
if (string3.length() > 155) {
|
||||
throw new InvalidHeaderException("file prefix is greater than 155 characters");
|
||||
}
|
||||
TarHeader.getNameBytes(new StringBuffer(string2), byArray, 0, 100);
|
||||
TarHeader.getNameBytes(new StringBuffer(string3), byArray, 345, 155);
|
||||
} else {
|
||||
TarHeader.getNameBytes(new StringBuffer(string), byArray, 0, 100);
|
||||
}
|
||||
return 100;
|
||||
}
|
||||
|
||||
public static int getNameBytes(StringBuffer stringBuffer, byte[] byArray, int n, int n2) {
|
||||
int n3 = 0;
|
||||
while (n3 < n2 && n3 < stringBuffer.length()) {
|
||||
byArray[n + n3] = (byte)stringBuffer.charAt(n3);
|
||||
++n3;
|
||||
}
|
||||
while (n3 < n2) {
|
||||
byArray[n + n3] = 0;
|
||||
++n3;
|
||||
}
|
||||
return n + n2;
|
||||
}
|
||||
|
||||
public static int getOctalBytes(long l, byte[] byArray, int n, int n2) {
|
||||
int n3 = n2 - 1;
|
||||
byArray[n + n3] = 0;
|
||||
byArray[n + --n3] = 32;
|
||||
--n3;
|
||||
if (l == 0L) {
|
||||
byArray[n + n3] = 48;
|
||||
--n3;
|
||||
} else {
|
||||
long l2 = l;
|
||||
while (n3 >= 0 && l2 > 0L) {
|
||||
byArray[n + n3] = (byte)(48 + (byte)(l2 & 7L));
|
||||
l2 >>= 3;
|
||||
--n3;
|
||||
}
|
||||
}
|
||||
while (n3 >= 0) {
|
||||
byArray[n + n3] = 32;
|
||||
--n3;
|
||||
}
|
||||
return n + n2;
|
||||
}
|
||||
|
||||
public static int getLongOctalBytes(long l, byte[] byArray, int n, int n2) {
|
||||
byte[] byArray2 = new byte[n2 + 1];
|
||||
TarHeader.getOctalBytes(l, byArray2, 0, n2 + 1);
|
||||
System.arraycopy(byArray2, 0, byArray, n, n2);
|
||||
return n + n2;
|
||||
}
|
||||
|
||||
public static int getCheckSumOctalBytes(long l, byte[] byArray, int n, int n2) {
|
||||
TarHeader.getOctalBytes(l, byArray, n, n2);
|
||||
byArray[n + n2 - 1] = 32;
|
||||
byArray[n + n2 - 2] = 0;
|
||||
return n + n2;
|
||||
}
|
||||
|
||||
public TarHeader() {
|
||||
this.name = new StringBuffer();
|
||||
this.linkName = new StringBuffer();
|
||||
String string = System.getProperty("user.name", "");
|
||||
if (string.length() > 31) {
|
||||
string = string.substring(0, 31);
|
||||
}
|
||||
this.userId = 0;
|
||||
this.groupId = 0;
|
||||
this.userName = new StringBuffer(string);
|
||||
this.groupName = new StringBuffer("");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,238 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.ice.tar;
|
||||
|
||||
import com.ice.tar.InvalidHeaderException;
|
||||
import com.ice.tar.TarBuffer;
|
||||
import com.ice.tar.TarEntry;
|
||||
import java.io.File;
|
||||
import java.io.FilterInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
public class TarInputStream
|
||||
extends FilterInputStream {
|
||||
protected boolean debug;
|
||||
protected boolean hasHitEOF;
|
||||
protected long entrySize;
|
||||
protected long entryOffset;
|
||||
protected byte[] oneBuf;
|
||||
protected byte[] readBuf;
|
||||
protected TarBuffer buffer;
|
||||
protected TarEntry currEntry;
|
||||
protected EntryFactory eFactory;
|
||||
|
||||
public void setDebug(boolean bl) {
|
||||
this.debug = bl;
|
||||
}
|
||||
|
||||
public void setEntryFactory(EntryFactory entryFactory) {
|
||||
this.eFactory = entryFactory;
|
||||
}
|
||||
|
||||
public void setBufferDebug(boolean bl) {
|
||||
this.buffer.setDebug(bl);
|
||||
}
|
||||
|
||||
public void close() throws IOException {
|
||||
this.buffer.close();
|
||||
}
|
||||
|
||||
public int getRecordSize() {
|
||||
return this.buffer.getRecordSize();
|
||||
}
|
||||
|
||||
public int available() throws IOException {
|
||||
return (int)(this.entrySize - this.entryOffset);
|
||||
}
|
||||
|
||||
public long skip(long l) throws IOException {
|
||||
byte[] byArray = new byte[8192];
|
||||
long l2 = l;
|
||||
while (l2 > 0L) {
|
||||
int n = this.read(byArray, 0, l2 > (long)byArray.length ? byArray.length : (int)l2);
|
||||
if (n == -1) break;
|
||||
l2 -= (long)n;
|
||||
}
|
||||
return l - l2;
|
||||
}
|
||||
|
||||
public boolean markSupported() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void mark(int n) {
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
}
|
||||
|
||||
public long getEntryPosition() {
|
||||
return this.entryOffset;
|
||||
}
|
||||
|
||||
public long getStreamPosition() {
|
||||
return this.buffer.getBlockSize() * this.buffer.getCurrentBlockNum() + this.buffer.getCurrentRecordNum();
|
||||
}
|
||||
|
||||
public TarEntry getNextEntry() throws IOException {
|
||||
byte[] byArray;
|
||||
if (this.hasHitEOF) {
|
||||
return null;
|
||||
}
|
||||
if (this.currEntry != null) {
|
||||
long l = this.entrySize - this.entryOffset;
|
||||
if (this.debug) {
|
||||
System.err.println("TarInputStream: SKIP currENTRY '" + this.currEntry.getName() + "' SZ " + this.entrySize + " OFF " + this.entryOffset + " skipping " + l + " bytes");
|
||||
}
|
||||
if (l > 0L) {
|
||||
this.skip(l);
|
||||
}
|
||||
this.readBuf = null;
|
||||
}
|
||||
if ((byArray = this.buffer.readRecord()) == null) {
|
||||
if (this.debug) {
|
||||
System.err.println("READ NULL RECORD");
|
||||
}
|
||||
this.hasHitEOF = true;
|
||||
} else if (this.buffer.isEOFRecord(byArray)) {
|
||||
if (this.debug) {
|
||||
System.err.println("READ EOF RECORD");
|
||||
}
|
||||
this.hasHitEOF = true;
|
||||
}
|
||||
if (this.hasHitEOF) {
|
||||
this.currEntry = null;
|
||||
} else {
|
||||
try {
|
||||
this.currEntry = this.eFactory == null ? new TarEntry(byArray) : this.eFactory.createEntry(byArray);
|
||||
if (this.debug) {
|
||||
System.err.println("TarInputStream: SET CURRENTRY '" + this.currEntry.getName() + "' size = " + this.currEntry.getSize());
|
||||
}
|
||||
this.entryOffset = 0L;
|
||||
this.entrySize = this.currEntry.getSize();
|
||||
}
|
||||
catch (InvalidHeaderException invalidHeaderException) {
|
||||
this.entrySize = 0L;
|
||||
this.entryOffset = 0L;
|
||||
this.currEntry = null;
|
||||
throw new InvalidHeaderException("bad header in block " + this.buffer.getCurrentBlockNum() + " record " + this.buffer.getCurrentRecordNum() + ", " + invalidHeaderException.getMessage());
|
||||
}
|
||||
}
|
||||
return this.currEntry;
|
||||
}
|
||||
|
||||
public int read() throws IOException {
|
||||
int n = this.read(this.oneBuf, 0, 1);
|
||||
if (n == -1) {
|
||||
return n;
|
||||
}
|
||||
return this.oneBuf[0];
|
||||
}
|
||||
|
||||
public int read(byte[] byArray) throws IOException {
|
||||
return this.read(byArray, 0, byArray.length);
|
||||
}
|
||||
|
||||
public int read(byte[] byArray, int n, int n2) throws IOException {
|
||||
int n3;
|
||||
int n4 = 0;
|
||||
if (this.entryOffset >= this.entrySize) {
|
||||
return -1;
|
||||
}
|
||||
if ((long)n2 + this.entryOffset > this.entrySize) {
|
||||
n2 = (int)(this.entrySize - this.entryOffset);
|
||||
}
|
||||
if (this.readBuf != null) {
|
||||
int n5 = n2 > this.readBuf.length ? this.readBuf.length : n2;
|
||||
System.arraycopy(this.readBuf, 0, byArray, n, n5);
|
||||
if (n5 >= this.readBuf.length) {
|
||||
this.readBuf = null;
|
||||
} else {
|
||||
n3 = this.readBuf.length - n5;
|
||||
byte[] byArray2 = new byte[n3];
|
||||
System.arraycopy(this.readBuf, n5, byArray2, 0, n3);
|
||||
this.readBuf = byArray2;
|
||||
}
|
||||
n4 += n5;
|
||||
n2 -= n5;
|
||||
n += n5;
|
||||
}
|
||||
while (n2 > 0) {
|
||||
byte[] byArray3 = this.buffer.readRecord();
|
||||
if (byArray3 == null) {
|
||||
throw new IOException("unexpected EOF with " + n2 + " bytes unread");
|
||||
}
|
||||
int n6 = byArray3.length;
|
||||
n3 = n2;
|
||||
if (n6 > n3) {
|
||||
System.arraycopy(byArray3, 0, byArray, n, n3);
|
||||
this.readBuf = new byte[n6 - n3];
|
||||
System.arraycopy(byArray3, n3, this.readBuf, 0, n6 - n3);
|
||||
} else {
|
||||
n3 = n6;
|
||||
System.arraycopy(byArray3, 0, byArray, n, n6);
|
||||
}
|
||||
n4 += n3;
|
||||
n2 -= n3;
|
||||
n += n3;
|
||||
}
|
||||
this.entryOffset += (long)n4;
|
||||
return n4;
|
||||
}
|
||||
|
||||
public void copyEntryContents(OutputStream outputStream) throws IOException {
|
||||
int n;
|
||||
byte[] byArray = new byte[32768];
|
||||
while ((n = this.read(byArray, 0, byArray.length)) != -1) {
|
||||
outputStream.write(byArray, 0, n);
|
||||
}
|
||||
}
|
||||
|
||||
public TarInputStream(InputStream inputStream) {
|
||||
this(inputStream, 10240, 512);
|
||||
}
|
||||
|
||||
public TarInputStream(InputStream inputStream, int n) {
|
||||
this(inputStream, n, 512);
|
||||
}
|
||||
|
||||
public TarInputStream(InputStream inputStream, int n, int n2) {
|
||||
super(inputStream);
|
||||
this.buffer = new TarBuffer(inputStream, n, n2);
|
||||
this.readBuf = null;
|
||||
this.oneBuf = new byte[1];
|
||||
this.debug = false;
|
||||
this.hasHitEOF = false;
|
||||
this.eFactory = null;
|
||||
}
|
||||
|
||||
public static interface EntryFactory {
|
||||
public TarEntry createEntry(String var1);
|
||||
|
||||
public TarEntry createEntry(File var1) throws InvalidHeaderException;
|
||||
|
||||
public TarEntry createEntry(byte[] var1) throws InvalidHeaderException;
|
||||
}
|
||||
|
||||
/*
|
||||
* Illegal identifiers - consider using --renameillegalidents true
|
||||
*/
|
||||
public class EntryAdapter
|
||||
implements EntryFactory {
|
||||
public TarEntry createEntry(String string) {
|
||||
return new TarEntry(string);
|
||||
}
|
||||
|
||||
public TarEntry createEntry(File file) throws InvalidHeaderException {
|
||||
return new TarEntry(file);
|
||||
}
|
||||
|
||||
public TarEntry createEntry(byte[] byArray) throws InvalidHeaderException {
|
||||
return new TarEntry(byArray);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.ice.tar;
|
||||
|
||||
import com.ice.tar.InvalidHeaderException;
|
||||
import com.ice.tar.TarBuffer;
|
||||
import com.ice.tar.TarEntry;
|
||||
import java.io.FilterOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
public class TarOutputStream
|
||||
extends FilterOutputStream {
|
||||
protected boolean debug;
|
||||
protected long currSize;
|
||||
protected long currBytes;
|
||||
protected byte[] oneBuf;
|
||||
protected byte[] recordBuf;
|
||||
protected int assemLen;
|
||||
protected byte[] assemBuf;
|
||||
protected TarBuffer buffer;
|
||||
|
||||
public void setDebug(boolean bl) {
|
||||
this.debug = bl;
|
||||
}
|
||||
|
||||
public void setBufferDebug(boolean bl) {
|
||||
this.buffer.setDebug(bl);
|
||||
}
|
||||
|
||||
public void finish() throws IOException {
|
||||
this.writeEOFRecord();
|
||||
}
|
||||
|
||||
public void close() throws IOException {
|
||||
this.finish();
|
||||
this.buffer.close();
|
||||
}
|
||||
|
||||
public int getRecordSize() {
|
||||
return this.buffer.getRecordSize();
|
||||
}
|
||||
|
||||
public void putNextEntry(TarEntry tarEntry) throws IOException {
|
||||
StringBuffer stringBuffer = tarEntry.getHeader().name;
|
||||
if (tarEntry.isUnixTarFormat() && stringBuffer.length() > 100 || !tarEntry.isUnixTarFormat() && stringBuffer.length() > 255) {
|
||||
throw new InvalidHeaderException("file name '" + stringBuffer + "' is too long ( " + stringBuffer.length() + " > " + (tarEntry.isUnixTarFormat() ? 100 : 255) + " bytes )");
|
||||
}
|
||||
tarEntry.writeEntryHeader(this.recordBuf);
|
||||
this.buffer.writeRecord(this.recordBuf);
|
||||
this.currBytes = 0L;
|
||||
this.currSize = tarEntry.isDirectory() ? 0L : tarEntry.getSize();
|
||||
}
|
||||
|
||||
public void closeEntry() throws IOException {
|
||||
if (this.assemLen > 0) {
|
||||
int n = this.assemLen;
|
||||
while (n < this.assemBuf.length) {
|
||||
this.assemBuf[n] = 0;
|
||||
++n;
|
||||
}
|
||||
this.buffer.writeRecord(this.assemBuf);
|
||||
this.currBytes += (long)this.assemLen;
|
||||
this.assemLen = 0;
|
||||
}
|
||||
if (this.currBytes < this.currSize) {
|
||||
throw new IOException("entry closed at '" + this.currBytes + "' before the '" + this.currSize + "' bytes specified in the header were written");
|
||||
}
|
||||
}
|
||||
|
||||
public void write(int n) throws IOException {
|
||||
this.oneBuf[0] = (byte)n;
|
||||
this.write(this.oneBuf, 0, 1);
|
||||
}
|
||||
|
||||
public void write(byte[] byArray) throws IOException {
|
||||
this.write(byArray, 0, byArray.length);
|
||||
}
|
||||
|
||||
public void write(byte[] byArray, int n, int n2) throws IOException {
|
||||
if (this.currBytes + (long)n2 > this.currSize) {
|
||||
throw new IOException("request to write '" + n2 + "' bytes exceeds size in header of '" + this.currSize + "' bytes");
|
||||
}
|
||||
if (this.assemLen > 0) {
|
||||
if (this.assemLen + n2 >= this.recordBuf.length) {
|
||||
int n3 = this.recordBuf.length - this.assemLen;
|
||||
System.arraycopy(this.assemBuf, 0, this.recordBuf, 0, this.assemLen);
|
||||
System.arraycopy(byArray, n, this.recordBuf, this.assemLen, n3);
|
||||
this.buffer.writeRecord(this.recordBuf);
|
||||
this.currBytes += (long)this.recordBuf.length;
|
||||
n += n3;
|
||||
n2 -= n3;
|
||||
this.assemLen = 0;
|
||||
} else {
|
||||
System.arraycopy(byArray, n, this.assemBuf, this.assemLen, n2);
|
||||
n += n2;
|
||||
this.assemLen += n2;
|
||||
n2 -= n2;
|
||||
}
|
||||
}
|
||||
while (n2 > 0) {
|
||||
if (n2 < this.recordBuf.length) {
|
||||
System.arraycopy(byArray, n, this.assemBuf, this.assemLen, n2);
|
||||
this.assemLen += n2;
|
||||
break;
|
||||
}
|
||||
this.buffer.writeRecord(byArray, n);
|
||||
long l = this.recordBuf.length;
|
||||
this.currBytes += l;
|
||||
n2 = (int)((long)n2 - l);
|
||||
n = (int)((long)n + l);
|
||||
}
|
||||
}
|
||||
|
||||
private final void writeEOFRecord() throws IOException {
|
||||
int n = 0;
|
||||
while (n < this.recordBuf.length) {
|
||||
this.recordBuf[n] = 0;
|
||||
++n;
|
||||
}
|
||||
this.buffer.writeRecord(this.recordBuf);
|
||||
}
|
||||
|
||||
public TarOutputStream(OutputStream outputStream) {
|
||||
this(outputStream, 10240, 512);
|
||||
}
|
||||
|
||||
public TarOutputStream(OutputStream outputStream, int n) {
|
||||
this(outputStream, n, 512);
|
||||
}
|
||||
|
||||
public TarOutputStream(OutputStream outputStream, int n, int n2) {
|
||||
super(outputStream);
|
||||
this.buffer = new TarBuffer(outputStream, n, n2);
|
||||
this.debug = false;
|
||||
this.assemLen = 0;
|
||||
this.assemBuf = new byte[n2];
|
||||
this.recordBuf = new byte[n2];
|
||||
this.oneBuf = new byte[1];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.ice.tar;
|
||||
|
||||
public interface TarProgressDisplay {
|
||||
public void showTarProgressMessage(String var1);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.ice.tar;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class TarTransFileTyper {
|
||||
public boolean isAsciiFile(File file) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isAsciiFile(String string) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,312 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.ice.tar;
|
||||
|
||||
import com.ice.tar.InvalidHeaderException;
|
||||
import com.ice.tar.TarArchive;
|
||||
import com.ice.tar.TarEntry;
|
||||
import com.ice.tar.TarProgressDisplay;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
public class tar
|
||||
implements TarProgressDisplay {
|
||||
private boolean debug = false;
|
||||
private boolean verbose = false;
|
||||
private boolean compressed = false;
|
||||
private boolean listingArchive = false;
|
||||
private boolean writingArchive = true;
|
||||
private boolean unixArchiveFormat = false;
|
||||
private boolean keepOldFiles = false;
|
||||
private boolean asciiTranslate = false;
|
||||
private String archiveName = null;
|
||||
private int blockSize = 10240;
|
||||
private int userId;
|
||||
private String userName;
|
||||
private int groupId;
|
||||
private String groupName;
|
||||
|
||||
public static void main(String[] stringArray) {
|
||||
tar tar2 = new tar();
|
||||
tar2.instanceMain(stringArray);
|
||||
}
|
||||
|
||||
public void instanceMain(String[] stringArray) {
|
||||
Object object;
|
||||
Object object2;
|
||||
TarArchive tarArchive = null;
|
||||
int n = this.processArguments(stringArray);
|
||||
if (this.writingArchive) {
|
||||
object2 = System.out;
|
||||
if (this.archiveName != null && !this.archiveName.equals("-")) {
|
||||
try {
|
||||
object2 = new FileOutputStream(this.archiveName);
|
||||
}
|
||||
catch (IOException iOException) {
|
||||
object2 = null;
|
||||
iOException.printStackTrace(System.err);
|
||||
}
|
||||
}
|
||||
if (object2 != null) {
|
||||
if (this.compressed) {
|
||||
try {
|
||||
object2 = new GZIPOutputStream((OutputStream)object2);
|
||||
}
|
||||
catch (IOException iOException) {
|
||||
object2 = null;
|
||||
iOException.printStackTrace(System.err);
|
||||
}
|
||||
}
|
||||
tarArchive = new TarArchive((OutputStream)object2, this.blockSize);
|
||||
}
|
||||
} else {
|
||||
object2 = System.in;
|
||||
if (this.archiveName != null && !this.archiveName.equals("-")) {
|
||||
try {
|
||||
object2 = new FileInputStream(this.archiveName);
|
||||
}
|
||||
catch (IOException iOException) {
|
||||
object2 = null;
|
||||
iOException.printStackTrace(System.err);
|
||||
}
|
||||
}
|
||||
if (object2 != null) {
|
||||
if (this.compressed) {
|
||||
try {
|
||||
object2 = new GZIPInputStream((InputStream)object2);
|
||||
}
|
||||
catch (IOException iOException) {
|
||||
object2 = null;
|
||||
iOException.printStackTrace(System.err);
|
||||
}
|
||||
}
|
||||
tarArchive = new TarArchive((InputStream)object2, this.blockSize);
|
||||
}
|
||||
}
|
||||
if (tarArchive != null) {
|
||||
tarArchive.setDebug(this.debug);
|
||||
tarArchive.setVerbose(this.verbose);
|
||||
tarArchive.setTarProgressDisplay(this);
|
||||
tarArchive.setKeepOldFiles(this.keepOldFiles);
|
||||
tarArchive.setAsciiTranslation(this.asciiTranslate);
|
||||
tarArchive.setUserInfo(this.userId, this.userName, this.groupId, this.groupName);
|
||||
}
|
||||
if (tarArchive == null) {
|
||||
System.err.println("no processing due to errors");
|
||||
} else if (this.writingArchive) {
|
||||
while (n < stringArray.length) {
|
||||
try {
|
||||
object2 = new File(stringArray[n]);
|
||||
object = new TarEntry((File)object2);
|
||||
if (this.unixArchiveFormat) {
|
||||
((TarEntry)object).setUnixTarFormat();
|
||||
} else {
|
||||
((TarEntry)object).setUSTarFormat();
|
||||
}
|
||||
tarArchive.writeEntry((TarEntry)object, true);
|
||||
}
|
||||
catch (IOException iOException) {
|
||||
iOException.printStackTrace(System.err);
|
||||
}
|
||||
++n;
|
||||
}
|
||||
} else if (this.listingArchive) {
|
||||
try {
|
||||
tarArchive.listContents();
|
||||
}
|
||||
catch (InvalidHeaderException invalidHeaderException) {
|
||||
invalidHeaderException.printStackTrace(System.err);
|
||||
}
|
||||
catch (IOException iOException) {
|
||||
iOException.printStackTrace(System.err);
|
||||
}
|
||||
} else {
|
||||
object2 = System.getProperty("user.dir", null);
|
||||
object = new File((String)object2);
|
||||
if (!((File)object).exists()) {
|
||||
if (!((File)object).mkdirs()) {
|
||||
Throwable throwable = new Throwable("ERROR, mkdirs() on '" + ((File)object).getPath() + "' returned false.");
|
||||
throwable.printStackTrace(System.err);
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
tarArchive.extractContents((File)object);
|
||||
}
|
||||
catch (InvalidHeaderException invalidHeaderException) {
|
||||
invalidHeaderException.printStackTrace(System.err);
|
||||
}
|
||||
catch (IOException iOException) {
|
||||
iOException.printStackTrace(System.err);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (tarArchive != null) {
|
||||
try {
|
||||
tarArchive.closeArchive();
|
||||
}
|
||||
catch (IOException iOException) {
|
||||
iOException.printStackTrace(System.err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final int processArguments(String[] stringArray) {
|
||||
int n = 0;
|
||||
boolean bl = false;
|
||||
while (n < stringArray.length) {
|
||||
String string = stringArray[n];
|
||||
if (!string.startsWith("-")) break;
|
||||
if (string.startsWith("--")) {
|
||||
if (string.equals("--usage")) {
|
||||
this.usage();
|
||||
System.exit(1);
|
||||
} else if (string.equals("--version")) {
|
||||
this.version();
|
||||
System.exit(1);
|
||||
} else {
|
||||
System.err.println("unknown option: " + string);
|
||||
this.usage();
|
||||
System.exit(1);
|
||||
}
|
||||
} else {
|
||||
int n2 = 1;
|
||||
while (n2 < string.length()) {
|
||||
char c = string.charAt(n2);
|
||||
if (c == '?') {
|
||||
this.usage();
|
||||
System.exit(1);
|
||||
} else if (c == 'f') {
|
||||
this.archiveName = stringArray[++n];
|
||||
} else if (c == 'z') {
|
||||
this.compressed = true;
|
||||
} else if (c == 'c') {
|
||||
bl = true;
|
||||
this.writingArchive = true;
|
||||
this.listingArchive = false;
|
||||
} else if (c == 'x') {
|
||||
bl = true;
|
||||
this.writingArchive = false;
|
||||
this.listingArchive = false;
|
||||
} else if (c == 't') {
|
||||
bl = true;
|
||||
this.writingArchive = false;
|
||||
this.listingArchive = true;
|
||||
} else if (c == 'k') {
|
||||
this.keepOldFiles = true;
|
||||
} else if (c == 'o') {
|
||||
this.unixArchiveFormat = true;
|
||||
} else if (c == 'b') {
|
||||
try {
|
||||
int n3 = Integer.parseInt(stringArray[++n]);
|
||||
this.blockSize = n3 * 512;
|
||||
}
|
||||
catch (NumberFormatException numberFormatException) {
|
||||
numberFormatException.printStackTrace(System.err);
|
||||
}
|
||||
} else if (c == 'u') {
|
||||
this.userName = stringArray[++n];
|
||||
} else if (c == 'U') {
|
||||
String string2 = stringArray[++n];
|
||||
try {
|
||||
this.userId = Integer.parseInt(string2);
|
||||
}
|
||||
catch (NumberFormatException numberFormatException) {
|
||||
this.userId = 0;
|
||||
numberFormatException.printStackTrace(System.err);
|
||||
}
|
||||
} else if (c == 'g') {
|
||||
this.groupName = stringArray[++n];
|
||||
} else if (c == 'G') {
|
||||
String string3 = stringArray[++n];
|
||||
try {
|
||||
this.groupId = Integer.parseInt(string3);
|
||||
}
|
||||
catch (NumberFormatException numberFormatException) {
|
||||
this.groupId = 0;
|
||||
numberFormatException.printStackTrace(System.err);
|
||||
}
|
||||
} else if (c == 'v') {
|
||||
this.verbose = true;
|
||||
} else if (c == 'D') {
|
||||
this.debug = true;
|
||||
} else {
|
||||
System.err.println("unknown option: " + c);
|
||||
this.usage();
|
||||
System.exit(1);
|
||||
}
|
||||
++n2;
|
||||
}
|
||||
}
|
||||
++n;
|
||||
}
|
||||
if (!bl) {
|
||||
System.err.println("you must specify an operation option (c, x, or t)");
|
||||
this.usage();
|
||||
System.exit(1);
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
public void showTarProgressMessage(String string) {
|
||||
System.out.println(string);
|
||||
}
|
||||
|
||||
private final void version() {
|
||||
System.err.println("Release 2.4 - $Revision: 3$ $Name: $");
|
||||
}
|
||||
|
||||
private final void usage() {
|
||||
System.err.println("usage: com.ice.tar.tar has three basic modes:");
|
||||
System.err.println(" com.ice.tar -c [options] archive files...");
|
||||
System.err.println(" Create new archive containing files.");
|
||||
System.err.println(" com.ice.tar -t [options] archive");
|
||||
System.err.println(" List contents of tar archive");
|
||||
System.err.println(" com.ice.tar -x [options] archive");
|
||||
System.err.println(" Extract contents of tar archive.");
|
||||
System.err.println("");
|
||||
System.err.println("options:");
|
||||
System.err.println(" -f file, use 'file' as the tar archive");
|
||||
System.err.println(" -v, verbose mode");
|
||||
System.err.println(" -z, use GZIP compression");
|
||||
System.err.println(" -D, debug archive and buffer operation");
|
||||
System.err.println(" -b blks, set blocking size to (blks * 512) bytes");
|
||||
System.err.println(" -o, write a V7 format archive rather than ANSI");
|
||||
System.err.println(" -u name, set user name to 'name'");
|
||||
System.err.println(" -U id, set user id to 'id'");
|
||||
System.err.println(" -g name, set group name to 'name'");
|
||||
System.err.println(" -G id, set group id to 'id'");
|
||||
System.err.println(" -?, print usage information");
|
||||
System.err.println(" --trans, translate 'text/*' files");
|
||||
System.err.println(" --mime file, use this mime types file and translate");
|
||||
System.err.println(" --usage, print usage information");
|
||||
System.err.println(" --version, print version information");
|
||||
System.err.println("");
|
||||
System.err.println("The translation options will translate from local line");
|
||||
System.err.println("endings to UNIX line endings of '\\n' when writing tar");
|
||||
System.err.println("archives, and from UNIX line endings into local line endings");
|
||||
System.err.println("when extracting archives.");
|
||||
System.err.println("");
|
||||
System.err.println("Written by Tim Endres");
|
||||
System.err.println("");
|
||||
System.err.println("This software has been placed into the public domain.");
|
||||
System.err.println("");
|
||||
this.version();
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
public tar() {
|
||||
String string = System.getProperty("user.name");
|
||||
this.userId = 0;
|
||||
this.userName = string == null ? "" : string;
|
||||
this.groupId = 0;
|
||||
this.groupName = "";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user