Use new split()

This commit is contained in:
zzz
2015-11-07 17:45:48 +00:00
parent 83b923151c
commit 1e5a35c7f8
31 changed files with 64 additions and 47 deletions

View File

@ -32,6 +32,8 @@ import java.util.Locale;
import java.util.Map;
import java.util.NoSuchElementException;
import net.i2p.data.DataHelper;
/**
* A class to iterate through a hosts.txt or config file without
* reading the whole thing into memory.
@ -69,7 +71,7 @@ class ConfigIterator implements Iterator<Map.Entry<String, String>>, Closeable {
String inputLine = input.readLine();
while (inputLine != null) {
inputLine = ConfigParser.stripComments(inputLine);
String[] splitLine = inputLine.split("=");
String[] splitLine = DataHelper.split(inputLine, "=");
if (splitLine.length == 2) {
next = new ConfigEntry(splitLine[0].trim().toLowerCase(Locale.US), splitLine[1].trim());
return true;

View File

@ -35,6 +35,7 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
import net.i2p.data.DataHelper;
import net.i2p.util.SecureFile;
import net.i2p.util.SecureFileOutputStream;
import net.i2p.util.SystemVersion;
@ -93,7 +94,7 @@ class ConfigParser {
inputLine = input.readLine();
while (inputLine != null) {
inputLine = stripComments(inputLine);
String[] splitLine = inputLine.split("=");
String[] splitLine = DataHelper.split(inputLine, "=");
if (splitLine.length == 2) {
result.put(splitLine[0].trim().toLowerCase(Locale.US), splitLine[1].trim());
}

View File

@ -189,7 +189,7 @@ public class SnarkManager implements CompleteListener {
for (int i = 1; i < DEFAULT_TRACKERS.length; i += 2) {
if (DEFAULT_TRACKERS[i-1].equals("TheBland") && !SigType.ECDSA_SHA256_P256.isAvailable())
continue;
String urls[] = DEFAULT_TRACKERS[i].split("=", 2);
String urls[] = DataHelper.split(DEFAULT_TRACKERS[i], "=", 2);
ann.add(urls[0]);
}
DEFAULT_TRACKER_ANNOUNCES = Collections.unmodifiableSet(ann);
@ -1078,7 +1078,7 @@ public class SnarkManager implements CompleteListener {
val = dflt;
if (val == null)
return Collections.emptyList();
return Arrays.asList(val.split(","));
return Arrays.asList(DataHelper.split(val, ","));
}
/**
@ -1611,7 +1611,7 @@ public class SnarkManager implements CompleteListener {
return;
int filecount = metainfo.getFiles().size();
int[] rv = new int[filecount];
String[] arr = pri.split(",");
String[] arr = DataHelper.split(pri, ",");
for (int i = 0; i < filecount && i < arr.length; i++) {
if (arr[i].length() > 0) {
try {
@ -2342,12 +2342,12 @@ public class SnarkManager implements CompleteListener {
if ( (trackers == null) || (trackers.trim().length() <= 0) ) {
setDefaultTrackerMap(true);
} else {
String[] toks = trackers.split(",");
String[] toks = DataHelper.split(trackers, ",");
for (int i = 0; i < toks.length; i += 2) {
String name = toks[i].trim().replace("&#44;", ",");
String url = toks[i+1].trim().replace("&#44;", ",");
if ( (name.length() > 0) && (url.length() > 0) ) {
String urls[] = url.split("=", 2);
String urls[] = DataHelper.split(url, "=", 2);
String url2 = urls.length > 1 ? urls[1] : "";
_trackerMap.put(name, new Tracker(name, urls[0], url2));
}
@ -2367,7 +2367,7 @@ public class SnarkManager implements CompleteListener {
String name = DEFAULT_TRACKERS[i];
if (name.equals("TheBland") && !SigType.ECDSA_SHA256_P256.isAvailable())
continue;
String urls[] = DEFAULT_TRACKERS[i+1].split("=", 2);
String urls[] = DataHelper.split(DEFAULT_TRACKERS[i+1], "=", 2);
String url2 = urls.length > 1 ? urls[1] : null;
_trackerMap.put(name, new Tracker(name, urls[0], url2));
}

View File

@ -912,7 +912,7 @@ public class TrackerClient implements Runnable {
if (path == null || path.length() < 517 ||
!path.startsWith("/"))
return null;
String[] parts = path.substring(1).split("[/\\?&;]", 2);
String[] parts = DataHelper.split(path.substring(1), "[/\\?&;]", 2);
return ConvertToHash.getHash(parts[0]);
}
return null;

View File

@ -102,7 +102,7 @@ class NodeInfo extends SimpleDataStructure {
*/
public NodeInfo(String s) throws DataFormatException {
super();
String[] parts = s.split(":", 4);
String[] parts = DataHelper.split(s, ":", 4);
if (parts.length != 4)
throw new DataFormatException("Bad format");
byte[] nid = Base64.decode(parts[0]);

View File

@ -414,7 +414,7 @@ public class I2PTunnelHTTPClient extends I2PTunnelHTTPClientBase implements Runn
_log.debug(getPrefix(requestId) + "First line [" + line + "]");
}
String[] params = line.split(" ", 3);
String[] params = DataHelper.split(line, " ", 3);
if(params.length != 3) {
break;
}
@ -1252,7 +1252,7 @@ public class I2PTunnelHTTPClient extends I2PTunnelHTTPClientBase implements Runn
String s = getTunnel().getClientOptions().getProperty(PROP_SSL_OUTPROXIES);
if (s == null)
return null;
String[] p = s.split("[,; \r\n\t]");
String[] p = DataHelper.split(s, "[,; \r\n\t]");
if (p.length == 0)
return null;
// todo doesn't check for ""

