Browse Source

checkstyle

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274796 13f79535-47bb-0310-9956-ffa450edef68
master
Conor MacNeill 22 years ago
parent
commit
88799e0669
8 changed files with 204 additions and 206 deletions
  1. +1
    -1
      check.xml
  2. +24
    -25
      src/main/org/apache/tools/bzip2/CBZip2InputStream.java
  3. +4
    -4
      src/main/org/apache/tools/bzip2/CBZip2OutputStream.java
  4. +85
    -85
      src/main/org/apache/tools/tar/TarBuffer.java
  5. +5
    -5
      src/main/org/apache/tools/tar/TarConstants.java
  6. +1
    -1
      src/main/org/apache/tools/tar/TarInputStream.java
  7. +51
    -52
      src/main/org/apache/tools/tar/TarOutputStream.java
  8. +33
    -33
      src/main/org/apache/tools/tar/TarUtils.java

+ 1
- 1
check.xml View File

@@ -29,7 +29,7 @@
<formatter type="xml" toFile="${checkstyle.raw}"/> <formatter type="xml" toFile="${checkstyle.raw}"/>
<fileset dir="${java.dir}"> <fileset dir="${java.dir}">
<include name="${tocheck}"/> <include name="${tocheck}"/>
<exclude name="**/BZip2Constants.java"/>
<exclude name="**/bzip2/*.java"/>
<exclude name="**/CVSPass.java"/> <exclude name="**/CVSPass.java"/>
</fileset> </fileset>
</checkstyle> </checkstyle>


+ 24
- 25
src/main/org/apache/tools/bzip2/CBZip2InputStream.java View File

@@ -139,12 +139,12 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants {
freq table collected to save a pass over the data freq table collected to save a pass over the data
during decompression. during decompression.
*/ */
private int unzftab[] = new int[256];
private int[] unzftab = new int[256];


private int limit[][] = new int[N_GROUPS][MAX_ALPHA_SIZE];
private int base[][] = new int[N_GROUPS][MAX_ALPHA_SIZE];
private int perm[][] = new int[N_GROUPS][MAX_ALPHA_SIZE];
private int minLens[] = new int[N_GROUPS];
private int[][] limit = new int[N_GROUPS][MAX_ALPHA_SIZE];
private int[][] base = new int[N_GROUPS][MAX_ALPHA_SIZE];
private int[][] perm = new int[N_GROUPS][MAX_ALPHA_SIZE];
private int[] minLens = new int[N_GROUPS];


private InputStream bsStream; private InputStream bsStream;


@@ -302,10 +302,11 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants {
if (this.bsStream != null) { if (this.bsStream != null) {
if (this.bsStream != System.in) { if (this.bsStream != System.in) {
this.bsStream.close(); this.bsStream.close();
this.bsStream= null;
this.bsStream = null;
} }
} }
} catch (IOException ioe) { } catch (IOException ioe) {
//ignore
} }
} }


@@ -319,22 +320,20 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants {


private int bsR(int n) { private int bsR(int n) {
int v; int v;
{
while (bsLive < n) {
int zzi;
char thech = 0;
try {
thech = (char) bsStream.read();
} catch (IOException e) {
compressedStreamEOF();
}
if (thech == -1) {
compressedStreamEOF();
}
zzi = thech;
bsBuff = (bsBuff << 8) | (zzi & 0xff);
bsLive += 8;
while (bsLive < n) {
int zzi;
char thech = 0;
try {
thech = (char) bsStream.read();
} catch (IOException e) {
compressedStreamEOF();
}
if (thech == -1) {
compressedStreamEOF();
} }
zzi = thech;
bsBuff = (bsBuff << 8) | (zzi & 0xff);
bsLive += 8;
} }


v = (bsBuff >> (bsLive - n)) & ((1 << n) - 1); v = (bsBuff >> (bsLive - n)) & ((1 << n) - 1);
@@ -376,7 +375,7 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants {
pp++; pp++;
} }
} }
};
}


for (i = 0; i < MAX_CODE_LEN; i++) { for (i = 0; i < MAX_CODE_LEN; i++) {
base[i] = 0; base[i] = 0;
@@ -618,7 +617,7 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants {
bsLive--; bsLive--;
} }
zvec = (zvec << 1) | zj; zvec = (zvec << 1) | zj;
};
}
nextSym = perm[zt][zvec - base[zt][zn]]; nextSym = perm[zt][zvec - base[zt][zn]];
} }
} while (nextSym == RUNA || nextSym == RUNB); } while (nextSym == RUNA || nextSym == RUNB);
@@ -631,7 +630,7 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants {
last++; last++;
ll8[last] = ch; ll8[last] = ch;
s--; s--;
};
}


if (last >= limitLast) { if (last >= limitLast) {
blockOverrun(); blockOverrun();
@@ -698,7 +697,7 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants {
bsLive--; bsLive--;
} }
zvec = (zvec << 1) | zj; zvec = (zvec << 1) | zj;
};
}
nextSym = perm[zt][zvec - base[zt][zn]]; nextSym = perm[zt][zvec - base[zt][zn]];
} }
continue; continue;


+ 4
- 4
src/main/org/apache/tools/bzip2/CBZip2OutputStream.java View File

