Added FilenameUtils from apache commons. Cleaned up code
This commit is contained in:
parent
c80209ac9d
commit
32d7e2ec4a
@ -80,6 +80,14 @@ Legal:
|
||||
|
||||
|
||||
|
||||
- ConcurrentHashMapV8 - CC0 License
|
||||
http://www.bouncycastle.org
|
||||
Written by Doug Lea with assistance from members of JCP JSR-166
|
||||
Expert Group and released to the public domain, as explained at
|
||||
http://creativecommons.org/publicdomain/zero/1.0/
|
||||
|
||||
|
||||
|
||||
- FastObjectPool - Apache 2.0 license
|
||||
http://ashkrit.blogspot.com/2013/05/lock-less-java-object-pool.html
|
||||
https://github.com/ashkrit/blog/tree/master/FastObjectPool
|
||||
@ -87,6 +95,15 @@ Legal:
|
||||
|
||||
|
||||
|
||||
- FilenameUtils.java, IOCase.java - Apache 2.0 license
|
||||
http://commons.apache.org/proper/commons-io/
|
||||
Copyright 2013 ASF
|
||||
Authors: Kevin A. Burton, Scott Sanders, Daniel Rall, Christoph.Reck,
|
||||
Peter Donald, Jeff Turner, Matthew Hawthorne, Martin Cooper,
|
||||
Jeremias Maerki, Stephen Colebourne
|
||||
|
||||
|
||||
|
||||
- LAN HostDiscovery from Apache Commons JCS - Apache 2.0 license
|
||||
https://issues.apache.org/jira/browse/JCS-40
|
||||
Copyright 2001-2014 The Apache Software Foundation.
|
||||
|
4348
Dorkbox-Util/src/dorkbox/util/ConcurrentHashMapV8.java
Normal file
4348
Dorkbox-Util/src/dorkbox/util/ConcurrentHashMapV8.java
Normal file
File diff suppressed because it is too large
Load Diff
@ -117,8 +117,8 @@ public class FileUtil {
|
||||
}
|
||||
|
||||
|
||||
String normalizedIn = in.getCanonicalFile().getAbsolutePath();
|
||||
String normalizedout = out.getCanonicalFile().getAbsolutePath();
|
||||
String normalizedIn = FilenameUtils.normalize(in.getAbsolutePath());
|
||||
String normalizedout = FilenameUtils.normalize(out.getAbsolutePath());
|
||||
|
||||
// if out doesn't exist, then create it.
|
||||
File parentOut = out.getParentFile();
|
||||
|
1401
Dorkbox-Util/src/dorkbox/util/FilenameUtils.java
Normal file
1401
Dorkbox-Util/src/dorkbox/util/FilenameUtils.java
Normal file
File diff suppressed because it is too large
Load Diff
256
Dorkbox-Util/src/dorkbox/util/IOCase.java
Normal file
256
Dorkbox-Util/src/dorkbox/util/IOCase.java
Normal file
@ -0,0 +1,256 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package dorkbox.util;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Enumeration of IO case sensitivity.
|
||||
* <p>
|
||||
* Different filing systems have different rules for case-sensitivity.
|
||||
* Windows is case-insensitive, Unix is case-sensitive.
|
||||
* <p>
|
||||
* This class captures that difference, providing an enumeration to
|
||||
* control how filename comparisons should be performed. It also provides
|
||||
* methods that use the enumeration to perform comparisons.
|
||||
* <p>
|
||||
* Wherever possible, you should use the <code>check</code> methods in this
|
||||
* class to compare filenames.
|
||||
*
|
||||
* @version $Id: IOCase.java 1307459 2012-03-30 15:11:44Z ggregory $
|
||||
* @since 1.3
|
||||
*/
|
||||
public final class IOCase implements Serializable {
|
||||
|
||||
/**
|
||||
* The constant for case sensitive regardless of operating system.
|
||||
*/
|
||||
public static final IOCase SENSITIVE = new IOCase("Sensitive", true);
|
||||
|
||||
/**
|
||||
* The constant for case insensitive regardless of operating system.
|
||||
*/
|
||||
public static final IOCase INSENSITIVE = new IOCase("Insensitive", false);
|
||||
|
||||
/**
|
||||
* The constant for case sensitivity determined by the current operating system.
|
||||
* Windows is case-insensitive when comparing filenames, Unix is case-sensitive.
|
||||
* <p>
|
||||
* <strong>Note:</strong> This only caters for Windows and Unix. Other operating
|
||||
* systems (e.g. OSX and OpenVMS) are treated as case sensitive if they use the
|
||||
* Unix file separator and case-insensitive if they use the Windows file separator
|
||||
* (see {@link java.io.File#separatorChar}).
|
||||
* <p>
|
||||
* If you derialize this constant of Windows, and deserialize on Unix, or vice
|
||||
* versa, then the value of the case-sensitivity flag will change.
|
||||
*/
|
||||
public static final IOCase SYSTEM = new IOCase("System", !FilenameUtils.isSystemWindows());
|
||||
|
||||
/** Serialization version. */
|
||||
private static final long serialVersionUID = -6343169151696340687L;
|
||||
|
||||
/** The enumeration name. */
|
||||
private final String name;
|
||||
|
||||
/** The sensitivity flag. */
|
||||
private final transient boolean sensitive;
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* Factory method to create an IOCase from a name.
|
||||
*
|
||||
* @param name the name to find
|
||||
* @return the IOCase object
|
||||
* @throws IllegalArgumentException if the name is invalid
|
||||
*/
|
||||
public static IOCase forName(String name) {
|
||||
if (IOCase.SENSITIVE.name.equals(name)){
|
||||
return IOCase.SENSITIVE;
|
||||
}
|
||||
if (IOCase.INSENSITIVE.name.equals(name)){
|
||||
return IOCase.INSENSITIVE;
|
||||
}
|
||||
if (IOCase.SYSTEM.name.equals(name)){
|
||||
return IOCase.SYSTEM;
|
||||
}
|
||||
throw new IllegalArgumentException("Invalid IOCase name: " + name);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* Private constructor.
|
||||
*
|
||||
* @param name the name
|
||||
* @param sensitive the sensitivity
|
||||
*/
|
||||
private IOCase(String name, boolean sensitive) {
|
||||
this.name = name;
|
||||
this.sensitive = sensitive;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces the enumeration from the stream with a real one.
|
||||
* This ensures that the correct flag is set for SYSTEM.
|
||||
*
|
||||
* @return the resolved object
|
||||
*/
|
||||
private Object readResolve() {
|
||||
return forName(this.name);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* Gets the name of the constant.
|
||||
*
|
||||
* @return the name of the constant
|
||||
*/
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the object represent case sensitive comparison.
|
||||
*
|
||||
* @return true if case sensitive
|
||||
*/
|
||||
public boolean isCaseSensitive() {
|
||||
return this.sensitive;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* Compares two strings using the case-sensitivity rule.
|
||||
* <p>
|
||||
* This method mimics {@link String#compareTo} but takes case-sensitivity
|
||||
* into account.
|
||||
*
|
||||
* @param str1 the first string to compare, not null
|
||||
* @param str2 the second string to compare, not null
|
||||
* @return true if equal using the case rules
|
||||
* @throws NullPointerException if either string is null
|
||||
*/
|
||||
public int checkCompareTo(String str1, String str2) {
|
||||
if (str1 == null || str2 == null) {
|
||||
throw new NullPointerException("The strings must not be null");
|
||||
}
|
||||
return this.sensitive ? str1.compareTo(str2) : str1.compareToIgnoreCase(str2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares two strings using the case-sensitivity rule.
|
||||
* <p>
|
||||
* This method mimics {@link String#equals} but takes case-sensitivity
|
||||
* into account.
|
||||
*
|
||||
* @param str1 the first string to compare, not null
|
||||
* @param str2 the second string to compare, not null
|
||||
* @return true if equal using the case rules
|
||||
* @throws NullPointerException if either string is null
|
||||
*/
|
||||
public boolean checkEquals(String str1, String str2) {
|
||||
if (str1 == null || str2 == null) {
|
||||
throw new NullPointerException("The strings must not be null");
|
||||
}
|
||||
return this.sensitive ? str1.equals(str2) : str1.equalsIgnoreCase(str2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if one string starts with another using the case-sensitivity rule.
|
||||
* <p>
|
||||
* This method mimics {@link String#startsWith(String)} but takes case-sensitivity
|
||||
* into account.
|
||||
*
|
||||
* @param str the string to check, not null
|
||||
* @param start the start to compare against, not null
|
||||
* @return true if equal using the case rules
|
||||
* @throws NullPointerException if either string is null
|
||||
*/
|
||||
public boolean checkStartsWith(String str, String start) {
|
||||
return str.regionMatches(!this.sensitive, 0, start, 0, start.length());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if one string ends with another using the case-sensitivity rule.
|
||||
* <p>
|
||||
* This method mimics {@link String#endsWith} but takes case-sensitivity
|
||||
* into account.
|
||||
*
|
||||
* @param str the string to check, not null
|
||||
* @param end the end to compare against, not null
|
||||
* @return true if equal using the case rules
|
||||
* @throws NullPointerException if either string is null
|
||||
*/
|
||||
public boolean checkEndsWith(String str, String end) {
|
||||
int endLen = end.length();
|
||||
return str.regionMatches(!this.sensitive, str.length() - endLen, end, 0, endLen);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if one string contains another starting at a specific index using the
|
||||
* case-sensitivity rule.
|
||||
* <p>
|
||||
* This method mimics parts of {@link String#indexOf(String, int)}
|
||||
* but takes case-sensitivity into account.
|
||||
*
|
||||
* @param str the string to check, not null
|
||||
* @param strStartIndex the index to start at in str
|
||||
* @param search the start to search for, not null
|
||||
* @return the first index of the search String,
|
||||
* -1 if no match or {@code null} string input
|
||||
* @throws NullPointerException if either string is null
|
||||
* @since 2.0
|
||||
*/
|
||||
public int checkIndexOf(String str, int strStartIndex, String search) {
|
||||
int endIndex = str.length() - search.length();
|
||||
if (endIndex >= strStartIndex) {
|
||||
for (int i = strStartIndex; i <= endIndex; i++) {
|
||||
if (checkRegionMatches(str, i, search)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if one string contains another at a specific index using the case-sensitivity rule.
|
||||
* <p>
|
||||
* This method mimics parts of {@link String#regionMatches(boolean, int, String, int, int)}
|
||||
* but takes case-sensitivity into account.
|
||||
*
|
||||
* @param str the string to check, not null
|
||||
* @param strStartIndex the index to start at in str
|
||||
* @param search the start to search for, not null
|
||||
* @return true if equal using the case rules
|
||||
* @throws NullPointerException if either string is null
|
||||
*/
|
||||
public boolean checkRegionMatches(String str, int strStartIndex, String search) {
|
||||
return str.regionMatches(!this.sensitive, strStartIndex, search, 0, search.length());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* Gets a string describing the sensitivity.
|
||||
*
|
||||
* @return a string describing the sensitivity
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
}
|
@ -861,13 +861,15 @@ public class Sys {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This will retrieve your IP address via an HTTP server.
|
||||
* <p>
|
||||
* <b>NOTE: Use DnsClient.getPublicIp() instead. It's much more reliable as it uses DNS.</b>
|
||||
* <b>NOTE: Use DnsClient.getPublicIp() instead. It's much faster and more reliable as it uses DNS.</b>
|
||||
*
|
||||
* @return the public IP address if found, or null if it didn't find it
|
||||
*/
|
||||
@Deprecated
|
||||
public static String getPublicIpViaHttp() {
|
||||
// method 1: use DNS servers
|
||||
// dig +short myip.opendns.com @resolver1.opendns.com
|
||||
|
@ -1,12 +1,12 @@
|
||||
package dorkbox.util.process;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.PrintStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import dorkbox.util.FilenameUtils;
|
||||
import dorkbox.util.OS;
|
||||
|
||||
/**
|
||||
@ -50,19 +50,19 @@ public class JavaProcessBuilder extends ShellProcessBuilder {
|
||||
}
|
||||
|
||||
public final void addJvmClasspath(String classpathEntry) {
|
||||
classpathEntries.add(classpathEntry);
|
||||
this.classpathEntries.add(classpathEntry);
|
||||
}
|
||||
|
||||
public final void addJvmClasspaths(List<String> paths) {
|
||||
classpathEntries.addAll(paths);
|
||||
this.classpathEntries.addAll(paths);
|
||||
}
|
||||
|
||||
public final void addJvmOption(String argument) {
|
||||
jvmOptions.add(argument);
|
||||
this.jvmOptions.add(argument);
|
||||
}
|
||||
|
||||
public final void addJvmOptions(List<String> paths) {
|
||||
jvmOptions.addAll(paths);
|
||||
this.jvmOptions.addAll(paths);
|
||||
}
|
||||
|
||||
public final void setJarFile(String jarFile) {
|
||||
@ -72,14 +72,14 @@ public class JavaProcessBuilder extends ShellProcessBuilder {
|
||||
private String getClasspath() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
int count = 0;
|
||||
final int totalSize = classpathEntries.size();
|
||||
final int totalSize = this.classpathEntries.size();
|
||||
final String pathseparator = File.pathSeparator;
|
||||
|
||||
// DO NOT QUOTE the elements in the classpath!
|
||||
for (String classpathEntry : classpathEntries) {
|
||||
for (String classpathEntry : this.classpathEntries) {
|
||||
try {
|
||||
// make sure the classpath is ABSOLUTE pathname
|
||||
classpathEntry = new File(classpathEntry).getCanonicalFile().getAbsolutePath();
|
||||
classpathEntry = FilenameUtils.normalize(new File(classpathEntry).getAbsolutePath());
|
||||
|
||||
// fix a nasty problem when spaces aren't properly escaped!
|
||||
classpathEntry = classpathEntry.replaceAll(" ", "\\ ");
|
||||
@ -107,30 +107,30 @@ public class JavaProcessBuilder extends ShellProcessBuilder {
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
setExecutable(javaLocation);
|
||||
setExecutable(this.javaLocation);
|
||||
|
||||
// save off the original arguments
|
||||
List<String> origArguments = new ArrayList<String>(arguments.size());
|
||||
origArguments.addAll(arguments);
|
||||
arguments = new ArrayList<String>(0);
|
||||
List<String> origArguments = new ArrayList<String>(this.arguments.size());
|
||||
origArguments.addAll(this.arguments);
|
||||
this.arguments = new ArrayList<String>(0);
|
||||
|
||||
|
||||
// two versions, java vs not-java
|
||||
arguments.add("-Xms" + startingHeapSizeInMegabytes + "M");
|
||||
arguments.add("-Xmx" + maximumHeapSizeInMegabytes + "M");
|
||||
arguments.add("-server");
|
||||
this.arguments.add("-Xms" + this.startingHeapSizeInMegabytes + "M");
|
||||
this.arguments.add("-Xmx" + this.maximumHeapSizeInMegabytes + "M");
|
||||
this.arguments.add("-server");
|
||||
|
||||
for (String option : jvmOptions) {
|
||||
arguments.add(option);
|
||||
for (String option : this.jvmOptions) {
|
||||
this.arguments.add(option);
|
||||
}
|
||||
|
||||
//same as -cp
|
||||
String classpath = getClasspath();
|
||||
|
||||
// two more versions. jar vs classs
|
||||
if (jarFile != null) {
|
||||
arguments.add("-jar");
|
||||
arguments.add(jarFile);
|
||||
if (this.jarFile != null) {
|
||||
this.arguments.add("-jar");
|
||||
this.arguments.add(this.jarFile);
|
||||
|
||||
// interesting note. You CANNOT have a classpath specified on the commandline
|
||||
// when using JARs!! It must be set in the jar's MANIFEST.
|
||||
@ -142,34 +142,34 @@ public class JavaProcessBuilder extends ShellProcessBuilder {
|
||||
|
||||
}
|
||||
// if we are running classes!
|
||||
else if (mainClass != null) {
|
||||
else if (this.mainClass != null) {
|
||||
if (!classpath.isEmpty()) {
|
||||
arguments.add("-classpath");
|
||||
arguments.add(classpath);
|
||||
this.arguments.add("-classpath");
|
||||
this.arguments.add(classpath);
|
||||
}
|
||||
|
||||
// main class must happen AFTER the classpath!
|
||||
arguments.add(mainClass);
|
||||
this.arguments.add(this.mainClass);
|
||||
} else {
|
||||
System.err.println("WHOOPS. You must specify a jar or main class when running java!");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
|
||||
for (String arg : mainClassArguments) {
|
||||
for (String arg : this.mainClassArguments) {
|
||||
if (arg.contains(" ")) {
|
||||
// individual arguments MUST be in their own element in order to
|
||||
// be processed properly (this is how it works on the command line!)
|
||||
String[] split = arg.split(" ");
|
||||
for (String s : split) {
|
||||
arguments.add(s);
|
||||
this.arguments.add(s);
|
||||
}
|
||||
} else {
|
||||
arguments.add(arg);
|
||||
this.arguments.add(arg);
|
||||
}
|
||||
}
|
||||
|
||||
arguments.addAll(origArguments);
|
||||
this.arguments.addAll(origArguments);
|
||||
|
||||
super.start();
|
||||
}
|
||||
@ -204,14 +204,11 @@ public class JavaProcessBuilder extends ShellProcessBuilder {
|
||||
// even though the former is a symlink to the latter! To work around this, see if the
|
||||
// desired jvm is in fact pointed to by /usr/bin/java and, if so, use that instead.
|
||||
if (OS.isMacOsX()) {
|
||||
try {
|
||||
File localVM = new File("/usr/bin/java").getCanonicalFile();
|
||||
if (localVM.equals(new File(vmpath).getCanonicalFile())) {
|
||||
String localVM = FilenameUtils.normalize(new File("/usr/bin/java").getAbsolutePath());
|
||||
String vmCheck = FilenameUtils.normalize(new File(vmpath).getAbsolutePath());
|
||||
if (localVM.equals(vmCheck)) {
|
||||
vmpath = "/usr/bin/java";
|
||||
}
|
||||
} catch (IOException ioe) {
|
||||
System.err.println("Failed to check Mac OS canonical VM path." + ioe);
|
||||
}
|
||||
}
|
||||
|
||||
return vmpath;
|
||||
|
Loading…
Reference in New Issue
Block a user