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,26 +79,21 @@ 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() {
state = new MD5State();
@ -136,15 +104,16 @@ public class MD5 {
* Class constructor
**/
public MD5() {
if (native_lib_init_pending) _initNativeLibrary();
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) {
this();
@ -152,91 +121,51 @@ public class MD5 {
}
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);
}*/
/*
* 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 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;
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);
@ -277,7 +206,6 @@ 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 = ((a << 5) | (a >>> 27)) + b;
@ -315,7 +243,6 @@ public class MD5 {
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 = ((a << 4) | (a >>> 28)) + b;
@ -353,7 +280,6 @@ public class MD5 {
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 = ((a << 6) | (a >>> 26)) + b;
@ -398,14 +324,16 @@ 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) {
int index, partlen, i, start;
@ -483,8 +411,7 @@ 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.
*/
/**
@ -501,7 +428,8 @@ public class MD5 {
/**
* 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[]) {
Update(buffer, 0, buffer.length);
@ -510,7 +438,8 @@ public class MD5 {
/**
* 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) {
byte buffer[] = new byte[1];
@ -520,18 +449,15 @@ 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) {
byte chars[] = s.getBytes();
@ -539,28 +465,27 @@ public class MD5 {
}
/**
* 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";
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) {
Update((byte) (i & 0xff));
@ -583,10 +508,8 @@ 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
**/
@ -614,16 +537,13 @@ 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[]) {
@ -652,11 +572,9 @@ public class MD5 {
}
/**
* 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
**/
@ -670,7 +588,8 @@ public class MD5 {
}
private static synchronized final void _initNativeLibrary() {
if (!native_lib_init_pending) return;
if (!native_lib_init_pending)
return;
native_lib_loaded = _loadNativeLibrary();
native_lib_init_pending = false;
}
@ -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
@ -858,42 +763,52 @@ 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());
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;
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,7 +39,9 @@ public class MD5InputStream extends FilterInputStream {
/**
* Creates a MD5InputStream
* @param in The input stream
*
* @param in
* The input stream
*/
public MD5InputStream(InputStream in) {
super(in);
@ -59,6 +51,7 @@ public class MD5InputStream extends FilterInputStream {
/**
* Read a byte of data.
*
* @see java.io.FilterInputStream
*/
public int read() throws IOException {
@ -93,8 +86,8 @@ 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() {
@ -106,8 +99,7 @@ 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 {
@ -160,7 +152,8 @@ public class MD5InputStream extends FilterInputStream {
// calculate the checksum
MD5InputStream in = new MD5InputStream(new BufferedInputStream(new FileInputStream(filename)));
while ((num_read = in.read(buf)) != -1);
while ((num_read = in.read(buf)) != -1)
;
System.out.println(MD5.asHex(in.hash()) + " " + filename);
in.close();
}
@ -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,7 +40,9 @@ public class MD5OutputStream extends FilterOutputStream {
/**
* Creates MD5OutputStream
* @param out The output stream
*
* @param out
* The output stream
*/
public MD5OutputStream(OutputStream out) {
@ -81,8 +74,8 @@ public class MD5OutputStream extends FilterOutputStream {
}
/**
* 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
*/
@ -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 {
@ -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)

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

@ -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;
@ -47,8 +46,7 @@ public class FST
int[] mapping;
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,9 +192,8 @@ 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();
@ -220,19 +223,13 @@ public class FST
bytes = new byte[nBytes];
in.readFully(bytes);
if (verbose) {
System.err.println("FST ("
+ fileSize + " Bytes, "
+ nArcs + " Arcs, "
+ nPairs + " Labels)"
+ " loaded");
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
{
private void createMapping(int[] mapping, byte[] bytes, String encoding) throws UnsupportedEncodingException {
mapping[0] = 0;
int last0 = -1;
String s;
@ -240,7 +237,8 @@ public class FST
for (int i = 0; i < bytes.length; i++) {
if (bytes[i] == 0) {
len = i - last0 - 1;
if (len==0) strings.add("");
if (len == 0)
strings.add("");
else {
String str;
if (encoding != null)
@ -255,6 +253,3 @@ public class FST
}
}
}

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

@ -21,6 +21,7 @@ package marytts.fst;
/**
* A Pair of Strings.
*
* @author benjaminroth
*/
public class StringPair {
@ -45,20 +46,18 @@ public class StringPair{
}
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;
@ -76,5 +75,3 @@ public class StringPair{
return string1 + " " + string2;
}
}

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

@ -23,28 +23,20 @@ package marytts.util;
* @author Oytun T&uumlrk
*
*/
public class ConversionUtils
{
public static byte[] toByteArray(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,16 +48,11 @@ 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;
@ -77,18 +64,12 @@ public class ConversionUtils
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;
@ -100,22 +81,13 @@ public class ConversionUtils
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;
@ -127,13 +99,11 @@ public class ConversionUtils
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;
@ -145,13 +115,11 @@ public class ConversionUtils
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;
@ -163,13 +131,11 @@ public class ConversionUtils
return byts;
}
public static byte[] toByteArray(boolean data)
{
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] });
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;
@ -486,22 +387,17 @@ public class ConversionUtils
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;
}
}

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

@ -40,4 +40,3 @@ public class PrintSystemProperties {
}
}

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

@ -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,23 +67,22 @@ 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)));
/* Load the Mary header */
@ -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,11 +204,14 @@ 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 {
@ -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,15 +235,27 @@ 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 ); }
public boolean hasCurrentVersion() {
return (version == VERSION);
}
private boolean hasLegalType() {
return (type <= TIMELINE) && (type > UNKNOWN);
}
private boolean hasLegalMagic() {
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,8 +102,11 @@ 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.
@ -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,58 +25,48 @@ 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
} 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;
@ -88,12 +78,19 @@ public class Address
this.httpAddress = null;
}
public String getHost() { return host; }
public int getPort() { return port; }
public String getFullAddress() { return fullAddress; }
public String getHttpAddress() { return httpAddress; }
public String getHost() {
return host;
}
public int getPort() {
return port;
}
public String getFullAddress() {
return fullAddress;
}
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;
@ -94,18 +93,21 @@ public class BasenameList
}
/**
* 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) {
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);
/* Check if the directory exists */
@ -136,7 +138,8 @@ 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);
@ -176,7 +179,8 @@ public class BasenameList
/* Open the file */
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) {
@ -185,15 +189,15 @@ public class BasenameList
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 );
if (!(line.matches("^\\s*$")))
add(line);
}
}
/*****************/
/* OTHER METHODS */
/*****************/
@ -202,7 +206,8 @@ public class BasenameList
* Adds a basename to the list.
*/
public void add(String str) {
if ( !bList.contains( str ) ) bList.add(str);
if (!bList.contains(str))
bList.add(str);
hasChanged = true;
}
@ -210,14 +215,16 @@ public class BasenameList
* Adds an array of basenames to the list.
*/
public void add(String[] str) {
for ( int i = 0; i < str.length; i++ ) add( str[i] );
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) {
@ -228,7 +235,8 @@ public class BasenameList
/**
* 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) {
@ -252,7 +260,8 @@ public class BasenameList
*/
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) );
for (int i = fromIndex; i < toIndex; i++)
subVec.add(this.getName(i));
return (new BasenameList(this.fromDir, this.fromExt, subVec));
}
@ -280,16 +289,14 @@ public class BasenameList
}
/**
* 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);
}
/**
* 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);
@ -298,7 +305,8 @@ public class BasenameList
/**
* 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) {
@ -308,7 +316,8 @@ public class BasenameList
/**
* 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) {
@ -318,14 +327,17 @@ public class BasenameList
/**
* 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) {
/* The list cannot contain a bigger one: */
if ( bnl.getLength() > this.getLength() ) 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 );
if (!this.contains(bnl.getName(i)))
return (false);
}
return (true);
}
@ -333,13 +345,16 @@ public class BasenameList
/**
* 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 );
if (bnl.getLength() != this.getLength())
return (false);
for (int i = 0; i < bnl.getLength(); i++) {
if ( !this.contains( bnl.getName(i) ) ) return( false );
if (!this.contains(bnl.getName(i)))
return (false);
}
return (true);
}

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

@ -32,25 +32,21 @@ 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)
{
public FileFilter(String ext) {
if (ext.startsWith(".") || ext.compareTo("*.*") == 0)
extension = ext;
else
extension = "." + ext;
}
public boolean accept(File dir, String name)
{
public boolean accept(File dir, String name) {
if (extension.compareTo("*.*") == 0)
return true;
else

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

@ -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();
@ -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,18 +132,19 @@ 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);
} else {
@ -150,44 +153,43 @@ public class General
}
/**
* 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 {
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,18 +198,19 @@ 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);
} else {
@ -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,13 +238,15 @@ 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));
@ -249,19 +254,19 @@ public class General
}
/**
* 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,12 +277,12 @@ 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 {
public static short readLittleEndianShort(DataInputStream dis) throws IOException {
short bits = (short) (0x0000ff & dis.readByte());
bits |= (((short) (0x0000ff & dis.readByte())) << 8);
return bits;
@ -286,28 +291,19 @@ public class General
/**
* 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;
@ -320,15 +316,16 @@ public class General
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 */
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);
@ -337,8 +334,9 @@ public class General
/**
* 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
*/
@ -354,20 +352,23 @@ public class General
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++) {
ulaw[i] = shortToUlaw(samples[i]);
@ -377,13 +378,15 @@ 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++) {
samples[i] = ulawToShort(ulaw[i]);
@ -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,13 +406,15 @@ 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
*
@ -418,13 +424,15 @@ public class General
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
*
@ -435,18 +443,21 @@ public class General
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);
}
/**
* 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
*
@ -459,9 +470,12 @@ public class General
/**
* 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
*
@ -472,19 +486,21 @@ public class General
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);
}
/**
* 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) {
@ -495,9 +511,9 @@ 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: */
/*
* cmd = cmdLine.split( " " ); pb.command( cmd ); /* /* Launch the process:
*/
/* proc = pb.start(); */
/* Java 1.0 equivalent: */
@ -524,14 +540,12 @@ public class General
proc.waitFor();
if (proc.exitValue() != 0) {
throw new RuntimeException( task + " computation failed on file [" + baseName + "]!\n"
+ "Command line was: [" + cmdLine + "]." );
throw new RuntimeException(task + " computation failed on file [" + baseName + "]!\n" + "Command line was: ["
+ cmdLine + "].");
}
}
catch ( IOException e ) {
} catch (IOException e) {
throw new RuntimeException(task + " computation provoked an IOException on file [" + baseName + "].", e);
}
catch ( InterruptedException e ) {
} catch (InterruptedException e) {
throw new RuntimeException(task + " computation interrupted on file [" + baseName + "].", e);
}
@ -539,10 +553,13 @@ public class General
/**
* 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) {
@ -574,9 +591,9 @@ public class General
/* Java 5.0 compliant code below. */
/* Hook the command line to the process builder: */
/* cmd = cmdLine.split( " " );
pb.command( cmd ); /*
/* Launch the process: */
/*
* cmd = cmdLine.split( " " ); pb.command( cmd ); /* /* Launch the process:
*/
/* proc = pb.start(); */
/* Java 1.0 equivalent: */
@ -606,8 +623,8 @@ public class General
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
@ -616,17 +633,12 @@ public class General
batchFile.delete();
}
}
catch ( IOException e ) {
} catch (IOException e) {
throw new RuntimeException(task + " computation provoked an IOException on file [" + filedir + "].", e);
}
catch ( InterruptedException 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,14 +76,15 @@ 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
{
public static String readUTF(DataInput in) throws IOException {
return DataInputStream.readUTF(in);
}
@ -92,43 +92,45 @@ public class LEDataInputStream implements DataInput {
/**
* 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);
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);
}
@ -138,16 +140,15 @@ 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
{
public final boolean[] readBoolean(int len) throws IOException {
boolean[] ret = new boolean[len];
for (int i = 0; i < len; i++)
@ -161,16 +162,15 @@ 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
{
public final byte[] readByte(int len) throws IOException {
byte[] ret = new byte[len];
for (int i = 0; i < len; i++)
@ -184,16 +184,15 @@ 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
{
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
{
public final char[] readChar(int len) throws IOException {
char[] ret = new char[len];
for (int i = 0; i < len; i++)
@ -201,6 +200,7 @@ public class LEDataInputStream implements DataInput {
return ret;
}
/**
* Read a double. like DataInputStream.readDouble except little endian.
*
@ -208,13 +208,11 @@ public class LEDataInputStream implements DataInput {
*
* @throws IOException
*/
public final double readDouble() throws IOException
{
public final double readDouble() throws IOException {
return Double.longBitsToDouble(readLong());
}
public final double [] readDouble(int len) throws IOException
{
public final double[] readDouble(int len) throws IOException {
double[] ret = new double[len];
for (int i = 0; i < len; i++)
@ -223,8 +221,7 @@ public class LEDataInputStream implements DataInput {
return ret;
}
public final int [] readDoubleToInt(int len) throws IOException
{
public final int[] readDoubleToInt(int len) throws IOException {
int[] ret = new int[len];
for (int i = 0; i < len; i++)
@ -238,15 +235,14 @@ 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
{
public final float readFloat() throws IOException {
return Float.intBitsToFloat(readInt());
}
public final float [] readFloat(int len) throws IOException
{
public final float[] readFloat(int len) throws IOException {
float[] ret = new float[len];
for (int i = 0; i < len; i++)
@ -260,21 +256,18 @@ public class LEDataInputStream implements DataInput {
*
* @see java.io.DataInput#readFully(byte[])
*/
public final void readFully( byte ba[] ) throws IOException
{
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
{
public final void readFully(byte ba[], int off, int len) throws IOException {
dis.readFully(ba, off, len);
}
@ -283,19 +276,15 @@ 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
{
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 );
return (work[3]) << 24 | (work[2] & 0xff) << 16 | (work[1] & 0xff) << 8 | (work[0] & 0xff);
}
public final int [] readInt(int len) throws IOException
{
public final int[] readInt(int len) throws IOException {
int[] ret = new int[len];
for (int i = 0; i < len; i++)
@ -307,44 +296,33 @@ 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
{
public final long readLong() throws IOException {
dis.readFully(work, 0, 8);
return (long) ( work[ 7 ] ) << 56
|
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[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
{
public final long[] readLong(int len) throws IOException {
long[] ret = new long[len];
for (int i = 0; i < len; i++)
@ -354,21 +332,19 @@ public class LEDataInputStream implements DataInput {
}
/**
* 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
{
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
{
public final short[] readShort(int len) throws IOException {
short[] ret = new short[len];
for (int i = 0; i < len; i++)
@ -382,25 +358,22 @@ 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
{
public final int[] readUnsignedByte(int len) throws IOException {
int[] ret = new int[len];
for (int i = 0; i < len; i++)
@ -410,21 +383,20 @@ public class LEDataInputStream implements DataInput {
}
/**
* 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
{
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
{
public final int[] readUnsignedShort(int len) throws IOException {
int[] ret = new int[len];
for (int i = 0; i < len; i++)
@ -434,19 +406,19 @@ public class LEDataInputStream implements DataInput {
}
/**
* 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
{
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,99 +87,96 @@ 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 )
{
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
{
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
{
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
{
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
{
public final void writeBoolean(boolean v) throws IOException {
dis.writeBoolean(v);
}
@ -192,21 +188,21 @@ 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
{
public final void writeByte(int v) throws IOException {
dis.writeByte(v);
}
@ -218,34 +214,34 @@ 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
{
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);
@ -260,22 +256,19 @@ 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++ )
{
for (int i = 0; i < len; i++) {
writeChar(s.charAt(i));
}
}// end writeChars
@ -283,40 +276,39 @@ public class LEDataOutputStream implements DataOutput {
/**
* 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
{
public final void writeDouble(double v) throws IOException {
writeLong(Double.doubleToLongBits(v));
}
public final void writeDouble( double [] v, int startPos, int len) throws IOException
{
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
{
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;
@ -325,20 +317,20 @@ public class LEDataOutputStream implements DataOutput {
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
{
public final void writeInt(int v) throws IOException {
work[0] = (byte) v;
work[1] = (byte) (v >> 8);
work[2] = (byte) (v >> 16);
@ -354,20 +346,20 @@ 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
{
public final void writeLong(long v) throws IOException {
work[0] = (byte) v;
work[1] = (byte) (v >> 8);
work[2] = (byte) (v >> 16);
@ -387,21 +379,20 @@ 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
{
public final void writeShort(int v) throws IOException {
work[0] = (byte) v;
work[1] = (byte) (v >> 8);
dis.write(work, 0, 2);
@ -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
{
public final void writeUTF(String s) throws IOException {
dis.writeUTF(s);
}
}// end LEDataOutputStream

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

@ -31,40 +31,32 @@ 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);
}
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;
@ -72,25 +64,21 @@ public class LittleEndianBinaryReader {
return accumLong;
}
public char readChar( ) throws IOException
{
public char readChar() throws IOException {
low = inputStream.readByte() & 0xff;
high = inputStream.readByte();
return (char) (high << 8 | low);
}
public int readInt( ) throws IOException
{
public int readInt() throws IOException {
accumInt = 0;
for (shiftBy=0; shiftBy<32; shiftBy+=8 )
{
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;
@ -98,8 +86,7 @@ public class LittleEndianBinaryReader {
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;
@ -107,15 +94,12 @@ public class LittleEndianBinaryReader {
return Float.intBitsToFloat(accumInt);
}
public byte readByte( ) throws IOException
{
public byte readByte() throws IOException {
return inputStream.readByte();
}
public void close() throws IOException
{
public void close() throws IOException {
if (inputStream != null)
inputStream.close();
}
}

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

@ -25,20 +25,17 @@ 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();
@ -48,8 +45,7 @@ public class LoggingReader extends FilterReader
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,15 +41,13 @@ 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
{
public final boolean[] readBoolean(int len) throws IOException {
boolean[] ret = new boolean[len];
for (int i = 0; i < len; i++)
@ -59,8 +56,7 @@ public final class MaryRandomAccessFile extends RandomAccessFile
return ret;
}
public final boolean [] readBooleanEndian(int len) throws IOException
{
public final boolean[] readBooleanEndian(int len) throws IOException {
boolean[] ret = new boolean[len];
for (int i = 0; i < len; i++)
@ -69,15 +65,13 @@ public final class MaryRandomAccessFile extends RandomAccessFile
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
{
public final byte[] readByte(int len) throws IOException {
byte[] ret = new byte[len];
for (int i = 0; i < len; i++)
@ -86,8 +80,7 @@ public final class MaryRandomAccessFile extends RandomAccessFile
return ret;
}
public final byte [] readByteEndian(int len) throws IOException
{
public final byte[] readByteEndian(int len) throws IOException {
byte[] ret = new byte[len];
for (int i = 0; i < len; i++)
@ -96,15 +89,13 @@ public final class MaryRandomAccessFile extends RandomAccessFile
return ret;
}
public final char readCharEndian() throws IOException
{
public final char readCharEndian() throws IOException {
char c = (char) readByte();
return c;
}
public final char [] readChar(int len) throws IOException
{
public final char[] readChar(int len) throws IOException {
char[] ret = new char[len];
for (int i = 0; i < len; i++)
@ -113,8 +104,7 @@ public final class MaryRandomAccessFile extends RandomAccessFile
return ret;
}
public final char [] readCharEndian(int len) throws IOException
{
public final char[] readCharEndian(int len) throws IOException {
char[] ret = new char[len];
for (int i = 0; i < len; i++)
@ -123,15 +113,13 @@ public final class MaryRandomAccessFile extends RandomAccessFile
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
{
public final double[] readDouble(int len) throws IOException {
double[] ret = new double[len];
for (int i = 0; i < len; i++)
@ -140,8 +128,7 @@ public final class MaryRandomAccessFile extends RandomAccessFile
return ret;
}
public final double [] readDoubleEndian(int len) throws IOException
{
public final double[] readDoubleEndian(int len) throws IOException {
double[] ret = new double[len];
for (int i = 0; i < len; i++)
@ -150,15 +137,13 @@ public final class MaryRandomAccessFile extends RandomAccessFile
return ret;
}
public final int readDoubleToIntEndian() throws IOException
{
public final int readDoubleToIntEndian() throws IOException {
int ret = (int) readDouble();
return ret;
}
public final int [] readDoubleToInt(int len) throws IOException
{
public final int[] readDoubleToInt(int len) throws IOException {
int[] ret = new int[len];
for (int i = 0; i < len; i++)
@ -167,8 +152,7 @@ public final class MaryRandomAccessFile extends RandomAccessFile
return ret;
}
public final int [] readDoubleToIntEndian(int len) throws IOException
{
public final int[] readDoubleToIntEndian(int len) throws IOException {
int[] ret = new int[len];
for (int i = 0; i < len; i++)
@ -177,15 +161,13 @@ public final class MaryRandomAccessFile extends RandomAccessFile
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
{
public final float[] readFloat(int len) throws IOException {
float[] ret = new float[len];
for (int i = 0; i < len; i++)
@ -194,8 +176,7 @@ public final class MaryRandomAccessFile extends RandomAccessFile
return ret;
}
public final float [] readFloatEndian(int len) throws IOException
{
public final float[] readFloatEndian(int len) throws IOException {
float[] ret = new float[len];
for (int i = 0; i < len; i++)
@ -204,15 +185,13 @@ public final class MaryRandomAccessFile extends RandomAccessFile
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
{
public final int[] readInt(int len) throws IOException {
int[] ret = new int[len];
for (int i = 0; i < len; i++)
@ -221,8 +200,7 @@ public final class MaryRandomAccessFile extends RandomAccessFile
return ret;
}
public final int [] readIntEndian(int len) throws IOException
{
public final int[] readIntEndian(int len) throws IOException {
int[] ret = new int[len];
for (int i = 0; i < len; i++)
@ -231,15 +209,13 @@ public final class MaryRandomAccessFile extends RandomAccessFile
return ret;
}
public final long readLongEndian() throws IOException
{
public final long readLongEndian() throws IOException {
long ret = (long) readInt();
return ret;
}
public final long [] readLong(int len) throws IOException
{
public final long[] readLong(int len) throws IOException {
long[] ret = new long[len];
for (int i = 0; i < len; i++)
@ -248,8 +224,7 @@ public final class MaryRandomAccessFile extends RandomAccessFile
return ret;
}
public final long [] readLongEndian(int len) throws IOException
{
public final long[] readLongEndian(int len) throws IOException {
long[] ret = new long[len];
for (int i = 0; i < len; i++)
@ -258,15 +233,13 @@ public final class MaryRandomAccessFile extends RandomAccessFile
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
{
public final short[] readShort(int len) throws IOException {
short[] ret = new short[len];
for (int i = 0; i < len; i++)
@ -275,8 +248,7 @@ public final class MaryRandomAccessFile extends RandomAccessFile
return ret;
}
public final short [] readShortEndian(int len) throws IOException
{
public final short[] readShortEndian(int len) throws IOException {
short[] ret = new short[len];
for (int i = 0; i < len; i++)
@ -285,15 +257,13 @@ public final class MaryRandomAccessFile extends RandomAccessFile
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
{
public final int[] readUnsignedByte(int len) throws IOException {
int[] ret = new int[len];
for (int i = 0; i < len; i++)
@ -302,8 +272,7 @@ public final class MaryRandomAccessFile extends RandomAccessFile
return ret;
}
public final int [] readUnsignedByteEndian(int len) throws IOException
{
public final int[] readUnsignedByteEndian(int len) throws IOException {
int[] ret = new int[len];
for (int i = 0; i < len; i++)
@ -312,15 +281,13 @@ public final class MaryRandomAccessFile extends RandomAccessFile
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
{
public final int[] readUnsignedShort(int len) throws IOException {
int[] ret = new int[len];
for (int i = 0; i < len; i++)
@ -329,8 +296,7 @@ public final class MaryRandomAccessFile extends RandomAccessFile
return ret;
}
public final int [] readUnsignedShortEndian(int len) throws IOException
{
public final int[] readUnsignedShortEndian(int len) throws IOException {
int[] ret = new int[len];
for (int i = 0; i < len; i++)
@ -339,8 +305,7 @@ public final class MaryRandomAccessFile extends RandomAccessFile
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,18 +353,15 @@ 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
{
public final void writeCharEndian(char c) throws IOException {
writeByte((byte) c);
}
@ -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
{
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
{
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,18 +459,15 @@ 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
{
public final void writeLongEndian(long v) throws IOException {
writeInt((int) v);
}
@ -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
*

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

@ -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 getExtension() { return extension; }
public String getDescription() {
return description;
}
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)
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,8 +38,7 @@ import java.nio.ByteBuffer;
*/
public class StreamUtils {
public static double[] readDoubleArray(DataInput stream, int len)
throws IOException {
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));
@ -50,7 +49,6 @@ public class StreamUtils {
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 {
@ -95,7 +90,8 @@ public class StreamUtils {
while (count < utflen) {
c = (int) bytearr[count] & 0xff;
if (c > 127) break;
if (c > 127)
break;
count++;
chararr[chararr_count++] = (char) c;
}
@ -103,43 +99,43 @@ public class StreamUtils {
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:
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
/* 0xxxxxxx */
count++;
chararr[chararr_count++] = (char) c;
break;
case 12: case 13:
case 12:
case 13:
/* 110x xxxx 10xx xxxx */
count += 2;
if (count > utflen)
throw new UTFDataFormatException(
"malformed input: partial character at end");
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");
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 {