重新格式化所有java代码

This commit is contained in:
veryben
2017-05-19 09:56:24 +08:00
parent 69417006f4
commit 75931a8053
32 changed files with 7826 additions and 8880 deletions
+399 -447
View File
@@ -19,7 +19,7 @@ import java.io.IOException;
* Optrak Distribution Software Ltd.
* http://www.optrak.co.uk
* and Kevin Kelley's http://www.ruralnet.net/~kelley/java/Base64.java
*
* <p>
* Base64 is a way of encoding 8-bit characters using only ASCII printable
* characters similar to UUENCODE. UUENCODE includes a filename where BASE64 does not.
* The spec is described in RFC 2045. Base64 is a scheme where
@@ -34,452 +34,129 @@ import java.io.IOException;
* If you don't like this code, there is another implementation at http://www.ruffboy.com/download.htm
* Sun has an undocumented method called sun.misc.Base64Encoder.encode.
* You could use hex, simpler to code, but not as compact.
*
* <p>
* If you wanted to encode a giant file, you could do it in large chunks that
* are even multiples of 3 bytes, except for the last chunk, and append the outputs.
*
* <p>
* To encode a string, rather than binary data java.net.URLEncoder may be better. See
* printable characters in the Java glossary for a discussion of the differences.
*
* <p>
* version 1.4 2002 February 15 -- correct bugs with uneven line lengths,
* allow you to configure line separator.
* now need Base64 object and instance methods.
* new mailing address.
* allow you to configure line separator.
* now need Base64 object and instance methods.
* new mailing address.
* version 1.3 2000 September 12 -- fix problems with estimating output length in encode
* version 1.2 2000 September 09 -- now handles decode as well.
* version 1.1 1999 December 04 -- more symmetrical encoding algorithm.
* more accurate StringBuffer allocation size.
* more accurate StringBuffer allocation size.
* version 1.0 1999 December 03 -- posted in comp.lang.java.programmer.
* Futures Streams or files.
*/
public class Base64
{
public class Base64 {
/**
* how we separate lines, e.g. \n, \r\n, \r etc.
*/
private String lineSeparator = System.getProperty( "line.separator" );
/**
* Marker value for chars we just ignore, e.g. \n \r high ascii
*/
static final int IGNORE = -1;
/**
* Marker for = trailing pad
*/
static final int PAD = -2;
/**
* used to disable test driver
*/
private static final boolean debug = true;
/**
* how we separate lines, e.g. \n, \r\n, \r etc.
*/
private String lineSeparator = System.getProperty("line.separator");
/**
* max chars per line, excluding lineSeparator. A multiple of 4.
*/
private int lineLength = 72;
private char[] valueToChar = new char[64];
/**
* binary value encoded by a given letter of the alphabet 0..63
*/
private int[] charToValue = new int[256];
private int[] charToPad = new int[4];
/**
* max chars per line, excluding lineSeparator. A multiple of 4.
*/
private int lineLength = 72;
/* constructor */
public Base64() {
this.init('+', '/', '=');
}
private char[] valueToChar = new char[64];
/* constructor */
public Base64(char chPlus, char chSplash, char chPad, int lineLength) {
this.init(chPlus, chSplash, chPad);
this.lineLength = lineLength;
}
/**
* binary value encoded by a given letter of the alphabet 0..63
*/
private int[] charToValue = new int[256];
private int[] charToPad = new int[4];
/* constructor */
public Base64()
{
this.init('+', '/', '=');
}
/* constructor */
public Base64(char chPlus, char chSplash, char chPad, int lineLength)
{
this.init(chPlus, chSplash, chPad);
this.lineLength = lineLength;
}
public Base64(int lineLength) {
this.lineLength = lineLength;
}
public Base64(int lineLength)
{
this.lineLength = lineLength;
}
/**
* debug display array
*/
public static void show(byte[] b) {
int count = 0;
int rows = 0;
/* initialise defaultValueToChar and defaultCharToValue tables */
private void init(char chPlus, char chSplash, char chPad)
{
int index = 0;
// build translate this.valueToChar table only once.
// 0..25 -> 'A'..'Z'
for ( int i='A'; i<='Z'; i++) {
this.valueToChar[index++] = (char)i;
for (int i = 0; i < b.length; i++) {
if (count == 8) {
System.out.print(" ");
} else if (count == 16) {
System.out.println("");
count = 0;
continue;
}
// 26..51 -> 'a'..'z'
for ( int i='a'; i<='z'; i++ ) {
this.valueToChar[index++] = (char)i;
System.out.print(Integer.toHexString(b[i] & 0xFF).toUpperCase() + " ");
count++;
}
System.out.println();
}
/**
* debug display array
*/
public static void display(byte[] b) {
for (int i = 0; i < b.length; i++) {
System.out.print((char) b[i]);
}
System.out.println();
}
/**
* test driver
*/
public static void main(String[] args) {
test();
System.exit(1);
if (debug) {
try {
Base64 b64 = new Base64();
String str = "agfrtu¿¦etʲ1234¼Ù´óerty¿Õ234·¢¿¦2344ʲµÄ";
String str64 = "";
//encode
str64 = b64.encode(str.getBytes());
System.out.println(str64);
//decode
byte[] theBytes = b64.decode(str64);
show(theBytes);
String rst = new String(theBytes);
System.out.println(rst);
System.out.println(str);
} catch (Exception e) {
e.printStackTrace();
}
// 52..61 -> '0'..'9'
for ( int i='0'; i<='9'; i++) {
this.valueToChar[index++] = (char)i;
}
this.valueToChar[index++] = chPlus;
this.valueToChar[index++] = chSplash;
// build translate defaultCharToValue table only once.
for ( int i=0; i<256; i++ )
{
this.charToValue[i] = IGNORE; // default is to ignore
}
for ( int i=0; i<64; i++ )
{
this.charToValue[this.valueToChar[i]] = i;
}
this.charToValue[chPad] = PAD;
java.util.Arrays.fill(this.charToPad, chPad);
}
/**
* Encode an arbitrary array of bytes as Base64 printable ASCII.
* It will be broken into lines of 72 chars each. The last line is not
* terminated with a line separator.
* The output will always have an even multiple of data characters,
* exclusive of \n. It is padded out with =.
*/
public String encode(byte[] b) throws IOException
{
// Each group or partial group of 3 bytes becomes four chars
// covered quotient
int outputLength = ((b.length + 2) / 3) * 4;
// account for trailing newlines, on all but the very last line
if ( lineLength != 0 )
{
int lines = ( outputLength + lineLength -1 ) / lineLength - 1;
if ( lines > 0 )
{
outputLength += lines * lineSeparator.length();
}
}
// must be local for recursion to work.
StringBuffer sb = new StringBuffer( outputLength );
// must be local for recursion to work.
int linePos = 0;
// first deal with even multiples of 3 bytes.
int len = (b.length / 3) * 3;
int leftover = b.length - len;
for ( int i=0; i<len; i+=3 )
{
// Start a new line if next 4 chars won't fit on the current line
// We can't encapsulete the following code since the variable need to
// be local to this incarnation of encode.
linePos += 4;
if ( linePos > lineLength )
{
if ( lineLength != 0 )
{
sb.append(lineSeparator);
}
linePos = 4;
}
// get next three bytes in unsigned form lined up,
// in big-endian order
int combined = b[i+0] & 0xff;
combined <<= 8;
combined |= b[i+1] & 0xff;
combined <<= 8;
combined |= b[i+2] & 0xff;
// break those 24 bits into a 4 groups of 6 bits,
// working LSB to MSB.
int c3 = combined & 0x3f;
combined >>>= 6;
int c2 = combined & 0x3f;
combined >>>= 6;
int c1 = combined & 0x3f;
combined >>>= 6;
int c0 = combined & 0x3f;
// Translate into the equivalent alpha character
// emitting them in big-endian order.
sb.append( valueToChar[c0]);
sb.append( valueToChar[c1]);
sb.append( valueToChar[c2]);
sb.append( valueToChar[c3]);
}
// deal with leftover bytes
switch ( leftover )
{
case 0:
default:
// nothing to do
break;
case 1:
// One leftover byte generates xx==
// Start a new line if next 4 chars won't fit on the current line
linePos += 4;
if ( linePos > lineLength )
{
if ( lineLength != 0 )
{
sb.append(lineSeparator);
}
linePos = 4;
}
// Handle this recursively with a faked complete triple.
// Throw away last two chars and replace with ==
sb.append(encode(new byte[] {b[len], 0, 0}
).substring(0,2));
sb.append("==");
break;
case 2:
// Two leftover bytes generates xxx=
// Start a new line if next 4 chars won't fit on the current line
linePos += 4;
if ( linePos > lineLength )
{
if ( lineLength != 0 )
{
sb.append(lineSeparator);
}
linePos = 4;
}
// Handle this recursively with a faked complete triple.
// Throw away last char and replace with =
sb.append(encode(new byte[] {b[len], b[len+1], 0}
).substring(0,3));
sb.append("=");
break;
} // end switch;
if ( outputLength != sb.length() )
{
System.out.println("oops: minor program flaw: output length mis-estimated");
System.out.println("estimate:" + outputLength);
System.out.println("actual:" + sb.length());
}
return sb.toString();
}// end encode
/**
* decode a well-formed complete Base64 string back into an array of bytes.
* It must have an even multiple of 4 data characters (not counting \n),
* padded out with = as needed.
*/
public byte[] decodeAuto( String s) {
int nRemain = s.length() % 4;
if (nRemain == 0) {
return this.decode(s);
} else {
return this.decode(s + new String(this.charToPad, 0, 4 - nRemain));
}
}
/**
* decode a well-formed complete Base64 string back into an array of bytes.
* It must have an even multiple of 4 data characters (not counting \n),
* padded out with = as needed.
*/
public byte[] decode( String s)
{
// estimate worst case size of output array, no embedded newlines.
byte[] b = new byte[(s.length() / 4) * 3];
// tracks where we are in a cycle of 4 input chars.
int cycle = 0;
// where we combine 4 groups of 6 bits and take apart as 3 groups of 8.
int combined = 0;
// how many bytes we have prepared.
int j = 0;
// will be an even multiple of 4 chars, plus some embedded \n
int len = s.length();
int dummies = 0;
for ( int i=0; i<len; i++ )
{
int c = s.charAt(i);
int value = (c <= 255) ? charToValue[c] : IGNORE;
// there are two magic values PAD (=) and IGNORE.
switch ( value )
{
case IGNORE:
// e.g. \n, just ignore it.
break;
case PAD:
value = 0;
dummies++;
// fallthrough
default:
/* regular value character */
switch ( cycle )
{
case 0:
combined = value;
cycle = 1;
break;
case 1:
combined <<= 6;
combined |= value;
cycle = 2;
break;
case 2:
combined <<= 6;
combined |= value;
cycle = 3;
break;
case 3:
combined <<= 6;
combined |= value;
// we have just completed a cycle of 4 chars.
// the four 6-bit values are in combined in big-endian order
// peel them off 8 bits at a time working lsb to msb
// to get our original 3 8-bit bytes back
b[j+2] = (byte)combined;
combined >>>= 8;
b[j+1] = (byte)combined;
combined >>>= 8;
b[j] = (byte)combined;
j += 3;
cycle = 0;
break;
}
break;
}
} // end for
if ( cycle != 0 )
{
throw new ArrayIndexOutOfBoundsException ("Input to decode not an even multiple of 4 characters; pad with =.");
}
j -= dummies;
if ( b.length != j )
{
byte[] b2 = new byte[j];
System.arraycopy(b, 0, b2, 0, j);
b = b2;
}
return b;
}// end decode
/**
* determines how long the lines are that are generated by encode.
* Ignored by decode.
* @param length 0 means no newlines inserted. Must be a multiple of 4.
*/
public void setLineLength(int length)
{
this.lineLength = (length/4) * 4;
}
/**
* How lines are separated.
* Ignored by decode.
* @param lineSeparator may be "" but not null.
* Usually contains only a combination of chars \n and \r.
* Could be any chars not in set A-Z a-z 0-9 + /.
*/
public void setLineSeparator(String lineSeparator)
{
this.lineSeparator = lineSeparator;
}
/**
* Marker value for chars we just ignore, e.g. \n \r high ascii
*/
static final int IGNORE = -1;
/**
* Marker for = trailing pad
*/
static final int PAD = -2;
/**
* used to disable test driver
*/
private static final boolean debug = true;
/**
* debug display array
*/
public static void show (byte[] b)
{
int count = 0;
int rows = 0;
for ( int i=0; i<b.length; i++ )
{
if(count == 8)
{
System.out.print(" ");
}
else if(count == 16)
{
System.out.println("");
count = 0;
continue;
}
System.out.print( Integer.toHexString(b[i] & 0xFF).toUpperCase() + " ");
count ++;
}
System.out.println();
}
/**
* debug display array
*/
public static void display (byte[] b)
{
for ( int i=0; i<b.length; i++ )
{
System.out.print( (char)b[i]);
}
System.out.println();
}
/**
* test driver
*/
public static void main(String[] args)
{
test();
System.exit(1);
if ( debug )
{
try
{
Base64 b64 = new Base64();
String str = "agfrtu¿¦etʲ1234¼Ù´óerty¿Õ234·¢¿¦2344ʲµÄ";
String str64 = "";
//encode
str64 = b64.encode(str.getBytes());
System.out.println(str64);
//decode
byte[] theBytes = b64.decode(str64);
show(theBytes);
String rst = new String(theBytes);
System.out.println(rst);
System.out.println(str);
}
catch(Exception e)
{
e.printStackTrace();
}
//getBytes(String charsetName);
//getBytes(String charsetName);
/*
byte[] a = { (byte)0xfc, (byte)0x0f, (byte)0xc0};
byte[] b = { (byte)0x03, (byte)0xf0, (byte)0x3f};
@@ -512,28 +189,303 @@ public class Base64
b64.setLineLength(8);
show((b64.encode(h)).getBytes());
*/
}
}// end main
}
}// end main
public static void test()
{
try
{
Base64 b64 = new Base64();
public static void test() {
try {
Base64 b64 = new Base64();
//encode
//str64 = b64.encode(str.getBytes());
//System.out.println(str64);
//encode
//str64 = b64.encode(str.getBytes());
//System.out.println(str64);
String str64 = "CwUEFYoAAAADjQMC7ELJiY6w05267ELJiY6w05267ELJiY6w05267ELJiY6w05267ELJiY6w05267ELJiY6w05267ELJiY6w05267ELJiY6w05267ELJiY6w05267ELJiY6w05267ELJiY6w05267ELJiY6w05267ELJiY6w05267ELJiY6w05267EI=";
//decode
byte[] theBytes = b64.decode(str64);
show(theBytes);
}
catch(Exception e)
{
e.printStackTrace();
}
}
String str64 = "CwUEFYoAAAADjQMC7ELJiY6w05267ELJiY6w05267ELJiY6w05267ELJiY6w05267ELJiY6w05267ELJiY6w05267ELJiY6w05267ELJiY6w05267ELJiY6w05267ELJiY6w05267ELJiY6w05267ELJiY6w05267ELJiY6w05267ELJiY6w05267EI=";
//decode
byte[] theBytes = b64.decode(str64);
show(theBytes);
} catch (Exception e) {
e.printStackTrace();
}
}
/* initialise defaultValueToChar and defaultCharToValue tables */
private void init(char chPlus, char chSplash, char chPad) {
int index = 0;
// build translate this.valueToChar table only once.
// 0..25 -> 'A'..'Z'
for (int i = 'A'; i <= 'Z'; i++) {
this.valueToChar[index++] = (char) i;
}
// 26..51 -> 'a'..'z'
for (int i = 'a'; i <= 'z'; i++) {
this.valueToChar[index++] = (char) i;
}
// 52..61 -> '0'..'9'
for (int i = '0'; i <= '9'; i++) {
this.valueToChar[index++] = (char) i;
}
this.valueToChar[index++] = chPlus;
this.valueToChar[index++] = chSplash;
// build translate defaultCharToValue table only once.
for (int i = 0; i < 256; i++) {
this.charToValue[i] = IGNORE; // default is to ignore
}
for (int i = 0; i < 64; i++) {
this.charToValue[this.valueToChar[i]] = i;
}
this.charToValue[chPad] = PAD;
java.util.Arrays.fill(this.charToPad, chPad);
}
/**
* Encode an arbitrary array of bytes as Base64 printable ASCII.
* It will be broken into lines of 72 chars each. The last line is not
* terminated with a line separator.
* The output will always have an even multiple of data characters,
* exclusive of \n. It is padded out with =.
*/
public String encode(byte[] b) throws IOException {
// Each group or partial group of 3 bytes becomes four chars
// covered quotient
int outputLength = ((b.length + 2) / 3) * 4;
// account for trailing newlines, on all but the very last line
if (lineLength != 0) {
int lines = (outputLength + lineLength - 1) / lineLength - 1;
if (lines > 0) {
outputLength += lines * lineSeparator.length();
}
}
// must be local for recursion to work.
StringBuffer sb = new StringBuffer(outputLength);
// must be local for recursion to work.
int linePos = 0;
// first deal with even multiples of 3 bytes.
int len = (b.length / 3) * 3;
int leftover = b.length - len;
for (int i = 0; i < len; i += 3) {
// Start a new line if next 4 chars won't fit on the current line
// We can't encapsulete the following code since the variable need to
// be local to this incarnation of encode.
linePos += 4;
if (linePos > lineLength) {
if (lineLength != 0) {
sb.append(lineSeparator);
}
linePos = 4;
}
// get next three bytes in unsigned form lined up,
// in big-endian order
int combined = b[i + 0] & 0xff;
combined <<= 8;
combined |= b[i + 1] & 0xff;
combined <<= 8;
combined |= b[i + 2] & 0xff;
// break those 24 bits into a 4 groups of 6 bits,
// working LSB to MSB.
int c3 = combined & 0x3f;
combined >>>= 6;
int c2 = combined & 0x3f;
combined >>>= 6;
int c1 = combined & 0x3f;
combined >>>= 6;
int c0 = combined & 0x3f;
// Translate into the equivalent alpha character
// emitting them in big-endian order.
sb.append(valueToChar[c0]);
sb.append(valueToChar[c1]);
sb.append(valueToChar[c2]);
sb.append(valueToChar[c3]);
}
// deal with leftover bytes
switch (leftover) {
case 0:
default:
// nothing to do
break;
case 1:
// One leftover byte generates xx==
// Start a new line if next 4 chars won't fit on the current line
linePos += 4;
if (linePos > lineLength) {
if (lineLength != 0) {
sb.append(lineSeparator);
}
linePos = 4;
}
// Handle this recursively with a faked complete triple.
// Throw away last two chars and replace with ==
sb.append(encode(new byte[]{b[len], 0, 0}
).substring(0, 2));
sb.append("==");
break;
case 2:
// Two leftover bytes generates xxx=
// Start a new line if next 4 chars won't fit on the current line
linePos += 4;
if (linePos > lineLength) {
if (lineLength != 0) {
sb.append(lineSeparator);
}
linePos = 4;
}
// Handle this recursively with a faked complete triple.
// Throw away last char and replace with =
sb.append(encode(new byte[]{b[len], b[len + 1], 0}
).substring(0, 3));
sb.append("=");
break;
} // end switch;
if (outputLength != sb.length()) {
System.out.println("oops: minor program flaw: output length mis-estimated");
System.out.println("estimate:" + outputLength);
System.out.println("actual:" + sb.length());
}
return sb.toString();
}// end encode
/**
* decode a well-formed complete Base64 string back into an array of bytes.
* It must have an even multiple of 4 data characters (not counting \n),
* padded out with = as needed.
*/
public byte[] decodeAuto(String s) {
int nRemain = s.length() % 4;
if (nRemain == 0) {
return this.decode(s);
} else {
return this.decode(s + new String(this.charToPad, 0, 4 - nRemain));
}
}
/**
* decode a well-formed complete Base64 string back into an array of bytes.
* It must have an even multiple of 4 data characters (not counting \n),
* padded out with = as needed.
*/
public byte[] decode(String s) {
// estimate worst case size of output array, no embedded newlines.
byte[] b = new byte[(s.length() / 4) * 3];
// tracks where we are in a cycle of 4 input chars.
int cycle = 0;
// where we combine 4 groups of 6 bits and take apart as 3 groups of 8.
int combined = 0;
// how many bytes we have prepared.
int j = 0;
// will be an even multiple of 4 chars, plus some embedded \n
int len = s.length();
int dummies = 0;
for (int i = 0; i < len; i++) {
int c = s.charAt(i);
int value = (c <= 255) ? charToValue[c] : IGNORE;
// there are two magic values PAD (=) and IGNORE.
switch (value) {
case IGNORE:
// e.g. \n, just ignore it.
break;
case PAD:
value = 0;
dummies++;
// fallthrough
default:
/* regular value character */
switch (cycle) {
case 0:
combined = value;
cycle = 1;
break;
case 1:
combined <<= 6;
combined |= value;
cycle = 2;
break;
case 2:
combined <<= 6;
combined |= value;
cycle = 3;
break;
case 3:
combined <<= 6;
combined |= value;
// we have just completed a cycle of 4 chars.
// the four 6-bit values are in combined in big-endian order
// peel them off 8 bits at a time working lsb to msb
// to get our original 3 8-bit bytes back
b[j + 2] = (byte) combined;
combined >>>= 8;
b[j + 1] = (byte) combined;
combined >>>= 8;
b[j] = (byte) combined;
j += 3;
cycle = 0;
break;
}
break;
}
} // end for
if (cycle != 0) {
throw new ArrayIndexOutOfBoundsException("Input to decode not an even multiple of 4 characters; pad with =.");
}
j -= dummies;
if (b.length != j) {
byte[] b2 = new byte[j];
System.arraycopy(b, 0, b2, 0, j);
b = b2;
}
return b;
}// end decode
/**
* determines how long the lines are that are generated by encode.
* Ignored by decode.
*
* @param length 0 means no newlines inserted. Must be a multiple of 4.
*/
public void setLineLength(int length) {
this.lineLength = (length / 4) * 4;
}
/**
* How lines are separated.
* Ignored by decode.
*
* @param lineSeparator may be "" but not null.
* Usually contains only a combination of chars \n and \r.
* Could be any chars not in set A-Z a-z 0-9 + /.
*/
public void setLineSeparator(String lineSeparator) {
this.lineSeparator = lineSeparator;
}
} // end Base64
@@ -1,130 +1,131 @@
/**
* Copyright (C) 2008 Happy Fish / YuQing
*
* FastDFS Java Client may be copied only under the terms of the GNU Lesser
* General Public License (LGPL).
* Please visit the FastDFS Home Page http://www.csource.org/ for more detail.
**/
* Copyright (C) 2008 Happy Fish / YuQing
* <p>
* FastDFS Java Client may be copied only under the terms of the GNU Lesser
* General Public License (LGPL).
* Please visit the FastDFS Home Page http://www.csource.org/ for more detail.
**/
package org.csource.common;
import java.io.*;
import java.util.*;
import org.csource.common.*;
import java.util.ArrayList;
import java.util.Hashtable;
/**
* ini file reader / parser
* @author Happy Fish / YuQing
* @version Version 1.0
*/
public class IniFileReader
{
private Hashtable paramTable;
private String conf_filename;
* ini file reader / parser
*
* @author Happy Fish / YuQing
* @version Version 1.0
*/
public class IniFileReader {
private Hashtable paramTable;
private String conf_filename;
/**
* @param conf_filename config filename
*/
public IniFileReader(String conf_filename) throws FileNotFoundException, IOException
{
this.conf_filename = conf_filename;
loadFromFile(conf_filename);
}
/**
* @param conf_filename config filename
*/
public IniFileReader(String conf_filename) throws FileNotFoundException, IOException {
this.conf_filename = conf_filename;
loadFromFile(conf_filename);
}
/**
* get the config filename
* @return config filename
*/
public String getConfFilename()
{
return this.conf_filename;
}
private static ClassLoader classLoader() {
ClassLoader loader = Thread.currentThread().getContextClassLoader();
if (loader == null) {
loader = ClassLoader.getSystemClassLoader();
}
return loader;
}
/**
* get string value from config file
* @param name item name in config file
* @return string value
*/
public String getStrValue(String name)
{
Object obj;
obj = this.paramTable.get(name);
if (obj == null)
{
return null;
}
/**
* get the config filename
*
* @return config filename
*/
public String getConfFilename() {
return this.conf_filename;
}
if (obj instanceof String)
{
return (String)obj;
}
/**
* get string value from config file
*
* @param name item name in config file
* @return string value
*/
public String getStrValue(String name) {
Object obj;
obj = this.paramTable.get(name);
if (obj == null) {
return null;
}
return (String)((ArrayList)obj).get(0);
}
if (obj instanceof String) {
return (String) obj;
}
/**
* get int value from config file
* @param name item name in config file
* @param default_value the default value
* @return int value
*/
public int getIntValue(String name, int default_value)
{
String szValue = this.getStrValue(name);
if (szValue == null)
{
return default_value;
}
return (String) ((ArrayList) obj).get(0);
}
return Integer.parseInt(szValue);
}
/**
* get int value from config file
*
* @param name item name in config file
* @param default_value the default value
* @return int value
*/
public int getIntValue(String name, int default_value) {
String szValue = this.getStrValue(name);
if (szValue == null) {
return default_value;
}
/**
* get boolean value from config file
* @param name item name in config file
* @param default_value the default value
* @return boolean value
*/
public boolean getBoolValue(String name, boolean default_value)
{
String szValue = this.getStrValue(name);
if (szValue == null)
{
return default_value;
}
return Integer.parseInt(szValue);
}
return szValue.equalsIgnoreCase("yes") || szValue.equalsIgnoreCase("on") ||
szValue.equalsIgnoreCase("true") || szValue.equals("1");
}
/**
* get boolean value from config file
*
* @param name item name in config file
* @param default_value the default value
* @return boolean value
*/
public boolean getBoolValue(String name, boolean default_value) {
String szValue = this.getStrValue(name);
if (szValue == null) {
return default_value;
}
/**
* get all values from config file
* @param name item name in config file
* @return string values (array)
*/
public String[] getValues(String name)
{
Object obj;
String[] values;
return szValue.equalsIgnoreCase("yes") || szValue.equalsIgnoreCase("on") ||
szValue.equalsIgnoreCase("true") || szValue.equals("1");
}
obj = this.paramTable.get(name);
if (obj == null)
{
return null;
}
/**
* get all values from config file
*
* @param name item name in config file
* @return string values (array)
*/
public String[] getValues(String name) {
Object obj;
String[] values;
if (obj instanceof String)
{
values = new String[1];
values[0] = (String)obj;
return values;
}
obj = this.paramTable.get(name);
if (obj == null) {
return null;
}
Object[] objs = ((ArrayList)obj).toArray();
values = new String[objs.length];
System.arraycopy(objs, 0, values, 0, objs.length);
return values;
}
if (obj instanceof String) {
values = new String[1];
values[0] = (String) obj;
return values;
}
Object[] objs = ((ArrayList) obj).toArray();
values = new String[objs.length];
System.arraycopy(objs, 0, values, 0, objs.length);
return values;
}
private void loadFromFile(String confFilePath) throws IOException {
InputStream in = null;
@@ -144,7 +145,7 @@ public class IniFileReader
ex.printStackTrace();
} finally {
try {
if(in != null) in.close();
if (in != null) in.close();
//System.out.println("loadFrom...finally...in.close(); done");
} catch (Exception ex) {
ex.printStackTrace();
@@ -193,8 +194,8 @@ public class IniFileReader
ex.printStackTrace();
} finally {
try {
if(bufferedReader != null) bufferedReader.close();
if(inReader != null) inReader.close();
if (bufferedReader != null) bufferedReader.close();
if (inReader != null) inReader.close();
//System.out.println("readToParamTable...finally...bufferedReader.close();inReader.close(); done");
} catch (Exception ex) {
ex.printStackTrace();
@@ -202,12 +203,4 @@ public class IniFileReader
}
}
private static ClassLoader classLoader() {
ClassLoader loader = Thread.currentThread().getContextClassLoader();
if (loader == null) {
loader = ClassLoader.getSystemClassLoader();
}
return loader;
}
}
@@ -9,18 +9,16 @@
package org.csource.common;
/**
* My Exception
* @author Happy Fish / YuQing
* @version Version 1.0
*/
public class MyException extends Exception
{
public MyException()
{
}
public MyException(String message)
{
super(message);
}
* My Exception
*
* @author Happy Fish / YuQing
* @version Version 1.0
*/
public class MyException extends Exception {
public MyException() {
}
public MyException(String message) {
super(message);
}
}
@@ -9,47 +9,40 @@
package org.csource.common;
/**
* name(key) and value pair model
* @author Happy Fish / YuQing
* @version Version 1.0
*/
public class NameValuePair
{
protected String name;
protected String value;
* name(key) and value pair model
*
* @author Happy Fish / YuQing
* @version Version 1.0
*/
public class NameValuePair {
protected String name;
protected String value;
public NameValuePair()
{
}
public NameValuePair() {
}
public NameValuePair(String name)
{
this.name = name;
}
public NameValuePair(String name) {
this.name = name;
}
public NameValuePair(String name, String value)
{
this.name = name;
this.value = value;
}
public NameValuePair(String name, String value) {
this.name = name;
this.value = value;
}
public String getName()
{
return this.name;
}
public String getName() {
return this.name;
}
public String getValue()
{
return this.value;
}
public void setName(String name) {
this.name = name;
}
public void setName(String name)
{
this.name = name;
}
public String getValue() {
return this.value;
}
public void setValue(String value)
{
this.value = value;
}
public void setValue(String value) {
this.value = value;
}
}