| @@ -625,8 +625,7 @@ public class Get extends Task { | |||
| connection = openConnection(source); | |||
| if (connection == null) | |||
| { | |||
| if (connection == null) { | |||
| return false; | |||
| } | |||
| @@ -719,19 +718,14 @@ public class Get extends Task { | |||
| if (connection instanceof HttpURLConnection) { | |||
| HttpURLConnection httpConnection = (HttpURLConnection) connection; | |||
| int responseCode = httpConnection.getResponseCode(); | |||
| if (responseCode == HttpURLConnection.HTTP_MOVED_PERM || | |||
| responseCode == HttpURLConnection.HTTP_MOVED_TEMP || | |||
| responseCode == HttpURLConnection.HTTP_SEE_OTHER || | |||
| responseCode == HTTP_MOVED_TEMP) | |||
| { | |||
| if (isMoved(responseCode)) { | |||
| String newLocation = httpConnection.getHeaderField("Location"); | |||
| String message = aSource | |||
| + (responseCode == HttpURLConnection.HTTP_MOVED_PERM ? " permanently" | |||
| : "") + " moved to " + newLocation; | |||
| log(message, logLevel); | |||
| URL newURL = new URL(aSource, newLocation); | |||
| if (!redirectionAllowed(aSource, newURL)) | |||
| { | |||
| if (!redirectionAllowed(aSource, newURL)) { | |||
| return null; | |||
| } | |||
| return openConnection(newURL); | |||
| @@ -767,6 +761,13 @@ public class Get extends Task { | |||
| return connection; | |||
| } | |||
| private boolean isMoved(int responseCode) { | |||
| return responseCode == HttpURLConnection.HTTP_MOVED_PERM || | |||
| responseCode == HttpURLConnection.HTTP_MOVED_TEMP || | |||
| responseCode == HttpURLConnection.HTTP_SEE_OTHER || | |||
| responseCode == HTTP_MOVED_TEMP; | |||
| } | |||
| private boolean downloadFile() | |||
| throws FileNotFoundException, IOException { | |||
| for (int i = 0; i < numberRetries; i++) { | |||
| @@ -120,8 +120,7 @@ public class HostInfo extends Task { | |||
| while (interfaces.hasMoreElements()) { | |||
| NetworkInterface currentif = interfaces.nextElement(); | |||
| Enumeration<InetAddress> addrs = currentif.getInetAddresses(); | |||
| while (addrs.hasMoreElements()) | |||
| { | |||
| while (addrs.hasMoreElements()) { | |||
| inetAddrs.add(addrs.nextElement()); | |||
| } | |||
| } | |||
| @@ -152,8 +151,7 @@ public class HostInfo extends Task { | |||
| } | |||
| } | |||
| private boolean hasHostName(InetAddress addr) | |||
| { | |||
| private boolean hasHostName(InetAddress addr) { | |||
| return !addr.getHostAddress().equals(addr.getCanonicalHostName()); | |||
| } | |||
| @@ -240,8 +238,7 @@ public class HostInfo extends Task { | |||
| } | |||
| } | |||
| private void setDomainAndName(String fqdn) | |||
| { | |||
| private void setDomainAndName(String fqdn) { | |||
| int idx = fqdn.indexOf('.'); | |||
| if (idx > 0) { | |||
| setProperty(NAME, fqdn.substring(0, idx)); | |||
| @@ -323,6 +323,7 @@ public class SubAnt extends Task { | |||
| ant = null; | |||
| } | |||
| } | |||
| /** whether we should even try to continue after this error */ | |||
| private boolean isHardError(Throwable t) { | |||
| if (t instanceof BuildException) { | |||
| @@ -175,16 +175,13 @@ public class CommandLauncher { | |||
| try { | |||
| launcher = (CommandLauncher) Class.forName(launcherClass) | |||
| .newInstance(); | |||
| } | |||
| catch(InstantiationException e) { | |||
| } catch(InstantiationException e) { | |||
| System.err.println("Could not instantiate launcher class " | |||
| + launcherClass + ": " + e.getMessage()); | |||
| } | |||
| catch(IllegalAccessException e) { | |||
| } catch(IllegalAccessException e) { | |||
| System.err.println("Could not instantiate launcher class " | |||
| + launcherClass + ": " + e.getMessage()); | |||
| } | |||
| catch(ClassNotFoundException e) { | |||
| } catch(ClassNotFoundException e) { | |||
| System.err.println("Could not instantiate launcher class " | |||
| + launcherClass + ": " + e.getMessage()); | |||
| } | |||
| @@ -56,8 +56,7 @@ public class MacCommandLauncher extends CommandLauncherProxy { | |||
| System.getProperties().put("user.dir", workingDir.getAbsolutePath()); | |||
| try { | |||
| return exec(project, cmd, env); | |||
| } | |||
| finally { | |||
| } finally { | |||
| System.getProperties().put("user.dir", System.getProperty("user.dir")); | |||
| } | |||
| } | |||
| @@ -742,9 +742,8 @@ public class NetRexxC extends MatchingTask { | |||
| if (!compile && srcFile.lastModified() > javaFile.lastModified()) { | |||
| filecopyList.put(srcFile.getAbsolutePath(), destFile.getAbsolutePath()); | |||
| compileList.addElement(destFile.getAbsolutePath()); | |||
| } | |||
| // compile case tests against .class file | |||
| else if (compile && srcFile.lastModified() > classFile.lastModified()) { | |||
| } else if (compile && srcFile.lastModified() > classFile.lastModified()) { | |||
| // compile case tests against .class file | |||
| filecopyList.put(srcFile.getAbsolutePath(), destFile.getAbsolutePath()); | |||
| compileList.addElement(destFile.getAbsolutePath()); | |||
| } | |||
| @@ -134,9 +134,9 @@ public class JUnitTask extends Task { | |||
| = System.getProperty("line.separator"); | |||
| private static final String CLASSPATH = "CLASSPATH"; | |||
| private CommandlineJava commandline; | |||
| private Vector tests = new Vector(); | |||
| private Vector batchTests = new Vector(); | |||
| private Vector formatters = new Vector(); | |||
| private Vector<JUnitTest> tests = new Vector<JUnitTest>(); | |||
| private Vector<BatchTest> batchTests = new Vector<BatchTest>(); | |||
| private Vector<FormatterElement> formatters = new Vector<FormatterElement>(); | |||
| private File dir = null; | |||
| private Integer timeout = null; | |||
| @@ -817,7 +817,7 @@ public class JUnitTask extends Task { | |||
| setupJUnitDelegate(); | |||
| List testLists = new ArrayList(); | |||
| List<List> testLists = new ArrayList<List>(); | |||
| /* parallel test execution is only supported for multi-process execution */ | |||
| int threads = ((!fork) || (forkMode.getValue().equals(ForkMode.ONCE)) | |||
| ? 1 | |||
| @@ -830,7 +830,7 @@ public class JUnitTask extends Task { | |||
| } else { /* forkMode.getValue().equals(ForkMode.PER_BATCH) */ | |||
| final int count = batchTests.size(); | |||
| for (int i = 0; i < count; i++) { | |||
| BatchTest batchtest = (BatchTest) batchTests.elementAt(i); | |||
| BatchTest batchtest = batchTests.elementAt(i); | |||
| testLists.addAll(executeOrQueue(batchtest.elements(), false)); | |||
| } | |||
| testLists.addAll(executeOrQueue(tests.elements(), forkPerTest)); | |||
| @@ -860,7 +860,7 @@ public class JUnitTask extends Task { | |||
| */ | |||
| private class JunitTestThread implements Runnable { | |||
| JunitTestThread(JUnitTask master, Iterator iterator, int id) { | |||
| JunitTestThread(JUnitTask master, Iterator<List> iterator, int id) { | |||
| this.masterTask = master; | |||
| this.iterator = iterator; | |||
| this.id = id; | |||
| @@ -876,7 +876,7 @@ public class JUnitTask extends Task { | |||
| } | |||
| private JUnitTask masterTask; | |||
| private Iterator iterator; | |||
| private Iterator<List> iterator; | |||
| private int id; | |||
| } | |||
| @@ -887,10 +887,10 @@ public class JUnitTask extends Task { | |||
| * threads get the same test, or two threads simultaneously pop the list so that a test | |||
| * gets skipped! | |||
| */ | |||
| private List getNextTest(Iterator iter) { | |||
| private List getNextTest(Iterator<List> iter) { | |||
| synchronized(iter) { | |||
| if (iter.hasNext()) { | |||
| return (List) iter.next(); | |||
| return iter.next(); | |||
| } | |||
| return null; | |||
| } | |||
| @@ -907,7 +907,7 @@ public class JUnitTask extends Task { | |||
| * fatal reason, no new tests/batches will be started but the running threads will be | |||
| * permitted to complete. Additional tests may start in already-running batch-test threads. | |||
| */ | |||
| private void oneJunitThread(Iterator iter, int threadId) { | |||
| private void oneJunitThread(Iterator<List> iter, int threadId) { | |||
| List l; | |||
| log("Starting test thread " + threadId, Project.MSG_VERBOSE); | |||
| @@ -923,27 +923,26 @@ public class JUnitTask extends Task { | |||
| } | |||
| private void runTestsInThreads(List testList, int numThreads) { | |||
| private void runTestsInThreads(List<List> testList, int numThreads) { | |||
| Iterator iter = testList.iterator(); | |||
| Iterator<List> iter = testList.iterator(); | |||
| if (numThreads == 1) { | |||
| /* with just one thread just run the test - don't create any threads */ | |||
| oneJunitThread(iter, 0); | |||
| } | |||
| else { | |||
| Thread threads[] = new Thread[numThreads]; | |||
| } else { | |||
| Thread[] threads = new Thread[numThreads]; | |||
| int i; | |||
| boolean exceptionOccurred; | |||
| /* Need to split apart tests, which are still grouped in batches */ | |||
| /* is there a simpler Java mechanism to do this? */ | |||
| /* I assume we don't want to do this with "per batch" forking. */ | |||
| List newlist = new ArrayList(); | |||
| List<List> newlist = new ArrayList<List>(); | |||
| if (forkMode.getValue().equals(ForkMode.PER_TEST)) { | |||
| Iterator i1 = testList.iterator(); | |||
| Iterator<List> i1 = testList.iterator(); | |||
| while (i1.hasNext()) { | |||
| List l = (List) i1.next(); | |||
| List l = i1.next(); | |||
| if (l.size() == 1) { | |||
| newlist.add(l); | |||
| } else { | |||
| @@ -974,8 +973,7 @@ public class JUnitTask extends Task { | |||
| for (i = 0; i < numThreads; i++) { | |||
| threads[i].join(); | |||
| } | |||
| } | |||
| catch (InterruptedException e) { | |||
| } catch (InterruptedException e) { | |||
| exceptionOccurred = true; | |||
| } | |||
| } while (exceptionOccurred); | |||
| @@ -1656,11 +1654,11 @@ public class JUnitTask extends Task { | |||
| * @return enumeration over individual tests | |||
| * @since Ant 1.3 | |||
| */ | |||
| protected Enumeration getIndividualTests() { | |||
| protected Enumeration<JUnitTest> getIndividualTests() { | |||
| final int count = batchTests.size(); | |||
| final Enumeration[] enums = new Enumeration[ count + 1]; | |||
| for (int i = 0; i < count; i++) { | |||
| BatchTest batchtest = (BatchTest) batchTests.elementAt(i); | |||
| BatchTest batchtest = batchTests.elementAt(i); | |||
| enums[i] = batchtest.elements(); | |||
| } | |||
| enums[enums.length - 1] = tests.elements(); | |||
| @@ -1681,9 +1679,9 @@ public class JUnitTask extends Task { | |||
| return; | |||
| } | |||
| Enumeration testsEnum = tests.elements(); | |||
| Enumeration<JUnitTest> testsEnum = tests.elements(); | |||
| while (testsEnum.hasMoreElements()) { | |||
| JUnitTest test = (JUnitTest) testsEnum.nextElement(); | |||
| JUnitTest test = testsEnum.nextElement(); | |||
| if (test.hasMethodsSpecified() && test.shouldRun(getProject())) { | |||
| test.resolveMethods(); | |||
| } | |||
| @@ -1695,7 +1693,7 @@ public class JUnitTask extends Task { | |||
| * @return enumeration | |||
| * @since Ant 1.3 | |||
| */ | |||
| protected Enumeration allTests() { | |||
| protected Enumeration<JUnitTest> allTests() { | |||
| Enumeration[] enums = {tests.elements(), batchTests.elements()}; | |||
| return Enumerations.fromCompound(enums); | |||
| } | |||
| @@ -1706,7 +1704,7 @@ public class JUnitTask extends Task { | |||
| * @since Ant 1.3 | |||
| */ | |||
| private FormatterElement[] mergeFormatters(JUnitTest test) { | |||
| Vector feVector = (Vector) formatters.clone(); | |||
| Vector<FormatterElement> feVector = (Vector<FormatterElement>) formatters.clone(); | |||
| test.addFormattersTo(feVector); | |||
| FormatterElement[] feArray = new FormatterElement[feVector.size()]; | |||
| feVector.copyInto(feArray); | |||
| @@ -2083,11 +2081,11 @@ public class JUnitTask extends Task { | |||
| * @return a list of tasks to be executed. | |||
| * @since 1.6.2 | |||
| */ | |||
| protected Collection executeOrQueue(Enumeration testList, | |||
| protected Collection<List> executeOrQueue(Enumeration<JUnitTest> testList, | |||
| boolean runIndividual) { | |||
| Map testConfigurations = new HashMap(); | |||
| Map<ForkedTestConfiguration, List> testConfigurations = new HashMap<ForkedTestConfiguration, List>(); | |||
| while (testList.hasMoreElements()) { | |||
| JUnitTest test = (JUnitTest) testList.nextElement(); | |||
| JUnitTest test = testList.nextElement(); | |||
| if (test.shouldRun(getProject())) { | |||
| /* with multi-threaded runs need to defer execution of even */ | |||
| /* individual tests so the threads can pick tests off the queue. */ | |||
| @@ -2096,9 +2094,9 @@ public class JUnitTask extends Task { | |||
| } else { | |||
| ForkedTestConfiguration c = | |||
| new ForkedTestConfiguration(test); | |||
| List l = (List) testConfigurations.get(c); | |||
| List<JUnitTest> l = testConfigurations.get(c); | |||
| if (l == null) { | |||
| l = new ArrayList(); | |||
| l = new ArrayList<JUnitTest>(); | |||
| testConfigurations.put(c, l); | |||
| } | |||
| l.add(test); | |||
| @@ -90,6 +90,7 @@ public class TearDownOnVmCrash implements JUnitResultFormatter { | |||
| testClass = Thread.currentThread().getContextClassLoader() | |||
| .loadClass(suiteName); | |||
| } catch (ClassNotFoundException cnfe) { | |||
| // ignore | |||
| } | |||
| } | |||
| if (testClass == null && getClass().getClassLoader() != null) { | |||
| @@ -97,6 +98,7 @@ public class TearDownOnVmCrash implements JUnitResultFormatter { | |||
| testClass = | |||
| getClass().getClassLoader().loadClass(suiteName); | |||
| } catch (ClassNotFoundException cnfe) { | |||
| // ignore | |||
| } | |||
| } | |||
| if (testClass == null) { | |||
| @@ -168,6 +168,7 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan | |||
| hostname = localHost.getHostName(); | |||
| } | |||
| } catch (UnknownHostException e) { | |||
| // fall back to default 'localhost' | |||
| } | |||
| return hostname; | |||
| } | |||
| @@ -256,8 +256,7 @@ public class SSHExec extends SSHBase { | |||
| * If suppressSystemOut is <code>false</code>, normal behavior | |||
| * @since Ant 1.9.0 | |||
| */ | |||
| public void setSuppressSystemOut(boolean suppressSystemOut) | |||
| { | |||
| public void setSuppressSystemOut(boolean suppressSystemOut) { | |||
| this.suppressSystemOut = suppressSystemOut; | |||
| } | |||
| @@ -266,8 +265,7 @@ public class SSHExec extends SSHBase { | |||
| * If suppressSystemErr is <code>false</code>, normal behavior | |||
| * @since Ant 1.9.4 | |||
| */ | |||
| public void setSuppressSystemErr(boolean suppressSystemErr) | |||
| { | |||
| public void setSuppressSystemErr(boolean suppressSystemErr) { | |||
| this.suppressSystemErr = suppressSystemErr; | |||
| } | |||
| @@ -225,27 +225,31 @@ public class SSHSession extends SSHBase { | |||
| int rport = 0; | |||
| public void setLPort(int lport) { | |||
| Integer portKey = new Integer(lport); | |||
| if (localPortsUsed.contains(portKey)) | |||
| if (localPortsUsed.contains(portKey)) { | |||
| throw new BuildException("Multiple local tunnels defined to" | |||
| + " use same local port " + lport); | |||
| } | |||
| localPortsUsed.add(portKey); | |||
| this.lport = lport; | |||
| } | |||
| public void setRHost(String rhost) { this.rhost = rhost; } | |||
| public void setRPort(int rport) { this.rport = rport; } | |||
| public int getLPort() { | |||
| if (lport == 0) throw new BuildException("lport is required for" | |||
| + " LocalTunnel."); | |||
| if (lport == 0) { | |||
| throw new BuildException("lport is required for LocalTunnel."); | |||
| } | |||
| return lport; | |||
| } | |||
| public String getRHost() { | |||
| if (rhost == null) throw new BuildException("rhost is required" | |||
| + " for LocalTunnel."); | |||
| if (rhost == null) { | |||
| throw new BuildException("rhost is required for LocalTunnel."); | |||
| } | |||
| return rhost; | |||
| } | |||
| public int getRPort() { | |||
| if (rport == 0) throw new BuildException("rport is required for" | |||
| + " LocalTunnel."); | |||
| if (rport == 0) { | |||
| throw new BuildException("rport is required for LocalTunnel."); | |||
| } | |||
| return rport; | |||
| } | |||
| } | |||
| @@ -260,25 +264,29 @@ public class SSHSession extends SSHBase { | |||
| public void setLHost(String lhost) { this.lhost = lhost; } | |||
| public void setRPort(int rport) { | |||
| Integer portKey = new Integer(rport); | |||
| if (remotePortsUsed.contains(portKey)) | |||
| throw new BuildException("Multiple remote tunnels defined to" | |||
| + " use same remote port " + rport); | |||
| if (remotePortsUsed.contains(portKey)) { | |||
| throw new BuildException("Multiple remote tunnels defined to" | |||
| + " use same remote port " + rport); | |||
| } | |||
| remotePortsUsed.add(portKey); | |||
| this.rport = rport; | |||
| } | |||
| public int getLPort() { | |||
| if (lport == 0) throw new BuildException("lport is required for" | |||
| + " RemoteTunnel."); | |||
| if (lport == 0) { | |||
| throw new BuildException("lport is required for RemoteTunnel."); | |||
| } | |||
| return lport; | |||
| } | |||
| public String getLHost() { | |||
| if (lhost == null) throw new BuildException("lhost is required for" | |||
| + " RemoteTunnel."); | |||
| if (lhost == null) { | |||
| throw new BuildException("lhost is required for RemoteTunnel."); | |||
| } | |||
| return lhost; | |||
| } | |||
| public int getRPort() { | |||
| if (rport == 0) throw new BuildException("rport is required for" | |||
| + " RemoteTunnel."); | |||
| if (rport == 0) { | |||
| throw new BuildException("rport is required for RemoteTunnel."); | |||
| } | |||
| return rport; | |||
| } | |||
| } | |||
| @@ -301,7 +309,7 @@ public class SSHSession extends SSHBase { | |||
| * This is a simple task container. | |||
| */ | |||
| public static class NestedSequential implements TaskContainer { | |||
| private List nested = new ArrayList(); | |||
| private List<Task> nested = new ArrayList<Task>(); | |||
| /** | |||
| * Add a task or type to the container. | |||
| @@ -315,7 +323,7 @@ public class SSHSession extends SSHBase { | |||
| /** | |||
| * @return the list of unknown elements | |||
| */ | |||
| public List getNested() { | |||
| public List<Task> getNested() { | |||
| return nested; | |||
| } | |||
| } | |||
| @@ -231,11 +231,9 @@ public class LayoutPreservingProperties extends Properties { | |||
| LogicalLine line = (LogicalLine) i.next(); | |||
| if (line instanceof Blank) { | |||
| out.println("blank: \"" + line + "\""); | |||
| } | |||
| else if (line instanceof Comment) { | |||
| } else if (line instanceof Comment) { | |||
| out.println("comment: \"" + line + "\""); | |||
| } | |||
| else if (line instanceof Pair) { | |||
| } else if (line instanceof Pair) { | |||
| out.println("pair: \"" + line + "\""); | |||
| } | |||
| } | |||
| @@ -294,8 +292,7 @@ public class LayoutPreservingProperties extends Properties { | |||
| } | |||
| } | |||
| osw.write(line.toString() + LS); | |||
| } | |||
| else if (line != null) { | |||
| } else if (line != null) { | |||
| osw.write(line.toString() + LS); | |||
| } | |||
| } | |||
| @@ -456,28 +453,26 @@ public class LayoutPreservingProperties extends Properties { | |||
| if (c == '\n') { | |||
| // we have hit out end-of-string marker | |||
| break; | |||
| } | |||
| else if (c == '\\') { | |||
| } else if (c == '\\') { | |||
| // possibly an escape sequence | |||
| c = ch[++i]; | |||
| if (c == 'n') | |||
| if (c == 'n') { | |||
| buffy.append('\n'); | |||
| else if (c == 'r') | |||
| } else if (c == 'r') { | |||
| buffy.append('\r'); | |||
| else if (c == 'f') | |||
| } else if (c == 'f') { | |||
| buffy.append('\f'); | |||
| else if (c == 't') | |||
| } else if (c == 't') { | |||
| buffy.append('\t'); | |||
| else if (c == 'u') { | |||
| } else if (c == 'u') { | |||
| // handle unicode escapes | |||
| c = unescapeUnicode(ch, i+1); | |||
| i += 4; | |||
| buffy.append(c); | |||
| } | |||
| else | |||
| } else { | |||
| buffy.append(c); | |||
| } | |||
| else { | |||
| } | |||
| } else { | |||
| buffy.append(c); | |||
| } | |||
| } | |||
| @@ -694,8 +689,7 @@ public class LayoutPreservingProperties extends Properties { | |||
| Object dolly = null; | |||
| try { | |||
| dolly = super.clone(); | |||
| } | |||
| catch (CloneNotSupportedException e) { | |||
| } catch (CloneNotSupportedException e) { | |||
| // should be fine | |||
| e.printStackTrace(); | |||
| } | |||
| @@ -709,8 +703,7 @@ public class LayoutPreservingProperties extends Properties { | |||
| // trim leading whitespace only | |||
| name = text; | |||
| value = null; | |||
| } | |||
| else { | |||
| } else { | |||
| name = text.substring(0, pos); | |||
| value = text.substring(pos+1, text.length()); | |||
| } | |||
| @@ -24,7 +24,8 @@ import java.lang.management.ManagementFactory; | |||
| * @since Ant 1.9.4 | |||
| */ | |||
| public class ProcessUtil { | |||
| /** | |||
| /** | |||
| * provide id of the current process | |||
| * @param fallback | |||
| * @return current process id | |||
| @@ -49,10 +50,13 @@ public class ProcessUtil { | |||
| } | |||
| return fallback; | |||
| } | |||
| public static void main(String [] args) { | |||
| System.out.println(getProcessId("<PID>")); | |||
| try { | |||
| Thread.sleep(120000); | |||
| } catch (Exception exc) {} | |||
| Thread.sleep(120000); | |||
| } catch (Exception exc) { | |||
| // ignore | |||
| } | |||
| } | |||
| } | |||
| @@ -84,7 +84,7 @@ import org.apache.tools.zip.ZipEncoding; | |||
| * field is the binary representation of the number. | |||
| * See TarUtils.parseOctalOrBinary. | |||
| * </pre> | |||
| * | |||
| * | |||
| * <p> | |||
| * The C structure for a old GNU Tar Entry's header is: | |||
| * <pre> | |||
| @@ -316,6 +316,7 @@ public class TarEntry implements TarConstants { | |||
| * @param headerBuf The header bytes from a tar archive entry. | |||
| * @param encoding encoding to use for file names | |||
| * @throws IllegalArgumentException if any of the numeric fields have an invalid format | |||
| * @throws IOException if an error occurs during reading the archive | |||
| */ | |||
| public TarEntry(byte[] headerBuf, ZipEncoding encoding) | |||
| throws IOException { | |||
| @@ -409,7 +410,7 @@ public class TarEntry implements TarConstants { | |||
| /** | |||
| * Set this entry's link name. | |||
| * | |||
| * | |||
| * @param link the link name to use. | |||
| */ | |||
| public void setLinkName(String link) { | |||
| @@ -572,8 +573,8 @@ public class TarEntry implements TarConstants { | |||
| * @throws IllegalArgumentException if the size is < 0. | |||
| */ | |||
| public void setSize(long size) { | |||
| if (size < 0){ | |||
| throw new IllegalArgumentException("Size is out of range: "+size); | |||
| if (size < 0) { | |||
| throw new IllegalArgumentException("Size is out of range: " + size); | |||
| } | |||
| this.size = size; | |||
| } | |||
| @@ -594,7 +595,7 @@ public class TarEntry implements TarConstants { | |||
| * @throws IllegalArgumentException if the devNo is < 0. | |||
| */ | |||
| public void setDevMajor(int devNo) { | |||
| if (devNo < 0){ | |||
| if (devNo < 0) { | |||
| throw new IllegalArgumentException("Major device number is out of " | |||
| + "range: " + devNo); | |||
| } | |||
| @@ -617,7 +618,7 @@ public class TarEntry implements TarConstants { | |||
| * @throws IllegalArgumentException if the devNo is < 0. | |||
| */ | |||
| public void setDevMinor(int devNo) { | |||
| if (devNo < 0){ | |||
| if (devNo < 0) { | |||
| throw new IllegalArgumentException("Minor device number is out of " | |||
| + "range: " + devNo); | |||
| } | |||
| @@ -644,7 +645,7 @@ public class TarEntry implements TarConstants { | |||
| } | |||
| /** | |||
| * Indicate if this entry is a GNU sparse block | |||
| * Indicate if this entry is a GNU sparse block. | |||
| * | |||
| * @return true if this is a sparse extension provided by GNU tar | |||
| */ | |||
| @@ -674,20 +675,20 @@ public class TarEntry implements TarConstants { | |||
| /** | |||
| * Check if this is a Pax header. | |||
| * | |||
| * | |||
| * @return {@code true} if this is a Pax header. | |||
| */ | |||
| public boolean isPaxHeader(){ | |||
| public boolean isPaxHeader() { | |||
| return linkFlag == LF_PAX_EXTENDED_HEADER_LC | |||
| || linkFlag == LF_PAX_EXTENDED_HEADER_UC; | |||
| } | |||
| /** | |||
| * Check if this is a Pax header. | |||
| * | |||
| * | |||
| * @return {@code true} if this is a Pax header. | |||
| */ | |||
| public boolean isGlobalPaxHeader(){ | |||
| public boolean isGlobalPaxHeader() { | |||
| return linkFlag == LF_PAX_GLOBAL_EXTENDED_HEADER; | |||
| } | |||
| @@ -713,7 +714,8 @@ public class TarEntry implements TarConstants { | |||
| } | |||
| /** | |||
| * Check if this is a "normal file" | |||
| * Check if this is a "normal file". | |||
| * @return <i>true</i> if it is a 'normal' file | |||
| */ | |||
| public boolean isFile() { | |||
| if (file != null) { | |||
| @@ -727,6 +729,7 @@ public class TarEntry implements TarConstants { | |||
| /** | |||
| * Check if this is a symbolic link entry. | |||
| * @return <i>true</i> if it is a symlink | |||
| */ | |||
| public boolean isSymbolicLink() { | |||
| return linkFlag == LF_SYMLINK; | |||
| @@ -734,6 +737,7 @@ public class TarEntry implements TarConstants { | |||
| /** | |||
| * Check if this is a link entry. | |||
| * @return <i>true</i> if it is a link | |||
| */ | |||
| public boolean isLink() { | |||
| return linkFlag == LF_LINK; | |||
| @@ -741,20 +745,21 @@ public class TarEntry implements TarConstants { | |||
| /** | |||
| * Check if this is a character device entry. | |||
| * @return <i>true</i> if it is a character device entry | |||
| */ | |||
| public boolean isCharacterDevice() { | |||
| return linkFlag == LF_CHR; | |||
| } | |||
| /** | |||
| * Check if this is a block device entry. | |||
| * @return <i>true</i> if this is a block device entry. | |||
| */ | |||
| public boolean isBlockDevice() { | |||
| return linkFlag == LF_BLK; | |||
| } | |||
| /** | |||
| * Check if this is a FIFO (pipe) entry. | |||
| * @return <i>true</i> if this is a FIFO (pipe) entry. | |||
| */ | |||
| public boolean isFIFO() { | |||
| return linkFlag == LF_FIFO; | |||
| @@ -809,6 +814,7 @@ public class TarEntry implements TarConstants { | |||
| * @param starMode whether to use the star/GNU tar/BSD tar | |||
| * extension for numeric fields if their value doesn't fit in the | |||
| * maximum size of standard tar archives | |||
| * @throws IOException if an error occurs while writing the archive | |||
| */ | |||
| public void writeEntryHeader(byte[] outbuf, ZipEncoding encoding, | |||
| boolean starMode) throws IOException { | |||
| @@ -857,7 +863,7 @@ public class TarEntry implements TarConstants { | |||
| private int writeEntryHeaderField(long value, byte[] outbuf, int offset, | |||
| int length, boolean starMode) { | |||
| if (!starMode && (value < 0 | |||
| || value >= (1l << (3 * (length - 1))))) { | |||
| || value >= (1L << (3 * (length - 1))))) { | |||
| // value doesn't fit into field when written as octal | |||
| // number, will be written to PAX header or causes an | |||
| // error | |||
| @@ -893,6 +899,7 @@ public class TarEntry implements TarConstants { | |||
| * @param encoding encoding to use for file names | |||
| * @throws IllegalArgumentException if any of the numeric fields | |||
| * have an invalid format | |||
| * @throws IOException if an error occurs while reading the archive | |||
| */ | |||
| public void parseTarHeader(byte[] header, ZipEncoding encoding) | |||
| throws IOException { | |||
| @@ -905,7 +912,7 @@ public class TarEntry implements TarConstants { | |||
| int offset = 0; | |||
| name = oldStyle ? TarUtils.parseName(header, offset, NAMELEN) | |||
| : TarUtils.parseName(header, offset, NAMELEN, encoding); | |||
| : TarUtils.parseName(header, offset, NAMELEN, encoding); | |||
| offset += NAMELEN; | |||
| mode = (int) TarUtils.parseOctalOrBinary(header, offset, MODELEN); | |||
| offset += MODELEN; | |||
| @@ -959,10 +966,10 @@ public class TarEntry implements TarConstants { | |||
| : TarUtils.parseName(header, offset, PREFIXLEN, encoding); | |||
| // SunOS tar -E does not add / to directory names, so fix | |||
| // up to be consistent | |||
| if (isDirectory() && !name.endsWith("/")){ | |||
| if (isDirectory() && !name.endsWith("/")) { | |||
| name = name + "/"; | |||
| } | |||
| if (prefix.length() > 0){ | |||
| if (prefix.length() > 0) { | |||
| name = prefix + "/" + name; | |||
| } | |||
| } | |||
| @@ -1030,7 +1037,7 @@ public class TarEntry implements TarConstants { | |||
| /** | |||
| * Check if buffer contents matches Ascii String. | |||
| * | |||
| * | |||
| * @param expected | |||
| * @param buffer | |||
| * @param offset | |||
| @@ -1038,7 +1045,7 @@ public class TarEntry implements TarConstants { | |||
| * @return {@code true} if buffer is the same as the expected string | |||
| */ | |||
| private static boolean matchAsciiBuffer(String expected, byte[] buffer, | |||
| int offset, int length){ | |||
| int offset, int length) { | |||
| byte[] buffer1; | |||
| try { | |||
| buffer1 = expected.getBytes("ASCII"); | |||
| @@ -1051,7 +1058,7 @@ public class TarEntry implements TarConstants { | |||
| /** | |||
| * Compare byte buffers, optionally ignoring trailing nulls | |||
| * | |||
| * | |||
| * @param buffer1 | |||
| * @param offset1 | |||
| * @param length1 | |||
| @@ -1064,26 +1071,26 @@ public class TarEntry implements TarConstants { | |||
| private static boolean isEqual( | |||
| final byte[] buffer1, final int offset1, final int length1, | |||
| final byte[] buffer2, final int offset2, final int length2, | |||
| boolean ignoreTrailingNulls){ | |||
| boolean ignoreTrailingNulls) { | |||
| int minLen=length1 < length2 ? length1 : length2; | |||
| for (int i=0; i < minLen; i++){ | |||
| if (buffer1[offset1+i] != buffer2[offset2+i]){ | |||
| for (int i=0; i < minLen; i++) { | |||
| if (buffer1[offset1+i] != buffer2[offset2+i]) { | |||
| return false; | |||
| } | |||
| } | |||
| if (length1 == length2){ | |||
| if (length1 == length2) { | |||
| return true; | |||
| } | |||
| if (ignoreTrailingNulls){ | |||
| if (ignoreTrailingNulls) { | |||
| if (length1 > length2){ | |||
| for(int i = length2; i < length1; i++){ | |||
| if (buffer1[offset1+i] != 0){ | |||
| if (buffer1[offset1+i] != 0) { | |||
| return false; | |||
| } | |||
| } | |||
| } else { | |||
| for(int i = length1; i < length2; i++){ | |||
| if (buffer2[offset2+i] != 0){ | |||
| for (int i = length1; i < length2; i++){ | |||
| if (buffer2[offset2+i] != 0) { | |||
| return false; | |||
| } | |||
| } | |||