Browse Source

magic number

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@579278 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Reilly 17 years ago
parent
commit
0b6d093f46
5 changed files with 31 additions and 3 deletions
  1. +6
    -0
      src/main/org/apache/tools/mail/SmtpResponseReader.java
  2. +4
    -2
      src/main/org/apache/tools/tar/TarInputStream.java
  3. +7
    -1
      src/main/org/apache/tools/tar/TarUtils.java
  4. +4
    -0
      src/main/org/apache/tools/zip/AsiExtraField.java
  5. +10
    -0
      src/main/org/apache/tools/zip/ZipOutputStream.java

+ 6
- 0
src/main/org/apache/tools/mail/SmtpResponseReader.java View File

@@ -56,10 +56,12 @@ public class SmtpResponseReader {
public String getResponse() throws IOException { public String getResponse() throws IOException {
result.setLength(0); result.setLength(0);
String line = reader.readLine(); String line = reader.readLine();
// CheckStyle:MagicNumber OFF
if (line != null && line.length() >= 3) { if (line != null && line.length() >= 3) {
result.append(line.substring(0, 3)); result.append(line.substring(0, 3));
result.append(" "); result.append(" ");
} }
// CheckStyle:MagicNumber ON


while (line != null) { while (line != null) {
append(line); append(line);
@@ -85,16 +87,20 @@ public class SmtpResponseReader {
* @return true if there are more lines to check. * @return true if there are more lines to check.
*/ */
protected boolean hasMoreLines(String line) { protected boolean hasMoreLines(String line) {
// CheckStyle:MagicNumber OFF
return line.length() > 3 && line.charAt(3) == '-'; return line.length() > 3 && line.charAt(3) == '-';
// CheckStyle:MagicNumber ON
} }


/** /**
* Append the text from this line of the resonse. * Append the text from this line of the resonse.
*/ */
private void append(String line) { private void append(String line) {
// CheckStyle:MagicNumber OFF
if (line.length() > 4) { if (line.length() > 4) {
result.append(line.substring(4)); result.append(line.substring(4));
result.append(" "); result.append(" ");
} }
// CheckStyle:MagicNumber ON
} }
} }

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

@@ -36,7 +36,9 @@ import java.io.OutputStream;
* *
*/ */
public class TarInputStream extends FilterInputStream { public class TarInputStream extends FilterInputStream {
private static final int SMALL_BUFFER_SIZE = 256;
private static final int BUFFER_SIZE = 8 * 1024; private static final int BUFFER_SIZE = 8 * 1024;
private static final int LARGE_BUFFER_SIZE = 32 * 1024;
private static final int BYTE_MASK = 0xFF; private static final int BYTE_MASK = 0xFF;


// CheckStyle:VisibilityModifier OFF - bc // CheckStyle:VisibilityModifier OFF - bc
@@ -257,7 +259,7 @@ public class TarInputStream extends FilterInputStream {
if (this.currEntry != null && this.currEntry.isGNULongNameEntry()) { if (this.currEntry != null && this.currEntry.isGNULongNameEntry()) {
// read in the name // read in the name
StringBuffer longName = new StringBuffer(); StringBuffer longName = new StringBuffer();
byte[] buf = new byte[256];
byte[] buf = new byte[SMALL_BUFFER_SIZE];
int length = 0; int length = 0;
while ((length = read(buf)) >= 0) { while ((length = read(buf)) >= 0) {
longName.append(new String(buf, 0, length)); longName.append(new String(buf, 0, length));
@@ -380,7 +382,7 @@ public class TarInputStream extends FilterInputStream {
* @throws IOException on error * @throws IOException on error
*/ */
public void copyEntryContents(OutputStream out) throws IOException { public void copyEntryContents(OutputStream out) throws IOException {
byte[] buf = new byte[32 * 1024];
byte[] buf = new byte[LARGE_BUFFER_SIZE];


while (true) { while (true) {
int numRead = this.read(buf, 0, buf.length); int numRead = this.read(buf, 0, buf.length);


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

@@ -30,6 +30,8 @@ package org.apache.tools.tar;
// CheckStyle:HideUtilityClassConstructorCheck OFF (bc) // CheckStyle:HideUtilityClassConstructorCheck OFF (bc)
public class TarUtils { public class TarUtils {


private static final int BYTE_MASK = 255;

/** /**
* 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.
@@ -60,7 +62,9 @@ public class TarUtils {
} }


stillPadding = false; stillPadding = false;
// CheckStyle:MagicNumber OFF
result = (result << 3) + (header[i] - '0'); result = (result << 3) + (header[i] - '0');
// CheckStyle:MagicNumber ON
} }


return result; return result;
@@ -134,8 +138,10 @@ public class TarUtils {
--idx; --idx;
} else { } else {
for (long val = value; idx >= 0 && val > 0; --idx) { for (long val = value; idx >= 0 && val > 0; --idx) {
// CheckStyle:MagicNumber OFF
buf[offset + idx] = (byte) ((byte) '0' + (byte) (val & 7)); buf[offset + idx] = (byte) ((byte) '0' + (byte) (val & 7));
val = val >> 3; val = val >> 3;
// CheckStyle:MagicNumber ON
} }
} }


@@ -192,7 +198,7 @@ public class TarUtils {
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 += BYTE_MASK & buf[i];
} }


return sum; return sum;


+ 4
- 0
src/main/org/apache/tools/zip/AsiExtraField.java View File

@@ -139,6 +139,7 @@ public class AsiExtraField implements ZipExtraField, UnixStat, Cloneable {
System.arraycopy(ZipShort.getBytes(getMode()), 0, data, 0, 2); System.arraycopy(ZipShort.getBytes(getMode()), 0, data, 0, 2);


byte[] linkArray = getLinkedFile().getBytes(); byte[] linkArray = getLinkedFile().getBytes();
// CheckStyle:MagicNumber OFF
System.arraycopy(ZipLong.getBytes(linkArray.length), System.arraycopy(ZipLong.getBytes(linkArray.length),
0, data, 2, WORD); 0, data, 2, WORD);


@@ -148,6 +149,7 @@ public class AsiExtraField implements ZipExtraField, UnixStat, Cloneable {
0, data, 8, 2); 0, data, 8, 2);


System.arraycopy(linkArray, 0, data, 10, linkArray.length); System.arraycopy(linkArray, 0, data, 10, linkArray.length);
// CheckStyle:MagicNumber ON


crc.reset(); crc.reset();
crc.update(data); crc.update(data);
@@ -300,6 +302,7 @@ public class AsiExtraField implements ZipExtraField, UnixStat, Cloneable {
} }


int newMode = ZipShort.getValue(tmp, 0); int newMode = ZipShort.getValue(tmp, 0);
// CheckStyle:MagicNumber OFF
byte[] linkArray = new byte[(int) ZipLong.getValue(tmp, 2)]; byte[] linkArray = new byte[(int) ZipLong.getValue(tmp, 2)];
uid = ZipShort.getValue(tmp, 6); uid = ZipShort.getValue(tmp, 6);
gid = ZipShort.getValue(tmp, 8); gid = ZipShort.getValue(tmp, 8);
@@ -310,6 +313,7 @@ public class AsiExtraField implements ZipExtraField, UnixStat, Cloneable {
System.arraycopy(tmp, 10, linkArray, 0, linkArray.length); System.arraycopy(tmp, 10, linkArray, 0, linkArray.length);
link = new String(linkArray); link = new String(linkArray);
} }
// CheckStyle:MagicNumber ON
setDirectory((newMode & DIR_FLAG) != 0); setDirectory((newMode & DIR_FLAG) != 0);
setMode(newMode); setMode(newMode);
} }


+ 10
- 0
src/main/org/apache/tools/zip/ZipOutputStream.java View File

@@ -599,6 +599,7 @@ public class ZipOutputStream extends FilterOutputStream {


// version needed to extract // version needed to extract
// general purpose bit flag // general purpose bit flag
// CheckStyle:MagicNumber OFF
if (zipMethod == DEFLATED && raf == null) { if (zipMethod == DEFLATED && raf == null) {
// requires version 2 as we are going to store length info // requires version 2 as we are going to store length info
// in the data descriptor // in the data descriptor
@@ -610,6 +611,7 @@ public class ZipOutputStream extends FilterOutputStream {
writeOut(ZipShort.getBytes(10)); writeOut(ZipShort.getBytes(10));
writeOut(ZERO); writeOut(ZERO);
} }
// CheckStyle:MagicNumber ON
written += WORD; written += WORD;


// compression method // compression method
@@ -633,7 +635,9 @@ public class ZipOutputStream extends FilterOutputStream {
writeOut(ZipLong.getBytes(ze.getSize())); writeOut(ZipLong.getBytes(ze.getSize()));
writeOut(ZipLong.getBytes(ze.getSize())); writeOut(ZipLong.getBytes(ze.getSize()));
} }
// CheckStyle:MagicNumber OFF
written += 12; written += 12;
// CheckStyle:MagicNumber ON


// file name length // file name length
byte[] name = getBytes(ze.getName()); byte[] name = getBytes(ze.getName());
@@ -671,7 +675,9 @@ public class ZipOutputStream extends FilterOutputStream {
writeOut(ZipLong.getBytes(entry.getCrc())); writeOut(ZipLong.getBytes(entry.getCrc()));
writeOut(ZipLong.getBytes(entry.getCompressedSize())); writeOut(ZipLong.getBytes(entry.getCompressedSize()));
writeOut(ZipLong.getBytes(entry.getSize())); writeOut(ZipLong.getBytes(entry.getSize()));
// CheckStyle:MagicNumber OFF
written += 16; written += 16;
// CheckStyle:MagicNumber ON
} }


/** /**
@@ -686,6 +692,7 @@ public class ZipOutputStream extends FilterOutputStream {
written += WORD; written += WORD;


// version made by // version made by
// CheckStyle:MagicNumber OFF
writeOut(ZipShort.getBytes((ze.getPlatform() << 8) | 20)); writeOut(ZipShort.getBytes((ze.getPlatform() << 8) | 20));
written += SHORT; written += SHORT;


@@ -702,6 +709,7 @@ public class ZipOutputStream extends FilterOutputStream {
writeOut(ZipShort.getBytes(10)); writeOut(ZipShort.getBytes(10));
writeOut(ZERO); writeOut(ZERO);
} }
// CheckStyle:MagicNumber ON
written += WORD; written += WORD;


// compression method // compression method
@@ -718,7 +726,9 @@ public class ZipOutputStream extends FilterOutputStream {
writeOut(ZipLong.getBytes(ze.getCrc())); writeOut(ZipLong.getBytes(ze.getCrc()));
writeOut(ZipLong.getBytes(ze.getCompressedSize())); writeOut(ZipLong.getBytes(ze.getCompressedSize()));
writeOut(ZipLong.getBytes(ze.getSize())); writeOut(ZipLong.getBytes(ze.getSize()));
// CheckStyle:MagicNumber OFF
written += 12; written += 12;
// CheckStyle:MagicNumber ON


// file name length // file name length
byte[] name = getBytes(ze.getName()); byte[] name = getBytes(ze.getName());


Loading…
Cancel
Save