View File

@ -285,7 +285,7 @@ public abstract class I2PTunnelHTTPClientBase extends I2PTunnelClientBase implem
// We send Accept-Charset: UTF-8 in the 407 so hopefully it comes back that way inside the B64 ?
try {
String dec = new String(decoded, "UTF-8");
String[] parts = dec.split(":");
String[] parts = DataHelper.split(dec, ":");
String user = parts[0];
String pw = parts[1];
// first try pw for that user

View File

@ -664,7 +664,7 @@ public class I2PTunnelHTTPServer extends I2PTunnelServer {
*/
@Override
protected String filterResponseLine(String line) {
String[] s = line.split(" ", 3);
String[] s = DataHelper.split(line, " ", 3);
if (s.length > 1 &&
(s[1].startsWith("3") || s[1].startsWith("5")))
_dataExpected = 0;

View File

@ -13,6 +13,7 @@ import java.util.Properties;
import net.i2p.client.streaming.I2PSocket;
import net.i2p.crypto.SHA256Generator;
import net.i2p.data.DataHelper;
import net.i2p.data.Destination;
import net.i2p.data.Hash;
import net.i2p.data.Base32;
@ -277,7 +278,7 @@ public class I2PTunnelIRCServer extends I2PTunnelServer implements Runnable {
//if (_log.shouldLog(Log.DEBUG))
// _log.debug("Got line: " + s);
String field[]=s.split(" ",5);
String field[] = DataHelper.split(s, " ", 5);
String command;
int idx=0;

View File

@ -19,6 +19,7 @@ import net.i2p.I2PException;
import net.i2p.client.I2PSession;
import net.i2p.client.I2PSessionException;
import net.i2p.client.streaming.I2PSocketManager;
import net.i2p.data.DataHelper;
import net.i2p.data.Destination;
import net.i2p.util.EventDispatcher;
import net.i2p.util.I2PAppThread;
@ -93,7 +94,7 @@ public class I2Ping extends I2PTunnelClientBase {
int localPort = 0;
int remotePort = 0;
boolean error = false;
String[] argv = cmd.split(" ");
String[] argv = DataHelper.split(cmd, " ");
Getopt g = new Getopt("ping", argv, "t:m:n:chl:f:p:");
int c;
while ((c = g.getopt()) != -1) {

View File

@ -33,7 +33,7 @@ abstract class IRCFilter {
*/
public static String inboundFilter(String s, StringBuffer expectedPong, DCCHelper helper) {
String field[]=s.split(" ",4);
String field[] = DataHelper.split(s, " ", 4);
String command;
int idx=0;
final String[] allowedCommands =
@ -274,7 +274,7 @@ abstract class IRCFilter {
*/
public static String outboundFilter(String s, StringBuffer expectedPong, DCCHelper helper) {
String field[]=s.split(" ",3);
String field[] = DataHelper.split(s, " ",3);
if(field[0].length()==0)
return null; // W T F?
@ -420,7 +420,7 @@ abstract class IRCFilter {
int ctcp = msg.indexOf(0x01);
if (ctcp > 0)
msg = msg.substring(0, ctcp);
String[] args = msg.split(" ", 5);
String[] args = DataHelper.split(msg, " ", 5);
if (args.length <= 0)
return null;
String type = args[0];
@ -512,7 +512,7 @@ abstract class IRCFilter {
int ctcp = msg.indexOf(0x01);
if (ctcp > 0)
msg = msg.substring(0, ctcp);
String[] args = msg.split(" ", 5);
String[] args = DataHelper.split(msg, " ", 5);
if (args.length <= 0)
return null;
String type = args[0];

View File

@ -207,7 +207,7 @@ public class ConfigNetHelper extends HelperBase {
configs = Collections.emptySet();
} else {
configs = new HashSet<String>(4);
String[] ca = cs.split("[,; \r\n\t]");
String[] ca = DataHelper.split(cs, "[,; \r\n\t]");
for (int i = 0; i < ca.length; i++) {
String c = ca[i];
if (c.length() > 0) {

View File

@ -108,7 +108,7 @@ public class ConfigSummaryHandler extends FormHandler {
}
}
} else if (moving) {
String parts[] = _action.split("_");
String parts[] = DataHelper.split(_action, "_");
try {
int from = Integer.parseInt(parts[1]);
int to = 0;

View File

@ -202,7 +202,7 @@ public class EventLogHelper extends FormHandler {
buf.append(fmt.format(new Date(time)));
buf.append("</td><td>");
if (isAll) {
String[] s = event.split(" ", 2);
String[] s = DataHelper.split(event, " ", 2);
String xs = _xevents.get(s[0]);
if (xs == null)
xs = s[0];

View File

@ -135,8 +135,10 @@ public class HomeHelper extends HelperBase {
return renderConfig(apps);
}
private static final String SS = Character.toString(S);
static Collection<App> buildApps(RouterContext ctx, String config) {
String[] args = config.split("" + S);
String[] args = DataHelper.split(config, SS);
Set<App> apps = new TreeSet<App>(new AppComparator());
for (int i = 0; i < args.length - 3; i += 4) {
String name = Messages.getString(args[i], ctx);
@ -149,7 +151,7 @@ public class HomeHelper extends HelperBase {
}
static Collection<App> buildSearchApps(String config) {
String[] args = config.split("" + S);
String[] args = DataHelper.split(config, SS);
Set<App> apps = new TreeSet<App>(new AppComparator());
for (int i = 0; i < args.length - 1; i += 2) {
String name = args[i];

View File

@ -43,9 +43,11 @@ public class SearchHelper extends HelperBase {
_query = s;
}
private static final String SS = Character.toString(S);
private void buildEngineMap() {
String config = _context.getProperty(PROP_ENGINES, ENGINES_DEFAULT);
String[] args = config.split("" + S);
String[] args = DataHelper.split(config, SS);
for (int i = 0; i < args.length - 1; i += 2) {
String name = args[i];
String url = args[i+1];

View File

@ -861,6 +861,8 @@ public class SummaryHelper extends HelperBase {
public void storeNewsHelper(NewsHelper n) { _newshelper = n; }
public NewsHelper getNewsHelper() { return _newshelper; }
private static final String SS = Character.toString(S);
public List<String> getSummaryBarSections(String page) {
String config = "";
if ("home".equals(page)) {
@ -870,7 +872,7 @@ public class SummaryHelper extends HelperBase {
if (config == null)
config = _context.getProperty(PROP_SUMMARYBAR + "default", DEFAULT_FULL);
}
return Arrays.asList(config.split("" + S));
return Arrays.asList(DataHelper.split(config, SS));
}
static void saveSummaryBarSections(RouterContext ctx, String page, Map<Integer, String> sections) {

View File

@ -42,6 +42,7 @@ import java.util.Locale;
import java.util.TimeZone;
import net.i2p.I2PAppContext;
import net.i2p.data.DataHelper;
/**
* data structure to hold a single message, mostly used with folder view and sorting
@ -190,7 +191,7 @@ class Mail {
address.indexOf( "\r" ) != -1 )
return false;
String[] tokens = address.split( "[ \t]+" );
String[] tokens = DataHelper.split(address, "[ \t]+");
int addresses = 0;
@ -208,7 +209,7 @@ class Mail {
*/
public static String getAddress(String address )
{
String[] tokens = address.split( "[ \t]+" );
String[] tokens = DataHelper.split(address, "[ \t]+");
for( int i = 0; i < tokens.length; i++ ) {
if( tokens[i].matches( "^[^@< \t]+@[^> \t]+$" ) )
@ -232,7 +233,7 @@ class Mail {
public static boolean getRecipientsFromList( ArrayList<String> recipients, String text, boolean ok )
{
if( text != null && text.length() > 0 ) {
String[] ccs = text.split( "," );
String[] ccs = DataHelper.split(text, ",");
for( int i = 0; i < ccs.length; i++ ) {
String recipient = ccs[i].trim();
if( validateAddress( recipient ) ) {

View File

@ -79,7 +79,7 @@ class MailPart {
beginBody = bb;
ReadBuffer decodedHeaders = EncodingFactory.getEncoding( "HEADERLINE" ).decode( buffer.content, begin, beginBody - begin );
headerLines = new String( decodedHeaders.content, decodedHeaders.offset, decodedHeaders.length ).split( "\r\n" );
headerLines = DataHelper.split(new String(decodedHeaders.content, decodedHeaders.offset, decodedHeaders.length), "\r\n");
String boundary = null;
String x_encoding = null;

View File

@ -996,7 +996,7 @@ public class WebMail extends HttpServlet
PrintWriter pw2 = new PrintWriter( text2 );
showPart( pw2, part, 0, TEXT_ONLY );
pw2.flush();
String[] lines = text2.toString().split( "\r\n" );
String[] lines = DataHelper.split(text2.toString(), "\r\n");
for( int i = 0; i < lines.length; i++ )
pw.println( "> " + lines[i] );
pw.flush();

View File

@ -282,7 +282,7 @@ public class SMTPClient {
error += e.getMessage();
}
if( !mailSent && lastResponse.length() > 0 ) {
String[] lines = lastResponse.split( "\r" );
String[] lines = DataHelper.split(lastResponse, "\r");
for( int i = 0; i < lines.length; i++ )
error += lines[i] + '\n';
}

View File

@ -1131,7 +1131,7 @@ public class EepGet {
private int handleStatus(String line) {
if (_log.shouldLog(Log.DEBUG))
_log.debug("Status line: [" + line.trim() + "]");
String[] toks = line.split(" ", 3);
String[] toks = DataHelper.split(line, " ", 3);
if (toks.length < 2) {
if (_log.shouldLog(Log.WARN))
_log.warn("ERR: status "+ line);

View File

@ -83,6 +83,7 @@ import javax.net.ssl.TrustManagerFactory;
import net.i2p.I2PAppContext;
import net.i2p.crypto.KeyStoreUtil;
import net.i2p.data.DataHelper;
import org.apache.http.conn.ssl.DefaultHostnameVerifier;
import org.apache.http.conn.util.PublicSuffixList;
@ -443,7 +444,7 @@ public class I2PSSLSocketFactory {
try {
if (line.charAt(0) == '#')
continue;
String[] s = line.split(",");
String[] s = DataHelper.split(line, ",");
String lc = s[0].toLowerCase(Locale.US);
tlds.add(lc);
i++;

View File

@ -35,6 +35,7 @@ import freenet.support.CPUInformation.UnknownCPUException;
import net.i2p.I2PAppContext;
import net.i2p.crypto.CryptoConstants;
import net.i2p.data.DataHelper;
/**
* <p>BigInteger that takes advantage of the jbigi library for the modPow operation,
@ -734,7 +735,7 @@ public class NativeBigInteger extends BigInteger {
in = new BufferedReader(new InputStreamReader(new FileInputStream("/proc/cpuinfo"), "ISO-8859-1"), 4096);
String line = null;
while ( (line = in.readLine()) != null) {
String[] parts = line.split(":", 2);
String[] parts = DataHelper.split(line, ":", 2);
if (parts.length < 2)
continue;
String key = parts[0].trim().toLowerCase(Locale.US);

View File

@ -211,7 +211,7 @@ public class WorkingDir {
String[] files = dir.list();
if (files == null)
return false;
String migrated[] = MIGRATE_BASE.split(",");
String migrated[] = DataHelper.split(MIGRATE_BASE, ",");
for (String file: files) {
for (int i = 0; i < migrated.length; i++) {
if (file.equals(migrated[i]))
@ -282,7 +282,7 @@ public class WorkingDir {
private static boolean migrate(String list, File olddir, File todir) {
boolean rv = true;
String files[] = list.split(",");
String files[] = DataHelper.split(list, ",");
for (int i = 0; i < files.length; i++) {
File from = new File(olddir, files[i]);
if (!copy(from, todir)) {

View File

@ -10,6 +10,7 @@ import java.util.Locale;
import java.util.Map;
import net.i2p.I2PAppContext;
import net.i2p.data.DataHelper;
import net.i2p.router.transport.GeoIP;
/**
@ -105,7 +106,7 @@ class Zones {
try {
if (line.charAt(0) == '#')
continue;
String[] s = line.split(",");
String[] s = DataHelper.split(line, ",");
String ucContinent = s[1].toUpperCase(Locale.US).trim();
String zone = _continentToZone.get(ucContinent);
if (zone == null)

View File

@ -17,6 +17,7 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
import net.i2p.I2PAppContext;
import net.i2p.data.DataHelper;
import net.i2p.data.Hash;
import net.i2p.router.Router;
import net.i2p.router.RouterContext;
@ -209,7 +210,7 @@ public class GeoIP {
if (line.charAt(0) == '#') {
continue;
}
String[] s = line.split(",");
String[] s = DataHelper.split(line, ",");
String lc = s[0].toLowerCase(Locale.US);
_codeToName.put(lc, s[1]);
_codeCache.put(lc, lc);
@ -274,7 +275,7 @@ public class GeoIP {
if (buf.charAt(0) == '#') {
continue;
}
String[] s = buf.split(",");
String[] s = DataHelper.split(buf, ",");
long ip1 = Long.parseLong(s[0]);
long ip2 = Long.parseLong(s[1]);
while (idx < search.length && search[idx].longValue() < ip1) {

View File

@ -170,7 +170,7 @@ class GeoIPv6 {
if (buf.charAt(0) == '#') {
continue;
}
String[] s = buf.split(",");
String[] s = DataHelper.split(buf, ",");
String ips1 = s[0].replace("\"", "").trim();
String ips2 = s[1].replace("\"", "").trim();
byte[] ip1 = InetAddress.getByName(ips1).getAddress();

View File

@ -224,7 +224,7 @@ class UPnP extends ControlPoint implements DeviceChangeListener, EventListener {
boolean ignore = false;
String toIgnore = _context.getProperty(PROP_IGNORE);
if (toIgnore != null) {
String[] ignores = toIgnore.split("[,; \r\n\t]");
String[] ignores = DataHelper.split(toIgnore, "[,; \r\n\t]");
for (int i = 0; i < ignores.length; i++) {
if (ignores[i].equals(udn)) {
ignore = true;

View File

@ -340,7 +340,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
List<InetAddress> bindToAddrs = new ArrayList<InetAddress>(4);
if (bindTo != null) {
String[] bta = bindTo.split("[,; \r\n\t]");
String[] bta = DataHelper.split(bindTo, "[,; \r\n\t]");
for (int i = 0; i < bta.length; i++) {
String bt = bta[i];
if (bt.length() <= 0)
@ -1896,7 +1896,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
if (explicitAddressSpecified()) {
host = _context.getProperty(PROP_EXTERNAL_HOST);
if (host != null) {
String[] hosts = host.split("[,; \r\n\t]");
String[] hosts = DataHelper.split(host, "[,; \r\n\t]");
RouterAddress rv = null;
for (int i = 0; i < hosts.length; i++) {
String h = hosts[i];

View File

@ -13,6 +13,7 @@ import java.util.SortedMap;
import java.util.TreeMap;
import net.i2p.I2PAppContext;
import net.i2p.data.DataHelper;
import net.i2p.util.SecureFileOutputStream;
/**
@ -125,7 +126,7 @@ public class EventLog {
String line = null;
while ( (line = br.readLine()) != null) {
try {
String[] s = line.split(" ", 3);
String[] s = DataHelper.split(line, " ", 3);
if (!s[1].equals(event))
continue;
long time = Long.parseLong(s[0]);
@ -167,7 +168,7 @@ public class EventLog {
String line = null;
while ( (line = br.readLine()) != null) {
try {
String[] s = line.split(" ", 2);
String[] s = DataHelper.split(line, " ", 2);
if (s.length < 2)
continue;
long time = Long.parseLong(s[0]);