Browse Source

more magic numbers

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@577308 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Reilly 18 years ago
parent
commit
a914355da2
7 changed files with 24 additions and 12 deletions
  1. +2
    -2
      src/main/org/apache/tools/ant/taskdefs/ProcessDestroyer.java
  2. +2
    -1
      src/main/org/apache/tools/ant/taskdefs/RecorderEntry.java
  3. +2
    -1
      src/main/org/apache/tools/ant/taskdefs/Redirector.java
  4. +2
    -0
      src/main/org/apache/tools/ant/taskdefs/Sleep.java
  5. +3
    -1
      src/main/org/apache/tools/ant/taskdefs/StreamPumper.java
  6. +2
    -1
      src/main/org/apache/tools/ant/taskdefs/Tar.java
  7. +11
    -6
      src/main/org/apache/tools/ant/taskdefs/Zip.java

+ 2
- 2
src/main/org/apache/tools/ant/taskdefs/ProcessDestroyer.java View File

@@ -29,7 +29,7 @@ import java.util.Vector;
* @since Ant 1.5
*/
class ProcessDestroyer implements Runnable {
private static final int TWENTY_SECONDS = 20000;
private Vector processes = new Vector();
// methods to register and unregister shutdown hooks
private Method addShutdownHookMethod;
@@ -150,7 +150,7 @@ class ProcessDestroyer implements Runnable {
}
// this should return quickly, since it basically is a NO-OP.
try {
destroyProcessThread.join(20000);
destroyProcessThread.join(TWENTY_SECONDS);
} catch (InterruptedException ie) {
// the thread didn't die in time
// it should not kill any processes unexpectedly


+ 2
- 1
src/main/org/apache/tools/ant/taskdefs/RecorderEntry.java View File

@@ -267,6 +267,7 @@ public class RecorderEntry implements BuildLogger, SubBuildListener {


private static String formatTime(long millis) {
// CheckStyle:MagicNumber OFF
long seconds = millis / 1000;
long minutes = seconds / 60;

@@ -280,7 +281,7 @@ public class RecorderEntry implements BuildLogger, SubBuildListener {
return Long.toString(seconds) + " second"
+ (seconds % 60 == 1 ? "" : "s");
}
// CheckStyle:MagicNumber ON
}

/**


+ 2
- 1
src/main/org/apache/tools/ant/taskdefs/Redirector.java View File

@@ -53,6 +53,7 @@ import org.apache.tools.ant.util.KeepAliveOutputStream;
* @since Ant 1.6
*/
public class Redirector {
private static final int ONE_SECOND = 1000;

private static final String DEFAULT_ENCODING
= System.getProperty("file.encoding");
@@ -779,7 +780,7 @@ public class Redirector {
// Ignore exception
}
}
wait(1000);
wait(ONE_SECOND);
} catch (InterruptedException eyeEx) {
Thread[] thread = new Thread[threadGroup.activeCount()];
threadGroup.enumerate(thread);


+ 2
- 0
src/main/org/apache/tools/ant/taskdefs/Sleep.java View File

@@ -144,8 +144,10 @@ public class Sleep extends Task {
*/

private long getSleepTime() {
// CheckStyle:MagicNumber OFF
return ((((long) hours * 60) + minutes) * 60 + seconds) * 1000
+ milliseconds;
// CheckStyle:MagicNumber ON
}




+ 3
- 1
src/main/org/apache/tools/ant/taskdefs/StreamPumper.java View File

@@ -28,6 +28,8 @@ import java.io.OutputStream;
*/
public class StreamPumper implements Runnable {

private static final int SMALL_BUFFER_SIZE = 128;

private InputStream is;
private OutputStream os;
private volatile boolean finish;
@@ -35,7 +37,7 @@ public class StreamPumper implements Runnable {
private boolean closeWhenExhausted;
private boolean autoflush = false;
private Exception exception = null;
private int bufferSize = 128;
private int bufferSize = SMALL_BUFFER_SIZE;
private boolean started = false;

/**


+ 2
- 1
src/main/org/apache/tools/ant/taskdefs/Tar.java View File

@@ -58,6 +58,7 @@ import org.apache.tools.tar.TarOutputStream;
* @ant.task category="packaging"
*/
public class Tar extends MatchingTask {
private static final int BUFFER_SIZE = 8 * 1024;

/**
* @deprecated since 1.5.x.
@@ -466,7 +467,7 @@ public class Tar extends MatchingTask {
if (!r.isDirectory()) {
in = r.getInputStream();

byte[] buffer = new byte[8 * 1024];
byte[] buffer = new byte[BUFFER_SIZE];
int count = 0;
do {
tOut.write(buffer, 0, count);


+ 11
- 6
src/main/org/apache/tools/ant/taskdefs/Zip.java View File

@@ -66,6 +66,8 @@ import org.apache.tools.zip.ZipOutputStream;
* @ant.task category="packaging"
*/
public class Zip extends MatchingTask {
private static final int BUFFER_SIZE = 8 * 1024;
private static final int ROUNDUP_MILLIS = 1999; // 2 seconds - 1
// CheckStyle:VisibilityModifier OFF - bc

protected File zipFile;
@@ -927,6 +929,7 @@ public class Zip extends MatchingTask {
OutputStream os = null;
try {
os = new FileOutputStream(zipFile);
// CheckStyle:MagicNumber OFF
// Cf. PKZIP specification.
byte[] empty = new byte[22];
empty[0] = 80; // P
@@ -934,6 +937,7 @@ public class Zip extends MatchingTask {
empty[2] = 5;
empty[3] = 6;
// remainder zeros
// CheckStyle:MagicNumber ON
os.write(empty);
} catch (IOException ioe) {
throw new BuildException("Could not create empty ZIP archive "
@@ -1404,10 +1408,11 @@ public class Zip extends MatchingTask {
ZipEntry ze = new ZipEntry (vPath);
if (dir != null && dir.exists()) {
// ZIPs store time with a granularity of 2 seconds, round up
ze.setTime(dir.lastModified() + (roundUp ? 1999 : 0));
ze.setTime(dir.lastModified() + (roundUp ? ROUNDUP_MILLIS : 0));
} else {
// ZIPs store time with a granularity of 2 seconds, round up
ze.setTime(System.currentTimeMillis() + (roundUp ? 1999 : 0));
ze.setTime(System.currentTimeMillis()
+ (roundUp ? ROUNDUP_MILLIS : 0));
}
ze.setSize (0);
ze.setMethod (ZipEntry.STORED);
@@ -1479,7 +1484,7 @@ public class Zip extends MatchingTask {
// Store data into a byte[]
ByteArrayOutputStream bos = new ByteArrayOutputStream();

byte[] buffer = new byte[8 * 1024];
byte[] buffer = new byte[BUFFER_SIZE];
int count = 0;
do {
size += count;
@@ -1491,7 +1496,7 @@ public class Zip extends MatchingTask {

} else {
in.mark(Integer.MAX_VALUE);
byte[] buffer = new byte[8 * 1024];
byte[] buffer = new byte[BUFFER_SIZE];
int count = 0;
do {
size += count;
@@ -1507,7 +1512,7 @@ public class Zip extends MatchingTask {
ze.setUnixMode(mode);
zOut.putNextEntry(ze);

byte[] buffer = new byte[8 * 1024];
byte[] buffer = new byte[BUFFER_SIZE];
int count = 0;
do {
if (count != 0) {
@@ -1544,7 +1549,7 @@ public class Zip extends MatchingTask {
try {
// ZIPs store time with a granularity of 2 seconds, round up
zipFile(fIn, zOut, vPath,
file.lastModified() + (roundUp ? 1999 : 0),
file.lastModified() + (roundUp ? ROUNDUP_MILLIS : 0),
null, mode);
} finally {
fIn.close();


Loading…
Cancel
Save