@@ -163,8 +163,8 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants {
if (yy > nHeap) { if (yy > nHeap) {
break; break;
} }
if (yy < nHeap &&
weight[heap[yy + 1]] < weight[heap[yy]]) {
if (yy < nHeap
&& weight[heap[yy + 1]] < weight[heap[yy]]) {
yy++; yy++;
} }
if (weight[tmp] < weight[heap[yy]]) { if (weight[tmp] < weight[heap[yy]]) {
@@ -187,8 +187,8 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants {
if (yy > nHeap) { if (yy > nHeap) {
break; break;
} }
if (yy < nHeap &&
weight[heap[yy + 1]] < weight[heap[yy]]) {
if (yy < nHeap
&& weight[heap[yy + 1]] < weight[heap[yy]]) {
yy++; yy++;
} }
if (weight[tmp] < weight[heap[yy]]) { if (weight[tmp] < weight[heap[yy]]) {


+ 85
- 85
src/main/org/apache/tools/tar/TarBuffer.java View File

@@ -53,10 +53,10 @@
*/ */


/* /*
* This package is based on the work done by Timothy Gerard Endres
* This package is based on the work done by Timothy Gerard Endres
* (time@ice.com) to whom the Ant project is very grateful for his great code. * (time@ice.com) to whom the Ant project is very grateful for his great code.
*/ */
package org.apache.tools.tar; package org.apache.tools.tar;


import java.io.InputStream; import java.io.InputStream;
@@ -73,15 +73,15 @@ import java.io.IOException;
* <p> * <p>
* You should never have a need to access this class directly. * You should never have a need to access this class directly.
* TarBuffers are created by Tar IO Streams. * TarBuffers are created by Tar IO Streams.
*
*
* @author Timothy Gerard Endres <a href="mailto:time@ice.com">time@ice.com</a> * @author Timothy Gerard Endres <a href="mailto:time@ice.com">time@ice.com</a>
*/ */
public class TarBuffer { public class TarBuffer {
public static final int DEFAULT_RCDSIZE = (512); public static final int DEFAULT_RCDSIZE = (512);
public static final int DEFAULT_BLKSIZE = (DEFAULT_RCDSIZE * 20); public static final int DEFAULT_BLKSIZE = (DEFAULT_RCDSIZE * 20);
private InputStream inStream; private InputStream inStream;
private OutputStream outStream; private OutputStream outStream;
private byte[] blockBuffer; private byte[] blockBuffer;
@@ -138,101 +138,101 @@ public class TarBuffer {
} else { } else {
this.currBlkIdx = 0; this.currBlkIdx = 0;
this.currRecIdx = 0; this.currRecIdx = 0;
}
}
}
}


/** /**
* Get the TAR Buffer's block size. Blocks consist of multiple records. * Get the TAR Buffer's block size. Blocks consist of multiple records.
*/ */
public int getBlockSize() { public int getBlockSize() {
return this.blockSize; return this.blockSize;
}
}


/** /**
* Get the TAR Buffer's record size. * Get the TAR Buffer's record size.
*/ */
public int getRecordSize() { public int getRecordSize() {
return this.recordSize; return this.recordSize;
}
}


/** /**
* Set the debugging flag for the buffer. * Set the debugging flag for the buffer.
*
*
* @param debug If true, print debugging output. * @param debug If true, print debugging output.
*/ */
public void setDebug(boolean debug) { public void setDebug(boolean debug) {
this.debug = debug; this.debug = debug;
}
}


/** /**
* Determine if an archive record indicate End of Archive. End of * Determine if an archive record indicate End of Archive. End of
* archive is indicated by a record that consists entirely of null bytes. * archive is indicated by a record that consists entirely of null bytes.
*
*
* @param record The record data to check. * @param record The record data to check.
*/ */
public boolean isEOFRecord(byte[] record) { public boolean isEOFRecord(byte[] record) {
for (int i = 0, sz = this.getRecordSize(); i < sz; ++i) { for (int i = 0, sz = this.getRecordSize(); i < sz; ++i) {
if (record[i] != 0) { if (record[i] != 0) {
return false; return false;
}
}
} }


return true; return true;
}
}


/** /**
* Skip over a record on the input stream. * Skip over a record on the input stream.
*/ */
public void skipRecord() throws IOException { public void skipRecord() throws IOException {
if (this.debug) { if (this.debug) {
System.err.println("SkipRecord: recIdx = " + this.currRecIdx
System.err.println("SkipRecord: recIdx = " + this.currRecIdx
+ " blkIdx = " + this.currBlkIdx); + " blkIdx = " + this.currBlkIdx);
}
}


if (this.inStream == null) { if (this.inStream == null) {
throw new IOException("reading (via skip) from an output buffer"); throw new IOException("reading (via skip) from an output buffer");
}
}


if (this.currRecIdx >= this.recsPerBlock) { if (this.currRecIdx >= this.recsPerBlock) {
if (!this.readBlock()) { if (!this.readBlock()) {
return; // UNDONE return; // UNDONE
}
}
}
}


this.currRecIdx++; this.currRecIdx++;
}
}


/** /**
* Read a record from the input stream and return the data. * Read a record from the input stream and return the data.
*
*
* @return The record data. * @return The record data.
*/ */
public byte[] readRecord() throws IOException { public byte[] readRecord() throws IOException {
if (this.debug) { if (this.debug) {
System.err.println("ReadRecord: recIdx = " + this.currRecIdx
System.err.println("ReadRecord: recIdx = " + this.currRecIdx
+ " blkIdx = " + this.currBlkIdx); + " blkIdx = " + this.currBlkIdx);
}
}


if (this.inStream == null) { if (this.inStream == null) {
throw new IOException("reading from an output buffer"); throw new IOException("reading from an output buffer");
}
}


if (this.currRecIdx >= this.recsPerBlock) { if (this.currRecIdx >= this.recsPerBlock) {
if (!this.readBlock()) { if (!this.readBlock()) {
return null; return null;
}
}
}
}


byte[] result = new byte[this.recordSize]; byte[] result = new byte[this.recordSize];


System.arraycopy(this.blockBuffer,
(this.currRecIdx * this.recordSize), result, 0,
System.arraycopy(this.blockBuffer,
(this.currRecIdx * this.recordSize), result, 0,
this.recordSize); this.recordSize);


this.currRecIdx++; this.currRecIdx++;


return result; return result;
}
}


/** /**
* @return false if End-Of-File, else true * @return false if End-Of-File, else true
@@ -240,11 +240,11 @@ public class TarBuffer {
private boolean readBlock() throws IOException { private boolean readBlock() throws IOException {
if (this.debug) { if (this.debug) {
System.err.println("ReadBlock: blkIdx = " + this.currBlkIdx); System.err.println("ReadBlock: blkIdx = " + this.currBlkIdx);
}
}


if (this.inStream == null) { if (this.inStream == null) {
throw new IOException("reading from an output buffer"); throw new IOException("reading from an output buffer");
}
}


this.currRecIdx = 0; this.currRecIdx = 0;


@@ -252,130 +252,130 @@ public class TarBuffer {
int bytesNeeded = this.blockSize; int bytesNeeded = this.blockSize;


while (bytesNeeded > 0) { while (bytesNeeded > 0) {
long numBytes = this.inStream.read(this.blockBuffer, offset,
long numBytes = this.inStream.read(this.blockBuffer, offset,
bytesNeeded); bytesNeeded);


//
//
// NOTE // NOTE
// We have fit EOF, and the block is not full! // We have fit EOF, and the block is not full!
//
//
// This is a broken archive. It does not follow the standard // This is a broken archive. It does not follow the standard
// blocking algorithm. However, because we are generous, and // blocking algorithm. However, because we are generous, and
// it requires little effort, we will simply ignore the error // it requires little effort, we will simply ignore the error
// and continue as if the entire block were read. This does // and continue as if the entire block were read. This does
// not appear to break anything upstream. We used to return // not appear to break anything upstream. We used to return
// false in this case. // false in this case.
//
//
// Thanks to 'Yohann.Roussel@alcatel.fr' for this fix. // Thanks to 'Yohann.Roussel@alcatel.fr' for this fix.
//
//
if (numBytes == -1) { if (numBytes == -1) {
break; break;
}
}


offset += numBytes; offset += numBytes;
bytesNeeded -= numBytes; bytesNeeded -= numBytes;


if (numBytes != this.blockSize) { if (numBytes != this.blockSize) {
if (this.debug) { if (this.debug) {
System.err.println("ReadBlock: INCOMPLETE READ "
+ numBytes + " of " + this.blockSize
System.err.println("ReadBlock: INCOMPLETE READ "
+ numBytes + " of " + this.blockSize
+ " bytes read."); + " bytes read.");
}
}
}
}
}
}


this.currBlkIdx++; this.currBlkIdx++;


return true; return true;
}
}


/** /**
* Get the current block number, zero based. * Get the current block number, zero based.
*
*
* @return The current zero based block number. * @return The current zero based block number.
*/ */
public int getCurrentBlockNum() { public int getCurrentBlockNum() {
return this.currBlkIdx; return this.currBlkIdx;
}
}


/** /**
* Get the current record number, within the current block, zero based. * Get the current record number, within the current block, zero based.
* Thus, current offset = (currentBlockNum * recsPerBlk) + currentRecNum. * Thus, current offset = (currentBlockNum * recsPerBlk) + currentRecNum.
*
*
* @return The current zero based record number. * @return The current zero based record number.
*/ */
public int getCurrentRecordNum() { public int getCurrentRecordNum() {
return this.currRecIdx - 1; return this.currRecIdx - 1;
}
}


/** /**
* Write an archive record to the archive. * Write an archive record to the archive.
*
*
* @param record The record data to write to the archive. * @param record The record data to write to the archive.
*/ */
public void writeRecord(byte[] record) throws IOException { public void writeRecord(byte[] record) throws IOException {
if (this.debug) { if (this.debug) {
System.err.println("WriteRecord: recIdx = " + this.currRecIdx
System.err.println("WriteRecord: recIdx = " + this.currRecIdx
+ " blkIdx = " + this.currBlkIdx); + " blkIdx = " + this.currBlkIdx);
}
}


if (this.outStream == null) { if (this.outStream == null) {
throw new IOException("writing to an input buffer"); throw new IOException("writing to an input buffer");
}
}


if (record.length != this.recordSize) { if (record.length != this.recordSize) {
throw new IOException("record to write has length '"
+ record.length
+ "' which is not the record size of '"
throw new IOException("record to write has length '"
+ record.length
+ "' which is not the record size of '"
+ this.recordSize + "'"); + this.recordSize + "'");
}
}


if (this.currRecIdx >= this.recsPerBlock) { if (this.currRecIdx >= this.recsPerBlock) {
this.writeBlock(); this.writeBlock();
}
}


System.arraycopy(record, 0, this.blockBuffer,
(this.currRecIdx * this.recordSize),
System.arraycopy(record, 0, this.blockBuffer,
(this.currRecIdx * this.recordSize),
this.recordSize); this.recordSize);


this.currRecIdx++; this.currRecIdx++;
}
}


/** /**
* Write an archive record to the archive, where the record may be * Write an archive record to the archive, where the record may be
* inside of a larger array buffer. The buffer must be "offset plus * inside of a larger array buffer. The buffer must be "offset plus
* record size" long. * record size" long.
*
*
* @param buf The buffer containing the record data to write. * @param buf The buffer containing the record data to write.
* @param offset The offset of the record data within buf. * @param offset The offset of the record data within buf.
*/ */
public void writeRecord(byte[] buf, int offset) throws IOException { public void writeRecord(byte[] buf, int offset) throws IOException {
if (this.debug) { if (this.debug) {
System.err.println("WriteRecord: recIdx = " + this.currRecIdx
System.err.println("WriteRecord: recIdx = " + this.currRecIdx
+ " blkIdx = " + this.currBlkIdx); + " blkIdx = " + this.currBlkIdx);
}
}


if (this.outStream == null) { if (this.outStream == null) {
throw new IOException("writing to an input buffer"); throw new IOException("writing to an input buffer");
}
}


if ((offset + this.recordSize) > buf.length) { if ((offset + this.recordSize) > buf.length) {
throw new IOException("record has length '" + buf.length
+ "' with offset '" + offset
+ "' which is less than the record size of '"
throw new IOException("record has length '" + buf.length
+ "' with offset '" + offset
+ "' which is less than the record size of '"
+ this.recordSize + "'"); + this.recordSize + "'");
}
}


if (this.currRecIdx >= this.recsPerBlock) { if (this.currRecIdx >= this.recsPerBlock) {
this.writeBlock(); this.writeBlock();
}
}


System.arraycopy(buf, offset, this.blockBuffer,
(this.currRecIdx * this.recordSize),
System.arraycopy(buf, offset, this.blockBuffer,
(this.currRecIdx * this.recordSize),
this.recordSize); this.recordSize);


this.currRecIdx++; this.currRecIdx++;
}
}


/** /**
* Write a TarBuffer block to the archive. * Write a TarBuffer block to the archive.
@@ -383,18 +383,18 @@ public class TarBuffer {
private void writeBlock() throws IOException { private void writeBlock() throws IOException {
if (this.debug) { if (this.debug) {
System.err.println("WriteBlock: blkIdx = " + this.currBlkIdx); System.err.println("WriteBlock: blkIdx = " + this.currBlkIdx);
}
}


if (this.outStream == null) { if (this.outStream == null) {
throw new IOException("writing to an input buffer"); throw new IOException("writing to an input buffer");
}
}


this.outStream.write(this.blockBuffer, 0, this.blockSize); this.outStream.write(this.blockBuffer, 0, this.blockSize);
this.outStream.flush(); this.outStream.flush();


this.currRecIdx = 0; this.currRecIdx = 0;
this.currBlkIdx++; this.currBlkIdx++;
}
}


/** /**
* Flush the current data block if it has any data in it. * Flush the current data block if it has any data in it.
@@ -402,16 +402,16 @@ public class TarBuffer {
private void flushBlock() throws IOException { private void flushBlock() throws IOException {
if (this.debug) { if (this.debug) {
System.err.println("TarBuffer.flushBlock() called."); System.err.println("TarBuffer.flushBlock() called.");
}
}


if (this.outStream == null) { if (this.outStream == null) {
throw new IOException("writing to an input buffer"); throw new IOException("writing to an input buffer");
}
}


if (this.currRecIdx > 0) { if (this.currRecIdx > 0) {
this.writeBlock(); this.writeBlock();
}
}
}
}


/** /**
* Close the TarBuffer. If this is an output buffer, also flush the * Close the TarBuffer. If this is an output buffer, also flush the
@@ -420,23 +420,23 @@ public class TarBuffer {
public void close() throws IOException { public void close() throws IOException {
if (this.debug) { if (this.debug) {
System.err.println("TarBuffer.closeBuffer()."); System.err.println("TarBuffer.closeBuffer().");
}
}


if (this.outStream != null) { if (this.outStream != null) {
this.flushBlock(); this.flushBlock();


if (this.outStream != System.out
if (this.outStream != System.out
&& this.outStream != System.err) { && this.outStream != System.err) {
this.outStream.close(); this.outStream.close();


this.outStream = null; this.outStream = null;
}
}
} else if (this.inStream != null) { } else if (this.inStream != null) {
if (this.inStream != System.in) { if (this.inStream != System.in) {
this.inStream.close(); this.inStream.close();


this.inStream = null; this.inStream = null;
}
}
}
}
}
}
} }

+ 5
- 5
src/main/org/apache/tools/tar/TarConstants.java View File

@@ -1,7 +1,7 @@
/* /*
* The Apache Software License, Version 1.1 * The Apache Software License, Version 1.1
* *
* Copyright (c) 2000-2002 The Apache Software Foundation. All rights
* Copyright (c) 2000-2002 The Apache Software Foundation. All rights
* reserved. * reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -53,7 +53,7 @@
*/ */


/* /*
* This package is based on the work done by Timothy Gerard Endres
* This package is based on the work done by Timothy Gerard Endres
* (time@ice.com) to whom the Ant project is very grateful for his great code. * (time@ice.com) to whom the Ant project is very grateful for his great code.
*/ */


@@ -67,7 +67,7 @@ package org.apache.tools.tar;
*/ */


public interface TarConstants { public interface TarConstants {
/** /**
* The length of the name field in a header buffer. * The length of the name field in a header buffer.
*/ */
@@ -183,9 +183,9 @@ public interface TarConstants {
* The namr of the GNU tar entry which contains a long name. * The namr of the GNU tar entry which contains a long name.
*/ */
String GNU_LONGLINK = "././@LongLink"; String GNU_LONGLINK = "././@LongLink";
/** /**
* Identifies the *next* file on the tape as having a long name.
* Identifies the *next* file on the tape as having a long name.
*/ */
byte LF_GNUTYPE_LONGNAME = (byte) 'L'; byte LF_GNUTYPE_LONGNAME = (byte) 'L';
} }

+ 1
- 1
src/main/org/apache/tools/tar/TarInputStream.java View File

@@ -84,7 +84,7 @@ public class TarInputStream extends FilterInputStream {
protected TarBuffer buffer; protected TarBuffer buffer;
protected TarEntry currEntry; protected TarEntry currEntry;
private boolean v7Format; private boolean v7Format;
public TarInputStream(InputStream is) { public TarInputStream(InputStream is) {
this(is, TarBuffer.DEFAULT_BLKSIZE, TarBuffer.DEFAULT_RCDSIZE); this(is, TarBuffer.DEFAULT_BLKSIZE, TarBuffer.DEFAULT_RCDSIZE);
} }


+ 51
- 52
src/main/org/apache/tools/tar/TarOutputStream.java View File

@@ -53,7 +53,7 @@
*/ */


/* /*
* This package is based on the work done by Timothy Gerard Endres
* This package is based on the work done by Timothy Gerard Endres
* (time@ice.com) to whom the Ant project is very grateful for his great code. * (time@ice.com) to whom the Ant project is very grateful for his great code.
*/ */


@@ -67,19 +67,19 @@ import java.io.IOException;
* The TarOutputStream writes a UNIX tar archive as an OutputStream. * The TarOutputStream writes a UNIX tar archive as an OutputStream.
* Methods are provided to put entries, and then write their contents * Methods are provided to put entries, and then write their contents
* by writing to this stream using write(). * by writing to this stream using write().
*
*
* @author Timothy Gerard Endres <a href="mailto:time@ice.com">time@ice.com</a> * @author Timothy Gerard Endres <a href="mailto:time@ice.com">time@ice.com</a>
*/ */
public class TarOutputStream extends FilterOutputStream { public class TarOutputStream extends FilterOutputStream {
/** Fail if a long file name is required in the archive. */ /** Fail if a long file name is required in the archive. */
public static final int LONGFILE_ERROR = 0; public static final int LONGFILE_ERROR = 0;
/** Long paths will be truncated in the archive. */ /** Long paths will be truncated in the archive. */
public static final int LONGFILE_TRUNCATE = 1; public static final int LONGFILE_TRUNCATE = 1;
/** GNU tar extensions are used to store long file names in the archive. */ /** GNU tar extensions are used to store long file names in the archive. */
public static final int LONGFILE_GNU = 2; public static final int LONGFILE_GNU = 2;
protected boolean debug; protected boolean debug;
protected int currSize; protected int currSize;
protected int currBytes; protected int currBytes;
@@ -112,25 +112,25 @@ public class TarOutputStream extends FilterOutputStream {
public void setLongFileMode(int longFileMode) { public void setLongFileMode(int longFileMode) {
this.longFileMode = longFileMode; this.longFileMode = longFileMode;
} }


/** /**
* Sets the debugging flag. * Sets the debugging flag.
*
*
* @param debugF True to turn on debugging. * @param debugF True to turn on debugging.
*/ */
public void setDebug(boolean debugF) { public void setDebug(boolean debugF) {
this.debug = debugF; this.debug = debugF;
}
}


/** /**
* Sets the debugging flag in this stream's TarBuffer. * Sets the debugging flag in this stream's TarBuffer.
*
*
* @param debugF True to turn on debugging. * @param debugF True to turn on debugging.
*/ */
public void setBufferDebug(boolean debug) { public void setBufferDebug(boolean debug) {
this.buffer.setDebug(debug); this.buffer.setDebug(debug);
}
}


/** /**
* Ends the TAR archive without closing the underlying OutputStream. * Ends the TAR archive without closing the underlying OutputStream.
@@ -138,7 +138,7 @@ public class TarOutputStream extends FilterOutputStream {
*/ */
public void finish() throws IOException { public void finish() throws IOException {
this.writeEOFRecord(); this.writeEOFRecord();
}
}


/** /**
* Ends the TAR archive and closes the underlying OutputStream. * Ends the TAR archive and closes the underlying OutputStream.
@@ -148,16 +148,16 @@ public class TarOutputStream extends FilterOutputStream {
public void close() throws IOException { public void close() throws IOException {
this.finish(); this.finish();
this.buffer.close(); this.buffer.close();
}
}


/** /**
* Get the record size being used by this stream's TarBuffer. * Get the record size being used by this stream's TarBuffer.
*
*
* @return The TarBuffer record size. * @return The TarBuffer record size.
*/ */
public int getRecordSize() { public int getRecordSize() {
return this.buffer.getRecordSize(); return this.buffer.getRecordSize();
}
}


/** /**
* Put an entry on the output stream. This writes the entry's * Put an entry on the output stream. This writes the entry's
@@ -167,7 +167,7 @@ public class TarOutputStream extends FilterOutputStream {
* contents. Once the contents are written, closeEntry() * contents. Once the contents are written, closeEntry()
* <B>MUST</B> be called to ensure that all buffered data * <B>MUST</B> be called to ensure that all buffered data
* is completely written to the output stream. * is completely written to the output stream.
*
*
* @param entry The TarEntry to be written to the archive. * @param entry The TarEntry to be written to the archive.
*/ */
public void putNextEntry(TarEntry entry) throws IOException { public void putNextEntry(TarEntry entry) throws IOException {
@@ -175,21 +175,21 @@ public class TarOutputStream extends FilterOutputStream {


if (longFileMode == LONGFILE_GNU) { if (longFileMode == LONGFILE_GNU) {
// create a TarEntry for the LongLink, the contents // create a TarEntry for the LongLink, the contents
// of which are the entry's name
// of which are the entry's name
TarEntry longLinkEntry = new TarEntry(TarConstants.GNU_LONGLINK, TarEntry longLinkEntry = new TarEntry(TarConstants.GNU_LONGLINK,
TarConstants.LF_GNUTYPE_LONGNAME); TarConstants.LF_GNUTYPE_LONGNAME);
longLinkEntry.setSize(entry.getName().length() + 1); longLinkEntry.setSize(entry.getName().length() + 1);
putNextEntry(longLinkEntry);
putNextEntry(longLinkEntry);
write(entry.getName().getBytes()); write(entry.getName().getBytes());
write(0); write(0);
closeEntry(); closeEntry();
} else if (longFileMode != LONGFILE_TRUNCATE) { } else if (longFileMode != LONGFILE_TRUNCATE) {
throw new RuntimeException("file name '" + entry.getName()
+ "' is too long ( > "
throw new RuntimeException("file name '" + entry.getName()
+ "' is too long ( > "
+ TarConstants.NAMELEN + " bytes)"); + TarConstants.NAMELEN + " bytes)");
} }
}
}


entry.writeEntryHeader(this.recordBuf); entry.writeEntryHeader(this.recordBuf);
this.buffer.writeRecord(this.recordBuf); this.buffer.writeRecord(this.recordBuf);
@@ -201,7 +201,7 @@ public class TarOutputStream extends FilterOutputStream {
} else { } else {
this.currSize = (int) entry.getSize(); this.currSize = (int) entry.getSize();
} }
}
}


/** /**
* Close an entry. This method MUST be called for all file * Close an entry. This method MUST be called for all file
@@ -222,39 +222,38 @@ public class TarOutputStream extends FilterOutputStream {


this.currBytes += this.assemLen; this.currBytes += this.assemLen;
this.assemLen = 0; this.assemLen = 0;
}
}


if (this.currBytes < this.currSize) { if (this.currBytes < this.currSize) {
throw new IOException("entry closed at '" + this.currBytes
+ "' before the '" + this.currSize
throw new IOException("entry closed at '" + this.currBytes
+ "' before the '" + this.currSize
+ "' bytes specified in the header were written"); + "' bytes specified in the header were written");
}
}
}
}


/** /**
* Writes a byte to the current tar archive entry. * Writes a byte to the current tar archive entry.
*
*
* This method simply calls read( byte[], int, int ). * This method simply calls read( byte[], int, int ).
*
*
* @param b The byte written. * @param b The byte written.
*/ */
public void write(int b) throws IOException { public void write(int b) throws IOException {
this.oneBuf[0] = (byte) b; this.oneBuf[0] = (byte) b;


this.write(this.oneBuf, 0, 1); this.write(this.oneBuf, 0, 1);
}
}


/** /**
* Writes bytes to the current tar archive entry. * Writes bytes to the current tar archive entry.
*
*
* This method simply calls write( byte[], int, int ). * This method simply calls write( byte[], int, int ).
*
*
* @param wBuf The buffer to write to the archive. * @param wBuf The buffer to write to the archive.
* @return The number of bytes read, or -1 at EOF.
*/ */
public void write(byte[] wBuf) throws IOException { public void write(byte[] wBuf) throws IOException {
this.write(wBuf, 0, wBuf.length); this.write(wBuf, 0, wBuf.length);
}
}


/** /**
* Writes bytes to the current tar archive entry. This method * Writes bytes to the current tar archive entry. This method
@@ -264,33 +263,33 @@ public class TarOutputStream extends FilterOutputStream {
* record buffering required by TarBuffer, and manages buffers * record buffering required by TarBuffer, and manages buffers
* that are not a multiple of recordsize in length, including * that are not a multiple of recordsize in length, including
* assembling records from small buffers. * assembling records from small buffers.
*
*
* @param wBuf The buffer to write to the archive. * @param wBuf The buffer to write to the archive.
* @param wOffset The offset in the buffer from which to get bytes. * @param wOffset The offset in the buffer from which to get bytes.
* @param numToWrite The number of bytes to write. * @param numToWrite The number of bytes to write.
*/ */
public void write(byte[] wBuf, int wOffset, int numToWrite) throws IOException { public void write(byte[] wBuf, int wOffset, int numToWrite) throws IOException {
if ((this.currBytes + numToWrite) > this.currSize) { if ((this.currBytes + numToWrite) > this.currSize) {
throw new IOException("request to write '" + numToWrite
+ "' bytes exceeds size in header of '"
throw new IOException("request to write '" + numToWrite
+ "' bytes exceeds size in header of '"
+ this.currSize + "' bytes"); + this.currSize + "' bytes");


//
//
// We have to deal with assembly!!! // We have to deal with assembly!!!
// The programmer can be writing little 32 byte chunks for all // The programmer can be writing little 32 byte chunks for all
// we know, and we must assemble complete records for writing. // we know, and we must assemble complete records for writing.
// REVIEW Maybe this should be in TarBuffer? Could that help to // REVIEW Maybe this should be in TarBuffer? Could that help to
// eliminate some of the buffer copying. // eliminate some of the buffer copying.
//
}
//
}


if (this.assemLen > 0) { if (this.assemLen > 0) {
if ((this.assemLen + numToWrite) >= this.recordBuf.length) { if ((this.assemLen + numToWrite) >= this.recordBuf.length) {
int aLen = this.recordBuf.length - this.assemLen; int aLen = this.recordBuf.length - this.assemLen;


System.arraycopy(this.assemBuf, 0, this.recordBuf, 0,
System.arraycopy(this.assemBuf, 0, this.recordBuf, 0,
this.assemLen); this.assemLen);
System.arraycopy(wBuf, wOffset, this.recordBuf,
System.arraycopy(wBuf, wOffset, this.recordBuf,
this.assemLen, aLen); this.assemLen, aLen);
this.buffer.writeRecord(this.recordBuf); this.buffer.writeRecord(this.recordBuf);


@@ -299,29 +298,29 @@ public class TarOutputStream extends FilterOutputStream {
numToWrite -= aLen; numToWrite -= aLen;
this.assemLen = 0; this.assemLen = 0;
} else { } else {
System.arraycopy(wBuf, wOffset, this.assemBuf, this.assemLen,
System.arraycopy(wBuf, wOffset, this.assemBuf, this.assemLen,
numToWrite); numToWrite);


wOffset += numToWrite; wOffset += numToWrite;
this.assemLen += numToWrite; this.assemLen += numToWrite;
numToWrite -= numToWrite; numToWrite -= numToWrite;
}
}
}
}


//
//
// When we get here we have EITHER: // When we get here we have EITHER:
// o An empty "assemble" buffer. // o An empty "assemble" buffer.
// o No bytes to write (numToWrite == 0) // o No bytes to write (numToWrite == 0)
//
//
while (numToWrite > 0) { while (numToWrite > 0) {
if (numToWrite < this.recordBuf.length) { if (numToWrite < this.recordBuf.length) {
System.arraycopy(wBuf, wOffset, this.assemBuf, this.assemLen,
System.arraycopy(wBuf, wOffset, this.assemBuf, this.assemLen,
numToWrite); numToWrite);


this.assemLen += numToWrite; this.assemLen += numToWrite;


break; break;
}
}


this.buffer.writeRecord(wBuf, wOffset); this.buffer.writeRecord(wBuf, wOffset);


@@ -330,8 +329,8 @@ public class TarOutputStream extends FilterOutputStream {
this.currBytes += num; this.currBytes += num;
numToWrite -= num; numToWrite -= num;
wOffset += num; wOffset += num;
}
}
}
}


/** /**
* Write an EOF (end of archive) record to the tar archive. * Write an EOF (end of archive) record to the tar archive.
@@ -343,7 +342,7 @@ public class TarOutputStream extends FilterOutputStream {
} }


this.buffer.writeRecord(this.recordBuf); this.buffer.writeRecord(this.recordBuf);
}
}
} }





+ 33
- 33
src/main/org/apache/tools/tar/TarUtils.java View File

@@ -53,7 +53,7 @@
*/ */


/* /*
* This package is based on the work done by Timothy Gerard Endres
* This package is based on the work done by Timothy Gerard Endres
* (time@ice.com) to whom the Ant project is very grateful for his great code. * (time@ice.com) to whom the Ant project is very grateful for his great code.
*/ */


@@ -61,7 +61,7 @@ package org.apache.tools.tar;


/** /**
* This class provides static utility methods to work with byte streams. * This class provides static utility methods to work with byte streams.
*
*
* @author Timothy Gerard Endres <a href="mailto:time@ice.com">time@ice.com</a> * @author Timothy Gerard Endres <a href="mailto:time@ice.com">time@ice.com</a>
* @author Stefano Mazzocchi <a href="mailto:stefano@apache.org">stefano@apache.org</a> * @author Stefano Mazzocchi <a href="mailto:stefano@apache.org">stefano@apache.org</a>
*/ */
@@ -70,7 +70,7 @@ public class TarUtils {
/** /**
* Parse an octal string from a header buffer. This is used for the * Parse an octal string from a header buffer. This is used for the
* file permission mode value. * file permission mode value.
*
*
* @param header The header buffer from which to parse. * @param header The header buffer from which to parse.
* @param offset The offset into the buffer from which to parse. * @param offset The offset into the buffer from which to parse.
* @param length The number of header bytes to parse. * @param length The number of header bytes to parse.
@@ -84,28 +84,28 @@ public class TarUtils {
for (int i = offset; i < end; ++i) { for (int i = offset; i < end; ++i) {
if (header[i] == 0) { if (header[i] == 0) {
break; break;
}
}


if (header[i] == (byte) ' ' || header[i] == '0') { if (header[i] == (byte) ' ' || header[i] == '0') {
if (stillPadding) { if (stillPadding) {
continue; continue;
}
}


if (header[i] == (byte) ' ') { if (header[i] == (byte) ' ') {
break; break;
}
}
}
}


stillPadding = false; stillPadding = false;
result = (result << 3) + (header[i] - '0'); result = (result << 3) + (header[i] - '0');
}
}


return result; return result;
}
}


/** /**
* Parse an entry name from a header buffer. * Parse an entry name from a header buffer.
*
*
* @param header The header buffer from which to parse. * @param header The header buffer from which to parse.
* @param offset The offset into the buffer from which to parse. * @param offset The offset into the buffer from which to parse.
* @param length The number of header bytes to parse. * @param length The number of header bytes to parse.
@@ -118,17 +118,17 @@ public class TarUtils {
for (int i = offset; i < end; ++i) { for (int i = offset; i < end; ++i) {
if (header[i] == 0) { if (header[i] == 0) {
break; break;
}
}


result.append((char) header[i]); result.append((char) header[i]);
}
}


return result; return result;
}
}


/** /**
* Determine the number of bytes in an entry name. * Determine the number of bytes in an entry name.
*
*
* @param header The header buffer from which to parse. * @param header The header buffer from which to parse.
* @param offset The offset into the buffer from which to parse. * @param offset The offset into the buffer from which to parse.
* @param length The number of header bytes to parse. * @param length The number of header bytes to parse.
@@ -139,18 +139,18 @@ public class TarUtils {


for (i = 0; i < length && i < name.length(); ++i) { for (i = 0; i < length && i < name.length(); ++i) {
buf[offset + i] = (byte) name.charAt(i); buf[offset + i] = (byte) name.charAt(i);
}
}


for (; i < length; ++i) { for (; i < length; ++i) {
buf[offset + i] = 0; buf[offset + i] = 0;
}
}


return offset + length; return offset + length;
}
}


/** /**
* Parse an octal integer from a header buffer. * Parse an octal integer from a header buffer.
*
*
* @param header The header buffer from which to parse. * @param header The header buffer from which to parse.
* @param offset The offset into the buffer from which to parse. * @param offset The offset into the buffer from which to parse.
* @param length The number of header bytes to parse. * @param length The number of header bytes to parse.
@@ -171,19 +171,19 @@ public class TarUtils {
for (long val = value; idx >= 0 && val > 0; --idx) { for (long val = value; idx >= 0 && val > 0; --idx) {
buf[offset + idx] = (byte) ((byte) '0' + (byte) (val & 7)); buf[offset + idx] = (byte) ((byte) '0' + (byte) (val & 7));
val = val >> 3; val = val >> 3;
}
}
}
}


for (; idx >= 0; --idx) { for (; idx >= 0; --idx) {
buf[offset + idx] = (byte) ' '; buf[offset + idx] = (byte) ' ';
}
}


return offset + length; return offset + length;
}
}


/** /**
* Parse an octal long integer from a header buffer. * Parse an octal long integer from a header buffer.
*
*
* @param header The header buffer from which to parse. * @param header The header buffer from which to parse.
* @param offset The offset into the buffer from which to parse. * @param offset The offset into the buffer from which to parse.
* @param length The number of header bytes to parse. * @param length The number of header bytes to parse.
@@ -196,11 +196,11 @@ public class TarUtils {
System.arraycopy(temp, 0, buf, offset, length); System.arraycopy(temp, 0, buf, offset, length);


return offset + length; return offset + length;
}
}


/** /**
* Parse the checksum octal integer from a header buffer. * Parse the checksum octal integer from a header buffer.
*
*
* @param header The header buffer from which to parse. * @param header The header buffer from which to parse.
* @param offset The offset into the buffer from which to parse. * @param offset The offset into the buffer from which to parse.
* @param length The number of header bytes to parse. * @param length The number of header bytes to parse.
@@ -214,20 +214,20 @@ public class TarUtils {


return offset + length; return offset + length;
} }
/**
/**
* Compute the checksum of a tar entry header. * Compute the checksum of a tar entry header.
*
*
* @param buf The tar entry's header buffer. * @param buf The tar entry's header buffer.
* @return The computed checksum. * @return The computed checksum.
*/
*/
public static long computeCheckSum(byte[] buf) { public static long computeCheckSum(byte[] buf) {
long sum = 0; long sum = 0;
for (int i = 0; i < buf.length; ++i) { for (int i = 0; i < buf.length; ++i) {
sum += 255 & buf[i]; sum += 255 & buf[i];
}
}
return sum; return sum;
}
}
} }

Loading…
Cancel
Save