format java code in marytts-common

incantation:
$ mvn com.googlecode.maven-java-formatter-plugin:maven-java-formatter-plugin:format -pl marytts-common
This commit is contained in:
Ingmar Steiner 2014-12-19 13:09:27 +01:00
Родитель f1ff6ad856
Коммит 1d71468ca8
37 изменённых файлов: 4978 добавлений и 5344 удалений

Просмотреть файл

@ -4,20 +4,16 @@ import java.io.IOException;
import java.io.OutputStream;
/**
* Copyright (c) 2001, 2002 by Pensamos Digital, Inc., All Rights Reserved.<p>
* Copyright (c) 2001, 2002 by Pensamos Digital, Inc., All Rights Reserved.
* <p>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
* <p>
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details.
* <p>
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
* <p>
* This OutputStream discards all data written to it.
@ -37,7 +33,8 @@ public class NullOutputStream extends OutputStream {
}
public void flush() throws IOException {
if (this.closed) _throwClosed();
if (this.closed)
_throwClosed();
}
private void _throwClosed() throws IOException {
@ -45,15 +42,18 @@ public class NullOutputStream extends OutputStream {
}
public void write(byte[] b) throws IOException {
if (this.closed) _throwClosed();
if (this.closed)
_throwClosed();
}
public void write(byte[] b, int offset, int len) throws IOException {
if (this.closed) _throwClosed();
if (this.closed)
_throwClosed();
}
public void write(int b) throws IOException {
if (this.closed) _throwClosed();
if (this.closed)
_throwClosed();
}
}

Просмотреть файл

@ -13,86 +13,59 @@ import java.io.InputStream;
* (c) Santeri Paavolainen, Helsinki Finland 1996<br>
* Many changes Copyright (c) 2002 - 2010 Timothy W Macinta<br>
* <p>
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
* <p>
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details.
* <p>
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
* <p>
* See http://www.twmacinta.com/myjava/fast_md5.php for more information
* on this file and the related files.
* See http://www.twmacinta.com/myjava/fast_md5.php for more information on this file and the related files.
* <p>
* This was originally a rather straight re-implementation of the
* reference implementation given in RFC1321 by RSA. It passes the MD5
* test suite as defined in RFC1321.
* This was originally a rather straight re-implementation of the reference implementation given in RFC1321 by RSA. It passes the
* MD5 test suite as defined in RFC1321.
* <p>
* Many optimizations made by Timothy W Macinta. Reduced time to checksum a
* test file in Java alone to roughly half the time taken compared with
* java.security.MessageDigest (within an intepretter). Also added an
* optional native method to reduce the time even further.
* See http://www.twmacinta.com/myjava/fast_md5.php for further information
* on the time improvements achieved.
* Many optimizations made by Timothy W Macinta. Reduced time to checksum a test file in Java alone to roughly half the time taken
* compared with java.security.MessageDigest (within an intepretter). Also added an optional native method to reduce the time even
* further. See http://www.twmacinta.com/myjava/fast_md5.php for further information on the time improvements achieved.
* <p>
* Some bug fixes also made by Timothy W Macinta.
* <p>
* Please note: I (Timothy Macinta) have put this code in the
* com.twmacinta.util package only because it came without a package. I
* was not the the original author of the code, although I did
* optimize it (substantially) and fix some bugs.
* Please note: I (Timothy Macinta) have put this code in the com.twmacinta.util package only because it came without a package. I
* was not the the original author of the code, although I did optimize it (substantially) and fix some bugs.
* <p>
* This Java class has been derived from the RSA Data Security, Inc. MD5
* Message-Digest Algorithm and its reference implementation.
* This Java class has been derived from the RSA Data Security, Inc. MD5 Message-Digest Algorithm and its reference
* implementation.
* <p>
* This class will attempt to use a native method to quickly compute
* checksums when the appropriate native library is available. On Linux,
* this library should be named "MD5.so" and on Windows it should be
* named "MD5.dll". The code will attempt to locate the library in the
* following locations in the order given:
* This class will attempt to use a native method to quickly compute checksums when the appropriate native library is available.
* On Linux, this library should be named "MD5.so" and on Windows it should be named "MD5.dll". The code will attempt to locate
* the library in the following locations in the order given:
*
* <ol>
* <li>The path specified by the system property
* "com.twmacinta.util.MD5.NATIVE_LIB_FILE"
* (be sure to include "MD5.so", "MD5.dll",
* or "MD5.jnilib" as appropriate at the end
* of the path).
* <li>A platform specific directory beneath the "lib/arch/" directory.
* For example, On Windows for 32 bit x86 architectures, this is
* "lib/arch/win32_x86/".
* <li>The path specified by the system property "com.twmacinta.util.MD5.NATIVE_LIB_FILE" (be sure to include "MD5.so", "MD5.dll",
* or "MD5.jnilib" as appropriate at the end of the path).
* <li>A platform specific directory beneath the "lib/arch/" directory. For example, On Windows for 32 bit x86 architectures, this
* is "lib/arch/win32_x86/".
* <li>Within the "lib/" directory.
* <li>Within the current directory.
* </ol>
*
* <p>
* If the library is not found, the code will fall back to the default
* (slower) Java code.
* If the library is not found, the code will fall back to the default (slower) Java code.
* <p>
* As a side effect of having the code search for the native library,
* SecurityExceptions might be thrown on JVMs that have a restrictive
* SecurityManager. The initialization code attempts to silently discard
* these exceptions and continue, but many SecurityManagers will
* attempt to notify the user directly of all SecurityExceptions thrown.
* Consequently, the code has provisions for skipping the search for
* the native library. Any of these provisions may be used to skip the
* search as long as they are performed <i>before</i> the first
* instance of a com.twmacinta.util.MD5 object is constructed (note that
* the convenience stream objects will implicitly create an MD5 object).
* As a side effect of having the code search for the native library, SecurityExceptions might be thrown on JVMs that have a
* restrictive SecurityManager. The initialization code attempts to silently discard these exceptions and continue, but many
* SecurityManagers will attempt to notify the user directly of all SecurityExceptions thrown. Consequently, the code has
* provisions for skipping the search for the native library. Any of these provisions may be used to skip the search as long as
* they are performed <i>before</i> the first instance of a com.twmacinta.util.MD5 object is constructed (note that the
* convenience stream objects will implicitly create an MD5 object).
* <p>
* The first option is to set the system property
* "com.twmacinta.util.MD5.NO_NATIVE_LIB" to "true" or "1".
* Unfortunately, SecurityManagers may also choose to disallow system
* property setting, so this won't be of use in all cases.
* The first option is to set the system property "com.twmacinta.util.MD5.NO_NATIVE_LIB" to "true" or "1". Unfortunately,
* SecurityManagers may also choose to disallow system property setting, so this won't be of use in all cases.
* <p>
* The second option is to call
* com.twmacinta.util.MD5.initNativeLibrary(true) before any MD5 objects
* are constructed.
* The second option is to call com.twmacinta.util.MD5.initNativeLibrary(true) before any MD5 objects are constructed.
*
* @author Santeri Paavolainen <sjpaavol@cc.helsinki.fi>
* @author Timothy W Macinta (twm@alum.mit.edu) (optimizations and bug fixes)
@ -106,28 +79,23 @@ public class MD5 {
MD5State state;
/**
* If Final() has been called, finals is set to the current finals
* state. Any Update() causes this to be set to null.
* If Final() has been called, finals is set to the current finals state. Any Update() causes this to be set to null.
**/
MD5State finals;
/**
* Padding for Final()
**/
static byte padding[] = {
(byte) 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
static byte padding[] = { (byte) 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
private static boolean native_lib_loaded = false;
private static boolean native_lib_init_pending = true;
/**
* Initialize MD5 internal state (object can be reused just by
* calling Init() after every Final()
* Initialize MD5 internal state (object can be reused just by calling Init() after every Final()
**/
public synchronized void Init () {
public synchronized void Init() {
state = new MD5State();
finals = null;
}
@ -135,133 +103,94 @@ public class MD5 {
/**
* Class constructor
**/
public MD5 () {
if (native_lib_init_pending) _initNativeLibrary();
public MD5() {
if (native_lib_init_pending)
_initNativeLibrary();
this.Init();
}
/**
* Initialize class, and update hash with ob.toString()
*
* @param ob Object, ob.toString() is used to update hash
* after initialization
* @param ob
* Object, ob.toString() is used to update hash after initialization
**/
public MD5 (Object ob) {
public MD5(Object ob) {
this();
Update(ob.toString());
}
private void Decode (byte buffer[], int shift, int[] out) {
/*len += shift;
for (int i = 0; shift < len; i++, shift += 4) {
out[i] = ((int) (buffer[shift] & 0xff)) |
(((int) (buffer[shift + 1] & 0xff)) << 8) |
(((int) (buffer[shift + 2] & 0xff)) << 16) |
(((int) buffer[shift + 3]) << 24);
}*/
private void Decode(byte buffer[], int shift, int[] out) {
/*
* len += shift; for (int i = 0; shift < len; i++, shift += 4) { out[i] = ((int) (buffer[shift] & 0xff)) | (((int)
* (buffer[shift + 1] & 0xff)) << 8) | (((int) (buffer[shift + 2] & 0xff)) << 16) | (((int) buffer[shift + 3]) << 24); }
*/
// unrolled loop (original loop shown above)
out[0] = ((int) (buffer[shift] & 0xff)) |
(((int) (buffer[shift + 1] & 0xff)) << 8) |
(((int) (buffer[shift + 2] & 0xff)) << 16) |
(((int) buffer[shift + 3]) << 24);
out[1] = ((int) (buffer[shift + 4] & 0xff)) |
(((int) (buffer[shift + 5] & 0xff)) << 8) |
(((int) (buffer[shift + 6] & 0xff)) << 16) |
(((int) buffer[shift + 7]) << 24);
out[2] = ((int) (buffer[shift + 8] & 0xff)) |
(((int) (buffer[shift + 9] & 0xff)) << 8) |
(((int) (buffer[shift + 10] & 0xff)) << 16) |
(((int) buffer[shift + 11]) << 24);
out[3] = ((int) (buffer[shift + 12] & 0xff)) |
(((int) (buffer[shift + 13] & 0xff)) << 8) |
(((int) (buffer[shift + 14] & 0xff)) << 16) |
(((int) buffer[shift + 15]) << 24);
out[4] = ((int) (buffer[shift + 16] & 0xff)) |
(((int) (buffer[shift + 17] & 0xff)) << 8) |
(((int) (buffer[shift + 18] & 0xff)) << 16) |
(((int) buffer[shift + 19]) << 24);
out[5] = ((int) (buffer[shift + 20] & 0xff)) |
(((int) (buffer[shift + 21] & 0xff)) << 8) |
(((int) (buffer[shift + 22] & 0xff)) << 16) |
(((int) buffer[shift + 23]) << 24);
out[6] = ((int) (buffer[shift + 24] & 0xff)) |
(((int) (buffer[shift + 25] & 0xff)) << 8) |
(((int) (buffer[shift + 26] & 0xff)) << 16) |
(((int) buffer[shift + 27]) << 24);
out[7] = ((int) (buffer[shift + 28] & 0xff)) |
(((int) (buffer[shift + 29] & 0xff)) << 8) |
(((int) (buffer[shift + 30] & 0xff)) << 16) |
(((int) buffer[shift + 31]) << 24);
out[8] = ((int) (buffer[shift + 32] & 0xff)) |
(((int) (buffer[shift + 33] & 0xff)) << 8) |
(((int) (buffer[shift + 34] & 0xff)) << 16) |
(((int) buffer[shift + 35]) << 24);
out[9] = ((int) (buffer[shift + 36] & 0xff)) |
(((int) (buffer[shift + 37] & 0xff)) << 8) |
(((int) (buffer[shift + 38] & 0xff)) << 16) |
(((int) buffer[shift + 39]) << 24);
out[10] = ((int) (buffer[shift + 40] & 0xff)) |
(((int) (buffer[shift + 41] & 0xff)) << 8) |
(((int) (buffer[shift + 42] & 0xff)) << 16) |
(((int) buffer[shift + 43]) << 24);
out[11] = ((int) (buffer[shift + 44] & 0xff)) |
(((int) (buffer[shift + 45] & 0xff)) << 8) |
(((int) (buffer[shift + 46] & 0xff)) << 16) |
(((int) buffer[shift + 47]) << 24);
out[12] = ((int) (buffer[shift + 48] & 0xff)) |
(((int) (buffer[shift + 49] & 0xff)) << 8) |
(((int) (buffer[shift + 50] & 0xff)) << 16) |
(((int) buffer[shift + 51]) << 24);
out[13] = ((int) (buffer[shift + 52] & 0xff)) |
(((int) (buffer[shift + 53] & 0xff)) << 8) |
(((int) (buffer[shift + 54] & 0xff)) << 16) |
(((int) buffer[shift + 55]) << 24);
out[14] = ((int) (buffer[shift + 56] & 0xff)) |
(((int) (buffer[shift + 57] & 0xff)) << 8) |
(((int) (buffer[shift + 58] & 0xff)) << 16) |
(((int) buffer[shift + 59]) << 24);
out[15] = ((int) (buffer[shift + 60] & 0xff)) |
(((int) (buffer[shift + 61] & 0xff)) << 8) |
(((int) (buffer[shift + 62] & 0xff)) << 16) |
(((int) buffer[shift + 63]) << 24);
out[0] = ((int) (buffer[shift] & 0xff)) | (((int) (buffer[shift + 1] & 0xff)) << 8)
| (((int) (buffer[shift + 2] & 0xff)) << 16) | (((int) buffer[shift + 3]) << 24);
out[1] = ((int) (buffer[shift + 4] & 0xff)) | (((int) (buffer[shift + 5] & 0xff)) << 8)
| (((int) (buffer[shift + 6] & 0xff)) << 16) | (((int) buffer[shift + 7]) << 24);
out[2] = ((int) (buffer[shift + 8] & 0xff)) | (((int) (buffer[shift + 9] & 0xff)) << 8)
| (((int) (buffer[shift + 10] & 0xff)) << 16) | (((int) buffer[shift + 11]) << 24);
out[3] = ((int) (buffer[shift + 12] & 0xff)) | (((int) (buffer[shift + 13] & 0xff)) << 8)
| (((int) (buffer[shift + 14] & 0xff)) << 16) | (((int) buffer[shift + 15]) << 24);
out[4] = ((int) (buffer[shift + 16] & 0xff)) | (((int) (buffer[shift + 17] & 0xff)) << 8)
| (((int) (buffer[shift + 18] & 0xff)) << 16) | (((int) buffer[shift + 19]) << 24);
out[5] = ((int) (buffer[shift + 20] & 0xff)) | (((int) (buffer[shift + 21] & 0xff)) << 8)
| (((int) (buffer[shift + 22] & 0xff)) << 16) | (((int) buffer[shift + 23]) << 24);
out[6] = ((int) (buffer[shift + 24] & 0xff)) | (((int) (buffer[shift + 25] & 0xff)) << 8)
| (((int) (buffer[shift + 26] & 0xff)) << 16) | (((int) buffer[shift + 27]) << 24);
out[7] = ((int) (buffer[shift + 28] & 0xff)) | (((int) (buffer[shift + 29] & 0xff)) << 8)
| (((int) (buffer[shift + 30] & 0xff)) << 16) | (((int) buffer[shift + 31]) << 24);
out[8] = ((int) (buffer[shift + 32] & 0xff)) | (((int) (buffer[shift + 33] & 0xff)) << 8)
| (((int) (buffer[shift + 34] & 0xff)) << 16) | (((int) buffer[shift + 35]) << 24);
out[9] = ((int) (buffer[shift + 36] & 0xff)) | (((int) (buffer[shift + 37] & 0xff)) << 8)
| (((int) (buffer[shift + 38] & 0xff)) << 16) | (((int) buffer[shift + 39]) << 24);
out[10] = ((int) (buffer[shift + 40] & 0xff)) | (((int) (buffer[shift + 41] & 0xff)) << 8)
| (((int) (buffer[shift + 42] & 0xff)) << 16) | (((int) buffer[shift + 43]) << 24);
out[11] = ((int) (buffer[shift + 44] & 0xff)) | (((int) (buffer[shift + 45] & 0xff)) << 8)
| (((int) (buffer[shift + 46] & 0xff)) << 16) | (((int) buffer[shift + 47]) << 24);
out[12] = ((int) (buffer[shift + 48] & 0xff)) | (((int) (buffer[shift + 49] & 0xff)) << 8)
| (((int) (buffer[shift + 50] & 0xff)) << 16) | (((int) buffer[shift + 51]) << 24);
out[13] = ((int) (buffer[shift + 52] & 0xff)) | (((int) (buffer[shift + 53] & 0xff)) << 8)
| (((int) (buffer[shift + 54] & 0xff)) << 16) | (((int) buffer[shift + 55]) << 24);
out[14] = ((int) (buffer[shift + 56] & 0xff)) | (((int) (buffer[shift + 57] & 0xff)) << 8)
| (((int) (buffer[shift + 58] & 0xff)) << 16) | (((int) buffer[shift + 59]) << 24);
out[15] = ((int) (buffer[shift + 60] & 0xff)) | (((int) (buffer[shift + 61] & 0xff)) << 8)
| (((int) (buffer[shift + 62] & 0xff)) << 16) | (((int) buffer[shift + 63]) << 24);
}
private native void Transform_native (int[] state, byte buffer[], int shift, int length);
private native void Transform_native(int[] state, byte buffer[], int shift, int length);
private void Transform (MD5State state, byte buffer[], int shift, int[] decode_buf) {
int
a = state.state[0],
b = state.state[1],
c = state.state[2],
d = state.state[3],
x[] = decode_buf;
private void Transform(MD5State state, byte buffer[], int shift, int[] decode_buf) {
int a = state.state[0], b = state.state[1], c = state.state[2], d = state.state[3], x[] = decode_buf;
Decode(buffer, shift, decode_buf);
/* Round 1 */
a += ((b & c) | (~b & d)) + x[ 0] + 0xd76aa478; /* 1 */
a += ((b & c) | (~b & d)) + x[0] + 0xd76aa478; /* 1 */
a = ((a << 7) | (a >>> 25)) + b;
d += ((a & b) | (~a & c)) + x[ 1] + 0xe8c7b756; /* 2 */
d += ((a & b) | (~a & c)) + x[1] + 0xe8c7b756; /* 2 */
d = ((d << 12) | (d >>> 20)) + a;
c += ((d & a) | (~d & b)) + x[ 2] + 0x242070db; /* 3 */
c += ((d & a) | (~d & b)) + x[2] + 0x242070db; /* 3 */
c = ((c << 17) | (c >>> 15)) + d;
b += ((c & d) | (~c & a)) + x[ 3] + 0xc1bdceee; /* 4 */
b += ((c & d) | (~c & a)) + x[3] + 0xc1bdceee; /* 4 */
b = ((b << 22) | (b >>> 10)) + c;
a += ((b & c) | (~b & d)) + x[ 4] + 0xf57c0faf; /* 5 */
a += ((b & c) | (~b & d)) + x[4] + 0xf57c0faf; /* 5 */
a = ((a << 7) | (a >>> 25)) + b;
d += ((a & b) | (~a & c)) + x[ 5] + 0x4787c62a; /* 6 */
d += ((a & b) | (~a & c)) + x[5] + 0x4787c62a; /* 6 */
d = ((d << 12) | (d >>> 20)) + a;
c += ((d & a) | (~d & b)) + x[ 6] + 0xa8304613; /* 7 */
c += ((d & a) | (~d & b)) + x[6] + 0xa8304613; /* 7 */
c = ((c << 17) | (c >>> 15)) + d;
b += ((c & d) | (~c & a)) + x[ 7] + 0xfd469501; /* 8 */
b += ((c & d) | (~c & a)) + x[7] + 0xfd469501; /* 8 */
b = ((b << 22) | (b >>> 10)) + c;
a += ((b & c) | (~b & d)) + x[ 8] + 0x698098d8; /* 9 */
a += ((b & c) | (~b & d)) + x[8] + 0x698098d8; /* 9 */
a = ((a << 7) | (a >>> 25)) + b;
d += ((a & b) | (~a & c)) + x[ 9] + 0x8b44f7af; /* 10 */
d += ((a & b) | (~a & c)) + x[9] + 0x8b44f7af; /* 10 */
d = ((d << 12) | (d >>> 20)) + a;
c += ((d & a) | (~d & b)) + x[10] + 0xffff5bb1; /* 11 */
c = ((c << 17) | (c >>> 15)) + d;
@ -277,118 +206,115 @@ public class MD5 {
b += ((c & d) | (~c & a)) + x[15] + 0x49b40821; /* 16 */
b = ((b << 22) | (b >>> 10)) + c;
/* Round 2 */
a += ((b & d) | (c & ~d)) + x[ 1] + 0xf61e2562; /* 17 */
a += ((b & d) | (c & ~d)) + x[1] + 0xf61e2562; /* 17 */
a = ((a << 5) | (a >>> 27)) + b;
d += ((a & c) | (b & ~c)) + x[ 6] + 0xc040b340; /* 18 */
d += ((a & c) | (b & ~c)) + x[6] + 0xc040b340; /* 18 */
d = ((d << 9) | (d >>> 23)) + a;
c += ((d & b) | (a & ~b)) + x[11] + 0x265e5a51; /* 19 */
c = ((c << 14) | (c >>> 18)) + d;
b += ((c & a) | (d & ~a)) + x[ 0] + 0xe9b6c7aa; /* 20 */
b += ((c & a) | (d & ~a)) + x[0] + 0xe9b6c7aa; /* 20 */
b = ((b << 20) | (b >>> 12)) + c;
a += ((b & d) | (c & ~d)) + x[ 5] + 0xd62f105d; /* 21 */
a += ((b & d) | (c & ~d)) + x[5] + 0xd62f105d; /* 21 */
a = ((a << 5) | (a >>> 27)) + b;
d += ((a & c) | (b & ~c)) + x[10] + 0x02441453; /* 22 */
d = ((d << 9) | (d >>> 23)) + a;
c += ((d & b) | (a & ~b)) + x[15] + 0xd8a1e681; /* 23 */
c = ((c << 14) | (c >>> 18)) + d;
b += ((c & a) | (d & ~a)) + x[ 4] + 0xe7d3fbc8; /* 24 */
b += ((c & a) | (d & ~a)) + x[4] + 0xe7d3fbc8; /* 24 */
b = ((b << 20) | (b >>> 12)) + c;
a += ((b & d) | (c & ~d)) + x[ 9] + 0x21e1cde6; /* 25 */
a += ((b & d) | (c & ~d)) + x[9] + 0x21e1cde6; /* 25 */
a = ((a << 5) | (a >>> 27)) + b;
d += ((a & c) | (b & ~c)) + x[14] + 0xc33707d6; /* 26 */
d = ((d << 9) | (d >>> 23)) + a;
c += ((d & b) | (a & ~b)) + x[ 3] + 0xf4d50d87; /* 27 */
c += ((d & b) | (a & ~b)) + x[3] + 0xf4d50d87; /* 27 */
c = ((c << 14) | (c >>> 18)) + d;
b += ((c & a) | (d & ~a)) + x[ 8] + 0x455a14ed; /* 28 */
b += ((c & a) | (d & ~a)) + x[8] + 0x455a14ed; /* 28 */
b = ((b << 20) | (b >>> 12)) + c;
a += ((b & d) | (c & ~d)) + x[13] + 0xa9e3e905; /* 29 */
a = ((a << 5) | (a >>> 27)) + b;
d += ((a & c) | (b & ~c)) + x[ 2] + 0xfcefa3f8; /* 30 */
d += ((a & c) | (b & ~c)) + x[2] + 0xfcefa3f8; /* 30 */
d = ((d << 9) | (d >>> 23)) + a;
c += ((d & b) | (a & ~b)) + x[ 7] + 0x676f02d9; /* 31 */
c += ((d & b) | (a & ~b)) + x[7] + 0x676f02d9; /* 31 */
c = ((c << 14) | (c >>> 18)) + d;
b += ((c & a) | (d & ~a)) + x[12] + 0x8d2a4c8a; /* 32 */
b = ((b << 20) | (b >>> 12)) + c;
/* Round 3 */
a += (b ^ c ^ d) + x[ 5] + 0xfffa3942; /* 33 */
a += (b ^ c ^ d) + x[5] + 0xfffa3942; /* 33 */
a = ((a << 4) | (a >>> 28)) + b;
d += (a ^ b ^ c) + x[ 8] + 0x8771f681; /* 34 */
d += (a ^ b ^ c) + x[8] + 0x8771f681; /* 34 */
d = ((d << 11) | (d >>> 21)) + a;
c += (d ^ a ^ b) + x[11] + 0x6d9d6122; /* 35 */
c = ((c << 16) | (c >>> 16)) + d;
b += (c ^ d ^ a) + x[14] + 0xfde5380c; /* 36 */
b = ((b << 23) | (b >>> 9)) + c;
a += (b ^ c ^ d) + x[ 1] + 0xa4beea44; /* 37 */
a += (b ^ c ^ d) + x[1] + 0xa4beea44; /* 37 */
a = ((a << 4) | (a >>> 28)) + b;
d += (a ^ b ^ c) + x[ 4] + 0x4bdecfa9; /* 38 */
d += (a ^ b ^ c) + x[4] + 0x4bdecfa9; /* 38 */
d = ((d << 11) | (d >>> 21)) + a;
c += (d ^ a ^ b) + x[ 7] + 0xf6bb4b60; /* 39 */
c += (d ^ a ^ b) + x[7] + 0xf6bb4b60; /* 39 */
c = ((c << 16) | (c >>> 16)) + d;
b += (c ^ d ^ a) + x[10] + 0xbebfbc70; /* 40 */
b = ((b << 23) | (b >>> 9)) + c;
a += (b ^ c ^ d) + x[13] + 0x289b7ec6; /* 41 */
a = ((a << 4) | (a >>> 28)) + b;
d += (a ^ b ^ c) + x[ 0] + 0xeaa127fa; /* 42 */
d += (a ^ b ^ c) + x[0] + 0xeaa127fa; /* 42 */
d = ((d << 11) | (d >>> 21)) + a;
c += (d ^ a ^ b) + x[ 3] + 0xd4ef3085; /* 43 */
c += (d ^ a ^ b) + x[3] + 0xd4ef3085; /* 43 */
c = ((c << 16) | (c >>> 16)) + d;
b += (c ^ d ^ a) + x[ 6] + 0x04881d05; /* 44 */
b += (c ^ d ^ a) + x[6] + 0x04881d05; /* 44 */
b = ((b << 23) | (b >>> 9)) + c;
a += (b ^ c ^ d) + x[ 9] + 0xd9d4d039; /* 33 */
a += (b ^ c ^ d) + x[9] + 0xd9d4d039; /* 33 */
a = ((a << 4) | (a >>> 28)) + b;
d += (a ^ b ^ c) + x[12] + 0xe6db99e5; /* 34 */
d = ((d << 11) | (d >>> 21)) + a;
c += (d ^ a ^ b) + x[15] + 0x1fa27cf8; /* 35 */
c = ((c << 16) | (c >>> 16)) + d;
b += (c ^ d ^ a) + x[ 2] + 0xc4ac5665; /* 36 */
b += (c ^ d ^ a) + x[2] + 0xc4ac5665; /* 36 */
b = ((b << 23) | (b >>> 9)) + c;
/* Round 4 */
a += (c ^ (b | ~d)) + x[ 0] + 0xf4292244; /* 49 */
a += (c ^ (b | ~d)) + x[0] + 0xf4292244; /* 49 */
a = ((a << 6) | (a >>> 26)) + b;
d += (b ^ (a | ~c)) + x[ 7] + 0x432aff97; /* 50 */
d += (b ^ (a | ~c)) + x[7] + 0x432aff97; /* 50 */
d = ((d << 10) | (d >>> 22)) + a;
c += (a ^ (d | ~b)) + x[14] + 0xab9423a7; /* 51 */
c = ((c << 15) | (c >>> 17)) + d;
b += (d ^ (c | ~a)) + x[ 5] + 0xfc93a039; /* 52 */
b += (d ^ (c | ~a)) + x[5] + 0xfc93a039; /* 52 */
b = ((b << 21) | (b >>> 11)) + c;
a += (c ^ (b | ~d)) + x[12] + 0x655b59c3; /* 53 */
a = ((a << 6) | (a >>> 26)) + b;
d += (b ^ (a | ~c)) + x[ 3] + 0x8f0ccc92; /* 54 */
d += (b ^ (a | ~c)) + x[3] + 0x8f0ccc92; /* 54 */
d = ((d << 10) | (d >>> 22)) + a;
c += (a ^ (d | ~b)) + x[10] + 0xffeff47d; /* 55 */
c = ((c << 15) | (c >>> 17)) + d;
b += (d ^ (c | ~a)) + x[ 1] + 0x85845dd1; /* 56 */
b += (d ^ (c | ~a)) + x[1] + 0x85845dd1; /* 56 */
b = ((b << 21) | (b >>> 11)) + c;
a += (c ^ (b | ~d)) + x[ 8] + 0x6fa87e4f; /* 57 */
a += (c ^ (b | ~d)) + x[8] + 0x6fa87e4f; /* 57 */
a = ((a << 6) | (a >>> 26)) + b;
d += (b ^ (a | ~c)) + x[15] + 0xfe2ce6e0; /* 58 */
d = ((d << 10) | (d >>> 22)) + a;
c += (a ^ (d | ~b)) + x[ 6] + 0xa3014314; /* 59 */
c += (a ^ (d | ~b)) + x[6] + 0xa3014314; /* 59 */
c = ((c << 15) | (c >>> 17)) + d;
b += (d ^ (c | ~a)) + x[13] + 0x4e0811a1; /* 60 */
b = ((b << 21) | (b >>> 11)) + c;
a += (c ^ (b | ~d)) + x[ 4] + 0xf7537e82; /* 61 */
a += (c ^ (b | ~d)) + x[4] + 0xf7537e82; /* 61 */
a = ((a << 6) | (a >>> 26)) + b;
d += (b ^ (a | ~c)) + x[11] + 0xbd3af235; /* 62 */
d = ((d << 10) | (d >>> 22)) + a;
c += (a ^ (d | ~b)) + x[ 2] + 0x2ad7d2bb; /* 63 */
c += (a ^ (d | ~b)) + x[2] + 0x2ad7d2bb; /* 63 */
c = ((c << 15) | (c >>> 17)) + d;
b += (d ^ (c | ~a)) + x[ 9] + 0xeb86d391; /* 64 */
b += (d ^ (c | ~a)) + x[9] + 0xeb86d391; /* 64 */
b = ((b << 21) | (b >>> 11)) + c;
state.state[0] += a;
@ -398,21 +324,23 @@ public class MD5 {
}
/**
* Updates hash with the bytebuffer given (using at maximum length bytes from
* that buffer)
* Updates hash with the bytebuffer given (using at maximum length bytes from that buffer)
*
* @param stat Which state is updated
* @param buffer Array of bytes to be hashed
* @param offset Offset to buffer array
* @param length Use at maximum `length' bytes (absolute
* maximum is buffer.length)
* @param stat
* Which state is updated
* @param buffer
* Array of bytes to be hashed
* @param offset
* Offset to buffer array
* @param length
* Use at maximum `length' bytes (absolute maximum is buffer.length)
*/
public void Update (MD5State stat, byte buffer[], int offset, int length) {
public void Update(MD5State stat, byte buffer[], int offset, int length) {
int index, partlen, i, start;
finals = null;
/* Length can be told to be shorter, but not inter */
if ((length - offset)> buffer.length)
if ((length - offset) > buffer.length)
length = buffer.length - offset;
/* compute number of bytes mod 64 */
@ -464,7 +392,7 @@ public class MD5 {
stat.buffer[i + index] = buffer[i + offset];
Transform(stat, stat.buffer, 0, decode_buf);
}
for (i = partlen; (i + 63) < length; i+= 64) {
for (i = partlen; (i + 63) < length; i += 64) {
Transform(stat, buffer, i + offset, decode_buf);
}
}
@ -483,36 +411,37 @@ public class MD5 {
}
/*
* Update()s for other datatypes than byte[] also. Update(byte[], int)
* is only the main driver.
* Update()s for other datatypes than byte[] also. Update(byte[], int) is only the main driver.
*/
/**
* Plain update, updates this object
**/
public void Update (byte buffer[], int offset, int length) {
public void Update(byte buffer[], int offset, int length) {
Update(this.state, buffer, offset, length);
}
public void Update (byte buffer[], int length) {
public void Update(byte buffer[], int length) {
Update(this.state, buffer, 0, length);
}
/**
* Updates hash with given array of bytes
*
* @param buffer Array of bytes to use for updating the hash
* @param buffer
* Array of bytes to use for updating the hash
**/
public void Update (byte buffer[]) {
public void Update(byte buffer[]) {
Update(buffer, 0, buffer.length);
}
/**
* Updates hash with a single byte
*
* @param b Single byte to update the hash
* @param b
* Single byte to update the hash
**/
public void Update (byte b) {
public void Update(byte b) {
byte buffer[] = new byte[1];
buffer[0] = b;
@ -520,53 +449,49 @@ public class MD5 {
}
/**
* Update buffer with given string. Note that because the version of
* the s.getBytes() method without parameters is used to convert the
* string to a byte array, the results of this method may be different
* on different platforms. The s.getBytes() method converts the string
* into a byte array using the current platform's default character set
* and may therefore have different results on platforms with different
* default character sets. If a version that works consistently
* across platforms with different default character sets is desired,
* use the overloaded version of the Update() method which takes a
* string and a character encoding.
* Update buffer with given string. Note that because the version of the s.getBytes() method without parameters is used to
* convert the string to a byte array, the results of this method may be different on different platforms. The s.getBytes()
* method converts the string into a byte array using the current platform's default character set and may therefore have
* different results on platforms with different default character sets. If a version that works consistently across platforms
* with different default character sets is desired, use the overloaded version of the Update() method which takes a string
* and a character encoding.
*
* @param s String to be update to hash (is used as s.getBytes())
* @param s
* String to be update to hash (is used as s.getBytes())
**/
public void Update (String s) {
public void Update(String s) {
byte chars[] = s.getBytes();
Update(chars, chars.length);
}
/**
* Update buffer with given string using the given encoding. If the
* given encoding is null, the encoding "ISO8859_1" is used.
* Update buffer with given string using the given encoding. If the given encoding is null, the encoding "ISO8859_1" is used.
*
* @param s String to be update to hash (is used as
* s.getBytes(charset_name))
* @param charset_name The character set to use to convert s to a
* byte array, or null if the "ISO8859_1"
* character set is desired.
* @exception java.io.UnsupportedEncodingException If the named
* charset is not supported.
* @param s
* String to be update to hash (is used as s.getBytes(charset_name))
* @param charset_name
* The character set to use to convert s to a byte array, or null if the "ISO8859_1" character set is desired.
* @exception java.io.UnsupportedEncodingException
* If the named charset is not supported.
**/
public void Update (String s, String charset_name) throws java.io.UnsupportedEncodingException {
if (charset_name == null) charset_name = "ISO8859_1";
public void Update(String s, String charset_name) throws java.io.UnsupportedEncodingException {
if (charset_name == null)
charset_name = "ISO8859_1";
byte chars[] = s.getBytes(charset_name);
Update(chars, chars.length);
}
/**
* Update buffer with a single integer (only & 0xff part is used,
* as a byte)
* Update buffer with a single integer (only & 0xff part is used, as a byte)
*
* @param i Integer value, which is then converted to byte as i & 0xff
* @param i
* Integer value, which is then converted to byte as i & 0xff
**/
public void Update (int i) {
public void Update(int i) {
Update((byte) (i & 0xff));
}
private byte[] Encode (int input[], int len) {
private byte[] Encode(int input[], int len) {
int i, j;
byte out[];
@ -583,14 +508,12 @@ public class MD5 {
}
/**
* Returns array of bytes (16 bytes) representing hash as of the
* current state of this object. Note: getting a hash does not
* invalidate the hash object, it only creates a copy of the real
* state which is finalized.
* Returns array of bytes (16 bytes) representing hash as of the current state of this object. Note: getting a hash does not
* invalidate the hash object, it only creates a copy of the real state which is finalized.
*
* @return Array of 16 bytes, the hash of all updated bytes
**/
public synchronized byte[] Final () {
public synchronized byte[] Final() {
byte bits[];
int index, padlen;
MD5State fin;
@ -598,7 +521,7 @@ public class MD5 {
if (finals == null) {
fin = new MD5State(state);
int[] count_ints = {(int) (fin.count << 3), (int) (fin.count >> 29)};
int[] count_ints = { (int) (fin.count << 3), (int) (fin.count >> 29) };
bits = Encode(count_ints, 8);
index = (int) (fin.count & 0x3f);
@ -614,19 +537,16 @@ public class MD5 {
return Encode(finals.state, 16);
}
private static final char[] HEX_CHARS = {'0', '1', '2', '3',
'4', '5', '6', '7',
'8', '9', 'a', 'b',
'c', 'd', 'e', 'f',};
private static final char[] HEX_CHARS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', };
/**
* Turns array of bytes into string representing each byte as
* unsigned hex number.
* Turns array of bytes into string representing each byte as unsigned hex number.
*
* @param hash Array of bytes to convert to hex-string
* @param hash
* Array of bytes to convert to hex-string
* @return Generated hex string
*/
public static String asHex (byte hash[]) {
public static String asHex(byte hash[]) {
char buf[] = new char[hash.length * 2];
for (int i = 0, x = 0; i < hash.length; i++) {
buf[x++] = HEX_CHARS[(hash[i] >>> 4) & 0xf];
@ -640,27 +560,25 @@ public class MD5 {
*
* @return String of this object's hash
*/
public String asHex () {
public String asHex() {
return asHex(this.Final());
}
/**
* Convenience method for initNativeLibrary(false).
**/
public static synchronized final boolean initNativeLibrary () {
public static synchronized final boolean initNativeLibrary() {
return initNativeLibrary(false);
}
/**
* Attempts to initialize native library support. If
* 'disallow_lib_loading' is true, will indicate that the native
* library should not be loaded now or in the future. If native
* library support has been previously loaded or disabled, this
* method has no effect.
* Attempts to initialize native library support. If 'disallow_lib_loading' is true, will indicate that the native library
* should not be loaded now or in the future. If native library support has been previously loaded or disabled, this method
* has no effect.
*
* @return true iff native library support has been loaded
**/
public static synchronized final boolean initNativeLibrary (boolean disallow_lib_loading) {
public static synchronized final boolean initNativeLibrary(boolean disallow_lib_loading) {
if (disallow_lib_loading) {
native_lib_init_pending = false;
} else {
@ -669,13 +587,14 @@ public class MD5 {
return native_lib_loaded;
}
private static synchronized final void _initNativeLibrary () {
if (!native_lib_init_pending) return;
private static synchronized final void _initNativeLibrary() {
if (!native_lib_init_pending)
return;
native_lib_loaded = _loadNativeLibrary();
native_lib_init_pending = false;
}
private static synchronized final boolean _loadNativeLibrary () {
private static synchronized final boolean _loadNativeLibrary() {
try {
// don't try to load if the right property is set
@ -683,7 +602,8 @@ public class MD5 {
String prop = System.getProperty("com.twmacinta.util.MD5.NO_NATIVE_LIB");
if (prop != null) {
prop = prop.trim();
if (prop.equalsIgnoreCase("true") || prop.equals("1")) return false;
if (prop.equalsIgnoreCase("true") || prop.equals("1"))
return false;
}
// the library to load can be specified as a property
@ -702,7 +622,8 @@ public class MD5 {
String os_name = System.getProperty("os.name");
String os_arch = System.getProperty("os.arch");
if (os_name == null || os_arch == null) return false;
if (os_name == null || os_arch == null)
return false;
os_name = os_name.toLowerCase();
os_arch = os_arch.toLowerCase();
@ -713,88 +634,71 @@ public class MD5 {
// fill in settings for Linux on x86
if (os_name.equals("linux") &&
(os_arch.equals("x86") ||
os_arch.equals("i386") ||
os_arch.equals("i486") ||
os_arch.equals("i586") ||
os_arch.equals("i686"))) {
if (os_name.equals("linux")
&& (os_arch.equals("x86") || os_arch.equals("i386") || os_arch.equals("i486") || os_arch.equals("i586") || os_arch
.equals("i686"))) {
arch_lib_path = new File(new File(new File("lib"), "arch"), "linux_x86");
arch_libfile_suffix = ".so";
}
// fill in settings for Linux on amd64
else if (os_name.equals("linux") &&
os_arch.equals("amd64")) {
else if (os_name.equals("linux") && os_arch.equals("amd64")) {
arch_lib_path = new File(new File(new File("lib"), "arch"), "linux_amd64");
arch_libfile_suffix = ".so";
}
// fill in settings for Windows on x86
else if (os_name.startsWith("windows ") &&
(os_arch.equals("x86") ||
os_arch.equals("i386") ||
os_arch.equals("i486") ||
os_arch.equals("i586") ||
os_arch.equals("i686"))) {
else if (os_name.startsWith("windows ")
&& (os_arch.equals("x86") || os_arch.equals("i386") || os_arch.equals("i486") || os_arch.equals("i586") || os_arch
.equals("i686"))) {
arch_lib_path = new File(new File(new File("lib"), "arch"), "win32_x86");
arch_libfile_suffix = ".dll";
}
// fill in settings for Windows on amd64
else if (os_name.startsWith("windows ") &&
os_arch.equals("amd64")) {
else if (os_name.startsWith("windows ") && os_arch.equals("amd64")) {
arch_lib_path = new File(new File(new File("lib"), "arch"), "win_amd64");
arch_libfile_suffix = ".dll";
}
// fill in settings for Mac OS X on PPC
else if (os_name.startsWith("mac os x") &&
(os_arch.equals("ppc"))) {
else if (os_name.startsWith("mac os x") && (os_arch.equals("ppc"))) {
arch_lib_path = new File(new File(new File("lib"), "arch"), "darwin_ppc");
arch_libfile_suffix = ".jnilib";
}
// fill in settings for Mac OS X on x86
else if (os_name.startsWith("mac os x") &&
(os_arch.equals("x86") ||
os_arch.equals("i386") ||
os_arch.equals("i486") ||
os_arch.equals("i586") ||
os_arch.equals("i686"))) {
else if (os_name.startsWith("mac os x")
&& (os_arch.equals("x86") || os_arch.equals("i386") || os_arch.equals("i486") || os_arch.equals("i586") || os_arch
.equals("i686"))) {
arch_lib_path = new File(new File(new File("lib"), "arch"), "darwin_x86");
arch_libfile_suffix = ".jnilib";
}
// fill in settings for Mac OS X on x86_64
else if (os_name.startsWith("mac os x") &&
os_arch.equals("x86_64")) {
else if (os_name.startsWith("mac os x") && os_arch.equals("x86_64")) {
arch_lib_path = new File(new File(new File("lib"), "arch"), "darwin_x86_64");
arch_libfile_suffix = ".jnilib";
}
// fill in settings for FreeBSD on x86
else if (os_name.equals("freebsd") &&
(os_arch.equals("x86") ||
os_arch.equals("i386") ||
os_arch.equals("i486") ||
os_arch.equals("i586") ||
os_arch.equals("i686"))) {
else if (os_name.equals("freebsd")
&& (os_arch.equals("x86") || os_arch.equals("i386") || os_arch.equals("i486") || os_arch.equals("i586") || os_arch
.equals("i686"))) {
arch_lib_path = new File(new File(new File("lib"), "arch"), "freebsd_x86");
arch_libfile_suffix = ".so";
}
// fill in settings for FreeBSD on amd64
else if (os_name.equals("freebsd") &&
os_arch.equals("amd64")) {
else if (os_name.equals("freebsd") && os_arch.equals("amd64")) {
arch_lib_path = new File(new File(new File("lib"), "arch"), "freebsd_amd64");
arch_libfile_suffix = ".so";
}
@ -838,7 +742,8 @@ public class MD5 {
// discard SecurityExceptions
catch (SecurityException e) {}
catch (SecurityException e) {
}
// Intercept UnsatisfiedLinkError since the code will still
// work without the native method, but report it because it
@ -857,43 +762,53 @@ public class MD5 {
/**
* Calculates and returns the hash of the contents of the given file.
**/
public static byte[] getHash (File f) throws IOException {
if (!f.exists()) throw new FileNotFoundException(f.toString());
public static byte[] getHash(File f) throws IOException {
if (!f.exists())
throw new FileNotFoundException(f.toString());
InputStream close_me = null;
try {
long buf_size = f.length();
if (buf_size < 512) buf_size = 512;
if (buf_size > 65536) buf_size = 65536;
if (buf_size < 512)
buf_size = 512;
if (buf_size > 65536)
buf_size = 65536;
byte[] buf = new byte[(int) buf_size];
MD5InputStream in = new MD5InputStream(new FileInputStream(f));
close_me = in;
while (in.read(buf) != -1);
while (in.read(buf) != -1)
;
in.close();
return in.hash();
} catch (IOException e) {
if (close_me != null) try { close_me.close(); } catch (Exception e2) {}
if (close_me != null)
try {
close_me.close();
} catch (Exception e2) {
}
throw e;
}
}
/**
* @return true iff the first 16 bytes of both hash1 and hash2 are
* equal; both hash1 and hash2 are null; or either hash
* array is less than 16 bytes in length and their lengths and
* all of their bytes are equal.
* @return true iff the first 16 bytes of both hash1 and hash2 are equal; both hash1 and hash2 are null; or either hash array
* is less than 16 bytes in length and their lengths and all of their bytes are equal.
**/
public static boolean hashesEqual (byte[] hash1, byte[] hash2) {
if (hash1 == null) return hash2 == null;
if (hash2 == null) return false;
public static boolean hashesEqual(byte[] hash1, byte[] hash2) {
if (hash1 == null)
return hash2 == null;
if (hash2 == null)
return false;
int targ = 16;
if (hash1.length < 16) {
if (hash2.length != hash1.length) return false;
if (hash2.length != hash1.length)
return false;
targ = hash1.length;
} else if (hash2.length < 16) {
return false;
}
for (int i = 0; i < targ; i++) {
if (hash1[i] != hash2[i]) return false;
if (hash1[i] != hash2[i])
return false;
}
return true;
}

Просмотреть файл

@ -7,40 +7,30 @@ import java.io.IOException;
import java.io.InputStream;
/**
* MD5InputStream, a subclass of FilterInputStream implementing MD5
* functionality on a stream.
* MD5InputStream, a subclass of FilterInputStream implementing MD5 functionality on a stream.
* <p>
* Originally written by Santeri Paavolainen, Helsinki Finland 1996 <br>
* (c) Santeri Paavolainen, Helsinki Finland 1996 <br>
* Some changes Copyright (c) 2002 Timothy W Macinta <br>
* <p>
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
* <p>
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details.
* <p>
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
* <p>
* See http://www.twmacinta.com/myjava/fast_md5.php for more information
* on this file.
* See http://www.twmacinta.com/myjava/fast_md5.php for more information on this file.
* <p>
* Please note: I (Timothy Macinta) have put this code in the
* com.twmacinta.util package only because it came without a package. I
* was not the the original author of the code, although I did
* optimize it (substantially) and fix some bugs.
* Please note: I (Timothy Macinta) have put this code in the com.twmacinta.util package only because it came without a package. I
* was not the the original author of the code, although I did optimize it (substantially) and fix some bugs.
*
* @author Santeri Paavolainen <santtu@cs.hut.fi>
* @author Timothy W Macinta (twm@alum.mit.edu) (added main() method)
**/
public class MD5InputStream extends FilterInputStream {
/**
* MD5 context
@ -49,9 +39,11 @@ public class MD5InputStream extends FilterInputStream {
/**
* Creates a MD5InputStream
* @param in The input stream
*
* @param in
* The input stream
*/
public MD5InputStream (InputStream in) {
public MD5InputStream(InputStream in) {
super(in);
md5 = new MD5();
@ -59,6 +51,7 @@ public class MD5InputStream extends FilterInputStream {
/**
* Read a byte of data.
*
* @see java.io.FilterInputStream
*/
public int read() throws IOException {
@ -81,7 +74,7 @@ public class MD5InputStream extends FilterInputStream {
*
* @see java.io.FilterInputStream
*/
public int read (byte bytes[], int offset, int length) throws IOException {
public int read(byte bytes[], int offset, int length) throws IOException {
int r;
if ((r = in.read(bytes, offset, length)) == -1)
@ -93,11 +86,11 @@ public class MD5InputStream extends FilterInputStream {
}
/**
* Returns array of bytes representing hash of the stream as
* finalized for the current state.
* Returns array of bytes representing hash of the stream as finalized for the current state.
*
* @see MD5#Final
*/
public byte[] hash () {
public byte[] hash() {
return md5.Final();
}
@ -106,24 +99,23 @@ public class MD5InputStream extends FilterInputStream {
}
/**
* This method is here for testing purposes only - do not rely
* on it being here.
* This method is here for testing purposes only - do not rely on it being here.
**/
public static void main(String[] arg) {
try {
////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////
//
// usage: java com.twmacinta.util.MD5InputStream [--use-default-md5] [--no-native-lib] filename
//
/////////
// ///////
// determine the filename to use and the MD5 impelementation to use
String filename = arg[arg.length-1];
String filename = arg[arg.length - 1];
boolean use_default_md5 = false;
boolean use_native_lib = true;
for (int i = 0; i < arg.length-1; i++) {
for (int i = 0; i < arg.length - 1; i++) {
if (arg[i].equals("--use-default-md5")) {
use_default_md5 = true;
} else if (arg[i].equals("--no-native-lib")) {
@ -144,7 +136,7 @@ public class MD5InputStream extends FilterInputStream {
while ((num_read = in.read(buf)) != -1) {
digest.update(buf, 0, num_read);
}
System.out.println(MD5.asHex(digest.digest())+" "+filename);
System.out.println(MD5.asHex(digest.digest()) + " " + filename);
in.close();
// Use the optimized MD5 implementation
@ -160,8 +152,9 @@ public class MD5InputStream extends FilterInputStream {
// calculate the checksum
MD5InputStream in = new MD5InputStream(new BufferedInputStream(new FileInputStream(filename)));
while ((num_read = in.read(buf)) != -1);
System.out.println(MD5.asHex(in.hash())+" "+filename);
while ((num_read = in.read(buf)) != -1)
;
System.out.println(MD5.asHex(in.hash()) + " " + filename);
in.close();
}
} catch (Exception e) {
@ -170,4 +163,3 @@ public class MD5InputStream extends FilterInputStream {
}
}

Просмотреть файл

@ -8,34 +8,25 @@ import java.io.InputStream;
import java.io.OutputStream;
/**
* MD5OutputStream is a subclass of FilterOutputStream adding MD5
* hashing of the output.
* MD5OutputStream is a subclass of FilterOutputStream adding MD5 hashing of the output.
* <p>
* Originally written by Santeri Paavolainen, Helsinki Finland 1996 <br>
* (c) Santeri Paavolainen, Helsinki Finland 1996 <br>
* Some changes Copyright (c) 2002 Timothy W Macinta <br>
* <p>
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
* <p>
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details.
* <p>
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
* <p>
* See http://www.twmacinta.com/myjava/fast_md5.php for more information
* on this file.
* See http://www.twmacinta.com/myjava/fast_md5.php for more information on this file.
* <p>
* Please note: I (Timothy Macinta) have put this code in the
* com.twmacinta.util package only because it came without a package. I
* was not the the original author of the code, although I did
* optimize it (substantially) and fix some bugs.
* Please note: I (Timothy Macinta) have put this code in the com.twmacinta.util package only because it came without a package. I
* was not the the original author of the code, although I did optimize it (substantially) and fix some bugs.
*
* @author Santeri Paavolainen <santtu@cs.hut.fi>
* @author Timothy W Macinta (twm@alum.mit.edu) (added main() method)
@ -49,10 +40,12 @@ public class MD5OutputStream extends FilterOutputStream {
/**
* Creates MD5OutputStream
* @param out The output stream
*
* @param out
* The output stream
*/
public MD5OutputStream (OutputStream out) {
public MD5OutputStream(OutputStream out) {
super(out);
md5 = new MD5();
@ -64,7 +57,7 @@ public class MD5OutputStream extends FilterOutputStream {
* @see java.io.FilterOutputStream
*/
public void write (int b) throws IOException {
public void write(int b) throws IOException {
out.write(b);
md5.Update((byte) b);
}
@ -75,18 +68,18 @@ public class MD5OutputStream extends FilterOutputStream {
* @see java.io.FilterOutputStream
*/
public void write (byte b[], int off, int len) throws IOException {
public void write(byte b[], int off, int len) throws IOException {
out.write(b, off, len);
md5.Update(b, off, len);
}
/**
* Returns array of bytes representing hash of the stream as finalized
* for the current state.
* Returns array of bytes representing hash of the stream as finalized for the current state.
*
* @see MD5#Final
*/
public byte[] hash () {
public byte[] hash() {
return md5.Final();
}
@ -95,8 +88,7 @@ public class MD5OutputStream extends FilterOutputStream {
}
/**
* This method is here for testing purposes only - do not rely
* on it being here.
* This method is here for testing purposes only - do not rely on it being here.
**/
public static void main(String[] arg) {
try {
@ -109,7 +101,7 @@ public class MD5OutputStream extends FilterOutputStream {
total_read += num_read;
out.write(buf, 0, num_read);
}
System.out.println(MD5.asHex(out.hash())+" "+arg[0]);
System.out.println(MD5.asHex(out.hash()) + " " + arg[0]);
in.close();
out.close();
} catch (Exception e) {
@ -117,6 +109,4 @@ public class MD5OutputStream extends FilterOutputStream {
}
}
}

Просмотреть файл

@ -6,29 +6,21 @@ package com.twmacinta.util;
* (c) Santeri Paavolainen, Helsinki Finland 1996 <br>
* Some changes Copyright (c) 2002 Timothy W Macinta <br>
* <p>
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
* <p>
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details.
* <p>
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
* <p>
* See http://www.twmacinta.com/myjava/fast_md5.php for more information
* on this file.
* See http://www.twmacinta.com/myjava/fast_md5.php for more information on this file.
* <p>
* Contains internal state of the MD5 class
* <p>
* Please note: I (Timothy Macinta) have put this code in the
* com.twmacinta.util package only because it came without a package. I
* was not the the original author of the code, although I did
* optimize it (substantially) and fix some bugs.
* Please note: I (Timothy Macinta) have put this code in the com.twmacinta.util package only because it came without a package. I
* was not the the original author of the code, although I did optimize it (substantially) and fix some bugs.
*
* @author Santeri Paavolainen <sjpaavol@cc.helsinki.fi>
* @author Timothy W Macinta (twm@alum.mit.edu) (optimizations and bug fixes)
@ -63,7 +55,7 @@ class MD5State {
}
/** Create this State as a copy of another state */
public MD5State (MD5State from) {
public MD5State(MD5State from) {
this();
int i;

Просмотреть файл

@ -24,9 +24,9 @@ import java.io.InputStream;
import marytts.util.io.FileUtils;
/**
* Provide Version information for the Mary server and client.
*
* @author Marc Schr&ouml;der
*
*/
@ -35,8 +35,7 @@ public class Version {
private static String implementationVersion;
static {
InputStream specVersionStream = Version.class.
getResourceAsStream("specification-version.txt");
InputStream specVersionStream = Version.class.getResourceAsStream("specification-version.txt");
if (specVersionStream != null) {
try {
specificationVersion = FileUtils.getStreamAsString(specVersionStream, "UTF-8").trim();
@ -47,8 +46,7 @@ public class Version {
specificationVersion = "unknown";
}
InputStream implVersionStream = Version.class.
getResourceAsStream("implementation-version.txt");
InputStream implVersionStream = Version.class.getResourceAsStream("implementation-version.txt");
if (implVersionStream != null) {
try {
implementationVersion = FileUtils.getStreamAsString(implVersionStream, "UTF-8").trim();
@ -64,10 +62,10 @@ public class Version {
public static String specificationVersion() {
return specificationVersion;
}
/** Implementation version */
public static String implementationVersion() {
return implementationVersion;
}
}

Просмотреть файл

@ -20,30 +20,27 @@
package marytts.exceptions;
/**
* A special type of expected error conditions
* This class represents error conditions for external scripts
* such as Exceptions at runtime when processing fails
* A special type of expected error conditions This class represents error conditions for external scripts such as Exceptions at
* runtime when processing fails
*
* @author sathish
*
*/
public class ExecutionException extends Exception
{
public ExecutionException()
{
public class ExecutionException extends Exception {
public ExecutionException() {
super();
}
public ExecutionException(String message)
{
public ExecutionException(String message) {
super(message);
}
public ExecutionException(String message, Throwable cause)
{
public ExecutionException(String message, Throwable cause) {
super(message, cause);
}
public ExecutionException(Throwable cause)
{
public ExecutionException(Throwable cause) {
super(cause);
}
}

Просмотреть файл

@ -5,6 +5,7 @@ package marytts.exceptions;
/**
* An exception class representing cases where data provided to a processing unit does not match the specifications.
*
* @author marc
*
*/

Просмотреть файл

@ -20,40 +20,37 @@
package marytts.exceptions;
/**
* A class representing severe expected error conditions,
* such as wrong format of data files needed to set up the system.
* Typically a MaryConfigurationException means it is impossible to continue operating.
* According to the fail-early strategy, it is preferable to throw MaryConfigurationException
* during server startup, and to abort the startup if one is thrown.
* A class representing severe expected error conditions, such as wrong format of data files needed to set up the system.
* Typically a MaryConfigurationException means it is impossible to continue operating. According to the fail-early strategy, it
* is preferable to throw MaryConfigurationException during server startup, and to abort the startup if one is thrown.
*
* @author marc
*
*/
public class MaryConfigurationException extends Exception
{
public class MaryConfigurationException extends Exception {
/**
* Construct a MaryConfigurationException with only an error message.
* This constructor should only be used if our program code
* has identified the error condition. In order to wrap
* another Exception into a MaryConfigurationException with a
* meaningful error message, use {@link #MaryConfigurationException(String, Throwable)}.
* @param message a meaningful error message describing the problem.
* Construct a MaryConfigurationException with only an error message. This constructor should only be used if our program code
* has identified the error condition. In order to wrap another Exception into a MaryConfigurationException with a meaningful
* error message, use {@link #MaryConfigurationException(String, Throwable)}.
*
* @param message
* a meaningful error message describing the problem.
*/
public MaryConfigurationException(String message)
{
public MaryConfigurationException(String message) {
super(message);
}
/**
* Create a MaryConfigurationException with a message and a cause.
* Use this to wrap another Exception into a MaryConfigurationException with a
* meaningful error message.
* @param message a meaningful error message describing the problem.
* @param cause the exception or error that caused the problem.
* Create a MaryConfigurationException with a message and a cause. Use this to wrap another Exception into a
* MaryConfigurationException with a meaningful error message.
*
* @param message
* a meaningful error message describing the problem.
* @param cause
* the exception or error that caused the problem.
*/
public MaryConfigurationException(String message, Throwable cause)
{
public MaryConfigurationException(String message, Throwable cause) {
super(message, cause);
}
}

Просмотреть файл

@ -28,9 +28,9 @@ public class NoSuchPropertyException extends RuntimeException {
public NoSuchPropertyException(String message) {
super(message);
}
public NoSuchPropertyException(String message, Throwable cause) {
super(message, cause);
}
}

Просмотреть файл

@ -19,24 +19,21 @@
*/
package marytts.exceptions;
public class SynthesisException extends Exception
{
public SynthesisException()
{
public class SynthesisException extends Exception {
public SynthesisException() {
super();
}
public SynthesisException(String message)
{
public SynthesisException(String message) {
super(message);
}
public SynthesisException(String message, Throwable cause)
{
public SynthesisException(String message, Throwable cause) {
super(message, cause);
}
public SynthesisException(Throwable cause)
{
public SynthesisException(Throwable cause) {
super(cause);
}
}

Просмотреть файл

@ -29,13 +29,12 @@ import java.nio.charset.Charset;
import java.util.ArrayList;
/**
* An implementation of a finite state transducer. This class does nothing but
* load and represent the FST. It is used by other classes doing something
* reasonable with it.
* An implementation of a finite state transducer. This class does nothing but load and represent the FST. It is used by other
* classes doing something reasonable with it.
*
* @author Andreas Eisele
*/
public class FST
{
public class FST {
// The following variables are package-readable, so that they can be
// directly accessed by all classes in this package.
int[] targets;
@ -45,10 +44,9 @@ public class FST
short[] offsets;
byte[] bytes;
int[] mapping;
ArrayList strings=new ArrayList();
ArrayList strings = new ArrayList();
public FST(String fileName) throws IOException
{
public FST(String fileName) throws IOException {
FileInputStream fis = new FileInputStream(fileName);
try {
load(fis);
@ -59,6 +57,7 @@ public class FST
/**
* Load the fst from the given input stream. Assumes header.
*
* @param inStream
* @throws IOException
*/
@ -66,50 +65,54 @@ public class FST
load(inStream);
}
/**
* Initialise the finite state transducer. Loads from headerless legacy file format.
* @param fileName the name of the file from which to load the FST.
* @param encoding the name of the encoding used in the file (e.g., UTF-8
* or ISO-8859-1).
* @throws IOException if the FST cannot be loaded from the given file.
* @throws UnsupportedEncodingException if the encoding is not supported.
*
* @param fileName
* the name of the file from which to load the FST.
* @param encoding
* the name of the encoding used in the file (e.g., UTF-8 or ISO-8859-1).
* @throws IOException
* if the FST cannot be loaded from the given file.
* @throws UnsupportedEncodingException
* if the encoding is not supported.
*/
public FST(String fileName, String encoding)
throws IOException, UnsupportedEncodingException
{
public FST(String fileName, String encoding) throws IOException, UnsupportedEncodingException {
this(fileName, encoding, false);
}
/**
* Initialise the finite state transducer. This constructor will
* assume that the file uses the system default encoding.
* @param fileName the name of the file from which to load the FST.
* @param verbose whether to write a report to stderr after loading.
* @throws IOException if the FST cannot be loaded from the given file.
* Initialise the finite state transducer. This constructor will assume that the file uses the system default encoding.
*
* @param fileName
* the name of the file from which to load the FST.
* @param verbose
* whether to write a report to stderr after loading.
* @throws IOException
* if the FST cannot be loaded from the given file.
*/
public FST(String fileName, boolean verbose) throws IOException
{
public FST(String fileName, boolean verbose) throws IOException {
this(fileName, null, verbose);
}
/**
* Initialise the finite state transducer.
* @param fileName the name of the file from which to load the FST.
* @param encoding the name of the encoding used in the file (e.g., UTF-8
* or ISO-8859-1).
*
* This constructor is to be used for old FST-files where the encoding was
* not yet specified in the header.
* @param fileName
* the name of the file from which to load the FST.
* @param encoding
* the name of the encoding used in the file (e.g., UTF-8 or ISO-8859-1).
*
* @param verbose whether to write a report to stderr after loading.
* @throws IOException if the FST cannot be loaded from the given file.
* @throws UnsupportedEncodingException if the encoding is not supported.
* This constructor is to be used for old FST-files where the encoding was not yet specified in the header.
*
* @param verbose
* whether to write a report to stderr after loading.
* @throws IOException
* if the FST cannot be loaded from the given file.
* @throws UnsupportedEncodingException
* if the encoding is not supported.
*/
public FST(String fileName, String encoding, boolean verbose)
throws IOException, UnsupportedEncodingException
{
public FST(String fileName, String encoding, boolean verbose) throws IOException, UnsupportedEncodingException {
FileInputStream fis = new FileInputStream(fileName);
try {
loadHeaderless(fis, encoding, verbose);
@ -120,6 +123,7 @@ public class FST
/**
* Load the fst from the given input stream. Assumes headerless legacy file format.
*
* @param inStream
* @param encoding
* @throws IOException
@ -188,73 +192,64 @@ public class FST
createMapping(mapping, bytes, encoding);
}
private void loadHeaderless(InputStream inStream, String encoding, boolean verbose)
throws IOException, UnsupportedEncodingException
{
private void loadHeaderless(InputStream inStream, String encoding, boolean verbose) throws IOException,
UnsupportedEncodingException {
int i;
DataInputStream in = new DataInputStream(new BufferedInputStream(inStream));
//int fileSize= (int) f.length();
// int fileSize= (int) f.length();
int fileSize = in.available(); // TODO: how robust is this??
int nArcs=in.readInt();
int nArcs = in.readInt();
// arcs = new int[nArcs];
targets = new int[nArcs];
labels = new short[nArcs];
isLast = new boolean[nArcs];
for(i=0; i<nArcs; i++) {
for (i = 0; i < nArcs; i++) {
int thisArc = in.readInt();
targets[i]= thisArc&1048575;
labels[i]=(short)((thisArc>>20) & 2047);
isLast[i]=((byte)(thisArc >> 31))!=0;
targets[i] = thisArc & 1048575;
labels[i] = (short) ((thisArc >> 20) & 2047);
isLast[i] = ((byte) (thisArc >> 31)) != 0;
}
int nPairs=in.readInt();
offsets = new short[2*nPairs];
for(i=0; i<2*nPairs; i++)
int nPairs = in.readInt();
offsets = new short[2 * nPairs];
for (i = 0; i < 2 * nPairs; i++)
offsets[i] = in.readShort();
int nBytes = fileSize - 8 - 4 * (nPairs + nArcs);
mapping=new int[nBytes];
mapping = new int[nBytes];
bytes = new byte[nBytes];
in.readFully(bytes);
if(verbose) {
System.err.println("FST ("
+ fileSize + " Bytes, "
+ nArcs + " Arcs, "
+ nPairs + " Labels)"
+ " loaded");
if (verbose) {
System.err.println("FST (" + fileSize + " Bytes, " + nArcs + " Arcs, " + nPairs + " Labels)" + " loaded");
}
in.close();
createMapping(mapping, bytes, encoding);
}
private void createMapping(int[] mapping, byte[] bytes, String encoding)
throws UnsupportedEncodingException
{
mapping[0]=0;
int last0=-1;
private void createMapping(int[] mapping, byte[] bytes, String encoding) throws UnsupportedEncodingException {
mapping[0] = 0;
int last0 = -1;
String s;
int len;
for (int i=0;i<bytes.length;i++) {
if (bytes[i]==0) {
len=i-last0-1;
if (len==0) strings.add("");
for (int i = 0; i < bytes.length; i++) {
if (bytes[i] == 0) {
len = i - last0 - 1;
if (len == 0)
strings.add("");
else {
String str;
if (encoding != null)
str = new String(bytes, last0+1, len, encoding);
str = new String(bytes, last0 + 1, len, encoding);
else
str = new String(bytes, last0+1, len);
str = new String(bytes, last0 + 1, len);
strings.add(str);
}
mapping[last0+1]=strings.size()-1;
last0=i;
mapping[last0 + 1] = strings.size() - 1;
last0 = i;
}
}
}
}

Просмотреть файл

@ -21,44 +21,43 @@ package marytts.fst;
/**
* A Pair of Strings.
*
* @author benjaminroth
*/
public class StringPair{
public class StringPair {
//private boolean hasHash;
//private int hash;
// private boolean hasHash;
// private int hash;
private String string1;
private String string2;
public StringPair(String s1, String s2) {
this.string1 = s1;
this.string2 = s2;
//this.hasHash = false;
// this.hasHash = false;
}
public void setString1(String s1){
public void setString1(String s1) {
this.string1 = s1;
}
public void setString2(String s2){
public void setString2(String s2) {
this.string2 = s2;
}
public int hashCode() {
/*if (!hasHash){
this.hash = 31 * string1.hashCode() + string2.hashCode();
this.hasHash = true;
}
return this.hash;*/
/*
* if (!hasHash){ this.hash = 31 * string1.hashCode() + string2.hashCode(); this.hasHash = true; }
*
* return this.hash;
*/
return 31 * string1.hashCode() + string2.hashCode();
}
public boolean equals(Object o) {
if (o instanceof StringPair &&
((StringPair) o).getString1().equals(string1) &&
((StringPair) o).getString2().equals(string2))
if (o instanceof StringPair && ((StringPair) o).getString1().equals(string1)
&& ((StringPair) o).getString2().equals(string2))
return true;
return false;
@ -72,9 +71,7 @@ public class StringPair{
return string2;
}
public String toString(){
public String toString() {
return string1 + " " + string2;
}
}

Просмотреть файл

@ -23,28 +23,20 @@ package marytts.util;
* @author Oytun T&uumlrk
*
*/
public class ConversionUtils
{
public static byte[] toByteArray(byte byteArray)
{
return new byte[]{byteArray};
public class ConversionUtils {
public static byte[] toByteArray(byte byteArray) {
return new byte[] { byteArray };
}
public static byte[] toByteArray(byte[] byteArray)
{
public static byte[] toByteArray(byte[] byteArray) {
return byteArray;
}
public static byte[] toByteArray(short data)
{
return new byte[] {
(byte)((data >> 8) & 0xff),
(byte)((data >> 0) & 0xff),
};
public static byte[] toByteArray(short data) {
return new byte[] { (byte) ((data >> 8) & 0xff), (byte) ((data >> 0) & 0xff), };
}
public static byte[] toByteArray(short[] data)
{
public static byte[] toByteArray(short[] data) {
if (data == null)
return null;
@ -56,120 +48,94 @@ public class ConversionUtils
return byts;
}
public static byte[] toByteArray(char data)
{
return new byte[] {
(byte)((data >> 8) & 0xff),
(byte)((data >> 0) & 0xff),
};
public static byte[] toByteArray(char data) {
return new byte[] { (byte) ((data >> 8) & 0xff), (byte) ((data >> 0) & 0xff), };
}
public static byte[] toByteArray(char[] data)
{
public static byte[] toByteArray(char[] data) {
if (data == null)
return null;
byte[] byts = new byte[data.length * 2];
for (int i = 0; i < data.length; i++)
System.arraycopy(toByteArray(data[i]), 0, byts, i*2, 2);
System.arraycopy(toByteArray(data[i]), 0, byts, i * 2, 2);
return byts;
}
public static byte[] toByteArray(int data)
{
return new byte[] {
(byte)((data >> 24) & 0xff),
(byte)((data >> 16) & 0xff),
(byte)((data >> 8) & 0xff),
(byte)((data >> 0) & 0xff),
};
public static byte[] toByteArray(int data) {
return new byte[] { (byte) ((data >> 24) & 0xff), (byte) ((data >> 16) & 0xff), (byte) ((data >> 8) & 0xff),
(byte) ((data >> 0) & 0xff), };
}
public static byte[] toByteArray(int[] data)
{
public static byte[] toByteArray(int[] data) {
if (data == null)
return null;
byte[] byts = new byte[data.length*4];
byte[] byts = new byte[data.length * 4];
for (int i = 0; i < data.length; i++)
System.arraycopy(toByteArray(data[i]), 0, byts, i*4, 4);
System.arraycopy(toByteArray(data[i]), 0, byts, i * 4, 4);
return byts;
}
public static byte[] toByteArray(long data)
{
return new byte[] {
(byte)((data >> 56) & 0xff),
(byte)((data >> 48) & 0xff),
(byte)((data >> 40) & 0xff),
(byte)((data >> 32) & 0xff),
(byte)((data >> 24) & 0xff),
(byte)((data >> 16) & 0xff),
(byte)((data >> 8) & 0xff),
(byte)((data >> 0) & 0xff),
};
public static byte[] toByteArray(long data) {
return new byte[] { (byte) ((data >> 56) & 0xff), (byte) ((data >> 48) & 0xff), (byte) ((data >> 40) & 0xff),
(byte) ((data >> 32) & 0xff), (byte) ((data >> 24) & 0xff), (byte) ((data >> 16) & 0xff),
(byte) ((data >> 8) & 0xff), (byte) ((data >> 0) & 0xff), };
}
public static byte[] toByteArray(long[] data)
{
public static byte[] toByteArray(long[] data) {
if (data == null)
return null;
byte[] byts = new byte[data.length*8];
byte[] byts = new byte[data.length * 8];
for (int i = 0; i < data.length; i++)
System.arraycopy(toByteArray(data[i]), 0, byts, i*8, 8);
System.arraycopy(toByteArray(data[i]), 0, byts, i * 8, 8);
return byts;
}
public static byte[] toByteArray(float data)
{
public static byte[] toByteArray(float data) {
return toByteArray(Float.floatToRawIntBits(data));
}
public static byte[] toByteArray(float[] data)
{
public static byte[] toByteArray(float[] data) {
if (data == null)
return null;
byte[] byts = new byte[data.length*4];
byte[] byts = new byte[data.length * 4];
for (int i = 0; i < data.length; i++)
System.arraycopy(toByteArray(data[i]), 0, byts, i*4, 4);
System.arraycopy(toByteArray(data[i]), 0, byts, i * 4, 4);
return byts;
}
public static byte[] toByteArray(double data)
{
public static byte[] toByteArray(double data) {
return toByteArray(Double.doubleToRawLongBits(data));
}
public static byte[] toByteArray(double[] data)
{
public static byte[] toByteArray(double[] data) {
if (data == null)
return null;
byte[] byts = new byte[data.length*8];
byte[] byts = new byte[data.length * 8];
for (int i = 0; i < data.length; i++)
System.arraycopy(toByteArray(data[i]), 0, byts, i*8, 8);
System.arraycopy(toByteArray(data[i]), 0, byts, i * 8, 8);
return byts;
}
public static byte[] toByteArray(boolean data)
{
return new byte[]{(byte)(data ? 0x01 : 0x00)};
public static byte[] toByteArray(boolean data) {
return new byte[] { (byte) (data ? 0x01 : 0x00) };
}
public static byte[] toByteArray(boolean[] data)
{
public static byte[] toByteArray(boolean[] data) {
if (data == null)
return null;
@ -179,17 +145,18 @@ public class ConversionUtils
System.arraycopy(lena, 0, byts, 0, lena.length);
for (int i = 0, j = lena.length, k = 7; i < data.length; i++)
{
for (int i = 0, j = lena.length, k = 7; i < data.length; i++) {
byts[j] |= (data[i] ? 1 : 0) << k--;
if (k < 0) { j++; k = 7; }
if (k < 0) {
j++;
k = 7;
}
}
return byts;
}
public static byte[] toByteArray(String data)
{
public static byte[] toByteArray(String data) {
return (data == null) ? null : data.getBytes();
}
@ -240,180 +207,124 @@ public class ConversionUtils
return bytes;
}
public static byte toByte(byte[] byteArray)
{
public static byte toByte(byte[] byteArray) {
return (byteArray == null || byteArray.length == 0) ? 0x0 : byteArray[0];
}
public static short toShort(byte[] byteArray)
{
if (byteArray == null || byteArray.length != 2) return 0x0;
public static short toShort(byte[] byteArray) {
if (byteArray == null || byteArray.length != 2)
return 0x0;
// ----------
return (short)(
(0xff & byteArray[0]) << 8 |
(0xff & byteArray[1]) << 0
);
return (short) ((0xff & byteArray[0]) << 8 | (0xff & byteArray[1]) << 0);
}
public static short[] toShortArray(byte[] byteArray)
{
public static short[] toShortArray(byte[] byteArray) {
if (byteArray == null || byteArray.length % 2 != 0)
return null;
short[] shts = new short[byteArray.length / 2];
for (int i = 0; i < shts.length; i++)
{
shts[i] = toShort( new byte[] {
byteArray[(i*2)],
byteArray[(i*2)+1]
} );
for (int i = 0; i < shts.length; i++) {
shts[i] = toShort(new byte[] { byteArray[(i * 2)], byteArray[(i * 2) + 1] });
}
return shts;
}
public static char toChar(byte[] byteArray)
{
public static char toChar(byte[] byteArray) {
if (byteArray == null || byteArray.length != 2)
return 0x0;
return (char)(
(0xff & byteArray[0]) << 8 |
(0xff & byteArray[1]) << 0
);
return (char) ((0xff & byteArray[0]) << 8 | (0xff & byteArray[1]) << 0);
}
public static char[] toCharArray(byte[] byteArray)
{
public static char[] toCharArray(byte[] byteArray) {
if (byteArray == null || byteArray.length % 2 != 0)
return null;
char[] chrs = new char[byteArray.length / 2];
for (int i = 0; i < chrs.length; i++)
{
chrs[i] = toChar( new byte[] {
byteArray[(i*2)],
byteArray[(i*2)+1],
} );
for (int i = 0; i < chrs.length; i++) {
chrs[i] = toChar(new byte[] { byteArray[(i * 2)], byteArray[(i * 2) + 1], });
}
return chrs;
}
public static int toInt(byte[] byteArray)
{
public static int toInt(byte[] byteArray) {
if (byteArray == null || byteArray.length != 4)
return 0x0;
return (int)(
(0xff & byteArray[0]) << 24 |
(0xff & byteArray[1]) << 16 |
(0xff & byteArray[2]) << 8 |
(0xff & byteArray[3]) << 0
);
return (int) ((0xff & byteArray[0]) << 24 | (0xff & byteArray[1]) << 16 | (0xff & byteArray[2]) << 8 | (0xff & byteArray[3]) << 0);
}
public static int[] toIntArray(byte[] byteArray)
{
public static int[] toIntArray(byte[] byteArray) {
if (byteArray == null || byteArray.length % 4 != 0)
return null;
int[] ints = new int[byteArray.length / 4];
for (int i = 0; i < ints.length; i++)
{
ints[i] = toInt( new byte[] {
byteArray[(i*4)],
byteArray[(i*4)+1],
byteArray[(i*4)+2],
byteArray[(i*4)+3],
} );
for (int i = 0; i < ints.length; i++) {
ints[i] = toInt(new byte[] { byteArray[(i * 4)], byteArray[(i * 4) + 1], byteArray[(i * 4) + 2],
byteArray[(i * 4) + 3], });
}
return ints;
}
public static long toLong(byte[] byteArray)
{
public static long toLong(byte[] byteArray) {
if (byteArray == null || byteArray.length != 8)
return 0x0;
return (long)(
(long)(0xff & byteArray[0]) << 56 |
(long)(0xff & byteArray[1]) << 48 |
(long)(0xff & byteArray[2]) << 40 |
(long)(0xff & byteArray[3]) << 32 |
(long)(0xff & byteArray[4]) << 24 |
(long)(0xff & byteArray[5]) << 16 |
(long)(0xff & byteArray[6]) << 8 |
(long)(0xff & byteArray[7]) << 0
);
return (long) ((long) (0xff & byteArray[0]) << 56 | (long) (0xff & byteArray[1]) << 48
| (long) (0xff & byteArray[2]) << 40 | (long) (0xff & byteArray[3]) << 32 | (long) (0xff & byteArray[4]) << 24
| (long) (0xff & byteArray[5]) << 16 | (long) (0xff & byteArray[6]) << 8 | (long) (0xff & byteArray[7]) << 0);
}
public static long[] toLongArray(byte[] byteArray)
{
public static long[] toLongArray(byte[] byteArray) {
if (byteArray == null || byteArray.length % 8 != 0)
return null;
long[] lngs = new long[byteArray.length / 8];
for (int i = 0; i < lngs.length; i++)
{
lngs[i] = toLong( new byte[] {
byteArray[(i*8)],
byteArray[(i*8)+1],
byteArray[(i*8)+2],
byteArray[(i*8)+3],
byteArray[(i*8)+4],
byteArray[(i*8)+5],
byteArray[(i*8)+6],
byteArray[(i*8)+7],
} );
for (int i = 0; i < lngs.length; i++) {
lngs[i] = toLong(new byte[] { byteArray[(i * 8)], byteArray[(i * 8) + 1], byteArray[(i * 8) + 2],
byteArray[(i * 8) + 3], byteArray[(i * 8) + 4], byteArray[(i * 8) + 5], byteArray[(i * 8) + 6],
byteArray[(i * 8) + 7], });
}
return lngs;
}
public static float toFloat(byte[] byteArray)
{
public static float toFloat(byte[] byteArray) {
if (byteArray == null || byteArray.length != 4)
return 0x0;
return Float.intBitsToFloat(toInt(byteArray));
}
public static float[] toFloatArray(byte[] byteArray)
{
public static float[] toFloatArray(byte[] byteArray) {
if (byteArray == null || byteArray.length % 4 != 0)
return null;
float[] flts = new float[byteArray.length / 4];
for (int i = 0; i < flts.length; i++)
{
flts[i] = toFloat( new byte[] {
byteArray[(i*4)],
byteArray[(i*4)+1],
byteArray[(i*4)+2],
byteArray[(i*4)+3],
} );
for (int i = 0; i < flts.length; i++) {
flts[i] = toFloat(new byte[] { byteArray[(i * 4)], byteArray[(i * 4) + 1], byteArray[(i * 4) + 2],
byteArray[(i * 4) + 3], });
}
return flts;
}
public static double toDouble(byte[] byteArray)
{
public static double toDouble(byte[] byteArray) {
if (byteArray == null || byteArray.length != 8)
return 0x0;
return Double.longBitsToDouble(toLong(byteArray));
}
public static double[] toDoubleArray(byte[] byteArray)
{
public static double[] toDoubleArray(byte[] byteArray) {
if (byteArray == null)
return null;
@ -422,52 +333,42 @@ public class ConversionUtils
double[] dbls = new double[byteArray.length / 8];
for (int i = 0; i < dbls.length; i++)
{
dbls[i] = toDouble( new byte[] {
byteArray[(i*8)],
byteArray[(i*8)+1],
byteArray[(i*8)+2],
byteArray[(i*8)+3],
byteArray[(i*8)+4],
byteArray[(i*8)+5],
byteArray[(i*8)+6],
byteArray[(i*8)+7],
} );
for (int i = 0; i < dbls.length; i++) {
dbls[i] = toDouble(new byte[] { byteArray[(i * 8)], byteArray[(i * 8) + 1], byteArray[(i * 8) + 2],
byteArray[(i * 8) + 3], byteArray[(i * 8) + 4], byteArray[(i * 8) + 5], byteArray[(i * 8) + 6],
byteArray[(i * 8) + 7], });
}
return dbls;
}
public static boolean toBoolean(byte[] byteArray)
{
public static boolean toBoolean(byte[] byteArray) {
return (byteArray == null || byteArray.length == 0) ? false : byteArray[0] != 0x00;
}
public static boolean[] toBooleanArray(byte[] byteArray)
{
public static boolean[] toBooleanArray(byte[] byteArray) {
if (byteArray == null || byteArray.length < 4)
return null;
int len = toInt(new byte[]{byteArray[0], byteArray[1], byteArray[2], byteArray[3]});
int len = toInt(new byte[] { byteArray[0], byteArray[1], byteArray[2], byteArray[3] });
boolean[] bools = new boolean[len];
for (int i = 0, j = 4, k = 7; i < bools.length; i++)
{
for (int i = 0, j = 4, k = 7; i < bools.length; i++) {
bools[i] = ((byteArray[j] >> k--) & 0x01) == 1;
if (k < 0) { j++; k = 7; }
if (k < 0) {
j++;
k = 7;
}
}
return bools;
}
public static String toString(byte[] byteArray)
{
public static String toString(byte[] byteArray) {
return (byteArray == null) ? null : new String(byteArray);
}
public static String[] toStringArray(byte[] byteArray)
{
public static String[] toStringArray(byte[] byteArray) {
if (byteArray == null || byteArray.length < 4)
return null;
@ -479,29 +380,24 @@ public class ConversionUtils
if (byteArray.length < (4 + (saLen * 4)))
return null;
bBuff = new byte[saLen*4];
bBuff = new byte[saLen * 4];
System.arraycopy(byteArray, 4, bBuff, 0, bBuff.length);
int[] sLens = toIntArray(bBuff);
if (sLens == null)
return null;
String[] strs = new String[saLen];
for (int i=0, dataPos=4+(saLen*4); i<saLen; i++)
{
if (sLens[i] > 0)
{
if (byteArray.length >= (dataPos + sLens[i]))
{
for (int i = 0, dataPos = 4 + (saLen * 4); i < saLen; i++) {
if (sLens[i] > 0) {
if (byteArray.length >= (dataPos + sLens[i])) {
bBuff = new byte[sLens[i]];
System.arraycopy(byteArray, dataPos, bBuff, 0, sLens[i]);
dataPos += sLens[i];
strs[i] = toString(bBuff);
}
else
} else
return null;
}
}
return strs;
}
}

Просмотреть файл

@ -33,11 +33,10 @@ public class PrintSystemProperties {
// TODO Auto-generated method stub
Properties p = System.getProperties();
SortedSet keys = new TreeSet(p.keySet());
for (Iterator it=keys.iterator(); it.hasNext(); ) {
for (Iterator it = keys.iterator(); it.hasNext();) {
String key = (String) it.next();
System.out.println(key + " = " + p.getProperty(key));
}
}
}

Просмотреть файл

@ -28,8 +28,7 @@ import java.io.Reader;
* @author Marc Schroeder
*/
public class UncloseableBufferedReader extends BufferedReader
{
public class UncloseableBufferedReader extends BufferedReader {
public UncloseableBufferedReader(Reader i) {
super(i);
}
@ -37,4 +36,3 @@ public class UncloseableBufferedReader extends BufferedReader
public void close() {
}
}

Просмотреть файл

@ -43,14 +43,12 @@ import java.nio.ByteBuffer;
import marytts.exceptions.MaryConfigurationException;
/**
* Common helper class to read/write a standard Mary header to/from the various
* Mary data files.
* Common helper class to read/write a standard Mary header to/from the various Mary data files.
*
* @author sacha
*
*/
public class MaryHeader
{
public class MaryHeader {
/* Global constants */
private final static int MAGIC = 0x4d415259; // "MARY"
private final static int VERSION = 40; // 4.0
@ -69,28 +67,27 @@ public class MaryHeader
public final static int PRECOMPUTED_JOINCOSTS = 450;
public final static int TIMELINE = 500;
/* Private fields */
private int magic = MAGIC;
private int version = VERSION;
private int type = UNKNOWN;
// STATIC CODE
/**
* For the given file, look inside and determine the file type.
*
* @param fileName
* @return the file type, or -1 if the file does not have a valid MARY header.
* @throws IOException if the file cannot be read
* @throws IOException
* if the file cannot be read
*/
public static int peekFileType(String fileName) throws IOException
{
public static int peekFileType(String fileName) throws IOException {
DataInputStream dis = null;
dis = new DataInputStream( new BufferedInputStream( new FileInputStream( fileName ) ) );
dis = new DataInputStream(new BufferedInputStream(new FileInputStream(fileName)));
/* Load the Mary header */
try {
MaryHeader hdr = new MaryHeader( dis );
MaryHeader hdr = new MaryHeader(dis);
int type = hdr.getType();
return type;
} catch (MaryConfigurationException e) {
@ -102,7 +99,6 @@ public class MaryHeader
}
/****************/
/* CONSTRUCTORS */
/****************/
@ -112,9 +108,11 @@ public class MaryHeader
*
* Fundamental guarantee: after construction, the MaryHeader has a valid magic number and a valid type.
*
* @param newType The type of MaryHeader to create. See public final constants in this class.
* @param newType
* The type of MaryHeader to create. See public final constants in this class.
*
* @throws IllegalArgumentException if the input type is unknown.
* @throws IllegalArgumentException
* if the input type is unknown.
*/
public MaryHeader( int newType ) {
if ( (newType > TIMELINE) || (newType < UNKNOWN) ) {
@ -129,12 +127,14 @@ public class MaryHeader
}
/**
* Construct a MaryHeader by reading from a file.
* Fundamental guarantee: after construction, the MaryHeader has a valid magic number and a valid type.
* Construct a MaryHeader by reading from a file. Fundamental guarantee: after construction, the MaryHeader has a valid magic
* number and a valid type.
*
* @param input a DataInputStream or RandomAccessFile to read the header from.
* @param input
* a DataInputStream or RandomAccessFile to read the header from.
*
* @throws MaryConfigurationException if no mary header can be read from input.
* @throws MaryConfigurationException
* if no mary header can be read from input.
*/
public MaryHeader( DataInput input ) throws MaryConfigurationException {
try {
@ -152,12 +152,14 @@ public class MaryHeader
}
/**
* Construct a MaryHeader by reading from a file.
* Fundamental guarantee: after construction, the MaryHeader has a valid magic number and a valid type.
* Construct a MaryHeader by reading from a file. Fundamental guarantee: after construction, the MaryHeader has a valid magic
* number and a valid type.
*
* @param input a byte buffer to read the header from.
* @param input
* a byte buffer to read the header from.
*
* @throws MaryConfigurationException if no mary header can be read from input.
* @throws MaryConfigurationException
* if no mary header can be read from input.
*/
public MaryHeader( ByteBuffer input ) throws MaryConfigurationException {
try {
@ -178,13 +180,16 @@ public class MaryHeader
/* OTHER METHODS */
/*****************/
/** Mary header writer
/**
* Mary header writer
*
* @param output The DataOutputStream or RandomAccessFile to write to
* @param output
* The DataOutputStream or RandomAccessFile to write to
*
* @return the number of written bytes.
*
* @throws IOException if the file type is unknown.
* @throws IOException
* if the file type is unknown.
*/
public long writeTo( DataOutput output ) throws IOException {
@ -199,13 +204,16 @@ public class MaryHeader
return( nBytes );
}
/** Load a mary header.
/**
* Load a mary header.
*
* @param input The data input (DataInputStream or RandomAccessFile) to read from.
* @param input
* The data input (DataInputStream or RandomAccessFile) to read from.
*
* @throws IOException if the header data cannot be read
* @throws IOException
* if the header data cannot be read
*/
private void load( DataInput input ) throws IOException {
private void load(DataInput input) throws IOException {
magic = input.readInt();
version = input.readInt();
@ -215,8 +223,10 @@ public class MaryHeader
/**
* Load a mary header.
*
* @param input the byte buffer from which to read the mary header.
* @throws BufferUnderflowException if the header data cannot be read
* @param input
* the byte buffer from which to read the mary header.
* @throws BufferUnderflowException
* if the header data cannot be read
*/
private void load(ByteBuffer input) {
magic = input.getInt();
@ -225,17 +235,29 @@ public class MaryHeader
}
/* Accessors */
public int getMagic() { return(magic); }
public int getVersion() { return(version); }
public int getType() { return(type); }
public int getMagic() {
return (magic);
}
public int getVersion() {
return (version);
}
public int getType() {
return (type);
}
/* Checkers */
public boolean hasCurrentVersion() { return( version == VERSION ); }
private boolean hasLegalType() {
return (type <= TIMELINE) && (type > UNKNOWN) ;
public boolean hasCurrentVersion() {
return (version == VERSION);
}
private boolean hasLegalType() {
return (type <= TIMELINE) && (type > UNKNOWN);
}
private boolean hasLegalMagic() {
return( magic == MAGIC );
return (magic == MAGIC);
}
}

Просмотреть файл

@ -29,63 +29,46 @@ import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXParseException;
/**
* Implements an ErrorHandler for XML parsing
* that provides error and warning messages to the log4j logger.
* Implements an ErrorHandler for XML parsing that provides error and warning messages to the log4j logger.
*
* @author Marc Schr&ouml;der
*/
public class LoggingErrorHandler implements ErrorHandler, ErrorListener
{
public class LoggingErrorHandler implements ErrorHandler, ErrorListener {
Logger logger;
public LoggingErrorHandler(String name)
{
public LoggingErrorHandler(String name) {
logger = MaryUtils.getLogger(name);
}
public void error(SAXParseException e)
throws SAXParseException
{
public void error(SAXParseException e) throws SAXParseException {
logger.warn(e.getMessage());
throw e;
}
public void error(TransformerException e)
throws TransformerException
{
public void error(TransformerException e) throws TransformerException {
logger.warn(e.getMessageAndLocation());
throw e;
}
public void warning(SAXParseException e)
throws SAXParseException
{
public void warning(SAXParseException e) throws SAXParseException {
logger.warn(e.getMessage());
throw e;
}
public void warning(TransformerException e)
throws TransformerException
{
public void warning(TransformerException e) throws TransformerException {
logger.warn(e.getMessageAndLocation());
throw e;
}
public void fatalError(SAXParseException e)
throws SAXParseException
{
public void fatalError(SAXParseException e) throws SAXParseException {
logger.warn(e.getMessage());
throw e;
}
public void fatalError(TransformerException e)
throws TransformerException
{
public void fatalError(TransformerException e) throws TransformerException {
logger.warn(e.getMessageAndLocation());
throw e;
}
}

Просмотреть файл

@ -46,9 +46,9 @@ import org.apache.log4j.Logger;
import org.w3c.dom.Node;
/**
* A wrapper class for output of XML DOM trees in a Mary normalised way:
* One tag or text node per line, no indentation.
* This is only needed during the transition phase to "real" XML modules.
* A wrapper class for output of XML DOM trees in a Mary normalised way: One tag or text node per line, no indentation. This is
* only needed during the transition phase to "real" XML modules.
*
* @author Marc Schr&ouml;der
*/
@ -60,13 +60,12 @@ public class MaryNormalisedWriter {
private Transformer transformer;
/** Default constructor.
* Calls <code>startup()</code> if it has not been called before.
/**
* Default constructor. Calls <code>startup()</code> if it has not been called before.
*
* @see #startup().
*/
public MaryNormalisedWriter()
throws MaryConfigurationException
{
public MaryNormalisedWriter() throws MaryConfigurationException {
try {
// startup every time:
startup();
@ -78,8 +77,9 @@ public class MaryNormalisedWriter {
// Methods
/** Start up the static parts, and compile the normalise-maryxml XSLT
* stylesheet which can then be used by multiple threads.
/**
* Start up the static parts, and compile the normalise-maryxml XSLT stylesheet which can then be used by multiple threads.
*
* @exception TransformerFactoryConfigurationError
* if the TransformerFactory cannot be instanciated.
* @exception FileNotFoundException
@ -87,18 +87,14 @@ public class MaryNormalisedWriter {
* @exception TransformerConfigurationException
* if the templates stylesheet cannot be generated.
*/
private static void startup()
throws TransformerFactoryConfigurationError, TransformerConfigurationException
{
private static void startup() throws TransformerFactoryConfigurationError, TransformerConfigurationException {
// only start the stuff if it hasn't been started yet.
if (tFactory == null) {
tFactory = TransformerFactory.newInstance();
}
if (stylesheet == null) {
StreamSource stylesheetStream =
new StreamSource(
MaryNormalisedWriter.class.getResourceAsStream(
"normalise-maryxml.xsl"));
StreamSource stylesheetStream = new StreamSource(
MaryNormalisedWriter.class.getResourceAsStream("normalise-maryxml.xsl"));
stylesheet = tFactory.newTemplates(stylesheetStream);
}
if (logger == null)
@ -106,16 +102,19 @@ public class MaryNormalisedWriter {
}
/** The actual output to stdout.
* @param input a DOMSource, a SAXSource or a StreamSource.
/**
* The actual output to stdout.
*
* @param input
* a DOMSource, a SAXSource or a StreamSource.
* @see javax.xml.transform.Transformer
* @exception TransformerException
* if the transformation cannot be performed.
*/
public void output(Source input, Result destination) throws TransformerException {
//logger.debug("Before transform");
// logger.debug("Before transform");
transformer.transform(input, destination);
//logger.debug("After transform");
// logger.debug("After transform");
}
/**
@ -125,7 +124,9 @@ public class MaryNormalisedWriter {
output(input, new StreamResult(new PrintStream(System.out, true)));
}
/** Output a DOM node to stdout.
/**
* Output a DOM node to stdout.
*
* @see #output(Source)
*/
public void output(Node input) throws TransformerException {
@ -140,9 +141,8 @@ public class MaryNormalisedWriter {
}
/**
* The simplest possible command line interface to the
* MaryNormalisedWriter. Reads a "real" XML document from stdin,
* and outputs it in the MaryNormalised form to stdout.
* The simplest possible command line interface to the MaryNormalisedWriter. Reads a "real" XML document from stdin, and
* outputs it in the MaryNormalised form to stdout.
*/
public static void main(String[] args) throws Throwable {
startup();
@ -156,4 +156,3 @@ public class MaryNormalisedWriter {
}
}
}

Просмотреть файл

@ -24,32 +24,27 @@ import java.util.regex.Pattern;
import org.w3c.dom.Node;
import org.w3c.dom.traversal.NodeFilter;
/**
* A NodeFilter accepting only nodes with names matching
* a given regular expression.
* A NodeFilter accepting only nodes with names matching a given regular expression.
*
* @author Marc Schr&ouml;der
*/
public class RENodeFilter implements NodeFilter
{
public class RENodeFilter implements NodeFilter {
private Pattern re;
public RENodeFilter(String reString)
{
public RENodeFilter(String reString) {
this.re = Pattern.compile(reString);
}
public RENodeFilter(Pattern re)
{
public RENodeFilter(Pattern re) {
this.re = re;
}
public short acceptNode(Node n)
{
public short acceptNode(Node n) {
if (re.matcher(n.getNodeName()).matches())
return NodeFilter.FILTER_ACCEPT;
else
return NodeFilter.FILTER_SKIP;
}
}

Просмотреть файл

@ -25,75 +25,72 @@ package marytts.util.http;
*
* @author Oytun T&uumlrk
*/
public class Address
{
public class Address {
private String host;
private int port;
private String fullAddress; // --> host:port
private String httpAddress; // --> http://host:port
public Address()
{
public Address() {
this("", "");
}
public Address(String hostIn, int portIn)
{
public Address(String hostIn, int portIn) {
this(hostIn, String.valueOf(portIn));
}
public Address(String hostIn, String portIn)
{
public Address(String hostIn, String portIn) {
init(hostIn, portIn);
}
public Address(String fullAddress)
{
public Address(String fullAddress) {
String tmpAddress = fullAddress.trim();
int index = tmpAddress.lastIndexOf(':');
String hostIn = "";
String portIn = "";
if (index>0)
{
if (index > 0) {
hostIn = tmpAddress.substring(0, index);
if (index+1<tmpAddress.length())
portIn = tmpAddress.substring(index+1);
}
else
if (index + 1 < tmpAddress.length())
portIn = tmpAddress.substring(index + 1);
} else
hostIn = tmpAddress;
init(hostIn, portIn);
}
public void init(String hostIn, String portIn)
{
public void init(String hostIn, String portIn) {
this.host = hostIn;
if (portIn!="")
{
if (portIn != "") {
this.port = Integer.valueOf(portIn);
this.fullAddress = this.host + ":" + portIn;
}
else //No port address specified, set fullAdrress equal to host address
} else // No port address specified, set fullAdrress equal to host address
{
this.port = Integer.MIN_VALUE;
this.fullAddress = this.host;
}
if (this.fullAddress!=null && this.fullAddress.length()>0)
if (this.fullAddress != null && this.fullAddress.length() > 0)
this.httpAddress = "http://" + this.fullAddress;
else
this.httpAddress = null;
}
public String getHost() { return host; }
public String getHost() {
return host;
}
public int getPort() { return port; }
public int getPort() {
return port;
}
public String getFullAddress() { return fullAddress; }
public String getFullAddress() {
return fullAddress;
}
public String getHttpAddress() { return httpAddress; }
public String getHttpAddress() {
return httpAddress;
}
}

Просмотреть файл

@ -44,14 +44,13 @@ import java.util.Arrays;
import java.util.Vector;
/**
* The BasenameList class produces and stores an alphabetically-sorted
* array of basenames issued from the .wav files present in a given directory.
* The BasenameList class produces and stores an alphabetically-sorted array of basenames issued from the .wav files present in a
* given directory.
*
* @author sacha
*
*/
public class BasenameList
{
public class BasenameList {
private Vector bList = null;
private String fromDir = null;
private String fromExt = null;
@ -68,14 +67,14 @@ public class BasenameList
public BasenameList() {
fromDir = null;
fromExt = null;
bList = new Vector( DEFAULT_INCREMENT, DEFAULT_INCREMENT );
bList = new Vector(DEFAULT_INCREMENT, DEFAULT_INCREMENT);
hasChanged = false;
}
/**
* Default constructor from an existing vector and fields.
*/
public BasenameList( String setFromDir, String setFromExt, Vector setVec ) {
public BasenameList(String setFromDir, String setFromExt, Vector setVec) {
fromDir = setFromDir;
fromExt = setFromExt;
bList = setVec;
@ -85,50 +84,53 @@ public class BasenameList
/**
* Constructor from an array of strings.
*/
public BasenameList( String[] str ) {
public BasenameList(String[] str) {
fromDir = null;
fromExt = null;
bList = new Vector( DEFAULT_INCREMENT, DEFAULT_INCREMENT );
add( str );
bList = new Vector(DEFAULT_INCREMENT, DEFAULT_INCREMENT);
add(str);
hasChanged = false;
}
/**
* This constructor lists the .<extension> files from directory dir,
* and initializes an an array with their list of alphabetically
* sorted basenames.
* This constructor lists the .<extension> files from directory dir, and initializes an an array with their list of
* alphabetically sorted basenames.
*
* @param dir The name of the directory to list the files from.
* @param extension The extension of the files to list.
* @param dir
* The name of the directory to list the files from.
* @param extension
* The extension of the files to list.
*
*/
public BasenameList( String dirName, final String extension ) {
public BasenameList(String dirName, final String extension) {
fromDir = dirName;
if ( extension.indexOf(".") != 0 ) fromExt = "." + extension; // If the dot was not included, add it.
else fromExt = extension;
if (extension.indexOf(".") != 0)
fromExt = "." + extension; // If the dot was not included, add it.
else
fromExt = extension;
/* Turn the directory name into a file, to allow for checking and listing */
File dir = new File( dirName );
File dir = new File(dirName);
/* Check if the directory exists */
if ( !dir.exists() ) {
throw new RuntimeException( "Directory [" + dirName + "] does not exist. Can't find the [" + extension + "] files." );
if (!dir.exists()) {
throw new RuntimeException("Directory [" + dirName + "] does not exist. Can't find the [" + extension + "] files.");
}
/* List the .extension files */
File[] selectedFiles = dir.listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.endsWith( extension );
return name.endsWith(extension);
}
});
/* Sort the file names alphabetically */
Arrays.sort( selectedFiles );
Arrays.sort(selectedFiles);
/* Extract the basenames and store them in a vector of strings */
bList = new Vector( selectedFiles.length, DEFAULT_INCREMENT );
bList = new Vector(selectedFiles.length, DEFAULT_INCREMENT);
String str = null;
int subtractFromFilename = extension.length();
for ( int i = 0; i < selectedFiles.length; i++ ) {
str = selectedFiles[i].getName().substring( 0, selectedFiles[i].getName().length() - subtractFromFilename );
add( str );
for (int i = 0; i < selectedFiles.length; i++) {
str = selectedFiles[i].getName().substring(0, selectedFiles[i].getName().length() - subtractFromFilename);
add(str);
}
hasChanged = false;
}
@ -136,10 +138,11 @@ public class BasenameList
/**
* This constructor loads the basename list from a random access file.
*
* @param fileName The file to read from.
* @param fileName
* The file to read from.
*/
public BasenameList( String fileName ) throws IOException {
load( fileName );
public BasenameList(String fileName) throws IOException {
load(fileName);
hasChanged = false;
}
@ -150,50 +153,51 @@ public class BasenameList
/**
* Write the basenameList to a file, identified by its name.
*/
public void write( String fileName ) throws IOException {
write( new File( fileName ) );
public void write(String fileName) throws IOException {
write(new File(fileName));
}
/**
* Write the basenameList to a File.
*/
public void write( File file ) throws IOException {
PrintWriter pw = new PrintWriter( new OutputStreamWriter( new FileOutputStream( file ), "UTF-8" ), true );
if ( fromDir != null ) {
pw.println( "FROM: " + fromDir + "*" + fromExt );
public void write(File file) throws IOException {
PrintWriter pw = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8"), true);
if (fromDir != null) {
pw.println("FROM: " + fromDir + "*" + fromExt);
}
String str = null;
for ( int i = 0; i < bList.size(); i++ ) {
str = (String)(bList.elementAt(i));
pw.println( str );
for (int i = 0; i < bList.size(); i++) {
str = (String) (bList.elementAt(i));
pw.println(str);
}
}
/**
* Read the basenameList from a file
*/
public void load( String fileName ) throws IOException {
public void load(String fileName) throws IOException {
/* Open the file */
BufferedReader bfr = new BufferedReader( new InputStreamReader( new FileInputStream( fileName ), "UTF-8" ) );
BufferedReader bfr = new BufferedReader(new InputStreamReader(new FileInputStream(fileName), "UTF-8"));
/* Make the vector */
if ( bList == null ) bList = new Vector( DEFAULT_INCREMENT, DEFAULT_INCREMENT );
if (bList == null)
bList = new Vector(DEFAULT_INCREMENT, DEFAULT_INCREMENT);
/* Check if the first line contains the origin information (directory+ext) */
String line = bfr.readLine();
if ( line.indexOf("FROM: ") != -1 ) {
line = line.substring( 6 );
if (line.indexOf("FROM: ") != -1) {
line = line.substring(6);
String[] parts = new String[2];
parts = line.split( "\\*", 2 );
parts = line.split("\\*", 2);
fromDir = parts[0];
fromExt = parts[1];
}
else if ( !(line.matches("^\\s*$")) ) add( line );
} else if (!(line.matches("^\\s*$")))
add(line);
/* Add the lines to the vector, ignoring the blank ones. */
while ( (line = bfr.readLine()) != null ) {
if ( !(line.matches("^\\s*$")) ) add( line );
while ((line = bfr.readLine()) != null) {
if (!(line.matches("^\\s*$")))
add(line);
}
}
/*****************/
/* OTHER METHODS */
/*****************/
@ -201,59 +205,64 @@ public class BasenameList
/**
* Adds a basename to the list.
*/
public void add( String str ) {
if ( !bList.contains( str ) ) bList.add(str);
public void add(String str) {
if (!bList.contains(str))
bList.add(str);
hasChanged = true;
}
/**
* Adds an array of basenames to the list.
*/
public void add( String[] str ) {
for ( int i = 0; i < str.length; i++ ) add( str[i] );
public void add(String[] str) {
for (int i = 0; i < str.length; i++)
add(str[i]);
hasChanged = true;
}
/**
* Removes a basename from the list, if it was present.
*
* @param str The basename to remove.
* @param str
* The basename to remove.
* @return true if the list was containing the basename.
*/
public boolean remove( String str ) {
public boolean remove(String str) {
hasChanged = true;
return( bList.remove( str ) );
return (bList.remove(str));
}
/**
* Removes a list from another list.
*
* @param bnl The basename list to remove.
* @param bnl
* The basename list to remove.
* @return true if the list was containing any element of the list to remove.
*/
public boolean remove( BasenameList bnl ) {
public boolean remove(BasenameList bnl) {
boolean ret = true;
for ( int i = 0; i < bnl.getLength(); i++ ) {
bList.remove( bnl.getName(i) );
for (int i = 0; i < bnl.getLength(); i++) {
bList.remove(bnl.getName(i));
}
hasChanged = true;
return( ret );
return (ret);
}
/**
* Duplicates the list (i.e., emits an autonomous copy of it).
*/
public BasenameList duplicate() {
return( new BasenameList( this.fromDir, this.fromExt, (Vector)(this.bList.clone()) ) );
return (new BasenameList(this.fromDir, this.fromExt, (Vector) (this.bList.clone())));
}
/**
* Returns an autonomous sublist between fromIndex, inclusive, and toIndex, exclusive.
*/
public BasenameList subList( int fromIndex, int toIndex ) {
Vector subVec = new Vector( toIndex - fromIndex, DEFAULT_INCREMENT );
for ( int i = fromIndex; i < toIndex; i++ ) subVec.add( this.getName(i) );
return( new BasenameList( this.fromDir, this.fromExt, subVec ) );
public BasenameList subList(int fromIndex, int toIndex) {
Vector subVec = new Vector(toIndex - fromIndex, DEFAULT_INCREMENT);
for (int i = fromIndex; i < toIndex; i++)
subVec.add(this.getName(i));
return (new BasenameList(this.fromDir, this.fromExt, subVec));
}
/**
@ -261,87 +270,93 @@ public class BasenameList
*/
public String[] getListAsArray() {
String[] ret = new String[this.getLength()];
ret = (String[]) bList.toArray( ret );
return( (String[])( ret ) );
ret = (String[]) bList.toArray(ret);
return ((String[]) (ret));
}
/**
* Another accessor for the list of basenames, returned as a vector of strings
*/
public Vector getListAsVector() {
return( bList );
return (bList);
}
/**
* An accessor for the list's length
*/
public int getLength() {
return( bList.size() );
return (bList.size());
}
/**
* An accessor for the original directory. Returns null if the original
* directory is undefined.
* An accessor for the original directory. Returns null if the original directory is undefined.
*/
public String getDir() {
return( fromDir );
return (fromDir);
}
/**
* An accessor for the original extension. Returns null if the original
* extension is undefined.
* An accessor for the original extension. Returns null if the original extension is undefined.
*/
public String getExt() {
return( fromExt );
return (fromExt);
}
/**
* Return a copy of the basename at index i.
*
* @param i The index of the basename to consider.
* @param i
* The index of the basename to consider.
* @return The corresponding basename.
*/
public String getName( int i ) {
public String getName(int i) {
return (String) bList.elementAt(i);
}
/**
* Check if the given basename is part of the list.
*
* @param str The basename to check for.
* @param str
* The basename to check for.
* @return true if yes, false if no.
*/
public boolean contains( String str ) {
return( bList.contains( str ) );
public boolean contains(String str) {
return (bList.contains(str));
}
/**
* Check if the list contains another given one.
*
* @param bnl The list of basenames to check for.
* @param bnl
* The list of basenames to check for.
* @return true if yes, false if no.
*/
public boolean contains( BasenameList bnl ) {
public boolean contains(BasenameList bnl) {
/* The list cannot contain a bigger one: */
if ( bnl.getLength() > this.getLength() ) return( false );
for ( int i = 0; i < bnl.getLength(); i++ ) {
if ( !this.contains( bnl.getName(i) ) ) return( false );
if (bnl.getLength() > this.getLength())
return (false);
for (int i = 0; i < bnl.getLength(); i++) {
if (!this.contains(bnl.getName(i)))
return (false);
}
return( true );
return (true);
}
/**
* Check if two lists are equal.
*
* @param bnl The list of basenames to check for.
* @param bnl
* The list of basenames to check for.
* @return true if yes, false if no.
*/
public boolean equals( BasenameList bnl ) {
if ( bnl.getLength() != this.getLength() ) return( false );
for ( int i = 0; i < bnl.getLength(); i++ ) {
if ( !this.contains( bnl.getName(i) ) ) return( false );
public boolean equals(BasenameList bnl) {
if (bnl.getLength() != this.getLength())
return (false);
for (int i = 0; i < bnl.getLength(); i++) {
if (!this.contains(bnl.getName(i)))
return (false);
}
return( true );
return (true);
}
/**
@ -350,9 +365,9 @@ public class BasenameList
*/
public void sort() {
String[] str = getListAsArray();
Arrays.sort( str );
Arrays.sort(str);
bList.removeAllElements();
add( str );
add(str);
hasChanged = true;
}
@ -367,7 +382,7 @@ public class BasenameList
hasChanged = true;
}
public boolean hasChanged(){
public boolean hasChanged() {
return hasChanged;
}

Просмотреть файл

@ -32,26 +32,22 @@ package marytts.util.io;
import java.io.File;
import java.io.FilenameFilter;
/**
* @author oytun.turk
*
*/
public class FileFilter implements FilenameFilter
{
public class FileFilter implements FilenameFilter {
private String extension;
public FileFilter(String ext)
{
if (ext.startsWith(".") || ext.compareTo("*.*")==0)
public FileFilter(String ext) {
if (ext.startsWith(".") || ext.compareTo("*.*") == 0)
extension = ext;
else
extension = "." + ext;
}
public boolean accept(File dir, String name)
{
if (extension.compareTo("*.*")==0)
public boolean accept(File dir, String name) {
if (extension.compareTo("*.*") == 0)
return true;
else
return name.endsWith(extension);

Просмотреть файл

@ -40,23 +40,21 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
/**
* This class is for general purpose functions such as reading and
* writing from files, or converting formats of numbers.
* This class is for general purpose functions such as reading and writing from files, or converting formats of numbers.
*/
public class General
{
public class General {
/**
* Reads the next word (text separated by whitespace) from the
* given stream
* Reads the next word (text separated by whitespace) from the given stream
*
* @param dis the input stream
* @param dis
* the input stream
*
* @return the next word
*
* @throws IOException on error
* @throws IOException
* on error
*/
public static String readWord(DataInputStream dis) throws IOException {
StringBuilder sb = new StringBuilder();
@ -65,7 +63,7 @@ public class General
// skip leading whitespace
do {
c = readChar(dis);
} while(Character.isWhitespace(c));
} while (Character.isWhitespace(c));
// read the word
do {
@ -78,10 +76,12 @@ public class General
/**
* Reads a single char from the stream
*
* @param dis the stream to read
* @param dis
* the stream to read
* @return the next character on the stream
*
* @throws IOException if an error occurs
* @throws IOException
* if an error occurs
*/
public static char readChar(DataInputStream dis) throws IOException {
return (char) dis.readByte();
@ -90,15 +90,17 @@ public class General
/**
* Reads a given number of chars from the stream
*
* @param dis the stream to read
* @param num the number of chars to read
* @param dis
* the stream to read
* @param num
* the number of chars to read
* @return a character array containing the next <code>num<code>
* in the stream
*
* @throws IOException if an error occurs
* @throws IOException
* if an error occurs
*/
public static char[] readChars(DataInputStream dis, int num)
throws IOException {
public static char[] readChars(DataInputStream dis, int num) throws IOException {
char[] carray = new char[num];
for (int i = 0; i < num; i++) {
carray[i] = readChar(dis);
@ -107,19 +109,19 @@ public class General
}
/**
* Read a float from the input stream, byte-swapping as
* necessary
* Read a float from the input stream, byte-swapping as necessary
*
* @param dis the inputstream
* @param isBigEndian whether or not the data being read in is in
* big endian format.
* @param dis
* the inputstream
* @param isBigEndian
* whether or not the data being read in is in big endian format.
*
* @return a floating pint value
*
* @throws IOException on error
* @throws IOException
* on error
*/
public static float readFloat(DataInputStream dis, boolean isBigEndian)
throws IOException {
public static float readFloat(DataInputStream dis, boolean isBigEndian) throws IOException {
float val;
if (!isBigEndian) {
val = readLittleEndianFloat(dis);
@ -130,64 +132,64 @@ public class General
}
/**
* Write a float from the output stream, byte-swapping as
* necessary
* Write a float from the output stream, byte-swapping as necessary
*
* @param dos the outputstream
* @param isBigEndian whether or not the data being read in is in
* big endian format.
* @param val the floating point value to write
* @param dos
* the outputstream
* @param isBigEndian
* whether or not the data being read in is in big endian format.
* @param val
* the floating point value to write
*
* @throws IOException on error
* @throws IOException
* on error
*/
public static void writeFloat(DataOutputStream dos, boolean isBigEndian, float val)
throws IOException {
public static void writeFloat(DataOutputStream dos, boolean isBigEndian, float val) throws IOException {
if (!isBigEndian) {
writeLittleEndianFloat(dos,val);
writeLittleEndianFloat(dos, val);
} else {
dos.writeFloat( val );
dos.writeFloat(val);
}
}
/**
* Reads the next float from the given DataInputStream,
* where the data is in little endian.
* Reads the next float from the given DataInputStream, where the data is in little endian.
*
* @param dataStream the DataInputStream to read from
* @param dataStream
* the DataInputStream to read from
*
* @return a float
*/
public static float readLittleEndianFloat(DataInputStream dataStream)
throws IOException {
public static float readLittleEndianFloat(DataInputStream dataStream) throws IOException {
return Float.intBitsToFloat(readLittleEndianInt(dataStream));
}
/**
* Writes a float to the given DataOutputStream,
* where the data is in little endian.
* Writes a float to the given DataOutputStream, where the data is in little endian.
*
* @param dataStream the DataOutputStream to write to.
* @param val The float value to write.
* @param dataStream
* the DataOutputStream to write to.
* @param val
* The float value to write.
*/
public static void writeLittleEndianFloat(DataOutputStream dataStream,float val)
throws IOException {
writeLittleEndianInt( dataStream, Float.floatToRawIntBits(val) );
public static void writeLittleEndianFloat(DataOutputStream dataStream, float val) throws IOException {
writeLittleEndianInt(dataStream, Float.floatToRawIntBits(val));
}
/**
* Read an integer from the input stream, byte-swapping as
* necessary
* Read an integer from the input stream, byte-swapping as necessary
*
* @param dis the inputstream
* @param isBigEndian whether or not the data being read in is in
* big endian format.
* @param dis
* the inputstream
* @param isBigEndian
* whether or not the data being read in is in big endian format.
*
* @return an integer value
*
* @throws IOException on error
* @throws IOException
* on error
*/
public static int readInt(DataInputStream dis, boolean isBigEndian)
throws IOException {
public static int readInt(DataInputStream dis, boolean isBigEndian) throws IOException {
if (!isBigEndian) {
return readLittleEndianInt(dis);
} else {
@ -196,20 +198,21 @@ public class General
}
/**
* Writes an integer to the output stream, byte-swapping as
* necessary
* Writes an integer to the output stream, byte-swapping as necessary
*
* @param dis the outputstream.
* @param isBigEndian whether or not the data being read in is in
* big endian format.
* @param val the integer value to write.
* @param dis
* the outputstream.
* @param isBigEndian
* whether or not the data being read in is in big endian format.
* @param val
* the integer value to write.
*
* @throws IOException on error
* @throws IOException
* on error
*/
public static void writeInt(DataOutputStream dis, boolean isBigEndian, int val)
throws IOException {
public static void writeInt(DataOutputStream dis, boolean isBigEndian, int val) throws IOException {
if (!isBigEndian) {
writeLittleEndianInt(dis,val);
writeLittleEndianInt(dis, val);
} else {
dis.writeInt(val);
}
@ -218,12 +221,12 @@ public class General
/**
* Reads the next little-endian integer from the given DataInputStream.
*
* @param dataStream the DataInputStream to read from
* @param dataStream
* the DataInputStream to read from
*
* @return an integer
*/
public static int readLittleEndianInt(DataInputStream dataStream)
throws IOException {
public static int readLittleEndianInt(DataInputStream dataStream) throws IOException {
int bits = 0x00000000;
for (int shift = 0; shift < 32; shift += 8) {
int byteRead = (0x000000ff & dataStream.readByte());
@ -235,33 +238,35 @@ public class General
/**
* Writes a little-endian integer to the given DataOutputStream.
*
* @param dataStream the DataOutputStream to write to
* @param val the integer value to write
* @param dataStream
* the DataOutputStream to write to
* @param val
* the integer value to write
*
* @throws IOException on error
* @throws IOException
* on error
*/
public static void writeLittleEndianInt(DataOutputStream dataStream, int val)
throws IOException {
public static void writeLittleEndianInt(DataOutputStream dataStream, int val) throws IOException {
int mask = 0x000000ff;
for (int shift = 0; shift < 32; shift += 8) {
dataStream.writeByte( mask & (val >> shift) );
dataStream.writeByte(mask & (val >> shift));
}
}
/**
* Read a short from the input stream, byte-swapping as
* necessary
* Read a short from the input stream, byte-swapping as necessary
*
* @param dis the inputstream
* @param isBigEndian whether or not the data being read in is in
* big endian format.
* @param dis
* the inputstream
* @param isBigEndian
* whether or not the data being read in is in big endian format.
*
* @return an integer value
*
* @throws IOException on error
* @throws IOException
* on error
*/
public static short readShort(DataInputStream dis, boolean isBigEndian)
throws IOException {
public static short readShort(DataInputStream dis, boolean isBigEndian) throws IOException {
if (!isBigEndian) {
return readLittleEndianShort(dis);
} else {
@ -272,42 +277,33 @@ public class General
/**
* Reads the next little-endian short from the given DataInputStream.
*
* @param dataStream the DataInputStream to read from
* @param dataStream
* the DataInputStream to read from
*
* @return a short
*/
public static short readLittleEndianShort(DataInputStream dis)
throws IOException {
short bits = (short)(0x0000ff & dis.readByte());
bits |= (((short)(0x0000ff & dis.readByte())) << 8);
public static short readLittleEndianShort(DataInputStream dis) throws IOException {
short bits = (short) (0x0000ff & dis.readByte());
bits |= (((short) (0x0000ff & dis.readByte())) << 8);
return bits;
}
/**
* Convert a short to ulaw format
*
* @param sample the short to convert
* @param sample
* the short to convert
*
* @return a short containing an unsigned 8-bit quantity
* representing the ulaw
* @return a short containing an unsigned 8-bit quantity representing the ulaw
*/
public static byte shortToUlaw(short sample) {
final int[] exp_lut = {0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,
4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7};
final int[] exp_lut = { 0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7 };
int sign, exponent, mantissa;
short ulawbyte;
@ -317,28 +313,30 @@ public class General
/* Get the sample into sign-magnitude. */
sign = (sample >> 8) & 0x80; /* set aside the sign */
if ( sign != 0 ) {
if (sign != 0) {
sample = (short) -sample; /* get magnitude */
}
if ( sample > CLIP ) sample = CLIP; /* clip the magnitude */
if (sample > CLIP)
sample = CLIP; /* clip the magnitude */
/* Convert from 16 bit linear to ulaw. */
sample = (short) (sample + BIAS);
exponent = exp_lut[( sample >> 7 ) & 0xFF];
mantissa = ( sample >> ( exponent + 3 ) ) & 0x0F;
ulawbyte = (short)
((~ ( sign | ( exponent << 4 ) | mantissa)) & 0x00FF);
if ( ulawbyte == 0 ) ulawbyte = 0x02; /* optional CCITT trap */
exponent = exp_lut[(sample >> 7) & 0xFF];
mantissa = (sample >> (exponent + 3)) & 0x0F;
ulawbyte = (short) ((~(sign | (exponent << 4) | mantissa)) & 0x00FF);
if (ulawbyte == 0)
ulawbyte = 0x02; /* optional CCITT trap */
// Now ulawbyte is an unsigned 8-bit entity.
// Return as a (signed) byte:
return (byte) (ulawbyte-128);
return (byte) (ulawbyte - 128);
}
/**
* Convert a ulaw format to short
*
* @param ulaw a (signed) byte which, after converting into a short and
* adding 128, will be an unsigned 8-but quantity representing a ulaw
* @param ulaw
* a (signed) byte which, after converting into a short and adding 128, will be an unsigned 8-but quantity
* representing a ulaw
*
* @return the short equivalent of the ulaw
*/
@ -350,26 +348,29 @@ public class General
ulawbyte = (short) (ulawbyte & 0x00FF);
ulawbyte = (short) (~ulawbyte);
sign = ( ulawbyte & ((short) 0x80) );
exponent = (int) ( (ulawbyte & (short) 0x00FF) >> 4 ) & 0x07;
sign = (ulawbyte & ((short) 0x80));
exponent = (int) ((ulawbyte & (short) 0x00FF) >> 4) & 0x07;
mantissa = ulawbyte & (short) 0x0F;
sample = (short) (exp_lut[exponent] + (mantissa << (exponent + 3)));
if ( sign != 0 ) sample = (short) (-sample);
if (sign != 0)
sample = (short) (-sample);
return sample;
}
/**
* Convert an array from short to ulaw.
* @param samples an array in linear representation
*
* @param samples
* an array in linear representation
* @return an array in ulaw representation.
* @see #shortToUlaw(short)
*/
public static byte[] shortToUlaw(short[] samples)
{
if (samples == null) return null;
public static byte[] shortToUlaw(short[] samples) {
if (samples == null)
return null;
byte[] ulaw = new byte[samples.length];
for (int i=0; i<samples.length; i++) {
for (int i = 0; i < samples.length; i++) {
ulaw[i] = shortToUlaw(samples[i]);
}
return ulaw;
@ -377,15 +378,17 @@ public class General
/**
* Convert an array from ulaw to short.
* @param samples an array in ulaw representation
*
* @param samples
* an array in ulaw representation
* @return an array in linear representation.
* @see #ulawToShort(byte)
*/
public static short[] ulawToShort(byte[] ulaw)
{
if (ulaw == null) return null;
public static short[] ulawToShort(byte[] ulaw) {
if (ulaw == null)
return null;
short[] samples = new short[ulaw.length];
for (int i=0; i<ulaw.length; i++) {
for (int i = 0; i < ulaw.length; i++) {
samples[i] = ulawToShort(ulaw[i]);
}
return samples;
@ -394,7 +397,8 @@ public class General
/**
* Print a float type's internal bit representation in hex
*
* @param f the float to print
* @param f
* the float to print
*
* @return a string containing the hex value of <code>f</code>
*/
@ -402,91 +406,103 @@ public class General
return Integer.toHexString(Float.floatToIntBits(f));
}
/**
* Quantize a float variable over the 16bits signed short range
*
* @param f the float to quantize
* @param min the minimum possible value for variable f
* @param range the possible range for variable f
* @param f
* the float to quantize
* @param min
* the minimum possible value for variable f
* @param range
* the possible range for variable f
*
* @return the 16bits signed codeword, returned as a signed short
*
* @author Sacha K.
*/
public static short quantize( float f, float fMin, float fRange ) {
return( (short)( ( (double)f - (double)fMin ) * 65535.0/((double)fRange) - 32768.0) );
public static short quantize(float f, float fMin, float fRange) {
return ((short) (((double) f - (double) fMin) * 65535.0 / ((double) fRange) - 32768.0));
}
/**
* Quantize an array of floats over the 16bits signed short range
*
* @param f the array of floats to quantize
* @param min the minimum possible value for variable f
* @param range the possible range for variable f
* @param f
* the array of floats to quantize
* @param min
* the minimum possible value for variable f
* @param range
* the possible range for variable f
*
* @return an array of 16bits signed codewords, returned as signed shorts
*
* @author Sacha K.
*/
public static short[] quantize( float[] f, float fMin, float fRange ) {
public static short[] quantize(float[] f, float fMin, float fRange) {
int len = f.length;
short[] ret = new short[len];
for( int i = 0; i < len; i++ ) ret[i] = quantize( f[i], fMin, fRange );
for (int i = 0; i < len; i++)
ret[i] = quantize(f[i], fMin, fRange);
return( ret );
return (ret);
}
/**
* Unquantize a 16bits signed short over a float range
*
* @param s the 16bits signed codeword
* @param min the minimum possible value for variable f
* @param range the possible range for variable f
* @param s
* the 16bits signed codeword
* @param min
* the minimum possible value for variable f
* @param range
* the possible range for variable f
*
* @return the corresponding float value
*
* @author Sacha K.
*/
public static float unQuantize( short s, float fMin, float fRange ) {
return( (float)( ((double)(s) + 32768.0) * (double)fRange / 65535.0 - (double)fMin ) );
public static float unQuantize(short s, float fMin, float fRange) {
return ((float) (((double) (s) + 32768.0) * (double) fRange / 65535.0 - (double) fMin));
}
/**
* Unquantize an array of 16bits signed shorts over a float range
*
* @param s the array of 16bits signed codewords
* @param min the minimum possible value for variable f
* @param range the possible range for variable f
* @param s
* the array of 16bits signed codewords
* @param min
* the minimum possible value for variable f
* @param range
* the possible range for variable f
*
* @return the corresponding array of float values
*
* @author Sacha K.
*/
public static float[] unQuantize( short[] s, float fMin, float fRange ) {
public static float[] unQuantize(short[] s, float fMin, float fRange) {
int len = s.length;
float[] ret = new float[len];
for( int i = 0; i < len; i++ ) ret[i] = unQuantize( s[i], fMin, fRange );
for (int i = 0; i < len; i++)
ret[i] = unQuantize(s[i], fMin, fRange);
return( ret );
return (ret);
}
/**
* A general process launcher for the various tasks
*
* @param cmdLine the command line to be launched.
* @param task a task tag for error messages, such as "Pitchmarks" or "LPC".
* @param the basename of the file currently processed, for error messages.
* @param cmdLine
* the command line to be launched.
* @param task
* a task tag for error messages, such as "Pitchmarks" or "LPC".
* @param the
* basename of the file currently processed, for error messages.
*/
public static void launchProc( String cmdLine, String task, String baseName ) {
public static void launchProc(String cmdLine, String task, String baseName) {
Process proc = null;
String line = null;
@ -495,13 +511,13 @@ public class General
try {
/* Java 5.0 compliant code below. */
/* Hook the command line to the process builder: */
/* cmd = cmdLine.split( " " );
pb.command( cmd ); /*
/* Launch the process: */
/*proc = pb.start(); */
/*
* cmd = cmdLine.split( " " ); pb.command( cmd ); /* /* Launch the process:
*/
/* proc = pb.start(); */
/* Java 1.0 equivalent: */
proc = Runtime.getRuntime().exec( cmdLine );
proc = Runtime.getRuntime().exec(cmdLine);
/* Collect stdout and send it to System.out: */
InputStream procStdOut = proc.getInputStream();
@ -523,35 +539,36 @@ public class General
/* Wait and check the exit value */
proc.waitFor();
if ( proc.exitValue() != 0 ) {
throw new RuntimeException( task + " computation failed on file [" + baseName + "]!\n"
+ "Command line was: [" + cmdLine + "]." );
if (proc.exitValue() != 0) {
throw new RuntimeException(task + " computation failed on file [" + baseName + "]!\n" + "Command line was: ["
+ cmdLine + "].");
}
}
catch ( IOException e ) {
throw new RuntimeException( task + " computation provoked an IOException on file [" + baseName + "].", e );
}
catch ( InterruptedException e ) {
throw new RuntimeException( task + " computation interrupted on file [" + baseName + "].", e );
} catch (IOException e) {
throw new RuntimeException(task + " computation provoked an IOException on file [" + baseName + "].", e);
} catch (InterruptedException e) {
throw new RuntimeException(task + " computation interrupted on file [" + baseName + "].", e);
}
}
/**
* A general process launcher for the various tasks but using an intermediate batch file
* @param cmdLine the command line to be launched.
* @param task a task tag for error messages, such as "Pitchmarks" or "LPC".
* @param the filedir of the file currently processed, for error messages and for creating a
* temporal batch file.
*
* @param cmdLine
* the command line to be launched.
* @param task
* a task tag for error messages, such as "Pitchmarks" or "LPC".
* @param the
* filedir of the file currently processed, for error messages and for creating a temporal batch file.
*/
public static void launchBatchProc( String cmdLine, String task, String filedir ) {
public static void launchBatchProc(String cmdLine, String task, String filedir) {
Process proc = null;
Process proctmp = null;
BufferedReader procStdout = null;
String line = null;
String tmpFile = filedir + "tmp.bat";
System.out.println("Running: "+ cmdLine);
System.out.println("Running: " + cmdLine);
// String[] cmd = null; // Java 5.0 compliant code
try {
@ -560,27 +577,27 @@ public class General
tmp.close();
/* make it executable... */
proctmp = Runtime.getRuntime().exec( "chmod +x "+tmpFile );
proctmp = Runtime.getRuntime().exec("chmod +x " + tmpFile);
proctmp.waitFor();
if ( proctmp.exitValue() != 0 ) {
if (proctmp.exitValue() != 0) {
BufferedReader errReader = new BufferedReader(new InputStreamReader(proctmp.getErrorStream()));
while ((line = errReader.readLine()) != null) {
System.err.println("ERR> "+line);
System.err.println("ERR> " + line);
}
errReader.close();
throw new RuntimeException( task + " computation failed on file [" + filedir + "]!\n"
+ "Command line was: [chmod +x " + tmpFile + "]." );
throw new RuntimeException(task + " computation failed on file [" + filedir + "]!\n"
+ "Command line was: [chmod +x " + tmpFile + "].");
}
/* Java 5.0 compliant code below. */
/* Hook the command line to the process builder: */
/* cmd = cmdLine.split( " " );
pb.command( cmd ); /*
/* Launch the process: */
/*proc = pb.start(); */
/*
* cmd = cmdLine.split( " " ); pb.command( cmd ); /* /* Launch the process:
*/
/* proc = pb.start(); */
/* Java 1.0 equivalent: */
proc = Runtime.getRuntime().exec( tmpFile );
proc = Runtime.getRuntime().exec(tmpFile);
InputStream procStdOut = proc.getInputStream();
InputStream procStdErr = proc.getErrorStream();
@ -600,33 +617,28 @@ public class General
/* Wait and check the exit value */
proc.waitFor();
if ( proc.exitValue() != 0 ) {
if (proc.exitValue() != 0) {
BufferedReader errReader = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
while ((line = errReader.readLine()) != null) {
System.err.println("ERR> "+line);
System.err.println("ERR> " + line);
}
errReader.close();
throw new RuntimeException( task + " computation failed on file [" + filedir + "]!\n"
+ "Command line was: [" + cmdLine + "]." );
throw new RuntimeException(task + " computation failed on file [" + filedir + "]!\n" + "Command line was: ["
+ cmdLine + "].");
}
// Delete tmp.bat if created
File batchFile = new File(tmpFile);
if(batchFile.exists()){
if (batchFile.exists()) {
batchFile.delete();
}
}
catch ( IOException e ) {
throw new RuntimeException( task + " computation provoked an IOException on file [" + filedir + "].", e );
}
catch ( InterruptedException e ) {
throw new RuntimeException( task + " computation interrupted on file [" + filedir + "].", e );
} catch (IOException e) {
throw new RuntimeException(task + " computation provoked an IOException on file [" + filedir + "].", e);
} catch (InterruptedException e) {
throw new RuntimeException(task + " computation interrupted on file [" + filedir + "].", e);
}
}
}

Просмотреть файл

@ -48,8 +48,7 @@ public class LEDataInputStream implements DataInput {
*
* @noinspection UnusedDeclaration
*/
private static final String EMBEDDEDCOPYRIGHT =
"copyright (c) 1999-2007 Roedy Green, Canadian Mind Products, http://mindprod.com";
private static final String EMBEDDEDCOPYRIGHT = "copyright (c) 1999-2007 Roedy Green, Canadian Mind Products, http://mindprod.com";
/**
* to get at the big-Endian methods of a basic DataInputStream
@ -77,60 +76,63 @@ public class LEDataInputStream implements DataInput {
/**
* Note. This is a STATIC method!
*
* @param in stream to read UTF chars from (endian irrelevant)
* @param in
* stream to read UTF chars from (endian irrelevant)
*
* @return string from stream
*
* @throws IOException if read fails.
* @throws IOException
* if read fails.
*/
public static String readUTF( DataInput in ) throws IOException
{
return DataInputStream.readUTF( in );
public static String readUTF(DataInput in) throws IOException {
return DataInputStream.readUTF(in);
}
// -------------------------- PUBLIC INSTANCE METHODS --------------------------
/**
* constructor.
*
* @param in binary inputstream of little-endian data.
* @param in
* binary inputstream of little-endian data.
*/
public LEDataInputStream( InputStream in )
{
public LEDataInputStream(InputStream in) {
this.is = in;
this.dis = new DataInputStream( in );
this.dis = new DataInputStream(in);
work = new byte[8];
}
public LEDataInputStream( String filename) throws FileNotFoundException
{
public LEDataInputStream(String filename) throws FileNotFoundException {
this(new FileInputStream(filename));
}
/**
* close.
*
* @throws IOException if close fails.
* @throws IOException
* if close fails.
*/
public final void close() throws IOException
{
public final void close() throws IOException {
dis.close();
}
/**
* Read bytes. Watch out, read may return fewer bytes than requested.
*
* @param ba where the bytes go.
* @param off offset in buffer, not offset in file.
* @param len count of bytes to read.
* @param ba
* where the bytes go.
* @param off
* offset in buffer, not offset in file.
* @param len
* count of bytes to read.
*
* @return how many bytes read.
*
* @throws IOException if read fails.
* @throws IOException
* if read fails.
*/
public final int read( byte ba[], int off, int len ) throws IOException
{
public final int read(byte ba[], int off, int len) throws IOException {
// For efficiency, we avoid one layer of wrapper
return is.read( ba, off, len );
return is.read(ba, off, len);
}
/**
@ -138,19 +140,18 @@ public class LEDataInputStream implements DataInput {
*
* @return true or false.
*
* @throws IOException if read fails.
* @throws IOException
* if read fails.
* @see java.io.DataInput#readBoolean()
*/
public final boolean readBoolean() throws IOException
{
public final boolean readBoolean() throws IOException {
return dis.readBoolean();
}
public final boolean [] readBoolean(int len) throws IOException
{
boolean [] ret = new boolean[len];
public final boolean[] readBoolean(int len) throws IOException {
boolean[] ret = new boolean[len];
for (int i=0; i<len; i++)
for (int i = 0; i < len; i++)
ret[i] = readBoolean();
return ret;
@ -161,19 +162,18 @@ public class LEDataInputStream implements DataInput {
*
* @return the byte read.
*
* @throws IOException if read fails.
* @throws IOException
* if read fails.
* @see java.io.DataInput#readByte()
*/
public final byte readByte() throws IOException
{
public final byte readByte() throws IOException {
return dis.readByte();
}
public final byte [] readByte(int len) throws IOException
{
byte [] ret = new byte[len];
public final byte[] readByte(int len) throws IOException {
byte[] ret = new byte[len];
for (int i=0; i<len; i++)
for (int i = 0; i < len; i++)
ret[i] = readByte();
return ret;
@ -184,23 +184,23 @@ public class LEDataInputStream implements DataInput {
*
* @return little endian 16-bit unicode char from the stream.
*
* @throws IOException if read fails.
* @throws IOException
* if read fails.
*/
public final char readChar() throws IOException
{
dis.readFully( work, 0, 2 );
return (char) ( ( work[ 1 ] & 0xff ) << 8 | ( work[ 0 ] & 0xff ) );
public final char readChar() throws IOException {
dis.readFully(work, 0, 2);
return (char) ((work[1] & 0xff) << 8 | (work[0] & 0xff));
}
public final char [] readChar(int len) throws IOException
{
char [] ret = new char[len];
public final char[] readChar(int len) throws IOException {
char[] ret = new char[len];
for (int i=0; i<len; i++)
for (int i = 0; i < len; i++)
ret[i] = readChar();
return ret;
}
/**
* Read a double. like DataInputStream.readDouble except little endian.
*
@ -208,27 +208,24 @@ public class LEDataInputStream implements DataInput {
*
* @throws IOException
*/
public final double readDouble() throws IOException
{
return Double.longBitsToDouble( readLong() );
public final double readDouble() throws IOException {
return Double.longBitsToDouble(readLong());
}
public final double [] readDouble(int len) throws IOException
{
double [] ret = new double[len];
public final double[] readDouble(int len) throws IOException {
double[] ret = new double[len];
for (int i=0; i<len; i++)
for (int i = 0; i < len; i++)
ret[i] = readDouble();
return ret;
}
public final int [] readDoubleToInt(int len) throws IOException
{
int [] ret = new int[len];
public final int[] readDoubleToInt(int len) throws IOException {
int[] ret = new int[len];
for (int i=0; i<len; i++)
ret[i] = (int)readDouble();
for (int i = 0; i < len; i++)
ret[i] = (int) readDouble();
return ret;
}
@ -238,18 +235,17 @@ public class LEDataInputStream implements DataInput {
*
* @return little endian IEEE float from the datastream.
*
* @throws IOException if read fails.
* @throws IOException
* if read fails.
*/
public final float readFloat() throws IOException
{
return Float.intBitsToFloat( readInt() );
public final float readFloat() throws IOException {
return Float.intBitsToFloat(readInt());
}
public final float [] readFloat(int len) throws IOException
{
float [] ret = new float[len];
public final float[] readFloat(int len) throws IOException {
float[] ret = new float[len];
for (int i=0; i<len; i++)
for (int i = 0; i < len; i++)
ret[i] = readFloat();
return ret;
@ -260,22 +256,19 @@ public class LEDataInputStream implements DataInput {
*
* @see java.io.DataInput#readFully(byte[])
*/
public final void readFully( byte ba[] ) throws IOException
{
dis.readFully( ba, 0, ba.length );
public final void readFully(byte ba[]) throws IOException {
dis.readFully(ba, 0, ba.length);
}
/**
* Read bytes until the count is satisfied.
*
* @throws IOException if read fails.
* @throws IOException
* if read fails.
* @see java.io.DataInput#readFully(byte[],int,int)
*/
public final void readFully( byte ba[],
int off,
int len ) throws IOException
{
dis.readFully( ba, off, len );
public final void readFully(byte ba[], int off, int len) throws IOException {
dis.readFully(ba, off, len);
}
/**
@ -283,22 +276,18 @@ public class LEDataInputStream implements DataInput {
*
* @return little-endian binary int from the datastream
*
* @throws IOException if read fails.
* @throws IOException
* if read fails.
*/
public final int readInt() throws IOException
{
dis.readFully( work, 0, 4 );
return ( work[ 3 ] ) << 24
| ( work[ 2 ] & 0xff ) << 16
| ( work[ 1 ] & 0xff ) << 8
| ( work[ 0 ] & 0xff );
public final int readInt() throws IOException {
dis.readFully(work, 0, 4);
return (work[3]) << 24 | (work[2] & 0xff) << 16 | (work[1] & 0xff) << 8 | (work[0] & 0xff);
}
public final int [] readInt(int len) throws IOException
{
int [] ret = new int[len];
public final int[] readInt(int len) throws IOException {
int[] ret = new int[len];
for (int i=0; i<len; i++)
for (int i = 0; i < len; i++)
ret[i] = readInt();
return ret;
@ -307,71 +296,58 @@ public class LEDataInputStream implements DataInput {
/**
* Read a line.
*
* @return a rough approximation of the 8-bit stream as a 16-bit unicode
* string
* @return a rough approximation of the 8-bit stream as a 16-bit unicode string
*
* @throws IOException
* @noinspection deprecation
* @deprecated This method does not properly convert bytes to characters.
* Use a Reader instead with a little-endian encoding.
* @deprecated This method does not properly convert bytes to characters. Use a Reader instead with a little-endian encoding.
*/
public final String readLine() throws IOException
{
public final String readLine() throws IOException {
return dis.readLine();
}
/**
* read a long, 64-bits. Like DataInputStream.readLong except little
* endian.
* read a long, 64-bits. Like DataInputStream.readLong except little endian.
*
* @return little-endian binary long from the datastream.
*
* @throws IOException
*/
public final long readLong() throws IOException
{
dis.readFully( work, 0, 8 );
return (long) ( work[ 7 ] ) << 56
|
public final long readLong() throws IOException {
dis.readFully(work, 0, 8);
return (long) (work[7]) << 56 |
/* long cast needed or shift done modulo 32 */
(long) ( work[ 6 ] & 0xff ) << 48
| (long) ( work[ 5 ] & 0xff ) << 40
| (long) ( work[ 4 ] & 0xff ) << 32
| (long) ( work[ 3 ] & 0xff ) << 24
| (long) ( work[ 2 ] & 0xff ) << 16
| (long) ( work[ 1 ] & 0xff ) << 8
| (long) ( work[ 0 ] & 0xff );
(long) (work[6] & 0xff) << 48 | (long) (work[5] & 0xff) << 40 | (long) (work[4] & 0xff) << 32
| (long) (work[3] & 0xff) << 24 | (long) (work[2] & 0xff) << 16 | (long) (work[1] & 0xff) << 8
| (long) (work[0] & 0xff);
}
public final long [] readLong(int len) throws IOException
{
long [] ret = new long[len];
public final long[] readLong(int len) throws IOException {
long[] ret = new long[len];
for (int i=0; i<len; i++)
for (int i = 0; i < len; i++)
ret[i] = readLong();
return ret;
}
/**
* Read short, 16-bits. Like DataInputStream.readShort except little
* endian.
* Read short, 16-bits. Like DataInputStream.readShort except little endian.
*
* @return little endian binary short from stream.
*
* @throws IOException if read fails.
* @throws IOException
* if read fails.
*/
public final short readShort() throws IOException
{
dis.readFully( work, 0, 2 );
return (short) ( ( work[ 1 ] & 0xff ) << 8 | ( work[ 0 ] & 0xff ) );
public final short readShort() throws IOException {
dis.readFully(work, 0, 2);
return (short) ((work[1] & 0xff) << 8 | (work[0] & 0xff));
}
public final short [] readShort(int len) throws IOException
{
short [] ret = new short[len];
public final short[] readShort(int len) throws IOException {
short[] ret = new short[len];
for (int i=0; i<len; i++)
for (int i = 0; i < len; i++)
ret[i] = readShort();
return ret;
@ -382,72 +358,68 @@ public class LEDataInputStream implements DataInput {
*
* @return String read.
*/
public final String readUTF() throws IOException
{
public final String readUTF() throws IOException {
return dis.readUTF();
}
/**
* Read an unsigned byte. Note: returns an int, even though says Byte
* (non-Javadoc)
* Read an unsigned byte. Note: returns an int, even though says Byte (non-Javadoc)
*
* @throws IOException if read fails.
* @throws IOException
* if read fails.
* @see java.io.DataInput#readUnsignedByte()
*/
public final int readUnsignedByte() throws IOException
{
public final int readUnsignedByte() throws IOException {
return dis.readUnsignedByte();
}
public final int [] readUnsignedByte(int len) throws IOException
{
int [] ret = new int[len];
public final int[] readUnsignedByte(int len) throws IOException {
int[] ret = new int[len];
for (int i=0; i<len; i++)
for (int i = 0; i < len; i++)
ret[i] = readUnsignedByte();
return ret;
}
/**
* Read an unsigned short, 16 bits. Like DataInputStream.readUnsignedShort
* except little endian. Note, returns int even though it reads a short.
* Read an unsigned short, 16 bits. Like DataInputStream.readUnsignedShort except little endian. Note, returns int even though
* it reads a short.
*
* @return little-endian int from the stream.
*
* @throws IOException if read fails.
* @throws IOException
* if read fails.
*/
public final int readUnsignedShort() throws IOException
{
dis.readFully( work, 0, 2 );
return ( ( work[ 1 ] & 0xff ) << 8 | ( work[ 0 ] & 0xff ) );
public final int readUnsignedShort() throws IOException {
dis.readFully(work, 0, 2);
return ((work[1] & 0xff) << 8 | (work[0] & 0xff));
}
public final int [] readUnsignedShort(int len) throws IOException
{
int [] ret = new int[len];
public final int[] readUnsignedShort(int len) throws IOException {
int[] ret = new int[len];
for (int i=0; i<len; i++)
for (int i = 0; i < len; i++)
ret[i] = readUnsignedShort();
return ret;
}
/**
* Skip over bytes in the stream. See the general contract of the
* <code>skipBytes</code> method of <code>DataInput</code>.
* Skip over bytes in the stream. See the general contract of the <code>skipBytes</code> method of <code>DataInput</code>.
* <p/>
* Bytes for this operation are read from the contained input stream.
*
* @param n the number of bytes to be skipped.
* @param n
* the number of bytes to be skipped.
*
* @return the actual number of bytes skipped.
*
* @throws IOException if an I/O error occurs.
* @throws IOException
* if an I/O error occurs.
*/
public final int skipBytes( int n ) throws IOException
{
return dis.skipBytes( n );
public final int skipBytes(int n) throws IOException {
return dis.skipBytes(n);
}
}// end class LEDataInputStream

Просмотреть файл

@ -67,8 +67,7 @@ public class LEDataOutputStream implements DataOutput {
*
* @noinspection UnusedDeclaration
*/
private static final String EMBEDDEDCOPYRIGHT =
"copyright (c) 1999-2007 Roedy Green, Canadian Mind Products, http://mindprod.com";
private static final String EMBEDDEDCOPYRIGHT = "copyright (c) 1999-2007 Roedy Green, Canadian Mind Products, http://mindprod.com";
/**
* to get at big-Endian write methods of DataOutPutStream.
@ -88,100 +87,97 @@ public class LEDataOutputStream implements DataOutput {
/**
* constructor.
*
* @param out the outputstream we write little endian binary data onto.
* @param out
* the outputstream we write little endian binary data onto.
*/
public LEDataOutputStream( OutputStream out )
{
this.dis = new DataOutputStream( out );
public LEDataOutputStream(OutputStream out) {
this.dis = new DataOutputStream(out);
work = new byte[8];// work array for composing output
}
public LEDataOutputStream( String filename) throws FileNotFoundException
{
public LEDataOutputStream(String filename) throws FileNotFoundException {
this(new FileOutputStream(filename));
}
/**
* Close stream.
*
* @throws IOException if close fails.
* @throws IOException
* if close fails.
*/
public final void close() throws IOException
{
public final void close() throws IOException {
dis.close();
}
/**
* Flush stream without closing.
*
* @throws IOException if flush fails.
* @throws IOException
* if flush fails.
*/
public void flush() throws IOException
{
public void flush() throws IOException {
dis.flush();
}
/**
* Get size of stream.
*
* @return bytes written so far in the stream. Note this is a int, not a
* long as you would exect. This because the underlying
* @return bytes written so far in the stream. Note this is a int, not a long as you would exect. This because the underlying
* DataInputStream has a design flaw.
*/
public final int size()
{
public final int size() {
return dis.size();
}
/**
* This method writes only one byte, even though it says int (non-Javadoc)
*
* @param ib the byte to write.
* @param ib
* the byte to write.
*
* @throws IOException if write fails.
* @throws IOException
* if write fails.
* @see java.io.DataOutput#write(int)
*/
public final synchronized void write( int ib ) throws IOException
{
dis.write( ib );
public final synchronized void write(int ib) throws IOException {
dis.write(ib);
}
/**
* Write out an array of bytes.
*
* @throws IOException if write fails.
* @throws IOException
* if write fails.
* @see java.io.DataOutput#write(byte[])
*/
public final void write( byte ba[] ) throws IOException
{
dis.write( ba, 0, ba.length );
public final void write(byte ba[]) throws IOException {
dis.write(ba, 0, ba.length);
}
/**
* Writes out part of an array of bytes.
*
* @throws IOException if write fails.
* @throws IOException
* if write fails.
* @see java.io.DataOutput#write(byte[],int,int)
*/
public final synchronized void write( byte ba[],
int off,
int len ) throws IOException
{
dis.write( ba, off, len );
public final synchronized void write(byte ba[], int off, int len) throws IOException {
dis.write(ba, off, len);
}
/**
* Write a booleans as one byte.
*
* @param v boolean to write.
* @param v
* boolean to write.
*
* @throws IOException if write fails.
* @throws IOException
* if write fails.
* @see java.io.DataOutput#writeBoolean(boolean)
*/
/* Only writes one byte */
public final void writeBoolean( boolean v ) throws IOException
{
dis.writeBoolean( v );
public final void writeBoolean(boolean v) throws IOException {
dis.writeBoolean(v);
}
public final void writeBoolean( boolean [] v, int startPos, int len) throws IOException
@ -192,22 +188,22 @@ public class LEDataOutputStream implements DataOutput {
writeBoolean(v[i]);
}
public final void writeBoolean( boolean [] v) throws IOException
{
public final void writeBoolean(boolean[] v) throws IOException {
writeBoolean(v, 0, v.length);
}
/**
* write a byte.
*
* @param v the byte to write.
* @param v
* the byte to write.
*
* @throws IOException if write fails.
* @throws IOException
* if write fails.
* @see java.io.DataOutput#writeByte(int)
*/
public final void writeByte( int v ) throws IOException
{
dis.writeByte( v );
public final void writeByte(int v) throws IOException {
dis.writeByte(v);
}
public final void writeByte( byte [] v, int startPos, int len) throws IOException
@ -218,38 +214,38 @@ public class LEDataOutputStream implements DataOutput {
writeByte(v[i]);
}
public final void writeByte( byte [] v) throws IOException
{
public final void writeByte(byte[] v) throws IOException {
writeByte(v, 0, v.length);
}
/**
* Write a string.
*
* @param s the string to write.
* @param s
* the string to write.
*
* @throws IOException if write fails.
* @throws IOException
* if write fails.
* @see java.io.DataOutput#writeBytes(java.lang.String)
*/
public final void writeBytes( String s ) throws IOException
{
dis.writeBytes( s );
public final void writeBytes(String s) throws IOException {
dis.writeBytes(s);
}
/**
* Write a char. Like DataOutputStream.writeChar. Note the parm is an int
* even though this as a writeChar
* Write a char. Like DataOutputStream.writeChar. Note the parm is an int even though this as a writeChar
*
* @param v the char to write
* @param v
* the char to write
*
* @throws IOException if write fails.
* @throws IOException
* if write fails.
*/
public final void writeChar( int v ) throws IOException
{
public final void writeChar(int v) throws IOException {
// same code as writeShort
work[ 0 ] = (byte) v;
work[ 1 ] = (byte) ( v >> 8 );
dis.write( work, 0, 2 );
work[0] = (byte) v;
work[1] = (byte) (v >> 8);
dis.write(work, 0, 2);
}
public final void writeChar( char [] v, int startPos, int len) throws IOException
@ -260,90 +256,86 @@ public class LEDataOutputStream implements DataOutput {
writeChar(v[i]);
}
public final void writeChar( char [] v) throws IOException
{
public final void writeChar(char[] v) throws IOException {
writeChar(v, 0, v.length);
}
/**
* Write a string, not a char[]. Like DataOutputStream.writeChars, flip
* endianness of each char.
* Write a string, not a char[]. Like DataOutputStream.writeChars, flip endianness of each char.
*
* @throws IOException if write fails.
* @throws IOException
* if write fails.
*/
public final void writeChars( String s ) throws IOException
{
public final void writeChars(String s) throws IOException {
int len = s.length();
for ( int i = 0; i < len; i++ )
{
writeChar( s.charAt( i ) );
for (int i = 0; i < len; i++) {
writeChar(s.charAt(i));
}
}// end writeChars
/**
* Write a double.
*
* @param v the double to write. Like DataOutputStream.writeDouble.
* @param v
* the double to write. Like DataOutputStream.writeDouble.
*
* @throws IOException if write fails.
* @throws IOException
* if write fails.
*/
public final void writeDouble( double v ) throws IOException
{
writeLong( Double.doubleToLongBits( v ) );
public final void writeDouble(double v) throws IOException {
writeLong(Double.doubleToLongBits(v));
}
public final void writeDouble( double [] v, int startPos, int len) throws IOException
{
for (int i=startPos; i<startPos+len; i++)
public final void writeDouble(double[] v, int startPos, int len) throws IOException {
for (int i = startPos; i < startPos + len; i++)
writeDouble(v[i]);
}
public final void writeDouble( double [] v) throws IOException
{
public final void writeDouble(double[] v) throws IOException {
writeDouble(v, 0, v.length);
}
/**
* Write a float. Like DataOutputStream.writeFloat.
*
* @param v the float to write.
* @param v
* the float to write.
*
* @throws IOException if write fails.
* @throws IOException
* if write fails.
*/
public final void writeFloat( float v ) throws IOException
{
writeInt( Float.floatToIntBits( v ) );
public final void writeFloat(float v) throws IOException {
writeInt(Float.floatToIntBits(v));
}
public final void writeFloat( float [] v, int startPos, int len) throws IOException
{
public final void writeFloat(float[] v, int startPos, int len) throws IOException {
// this will always fire, since 0 + v.length never be > v.length!
// TODO remove this assert:
// assert v.length<startPos+len;
for (int i=startPos; i<startPos+len; i++)
for (int i = startPos; i < startPos + len; i++)
writeFloat(v[i]);
}
public final void writeFloat( float [] v) throws IOException
{
public final void writeFloat(float[] v) throws IOException {
writeFloat(v, 0, v.length);
}
/**
* Write an int, 32-bits. Like DataOutputStream.writeInt.
*
* @param v the int to write
* @param v
* the int to write
*
* @throws IOException if write fails.
* @throws IOException
* if write fails.
*/
public final void writeInt( int v ) throws IOException
{
work[ 0 ] = (byte) v;
work[ 1 ] = (byte) ( v >> 8 );
work[ 2 ] = (byte) ( v >> 16 );
work[ 3 ] = (byte) ( v >> 24 );
dis.write( work, 0, 4 );
public final void writeInt(int v) throws IOException {
work[0] = (byte) v;
work[1] = (byte) (v >> 8);
work[2] = (byte) (v >> 16);
work[3] = (byte) (v >> 24);
dis.write(work, 0, 4);
}
public final void writeInt( int [] v, int startPos, int len) throws IOException
@ -354,29 +346,29 @@ public class LEDataOutputStream implements DataOutput {
writeInt(v[i]);
}
public final void writeInt( int [] v) throws IOException
{
public final void writeInt(int[] v) throws IOException {
writeInt(v, 0, v.length);
}
/**
* Write a long, 64-bits. like DataOutputStream.writeLong.
*
* @param v the long to write
* @param v
* the long to write
*
* @throws IOException if write fails.
* @throws IOException
* if write fails.
*/
public final void writeLong( long v ) throws IOException
{
work[ 0 ] = (byte) v;
work[ 1 ] = (byte) ( v >> 8 );
work[ 2 ] = (byte) ( v >> 16 );
work[ 3 ] = (byte) ( v >> 24 );
work[ 4 ] = (byte) ( v >> 32 );
work[ 5 ] = (byte) ( v >> 40 );
work[ 6 ] = (byte) ( v >> 48 );
work[ 7 ] = (byte) ( v >> 56 );
dis.write( work, 0, 8 );
public final void writeLong(long v) throws IOException {
work[0] = (byte) v;
work[1] = (byte) (v >> 8);
work[2] = (byte) (v >> 16);
work[3] = (byte) (v >> 24);
work[4] = (byte) (v >> 32);
work[5] = (byte) (v >> 40);
work[6] = (byte) (v >> 48);
work[7] = (byte) (v >> 56);
dis.write(work, 0, 8);
}
public final void writeLong (long [] v, int startPos, int len) throws IOException
@ -387,24 +379,23 @@ public class LEDataOutputStream implements DataOutput {
writeLong(v[i]);
}
public final void writeLong( long [] v) throws IOException
{
public final void writeLong(long[] v) throws IOException {
writeLong(v, 0, v.length);
}
/**
* Write short, 16-bits. Like DataOutputStream.writeShort. also acts as a
* writeUnsignedShort
* Write short, 16-bits. Like DataOutputStream.writeShort. also acts as a writeUnsignedShort
*
* @param v the short you want written in little endian binary format
* @param v
* the short you want written in little endian binary format
*
* @throws IOException if write fails.
* @throws IOException
* if write fails.
*/
public final void writeShort( int v ) throws IOException
{
work[ 0 ] = (byte) v;
work[ 1 ] = (byte) ( v >> 8 );
dis.write( work, 0, 2 );
public final void writeShort(int v) throws IOException {
work[0] = (byte) v;
work[1] = (byte) (v >> 8);
dis.write(work, 0, 2);
}
public final void writeShort( short [] v, int startPos, int len) throws IOException
@ -415,24 +406,23 @@ public class LEDataOutputStream implements DataOutput {
writeShort(v[i]);
}
public final void writeShort( short [] v) throws IOException
{
public final void writeShort(short[] v) throws IOException {
writeShort(v, 0, v.length);
}
/**
* Write a string as a UTF counted string.
*
* @param s the string to write.
* @param s
* the string to write.
*
* @throws IOException if write fails.
* @throws IOException
* if write fails.
* @see java.io.DataOutput#writeUTF(java.lang.String)
*/
public final void writeUTF( String s ) throws IOException
{
dis.writeUTF( s );
public final void writeUTF(String s) throws IOException {
dis.writeUTF(s);
}
}// end LEDataOutputStream

Просмотреть файл

@ -31,91 +31,75 @@ public class LittleEndianBinaryReader {
private int low;
private int high;
public LittleEndianBinaryReader(DataInputStream d)
{
public LittleEndianBinaryReader(DataInputStream d) {
this.inputStream = d;
}
public LittleEndianBinaryReader(FileInputStream f)
{
public LittleEndianBinaryReader(FileInputStream f) {
this(new DataInputStream(f));
}
public LittleEndianBinaryReader(String filename) throws IOException
{
public LittleEndianBinaryReader(String filename) throws IOException {
this(new DataInputStream(new FileInputStream(filename)));
}
/*
public float readFloat() throws IOException {
for (int i=0; i<4; i++)
bytes[i] = inputStream.readByte();
return Float.intBitsToFloat(((0x0ff & bytes[0])<<0) | ((0x0ff & bytes[1])<<8) | ((0x0ff & bytes[2])<<16) | ((0x0ff & bytes[3])<<24));
}
* public float readFloat() throws IOException { for (int i=0; i<4; i++) bytes[i] = inputStream.readByte();
*
* return Float.intBitsToFloat(((0x0ff & bytes[0])<<0) | ((0x0ff & bytes[1])<<8) | ((0x0ff & bytes[2])<<16) | ((0x0ff &
* bytes[3])<<24)); }
*/
public short readShort() throws IOException
{
public short readShort() throws IOException {
low = inputStream.readByte() & 0xff;
high = inputStream.readByte() & 0xff;
return(short)( high << 8 | low );
return (short) (high << 8 | low);
}
public long readLong() throws IOException
{
public long readLong() throws IOException {
accumLong = 0;
for (shiftBy=0; shiftBy<64; shiftBy+=8 )
accumLong |= (long)(inputStream.readByte() & 0xff ) << shiftBy;
for (shiftBy = 0; shiftBy < 64; shiftBy += 8)
accumLong |= (long) (inputStream.readByte() & 0xff) << shiftBy;
return accumLong;
}
public char readChar( ) throws IOException
{
public char readChar() throws IOException {
low = inputStream.readByte() & 0xff;
high = inputStream.readByte();
return(char)( high << 8 | low );
return (char) (high << 8 | low);
}
public int readInt( ) throws IOException
{
public int readInt() throws IOException {
accumInt = 0;
for (shiftBy=0; shiftBy<32; shiftBy+=8 )
{
accumInt |= (inputStream.readByte() & 0xff ) << shiftBy;
for (shiftBy = 0; shiftBy < 32; shiftBy += 8) {
accumInt |= (inputStream.readByte() & 0xff) << shiftBy;
}
return accumInt;
}
public double readDouble() throws IOException
{
public double readDouble() throws IOException {
accumLong = 0;
for (shiftBy=0; shiftBy<64; shiftBy+=8 )
accumLong |= ( (long)( inputStream.readByte() & 0xff ) ) << shiftBy;
for (shiftBy = 0; shiftBy < 64; shiftBy += 8)
accumLong |= ((long) (inputStream.readByte() & 0xff)) << shiftBy;
return Double.longBitsToDouble( accumLong );
return Double.longBitsToDouble(accumLong);
}
public float readFloat() throws IOException
{
public float readFloat() throws IOException {
accumInt = 0;
for (shiftBy=0; shiftBy<32; shiftBy+=8 )
accumInt |= (inputStream.readByte () & 0xff ) << shiftBy;
for (shiftBy = 0; shiftBy < 32; shiftBy += 8)
accumInt |= (inputStream.readByte() & 0xff) << shiftBy;
return Float.intBitsToFloat( accumInt );
return Float.intBitsToFloat(accumInt);
}
public byte readByte( ) throws IOException
{
public byte readByte() throws IOException {
return inputStream.readByte();
}
public void close() throws IOException
{
if (inputStream!=null)
public void close() throws IOException {
if (inputStream != null)
inputStream.close();
}
}

Просмотреть файл

@ -25,31 +25,27 @@ import java.io.Reader;
import org.apache.log4j.Logger;
public class LoggingReader extends FilterReader
{
public class LoggingReader extends FilterReader {
protected Logger logger;
protected StringBuffer logText;
public LoggingReader(Reader in, Logger logger)
{
public LoggingReader(Reader in, Logger logger) {
super(in);
this.logger = logger;
logText = new StringBuffer();
}
public int read() throws IOException
{
public int read() throws IOException {
int c = super.read();
if (c == -1) {
logRead();
} else {
logText.append((char)c);
logText.append((char) c);
}
return c;
}
public int read(char[] cbuf, int off, int len) throws IOException
{
public int read(char[] cbuf, int off, int len) throws IOException {
int nr = super.read(cbuf, off, len);
if (nr == -1) {
logRead();
@ -59,18 +55,15 @@ public class LoggingReader extends FilterReader
return nr;
}
public void close() throws IOException
{
public void close() throws IOException {
super.close();
logRead();
}
public void logRead()
{
public void logRead() {
if (logText.length() > 0) {
logger.info("Read:\n" + logText.toString());
logText.setLength(0);
}
}
}

Просмотреть файл

@ -25,15 +25,14 @@ import java.io.IOException;
import java.io.RandomAccessFile;
/**
* A class that extends RandomAccessFile to read/write arrays of different types while allowing random
* access to a binary file (i.e. the file can be opened in both read/write mode and there is support for
* moving the file pointer to any location as required
* A class that extends RandomAccessFile to read/write arrays of different types while allowing random access to a binary file
* (i.e. the file can be opened in both read/write mode and there is support for moving the file pointer to any location as
* required
*
* @author Oytun T&uumlrk
*/
public final class MaryRandomAccessFile extends RandomAccessFile
{
public final class MaryRandomAccessFile extends RandomAccessFile {
public MaryRandomAccessFile(File arg0, String arg1) throws FileNotFoundException {
super(arg0, arg1);
}
@ -42,305 +41,271 @@ public final class MaryRandomAccessFile extends RandomAccessFile
super(arg0, arg1);
}
public final boolean readBooleanEndian() throws IOException
{
public final boolean readBooleanEndian() throws IOException {
boolean ret = readBoolean();
return ret;
}
public final boolean [] readBoolean(int len) throws IOException
{
boolean [] ret = new boolean[len];
public final boolean[] readBoolean(int len) throws IOException {
boolean[] ret = new boolean[len];
for (int i=0; i<len; i++)
for (int i = 0; i < len; i++)
ret[i] = readBoolean();
return ret;
}
public final boolean [] readBooleanEndian(int len) throws IOException
{
boolean [] ret = new boolean[len];
public final boolean[] readBooleanEndian(int len) throws IOException {
boolean[] ret = new boolean[len];
for (int i=0; i<len; i++)
for (int i = 0; i < len; i++)
ret[i] = readBooleanEndian();
return ret;
}
public final byte readByteEndian() throws IOException
{
public final byte readByteEndian() throws IOException {
byte ret = readByte();
return ret;
}
public final byte [] readByte(int len) throws IOException
{
byte [] ret = new byte[len];
public final byte[] readByte(int len) throws IOException {
byte[] ret = new byte[len];
for (int i=0; i<len; i++)
for (int i = 0; i < len; i++)
ret[i] = readByte();
return ret;
}
public final byte [] readByteEndian(int len) throws IOException
{
byte [] ret = new byte[len];
public final byte[] readByteEndian(int len) throws IOException {
byte[] ret = new byte[len];
for (int i=0; i<len; i++)
for (int i = 0; i < len; i++)
ret[i] = readByteEndian();
return ret;
}
public final char readCharEndian() throws IOException
{
char c = (char)readByte();
public final char readCharEndian() throws IOException {
char c = (char) readByte();
return c;
}
public final char [] readChar(int len) throws IOException
{
char [] ret = new char[len];
public final char[] readChar(int len) throws IOException {
char[] ret = new char[len];
for (int i=0; i<len; i++)
for (int i = 0; i < len; i++)
ret[i] = readChar();
return ret;
}
public final char [] readCharEndian(int len) throws IOException
{
char [] ret = new char[len];
public final char[] readCharEndian(int len) throws IOException {
char[] ret = new char[len];
for (int i=0; i<len; i++)
for (int i = 0; i < len; i++)
ret[i] = readCharEndian();
return ret;
}
public final double readDoubleEndian() throws IOException
{
public final double readDoubleEndian() throws IOException {
double ret = readDouble();
return ret;
}
public final double [] readDouble(int len) throws IOException
{
double [] ret = new double[len];
public final double[] readDouble(int len) throws IOException {
double[] ret = new double[len];
for (int i=0; i<len; i++)
for (int i = 0; i < len; i++)
ret[i] = readDouble();
return ret;
}
public final double [] readDoubleEndian(int len) throws IOException
{
double [] ret = new double[len];
public final double[] readDoubleEndian(int len) throws IOException {
double[] ret = new double[len];
for (int i=0; i<len; i++)
for (int i = 0; i < len; i++)
ret[i] = readDoubleEndian();
return ret;
}
public final int readDoubleToIntEndian() throws IOException
{
int ret = (int)readDouble();
public final int readDoubleToIntEndian() throws IOException {
int ret = (int) readDouble();
return ret;
}
public final int [] readDoubleToInt(int len) throws IOException
{
int [] ret = new int[len];
public final int[] readDoubleToInt(int len) throws IOException {
int[] ret = new int[len];
for (int i=0; i<len; i++)
ret[i] = (int)readDouble();
for (int i = 0; i < len; i++)
ret[i] = (int) readDouble();
return ret;
}
public final int [] readDoubleToIntEndian(int len) throws IOException
{
int [] ret = new int[len];
public final int[] readDoubleToIntEndian(int len) throws IOException {
int[] ret = new int[len];
for (int i=0; i<len; i++)
for (int i = 0; i < len; i++)
ret[i] = readDoubleToIntEndian();
return ret;
}
public final float readFloatEndian() throws IOException
{
public final float readFloatEndian() throws IOException {
float ret = readFloat();
return ret;
}
public final float [] readFloat(int len) throws IOException
{
float [] ret = new float[len];
public final float[] readFloat(int len) throws IOException {
float[] ret = new float[len];
for (int i=0; i<len; i++)
for (int i = 0; i < len; i++)
ret[i] = readFloat();
return ret;
}
public final float [] readFloatEndian(int len) throws IOException
{
float [] ret = new float[len];
public final float[] readFloatEndian(int len) throws IOException {
float[] ret = new float[len];
for (int i=0; i<len; i++)
for (int i = 0; i < len; i++)
ret[i] = readFloatEndian();
return ret;
}
public final int readIntEndian() throws IOException
{
public final int readIntEndian() throws IOException {
int ret = readInt();
return ret;
}
public final int [] readInt(int len) throws IOException
{
int [] ret = new int[len];
public final int[] readInt(int len) throws IOException {
int[] ret = new int[len];
for (int i=0; i<len; i++)
for (int i = 0; i < len; i++)
ret[i] = readInt();
return ret;
}
public final int [] readIntEndian(int len) throws IOException
{
int [] ret = new int[len];
public final int[] readIntEndian(int len) throws IOException {
int[] ret = new int[len];
for (int i=0; i<len; i++)
for (int i = 0; i < len; i++)
ret[i] = readIntEndian();
return ret;
}
public final long readLongEndian() throws IOException
{
long ret = (long)readInt();
public final long readLongEndian() throws IOException {
long ret = (long) readInt();
return ret;
}
public final long [] readLong(int len) throws IOException
{
long [] ret = new long[len];
public final long[] readLong(int len) throws IOException {
long[] ret = new long[len];
for (int i=0; i<len; i++)
for (int i = 0; i < len; i++)
ret[i] = readLong();
return ret;
}
public final long [] readLongEndian(int len) throws IOException
{
long [] ret = new long[len];
public final long[] readLongEndian(int len) throws IOException {
long[] ret = new long[len];
for (int i=0; i<len; i++)
for (int i = 0; i < len; i++)
ret[i] = readLongEndian();
return ret;
}
public final short readShortEndian() throws IOException
{
public final short readShortEndian() throws IOException {
short ret = readShort();
return ret;
}
public final short [] readShort(int len) throws IOException
{
short [] ret = new short[len];
public final short[] readShort(int len) throws IOException {
short[] ret = new short[len];
for (int i=0; i<len; i++)
for (int i = 0; i < len; i++)
ret[i] = readShort();
return ret;
}
public final short [] readShortEndian(int len) throws IOException
{
short [] ret = new short[len];
public final short[] readShortEndian(int len) throws IOException {
short[] ret = new short[len];
for (int i=0; i<len; i++)
for (int i = 0; i < len; i++)
ret[i] = readShortEndian();
return ret;
}
public final int readUnsignedByteEndian() throws IOException
{
public final int readUnsignedByteEndian() throws IOException {
int ret = readUnsignedByte();
return ret;
}
public final int [] readUnsignedByte(int len) throws IOException
{
int [] ret = new int[len];
public final int[] readUnsignedByte(int len) throws IOException {
int[] ret = new int[len];
for (int i=0; i<len; i++)
for (int i = 0; i < len; i++)
ret[i] = readUnsignedByte();
return ret;
}
public final int [] readUnsignedByteEndian(int len) throws IOException
{
int [] ret = new int[len];
public final int[] readUnsignedByteEndian(int len) throws IOException {
int[] ret = new int[len];
for (int i=0; i<len; i++)
for (int i = 0; i < len; i++)
ret[i] = readUnsignedByteEndian();
return ret;
}
public final int readUnsignedShortEndian() throws IOException
{
public final int readUnsignedShortEndian() throws IOException {
int ret = readUnsignedShort();
return ret;
}
public final int [] readUnsignedShort(int len) throws IOException
{
int [] ret = new int[len];
public final int[] readUnsignedShort(int len) throws IOException {
int[] ret = new int[len];
for (int i=0; i<len; i++)
for (int i = 0; i < len; i++)
ret[i] = readUnsignedShort();
return ret;
}
public final int [] readUnsignedShortEndian(int len) throws IOException
{
int [] ret = new int[len];
public final int[] readUnsignedShortEndian(int len) throws IOException {
int[] ret = new int[len];
for (int i=0; i<len; i++)
for (int i = 0; i < len; i++)
ret[i] = readUnsignedShortEndian();
return ret;
}
public final void writeBooleanEndian(boolean v) throws IOException
{
public final void writeBooleanEndian(boolean v) throws IOException {
writeBoolean(v);
}
@ -360,18 +325,15 @@ public final class MaryRandomAccessFile extends RandomAccessFile
writeBooleanEndian(v[i]);
}
public final void writeBoolean(boolean [] v) throws IOException
{
public final void writeBoolean(boolean[] v) throws IOException {
writeBoolean(v, 0, v.length);
}
public final void writeBooleanEndian( boolean [] v) throws IOException
{
public final void writeBooleanEndian(boolean[] v) throws IOException {
writeBooleanEndian(v, 0, v.length);
}
public final void writeByteEndian(byte v) throws IOException
{
public final void writeByteEndian(byte v) throws IOException {
writeByte(v);
}
@ -391,19 +353,16 @@ public final class MaryRandomAccessFile extends RandomAccessFile
writeByteEndian(v[i]);
}
public final void writeByte(byte [] v) throws IOException
{
public final void writeByte(byte[] v) throws IOException {
writeByte(v, 0, v.length);
}
public final void writeByteEndian(byte [] v) throws IOException
{
public final void writeByteEndian(byte[] v) throws IOException {
writeByteEndian(v, 0, v.length);
}
public final void writeCharEndian(char c) throws IOException
{
writeByte((byte)c);
public final void writeCharEndian(char c) throws IOException {
writeByte((byte) c);
}
public final void writeChar(char [] v, int startPos, int len) throws IOException
@ -422,45 +381,37 @@ public final class MaryRandomAccessFile extends RandomAccessFile
writeCharEndian(v[i]);
}
public final void writeChar(char [] v) throws IOException
{
public final void writeChar(char[] v) throws IOException {
writeChar(v, 0, v.length);
}
public final void writeCharEndian(char [] v) throws IOException
{
public final void writeCharEndian(char[] v) throws IOException {
writeCharEndian(v, 0, v.length);
}
public final void writeDoubleEndian(double v) throws IOException
{
public final void writeDoubleEndian(double v) throws IOException {
writeDouble(v);
}
public final void writeDouble(double [] v, int startPos, int len) throws IOException
{
for (int i=startPos; i<startPos+len; i++)
public final void writeDouble(double[] v, int startPos, int len) throws IOException {
for (int i = startPos; i < startPos + len; i++)
writeDouble(v[i]);
}
public final void writeDoubleEndian(double [] v, int startPos, int len) throws IOException
{
for (int i=startPos; i<startPos+len; i++)
public final void writeDoubleEndian(double[] v, int startPos, int len) throws IOException {
for (int i = startPos; i < startPos + len; i++)
writeDoubleEndian(v[i]);
}
public final void writeDouble(double [] v) throws IOException
{
public final void writeDouble(double[] v) throws IOException {
writeDouble(v, 0, v.length);
}
public final void writeDoubleEndian(double [] v) throws IOException
{
public final void writeDoubleEndian(double[] v) throws IOException {
writeDoubleEndian(v, 0, v.length);
}
public final void writeFloatEndian(float v) throws IOException
{
public final void writeFloatEndian(float v) throws IOException {
writeFloat(v);
}
@ -480,18 +431,15 @@ public final class MaryRandomAccessFile extends RandomAccessFile
writeFloatEndian(v[i]);
}
public final void writeFloat(float [] v) throws IOException
{
public final void writeFloat(float[] v) throws IOException {
writeFloat(v, 0, v.length);
}
public final void writeFloatEndian(float [] v) throws IOException
{
public final void writeFloatEndian(float[] v) throws IOException {
writeFloatEndian(v, 0, v.length);
}
public final void writeIntEndian(int v) throws IOException
{
public final void writeIntEndian(int v) throws IOException {
writeInt(v);
}
@ -511,19 +459,16 @@ public final class MaryRandomAccessFile extends RandomAccessFile
writeIntEndian(v[i]);
}
public final void writeInt(int [] v) throws IOException
{
public final void writeInt(int[] v) throws IOException {
writeInt(v, 0, v.length);
}
public final void writeIntEndian(int [] v) throws IOException
{
public final void writeIntEndian(int[] v) throws IOException {
writeIntEndian(v, 0, v.length);
}
public final void writeLongEndian(long v) throws IOException
{
writeInt((int)v);
public final void writeLongEndian(long v) throws IOException {
writeInt((int) v);
}
public final void writeLong (long [] v, int startPos, int len) throws IOException
@ -542,18 +487,15 @@ public final class MaryRandomAccessFile extends RandomAccessFile
writeLongEndian(v[i]);
}
public final void writeLong(long [] v) throws IOException
{
public final void writeLong(long[] v) throws IOException {
writeLong(v, 0, v.length);
}
public final void writeLongEndian(long [] v) throws IOException
{
public final void writeLongEndian(long[] v) throws IOException {
writeLongEndian(v, 0, v.length);
}
public final void writeShortEndian(short v) throws IOException
{
public final void writeShortEndian(short v) throws IOException {
writeShort(v);
}
@ -573,14 +515,11 @@ public final class MaryRandomAccessFile extends RandomAccessFile
writeShortEndian(v[i]);
}
public final void writeShort(short [] v) throws IOException
{
public final void writeShort(short[] v) throws IOException {
writeShort(v, 0, v.length);
}
public final void writeShortEndian(short [] v) throws IOException
{
public final void writeShortEndian(short[] v) throws IOException {
writeShort(v);
}
}

Просмотреть файл

@ -7,7 +7,6 @@ import java.io.InputStream;
import java.util.Properties;
import java.util.Scanner;
/**
* extends properties class to allow trimming of trailing whitespace from input streams
*
@ -22,7 +21,7 @@ public class PropertiesTrimTrailingWhitespace extends Properties {
Scanner in = new Scanner(fis);
ByteArrayOutputStream out = new ByteArrayOutputStream();
while(in.hasNext()) {
while (in.hasNext()) {
out.write(in.nextLine().trim().getBytes());
out.write("\n".getBytes());
}

Просмотреть файл

@ -26,36 +26,29 @@ import java.io.Reader;
import java.io.StringReader;
/**
* A class splitting a Reader into chunks.
* In a continuous input Reader, search for lines containing
* a specific "end-of-chunk" marking (e.g., an XML root end tag),
* and return individual readers, each of which will provide
* one chunk (including the line containing the end-of-chunk marking).
* A class splitting a Reader into chunks. In a continuous input Reader, search for lines containing a specific "end-of-chunk"
* marking (e.g., an XML root end tag), and return individual readers, each of which will provide one chunk (including the line
* containing the end-of-chunk marking).
*
* @author Marc Schr&ouml;der
*/
public class ReaderSplitter
{
public class ReaderSplitter {
private BufferedReader in;
private StringBuffer buf;
private String endMarker;
public ReaderSplitter(Reader in, String endMarker)
{
public ReaderSplitter(Reader in, String endMarker) {
this.in = new BufferedReader(in);
this.endMarker = endMarker;
buf = new StringBuffer(1000);
}
/**
* Return a reader from which one chunk can be read, followed by EOF.
* Chunks are delimited by start of file, lines containing the end marker
* string (line is last line in chunk), and end of file.
* Returns null if nothing more can be read.
* Return a reader from which one chunk can be read, followed by EOF. Chunks are delimited by start of file, lines containing
* the end marker string (line is last line in chunk), and end of file. Returns null if nothing more can be read.
*/
public Reader nextReader()
throws IOException
{
public Reader nextReader() throws IOException {
String line = null;
buf.setLength(0); // start with an empty buffer
while ((line = in.readLine()) != null) {
@ -65,8 +58,8 @@ public class ReaderSplitter
break;
}
}
if (buf.length() == 0) return null; // nothing more to read.
if (buf.length() == 0)
return null; // nothing more to read.
return (Reader) new StringReader(buf.toString());
}
}

Просмотреть файл

@ -25,17 +25,16 @@ import javax.swing.filechooser.FileFilter;
import marytts.util.MaryUtils;
/**
* A simple file filter accepting files with a given extension.
*
* @author Marc Schr&ouml;der
*/
public class SimpleFileFilter extends FileFilter
{
public class SimpleFileFilter extends FileFilter {
String extension;
String description;
public SimpleFileFilter(String extension, String description)
{
public SimpleFileFilter(String extension, String description) {
this.extension = extension;
this.description = description;
}
@ -51,8 +50,11 @@ public class SimpleFileFilter extends FileFilter
return false;
}
public String getDescription() { return description; }
public String getDescription() {
return description;
}
public String getExtension() { return extension; }
public String getExtension() {
return extension;
}
}

Просмотреть файл

@ -8,28 +8,23 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
public class StreamGobbler extends Thread
{
public class StreamGobbler extends Thread {
InputStream is;
String type;
public StreamGobbler(InputStream is, String type)
{
public StreamGobbler(InputStream is, String type) {
this.is = is;
this.type = type;
}
public void run()
{
try
{
public void run() {
try {
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line=null;
while ( (line = br.readLine()) != null)
String line = null;
while ((line = br.readLine()) != null)
System.out.println(type + ">" + line);
} catch (IOException ioe)
{
} catch (IOException ioe) {
ioe.printStackTrace();
}
}

Просмотреть файл

@ -31,31 +31,25 @@ import marytts.util.MaryUtils;
import org.apache.log4j.Logger;
/**
* Read from a stream and log.
*
* @author Marc Schr&ouml;der
*/
public class StreamLogger extends Thread
{
public class StreamLogger extends Thread {
private InputStream is;
private PrintStream ps;
private Logger logger;
private Pattern ignorePattern = null;
/**
* Read from an input stream, logging to category <code>logCategory</code>,
* ignoring lines matching
* the regular expression specified in <code>ignorePattern</code>.
* If <code>logCategory</code> is <code>null</code>, "unnamed" will be used.
* If <code>ignorePattern</code> is <code>null</code>, no filtering will be
* performed.
* The thread will silently die when it reaches end-of-file from the input
* stream.
* Read from an input stream, logging to category <code>logCategory</code>, ignoring lines matching the regular expression
* specified in <code>ignorePattern</code>. If <code>logCategory</code> is <code>null</code>, "unnamed" will be used. If
* <code>ignorePattern</code> is <code>null</code>, no filtering will be performed. The thread will silently die when it
* reaches end-of-file from the input stream.
*/
public StreamLogger(InputStream is, String logCategory, String ignorePattern)
{
public StreamLogger(InputStream is, String logCategory, String ignorePattern) {
this.is = is;
if (logCategory == null)
logger = MaryUtils.getLogger("unnamed");
@ -76,8 +70,7 @@ public class StreamLogger extends Thread
this.ps = ps;
}
public void run()
{
public void run() {
String line = null;
try {
BufferedReader b = new BufferedReader(new InputStreamReader(is));
@ -99,5 +92,3 @@ public class StreamLogger extends Thread
}
}
}

Просмотреть файл

@ -38,19 +38,17 @@ import java.nio.ByteBuffer;
*/
public class StreamUtils {
public static double[] readDoubleArray(DataInput stream, int len)
throws IOException {
byte[] raw = new byte[len*Double.SIZE/8];
public static double[] readDoubleArray(DataInput stream, int len) throws IOException {
byte[] raw = new byte[len * Double.SIZE / 8];
stream.readFully(raw);
DataInputStream in = new DataInputStream(new ByteArrayInputStream(raw));
double[] data = new double[len];
for (int i=0; i<len; i++) {
for (int i = 0; i < len; i++) {
data[i] = in.readDouble();
}
return data;
}
public static void writeDoubleArray(DataOutput stream, double[] data)
throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
@ -65,21 +63,18 @@ public class StreamUtils {
}
/**
* Reads from the
* bytebuffer <code>bb</code> a representation
* of a Unicode character string encoded in
* <a href="DataInput.html#modified-utf-8">modified UTF-8</a> format;
* this string of characters is then returned as a <code>String</code>.
* The details of the modified UTF-8 representation
* are exactly the same as for the <code>readUTF</code>
* Reads from the bytebuffer <code>bb</code> a representation of a Unicode character string encoded in <a
* href="DataInput.html#modified-utf-8">modified UTF-8</a> format; this string of characters is then returned as a
* <code>String</code>. The details of the modified UTF-8 representation are exactly the same as for the <code>readUTF</code>
* method of <code>DataInput</code>.
*
* @param in a byte buffer.
* @param in
* a byte buffer.
* @return a Unicode string.
* @exception BufferUnderflowException if the input stream reaches the end
* before all the bytes.
* @exception UTFDataFormatException if the bytes do not represent a
* valid modified UTF-8 encoding of a Unicode string.
* @exception BufferUnderflowException
* if the input stream reaches the end before all the bytes.
* @exception UTFDataFormatException
* if the bytes do not represent a valid modified UTF-8 encoding of a Unicode string.
* @see java.io.DataInputStream#readUnsignedShort()
*/
public static String readUTF(ByteBuffer bb) throws BufferUnderflowException, UTFDataFormatException {
@ -89,57 +84,58 @@ public class StreamUtils {
int c, char2, char3;
int count = 0;
int chararr_count=0;
int chararr_count = 0;
bb.get(bytearr);
while (count < utflen) {
c = (int) bytearr[count] & 0xff;
if (c > 127) break;
if (c > 127)
break;
count++;
chararr[chararr_count++]=(char)c;
chararr[chararr_count++] = (char) c;
}
while (count < utflen) {
c = (int) bytearr[count] & 0xff;
switch (c >> 4) {
case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
/* 0xxxxxxx*/
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
/* 0xxxxxxx */
count++;
chararr[chararr_count++]=(char)c;
chararr[chararr_count++] = (char) c;
break;
case 12: case 13:
/* 110x xxxx 10xx xxxx*/
case 12:
case 13:
/* 110x xxxx 10xx xxxx */
count += 2;
if (count > utflen)
throw new UTFDataFormatException(
"malformed input: partial character at end");
char2 = (int) bytearr[count-1];
throw new UTFDataFormatException("malformed input: partial character at end");
char2 = (int) bytearr[count - 1];
if ((char2 & 0xC0) != 0x80)
throw new UTFDataFormatException(
"malformed input around byte " + count);
chararr[chararr_count++]=(char)(((c & 0x1F) << 6) |
(char2 & 0x3F));
throw new UTFDataFormatException("malformed input around byte " + count);
chararr[chararr_count++] = (char) (((c & 0x1F) << 6) | (char2 & 0x3F));
break;
case 14:
/* 1110 xxxx 10xx xxxx 10xx xxxx */
count += 3;
if (count > utflen)
throw new UTFDataFormatException(
"malformed input: partial character at end");
char2 = (int) bytearr[count-2];
char3 = (int) bytearr[count-1];
throw new UTFDataFormatException("malformed input: partial character at end");
char2 = (int) bytearr[count - 2];
char3 = (int) bytearr[count - 1];
if (((char2 & 0xC0) != 0x80) || ((char3 & 0xC0) != 0x80))
throw new UTFDataFormatException(
"malformed input around byte " + (count-1));
chararr[chararr_count++]=(char)(((c & 0x0F) << 12) |
((char2 & 0x3F) << 6) |
((char3 & 0x3F) << 0));
throw new UTFDataFormatException("malformed input around byte " + (count - 1));
chararr[chararr_count++] = (char) (((c & 0x0F) << 12) | ((char2 & 0x3F) << 6) | ((char3 & 0x3F) << 0));
break;
default:
/* 10xx xxxx, 1111 xxxx */
throw new UTFDataFormatException(
"malformed input around byte " + count);
throw new UTFDataFormatException("malformed input around byte " + count);
}
}
// The number of chars produced may be less than utflen
@ -147,19 +143,16 @@ public class StreamUtils {
}
/**
* See the general contract of the <code>readUnsignedShort</code>
* method of <code>DataInput</code>.
* See the general contract of the <code>readUnsignedShort</code> method of <code>DataInput</code>.
* <p>
* Bytes
* for this operation are read from the given byte buffer
* Bytes for this operation are read from the given byte buffer
*
* @return the next two bytes of this input stream, interpreted as an
* unsigned 16-bit integer.
* @exception EOFException if this input stream reaches the end before
* reading two bytes.
* @exception IOException the stream has been closed and the contained
* input stream does not support reading after close, or
* another I/O error occurs.
* @return the next two bytes of this input stream, interpreted as an unsigned 16-bit integer.
* @exception EOFException
* if this input stream reaches the end before reading two bytes.
* @exception IOException
* the stream has been closed and the contained input stream does not support reading after close, or another
* I/O error occurs.
* @see java.io.FilterInputStream#in
*/
public static int readUnsignedShort(ByteBuffer bb) throws BufferUnderflowException {