public static Properties load(InputStream is, String charsetName) throws IOException { if (JavaDetector.isJDK6()) { return loadJDK6(new InputStreamReader(is, charsetName)); } else { return loadJDK5(is, charsetName); } }
public static Properties load(String s, String charsetName) throws IOException { if (JavaDetector.isJDK6()) { return loadJDK6(new UnsyncStringReader(s)); } else { ByteBuffer byteBuffer = CharsetEncoderUtil.encode(charsetName, s); InputStream is = new UnsyncByteArrayInputStream( byteBuffer.array(), byteBuffer.arrayOffset(), byteBuffer.limit()); return loadJDK5(is, charsetName); } }
private static long _parseLong(String value, long defaultValue) { if (_useJDKParseLong == null) { if (OSDetector.isAIX() && ServerDetector.isWebSphere() && JavaDetector.isIBM() && JavaDetector.is64bit()) { _useJDKParseLong = Boolean.TRUE; } else { _useJDKParseLong = Boolean.FALSE; } } if (_useJDKParseLong) { try { return Long.parseLong(value); } catch (NumberFormatException nfe) { return defaultValue; } } int length = value.length(); if (length <= 0) { return defaultValue; } int pos = 0; long limit = -Long.MAX_VALUE; boolean negative = false; char c = value.charAt(0); if (c < CharPool.NUMBER_0) { if (c == CharPool.MINUS) { limit = Long.MIN_VALUE; negative = true; } else if (c != CharPool.PLUS) { return defaultValue; } if (length == 1) { return defaultValue; } pos++; } long smallLimit = limit / 10; long result = 0; while (pos < length) { if (result < smallLimit) { return defaultValue; } c = value.charAt(pos++); if ((c < CharPool.NUMBER_0) || (c > CharPool.NUMBER_9)) { return defaultValue; } int number = c - CharPool.NUMBER_0; result *= 10; if (result < (limit + number)) { return defaultValue; } result -= number; } if (negative) { return result; } else { return -result; } }