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';
}