diff --git a/NiHao/src/nihao/WebCall.java b/NiHao/src/nihao/WebCall.java
index 0a53229..f35298d 100644
--- a/NiHao/src/nihao/WebCall.java
+++ b/NiHao/src/nihao/WebCall.java
@@ -154,7 +154,7 @@
* @param name
* String clave del valor, 4 tipos:
* · si se antepone "@" se retorna un valor de contexto
- * · si se antepone "$" se retorna un valor se desión
+ * · si se antepone "$" se retorna un valor se sesión
* · si se antepone "%" se retorna un valor de atributo
* del request
* en cualquier otro caso, el campo hace referencia a un valor en
diff --git a/NiHao/src/nihao/types/TextEncoding.java b/NiHao/src/nihao/types/TextEncoding.java
new file mode 100644
index 0000000..4c7bb25
--- /dev/null
+++ b/NiHao/src/nihao/types/TextEncoding.java
@@ -0,0 +1,38 @@
+package nihao.types;
+
+public enum TextEncoding {
+ /**
+ * Desconocido
+ */
+ Unknown,
+
+ /**
+ * ASCII (usado tambi�n para ANSI)
+ */
+ ASCII,
+
+ /**
+ * UTF-8
+ */
+ UTF8,
+
+ /**
+ * UTF-16 (UNICODE) Little Endian
+ */
+ UTF16LE,
+
+ /**
+ * UTF-16 (UNICODE) Big Endian
+ */
+ UTF16BE,
+
+ /**
+ * UTF-32 (UNICODE) Little Endian
+ */
+ UTF32LE,
+
+ /**
+ * UTF-32 (UNICODE) Big Endian
+ */
+ UTF32BE,
+}
diff --git a/NiHao/src/nihao/util/Base64Codec.java b/NiHao/src/nihao/util/Base64Codec.java
deleted file mode 100644
index b20166e..0000000
--- a/NiHao/src/nihao/util/Base64Codec.java
+++ /dev/null
@@ -1,183 +0,0 @@
-package nihao.util;
-
-/**
- * A Base64 encoder/decoder.
- *
- *
- * This class is used to encode and decode data in Base64 format as described in - * RFC 1521. - * - *
- * Project home page: www.
- * source-code.biz/base64coder/java
- * Author: Christian d'Heureuse, Inventec Informatik AG, Zurich, Switzerland
- * Multi-licensed: EPL / LGPL / GPL / AL / BSD / MIT.
- */
-public class Base64Codec {
- // Mapping table from 6-bit nibbles to Base64 characters.
- private static final byte[] map1 = new byte[64];
- static {
- int i = 0;
- for (char c = 'A'; c <= 'Z'; c++)
- map1[i++] = (byte) c;
- for (char c = 'a'; c <= 'z'; c++)
- map1[i++] = (byte) c;
- for (char c = '0'; c <= '9'; c++)
- map1[i++] = (byte) c;
- map1[i++] = '+';
- map1[i++] = '/';
- }
-
- // Mapping table from Base64 characters to 6-bit nibbles.
- private static final byte[] map2 = new byte[128];
- static {
- for (int i = 0; i < map2.length; i++)
- map2[i] = -1;
- for (int i = 0; i < 64; i++)
- map2[map1[i]] = (byte) i;
- }
-
- /**
- * Encodes a byte array into Base64 format. No blanks or line breaks are
- * inserted in the output.
- *
- * @param in
- * An array containing the data bytes to be encoded.
- * @return A character array containing the Base64 encoded data.
- */
- public static byte[] encode(byte[] in) {
- return encode(in, 0, in.length);
- }
-
- /**
- * Encodes a byte array into Base64 format. No blanks or line breaks are
- * inserted in the output.
- *
- * @param in
- * An array containing the data bytes to be encoded.
- * @param iOff
- * Offset of the first byte in in to be processed.
- * @param iLen
- * Number of bytes to process in in, starting at
- * iOff.
- * @return A character array containing the Base64 encoded data.
- */
- public static byte[] encode(byte[] in, int iOff, int iLen) {
- int oDataLen = (iLen * 4 + 2) / 3; // output length without padding
- int oLen = ((iLen + 2) / 3) * 4; // output length including padding
- byte[] out = new byte[oLen];
- int ip = iOff;
- int iEnd = iOff + iLen;
- int op = 0;
- while (ip < iEnd) {
- int i0 = in[ip++] & 0xff;
- int i1 = ip < iEnd ? in[ip++] & 0xff : 0;
- int i2 = ip < iEnd ? in[ip++] & 0xff : 0;
- int o0 = i0 >>> 2;
- int o1 = ((i0 & 3) << 4) | (i1 >>> 4);
- int o2 = ((i1 & 0xf) << 2) | (i2 >>> 6);
- int o3 = i2 & 0x3F;
- out[op++] = map1[o0];
- out[op++] = map1[o1];
- out[op] = (byte) (op < oDataLen ? map1[o2] : '=');
- op++;
- out[op] = (byte) (op < oDataLen ? map1[o3] : '=');
- op++;
- }
- return out;
- }
-
- /**
- * Decodes a byte array from Base64 format. No blanks or line breaks are
- * allowed within the Base64 encoded input data.
- *
- * @param in
- * A character array containing the Base64 encoded data.
- * @return An array containing the decoded data bytes.
- * @throws IllegalArgumentException
- * If the input is not valid Base64 encoded data.
- */
- public static byte[] decode(byte[] in) {
- return decode(in, 0, in.length);
- }
-
- /**
- * Decodes a byte array from Base64 format.
- *
- * @param in
- * A character array containing the Base64 encoded data.
- * @param iOff
- * Offset of the first character in in to be
- * processed.
- * @param iLen
- * Number of characters to process in in, starting
- * at iOff.
- * @return An array containing the decoded data bytes.
- * @throws IllegalArgumentException
- * If the input is not valid Base64 encoded data.
- */
- public static byte[] decode(byte[] in, int iOff, int iLen) {
- int ip=0;
- for (int i=0;iin, starting
- * at iOff.
- * @return An array containing the decoded data bytes.
- * @throws IllegalArgumentException
- * If the input is not valid Base64 encoded data.
- */
- private static byte[] idecode(byte[] in, int iOff, int iLen) {
- if (iLen % 4 != 0)
- throw new IllegalArgumentException("Length of Base64 encoded input string is not a multiple of 4.");
- while (iLen > 0 && in[iOff + iLen - 1] == '=')
- iLen--;
- int oLen = (iLen * 3) / 4;
- byte[] out = new byte[oLen];
- int ip = iOff;
- int iEnd = iOff + iLen;
- int op = 0;
- while (ip < iEnd) {
- int i0 = in[ip++];
- int i1 = in[ip++];
- int i2 = ip < iEnd ? in[ip++] : 'A';
- int i3 = ip < iEnd ? in[ip++] : 'A';
- if (i0 > 127 || i1 > 127 || i2 > 127 || i3 > 127)
- throw new IllegalArgumentException("Illegal character in Base64 encoded data.");
- int b0 = map2[i0];
- int b1 = map2[i1];
- int b2 = map2[i2];
- int b3 = map2[i3];
- if (b0 < 0 || b1 < 0 || b2 < 0 || b3 < 0)
- throw new IllegalArgumentException("Illegal character in Base64 encoded data.");
- int o0 = (b0 << 2) | (b1 >>> 4);
- int o1 = ((b1 & 0xf) << 4) | (b2 >>> 2);
- int o2 = ((b2 & 3) << 6) | b3;
- out[op++] = (byte) o0;
- if (op < oLen)
- out[op++] = (byte) o1;
- if (op < oLen)
- out[op++] = (byte) o2;
- }
- return out;
- }
-
- private Base64Codec() {
- }
-}
\ No newline at end of file
diff --git a/NiHao/src/nihao/util/Conversor.java b/NiHao/src/nihao/util/Conversor.java
index 636cd66..5ad178d 100644
--- a/NiHao/src/nihao/util/Conversor.java
+++ b/NiHao/src/nihao/util/Conversor.java
@@ -18,7 +18,10 @@
import java.util.ArrayList;
import java.util.Collection;
+import javax.xml.bind.DatatypeConverter;
+
import nihao.NiHaoException;
+import nihao.types.TextEncoding;
public class Conversor {
static final String ASCIICharset = "ISO-8859-1";
@@ -137,8 +140,7 @@
* @return String
*/
public static String bytesToBase64(byte[] data) {
- byte[] result = Base64Codec.encode(data);
- return bytesToASCII(result);
+ return DatatypeConverter.printBase64Binary(data);
}
/**
@@ -149,7 +151,7 @@
* @return Array de bytes
*/
public static byte[] base64ToBytes(String data64) {
- return Base64Codec.decode(asciiToBytes(data64));
+ return DatatypeConverter.parseBase64Binary(data64);
}
/**
@@ -160,7 +162,7 @@
* @return Array de bytes
*/
public static byte[] base64ToBytes(byte[] data64) {
- return Base64Codec.decode(data64);
+ return DatatypeConverter.parseBase64Binary(bytesToASCII(data64));
}
/**
@@ -521,7 +523,7 @@
* @return String
*/
public static String nvl(Object o, String nval) {
- return o==null?nval:o.toString();
+ return o == null ? nval : o.toString();
}
/**
diff --git a/NiHao/src/nihao/util/FileUtil.java b/NiHao/src/nihao/util/FileUtil.java
index e5e8419..b5ff2f3 100644
--- a/NiHao/src/nihao/util/FileUtil.java
+++ b/NiHao/src/nihao/util/FileUtil.java
@@ -1,30 +1,22 @@
package nihao.util;
-import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
-import java.io.BufferedReader;
-import java.io.BufferedWriter;
import java.io.ByteArrayInputStream;
-import java.io.CharArrayReader;
-import java.io.Closeable;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
-import java.io.FileReader;
-import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
-import java.io.Reader;
-import java.util.ArrayList;
-import java.util.List;
public class FileUtil {
private static String tempDirPropertyName = "java.io.tmpdir";
private static String NOT_FOUND = "NOT_FOUND";
- private static final String LINE_SEPARATOR = System.getProperty("line.separator");
+
+ // private static final String LINE_SEPARATOR =
+ // System.getProperty("line.separator");
/**
* Escribe en un fichero un array de bytes
@@ -106,579 +98,6 @@
return;
}
- // Writers
- // ------------------------------------------------------------------------------------
-
- /**
- * Write byte array to file. If file already exists, it will be overwritten.
- *
- * @param file
- * The file where the given byte array have to be written to.
- * @param bytes
- * The byte array which have to be written to the given file.
- * @throws IOException
- * If writing file fails.
- */
- public static void write(java.io.File file, byte[] bytes) throws IOException {
- write(file, new ByteArrayInputStream(bytes), false);
- }
-
- /**
- * Write byte array to file with option to append to file or not. If not,
- * then any existing file will be overwritten.
- *
- * @param file
- * The file where the given byte array have to be written to.
- * @param bytes
- * The byte array which have to be written to the given file.
- * @param append
- * Append to file?
- * @throws IOException
- * If writing file fails.
- */
- public static void write(java.io.File file, byte[] bytes, boolean append) throws IOException {
- write(file, new ByteArrayInputStream(bytes), append);
- }
-
- /**
- * Write byte inputstream to file. If file already exists, it will be
- * overwritten.It's highly recommended to feed the inputstream as
- * BufferedInputStream or ByteArrayInputStream as those are been
- * automatically buffered.
- *
- * @param file
- * The file where the given byte inputstream have to be written
- * to.
- * @param input
- * The byte inputstream which have to be written to the given
- * file.
- * @throws IOException
- * If writing file fails.
- */
- public static void write(java.io.File file, InputStream input) throws IOException {
- write(file, input, false);
- }
-
- /**
- * Write byte inputstream to file with option to append to file or not. If
- * not, then any existing file will be overwritten. It's highly recommended
- * to feed the inputstream as BufferedInputStream or ByteArrayInputStream as
- * those are been automatically buffered.
- *
- * @param file
- * The file where the given byte inputstream have to be written
- * to.
- * @param input
- * The byte inputstream which have to be written to the given
- * file.
- * @param append
- * Append to file?
- * @throws IOException
- * If writing file fails.
- */
- public static void write(java.io.File file, InputStream input, boolean append) throws IOException {
- mkdirs(file);
- BufferedOutputStream output = null;
- try {
- output = new BufferedOutputStream(new FileOutputStream(file, append));
- int data = -1;
- while ((data = input.read()) != -1) {
- output.write(data);
- }
- } finally {
- close(input, file);
- close(output, file);
- }
- }
-
- /**
- * Write character array to file. If file already exists, it will be
- * overwritten.
- *
- * @param file
- * The file where the given character array have to be written
- * to.
- * @param chars
- * The character array which have to be written to the given
- * file.
- * @throws IOException
- * If writing file fails.
- */
- public static void write(java.io.File file, char[] chars) throws IOException {
- write(file, new CharArrayReader(chars), false);
- }
-
- /**
- * Write character array to file with option to append to file or not. If
- * not, then any existing file will be overwritten.
- *
- * @param file
- * The file where the given character array have to be written
- * to.
- * @param chars
- * The character array which have to be written to the given
- * file.
- * @param append
- * Append to file?
- * @throws IOException
- * If writing file fails.
- */
- public static void write(java.io.File file, char[] chars, boolean append) throws IOException {
- write(file, new CharArrayReader(chars), append);
- }
-
- /**
- * Write string value to file. If file already exists, it will be
- * overwritten.
- *
- * @param file
- * The file where the given string value have to be written to.
- * @param string
- * The string value which have to be written to the given file.
- * @throws IOException
- * If writing file fails.
- */
- public static void write(java.io.File file, String string) throws IOException {
- write(file, new CharArrayReader(string.toCharArray()), false);
- }
-
- /**
- * Write string value to file with option to append to file or not. If not,
- * then any existing file will be overwritten.
- *
- * @param file
- * The file where the given string value have to be written to.
- * @param string
- * The string value which have to be written to the given file.
- * @param append
- * Append to file?
- * @throws IOException
- * If writing file fails.
- */
- public static void write(java.io.File file, String string, boolean append) throws IOException {
- write(file, new CharArrayReader(string.toCharArray()), append);
- }
-
- /**
- * Write character reader to file. If file already exists, it will be
- * overwritten. It's highly recommended to feed the reader as BufferedReader
- * or CharArrayReader as those are been automatically buffered.
- *
- * @param file
- * The file where the given character reader have to be written
- * to.
- * @param reader
- * The character reader which have to be written to the given
- * file.
- * @throws IOException
- * If writing file fails.
- */
- public static void write(java.io.File file, Reader reader) throws IOException {
- write(file, reader, false);
- }
-
- /**
- * Write character reader to file with option to append to file or not. If
- * not, then any existing file will be overwritten. It's highly recommended
- * to feed the reader as BufferedReader or CharArrayReader as those are been
- * automatically buffered.
- *
- * @param file
- * The file where the given character reader have to be written
- * to.
- * @param reader
- * The character reader which have to be written to the given
- * file.
- * @param append
- * Append to file?
- * @throws IOException
- * If writing file fails.
- */
- public static void write(java.io.File file, Reader reader, boolean append) throws IOException {
- mkdirs(file);
- BufferedWriter writer = null;
- try {
- writer = new BufferedWriter(new FileWriter(file, append));
- int data = -1;
- while ((data = reader.read()) != -1) {
- writer.write(data);
- }
- } finally {
- close(reader, file);
- close(writer, file);
- }
- }
-
- /**
- * Write list of String records to file. If file already exists, it will be
- * overwritten.
- *
- * @param file
- * The file where the given character reader have to be written
- * to.
- * @param records
- * The list of String records which have to be written to the
- * given file.
- * @throws IOException
- * If writing file fails.
- */
- public static void write(java.io.File file, List