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.
@ -27,33 +23,37 @@ import java.io.OutputStream;
public class NullOutputStream extends OutputStream {
private boolean closed = false;
private boolean closed = false;
public NullOutputStream() {
}
public NullOutputStream() {
}
public void close() {
this.closed = true;
}
public void close() {
this.closed = true;
}
public void flush() throws IOException {
if (this.closed) _throwClosed();
}
public void flush() throws IOException {
if (this.closed)
_throwClosed();
}
private void _throwClosed() throws IOException {
throw new IOException("This OutputStream has been closed");
}
private void _throwClosed() throws IOException {
throw new IOException("This OutputStream has been closed");
}
public void write(byte[] b) throws IOException {
if (this.closed) _throwClosed();
}
public void write(byte[] b) throws IOException {
if (this.closed)
_throwClosed();
}
public void write(byte[] b, int offset, int len) throws IOException {
if (this.closed) _throwClosed();
}
public void write(byte[] b, int offset, int len) throws IOException {
if (this.closed)
_throwClosed();
}
public void write(int b) throws IOException {
if (this.closed) _throwClosed();
}
public void write(int b) throws IOException {
if (this.closed)
_throwClosed();
}
}

Разница между файлами не показана из-за своего большого размера Загрузить разницу

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

@ -7,167 +7,159 @@ 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)
* @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
*/
private MD5 md5;
/**
* MD5 context
*/
private MD5 md5;
/**
* Creates a MD5InputStream
* @param in The input stream
*/
public MD5InputStream (InputStream in) {
super(in);
/**
* Creates a MD5InputStream
*
* @param in
* The input stream
*/
public MD5InputStream(InputStream in) {
super(in);
md5 = new MD5();
}
/**
* Read a byte of data.
* @see java.io.FilterInputStream
*/
public int read() throws IOException {
int c = in.read();
if (c == -1)
return -1;
if ((c & ~0xff) != 0) {
System.out.println("MD5InputStream.read() got character with (c & ~0xff) != 0)!");
} else {
md5.Update(c);
}
return c;
}
/**
* Reads into an array of bytes.
*
* @see java.io.FilterInputStream
*/
public int read (byte bytes[], int offset, int length) throws IOException {
int r;
if ((r = in.read(bytes, offset, length)) == -1)
return r;
md5.Update(bytes, offset, r);
return r;
}
/**
* Returns array of bytes representing hash of the stream as
* finalized for the current state.
* @see MD5#Final
*/
public byte[] hash () {
return md5.Final();
}
public MD5 getMD5() {
return md5;
}
/**
* This method is here for testing purposes only - do not rely
* on it being here.
**/
public static void main(String[] arg) {
try {
////////////////////////////////////////////////////////////////
//
// usage: java com.twmacinta.util.MD5InputStream [--use-default-md5] [--no-native-lib] filename
//
/////////
// determine the filename to use and the MD5 impelementation to use
String filename = arg[arg.length-1];
boolean use_default_md5 = false;
boolean use_native_lib = true;
for (int i = 0; i < arg.length-1; i++) {
if (arg[i].equals("--use-default-md5")) {
use_default_md5 = true;
} else if (arg[i].equals("--no-native-lib")) {
use_native_lib = false;
}
}
// initialize common variables
byte[] buf = new byte[65536];
int num_read;
// Use the default MD5 implementation that comes with Java
if (use_default_md5) {
InputStream in = new BufferedInputStream(new FileInputStream(filename));
java.security.MessageDigest digest = java.security.MessageDigest.getInstance("MD5");
while ((num_read = in.read(buf)) != -1) {
digest.update(buf, 0, num_read);
}
System.out.println(MD5.asHex(digest.digest())+" "+filename);
in.close();
// Use the optimized MD5 implementation
} else {
// disable the native library search, if requested
if (!use_native_lib) {
MD5.initNativeLibrary(true);
md5 = new MD5();
}
// calculate the checksum
/**
* Read a byte of data.
*
* @see java.io.FilterInputStream
*/
public int read() throws IOException {
int c = in.read();
MD5InputStream in = new MD5InputStream(new BufferedInputStream(new FileInputStream(filename)));
while ((num_read = in.read(buf)) != -1);
System.out.println(MD5.asHex(in.hash())+" "+filename);
in.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
if (c == -1)
return -1;
if ((c & ~0xff) != 0) {
System.out.println("MD5InputStream.read() got character with (c & ~0xff) != 0)!");
} else {
md5.Update(c);
}
return c;
}
/**
* Reads into an array of bytes.
*
* @see java.io.FilterInputStream
*/
public int read(byte bytes[], int offset, int length) throws IOException {
int r;
if ((r = in.read(bytes, offset, length)) == -1)
return r;
md5.Update(bytes, offset, r);
return r;
}
/**
* Returns array of bytes representing hash of the stream as finalized for the current state.
*
* @see MD5#Final
*/
public byte[] hash() {
return md5.Final();
}
public MD5 getMD5() {
return md5;
}
/**
* This method is here for testing purposes only - do not rely on it being here.
**/
public static void main(String[] arg) {
try {
// //////////////////////////////////////////////////////////////
//
// usage: java com.twmacinta.util.MD5InputStream [--use-default-md5] [--no-native-lib] filename
//
// ///////
// determine the filename to use and the MD5 impelementation to use
String filename = arg[arg.length - 1];
boolean use_default_md5 = false;
boolean use_native_lib = true;
for (int i = 0; i < arg.length - 1; i++) {
if (arg[i].equals("--use-default-md5")) {
use_default_md5 = true;
} else if (arg[i].equals("--no-native-lib")) {
use_native_lib = false;
}
}
// initialize common variables
byte[] buf = new byte[65536];
int num_read;
// Use the default MD5 implementation that comes with Java
if (use_default_md5) {
InputStream in = new BufferedInputStream(new FileInputStream(filename));
java.security.MessageDigest digest = java.security.MessageDigest.getInstance("MD5");
while ((num_read = in.read(buf)) != -1) {
digest.update(buf, 0, num_read);
}
System.out.println(MD5.asHex(digest.digest()) + " " + filename);
in.close();
// Use the optimized MD5 implementation
} else {
// disable the native library search, if requested
if (!use_native_lib) {
MD5.initNativeLibrary(true);
}
// calculate the checksum
MD5InputStream in = new MD5InputStream(new BufferedInputStream(new FileInputStream(filename)));
while ((num_read = in.read(buf)) != -1)
;
System.out.println(MD5.asHex(in.hash()) + " " + filename);
in.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}

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

@ -8,115 +8,105 @@ 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)
* @author Santeri Paavolainen <santtu@cs.hut.fi>
* @author Timothy W Macinta (twm@alum.mit.edu) (added main() method)
**/
public class MD5OutputStream extends FilterOutputStream {
/**
* MD5 context
*/
private MD5 md5;
/**
* MD5 context
*/
private MD5 md5;
/**
* Creates MD5OutputStream
* @param out The output stream
*/
/**
* Creates MD5OutputStream
*
* @param out
* The output stream
*/
public MD5OutputStream (OutputStream out) {
super(out);
public MD5OutputStream(OutputStream out) {
super(out);
md5 = new MD5();
}
md5 = new MD5();
}
/**
* Writes a byte.
*
* @see java.io.FilterOutputStream
*/
/**
* Writes a byte.
*
* @see java.io.FilterOutputStream
*/
public void write (int b) throws IOException {
out.write(b);
md5.Update((byte) b);
}
public void write(int b) throws IOException {
out.write(b);
md5.Update((byte) b);
}
/**
* Writes a sub array of bytes.
*
* @see java.io.FilterOutputStream
*/
/**
* Writes a sub array of bytes.
*
* @see java.io.FilterOutputStream
*/
public void write (byte b[], int off, int len) throws IOException {
out.write(b, off, len);
md5.Update(b, off, len);
}
public void write(byte b[], int off, int len) throws IOException {
out.write(b, off, len);
md5.Update(b, off, len);
}
/**
* Returns array of bytes representing hash of the stream as finalized
* for the current state.
* @see MD5#Final
*/
/**
* Returns array of bytes representing hash of the stream as finalized for the current state.
*
* @see MD5#Final
*/
public byte[] hash () {
return md5.Final();
}
public byte[] hash() {
return md5.Final();
}
public MD5 getMD5() {
return md5;
}
/**
* This method is here for testing purposes only - do not rely
* on it being here.
**/
public static void main(String[] arg) {
try {
MD5OutputStream out = new MD5OutputStream(new com.twmacinta.io.NullOutputStream());
InputStream in = new BufferedInputStream(new FileInputStream(arg[0]));
byte[] buf = new byte[65536];
int num_read;
long total_read = 0;
while ((num_read = in.read(buf)) != -1) {
total_read += num_read;
out.write(buf, 0, num_read);
}
System.out.println(MD5.asHex(out.hash())+" "+arg[0]);
in.close();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public MD5 getMD5() {
return md5;
}
/**
* This method is here for testing purposes only - do not rely on it being here.
**/
public static void main(String[] arg) {
try {
MD5OutputStream out = new MD5OutputStream(new com.twmacinta.io.NullOutputStream());
InputStream in = new BufferedInputStream(new FileInputStream(arg[0]));
byte[] buf = new byte[65536];
int num_read;
long total_read = 0;
while ((num_read = in.read(buf)) != -1) {
total_read += num_read;
out.write(buf, 0, num_read);
}
System.out.println(MD5.asHex(out.hash()) + " " + arg[0]);
in.close();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}

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

@ -6,74 +6,66 @@ 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)
* @author Santeri Paavolainen <sjpaavol@cc.helsinki.fi>
* @author Timothy W Macinta (twm@alum.mit.edu) (optimizations and bug fixes)
**/
class MD5State {
/**
* 128-bit state
*/
int state[];
/**
* 128-bit state
*/
int state[];
/**
* 64-bit character count
*/
long count;
/**
* 64-bit character count
*/
long count;
/**
* 64-byte buffer (512 bits) for storing to-be-hashed characters
*/
byte buffer[];
/**
* 64-byte buffer (512 bits) for storing to-be-hashed characters
*/
byte buffer[];
public MD5State() {
buffer = new byte[64];
count = 0;
state = new int[4];
public MD5State() {
buffer = new byte[64];
count = 0;
state = new int[4];
state[0] = 0x67452301;
state[1] = 0xefcdab89;
state[2] = 0x98badcfe;
state[3] = 0x10325476;
state[0] = 0x67452301;
state[1] = 0xefcdab89;
state[2] = 0x98badcfe;
state[3] = 0x10325476;
}
}
/** Create this State as a copy of another state */
public MD5State (MD5State from) {
this();
/** Create this State as a copy of another state */
public MD5State(MD5State from) {
this();
int i;
int i;
for (i = 0; i < buffer.length; i++)
this.buffer[i] = from.buffer[i];
for (i = 0; i < buffer.length; i++)
this.buffer[i] = from.buffer[i];
for (i = 0; i < state.length; i++)
this.state[i] = from.state[i];
for (i = 0; i < state.length; i++)
this.state[i] = from.state[i];
this.count = from.count;
}
this.count = from.count;
}
};

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

@ -24,50 +24,48 @@ import java.io.InputStream;
import marytts.util.io.FileUtils;
/**
* Provide Version information for the Mary server and client.
*
* @author Marc Schr&ouml;der
*
*/
public class Version {
private static String specificationVersion;
private static String implementationVersion;
private static String specificationVersion;
private static String implementationVersion;
static {
InputStream specVersionStream = Version.class.
getResourceAsStream("specification-version.txt");
if (specVersionStream != null) {
try {
specificationVersion = FileUtils.getStreamAsString(specVersionStream, "UTF-8").trim();
} catch (IOException e) {
specificationVersion = "undeterminable";
}
} else {
specificationVersion = "unknown";
}
static {
InputStream specVersionStream = Version.class.getResourceAsStream("specification-version.txt");
if (specVersionStream != null) {
try {
specificationVersion = FileUtils.getStreamAsString(specVersionStream, "UTF-8").trim();
} catch (IOException e) {
specificationVersion = "undeterminable";
}
} else {
specificationVersion = "unknown";
}
InputStream implVersionStream = Version.class.
getResourceAsStream("implementation-version.txt");
if (implVersionStream != null) {
try {
implementationVersion = FileUtils.getStreamAsString(implVersionStream, "UTF-8").trim();
} catch (IOException e) {
implementationVersion = "undeterminable";
}
} else {
implementationVersion = "unknown";
}
}
InputStream implVersionStream = Version.class.getResourceAsStream("implementation-version.txt");
if (implVersionStream != null) {
try {
implementationVersion = FileUtils.getStreamAsString(implVersionStream, "UTF-8").trim();
} catch (IOException e) {
implementationVersion = "undeterminable";
}
} else {
implementationVersion = "unknown";
}
}
/** Specification version */
public static String specificationVersion() {
return specificationVersion;
}
/** Implementation version */
public static String implementationVersion() {
return implementationVersion;
}
/** Specification 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()
{
super();
}
public ExecutionException(String message)
{
super(message);
}
public ExecutionException(String message, Throwable cause)
{
super(message, cause);
}
public ExecutionException(Throwable cause)
{
super(cause);
}
public class ExecutionException extends Exception {
public ExecutionException() {
super();
}
public ExecutionException(String message) {
super(message);
}
public ExecutionException(String message, Throwable cause) {
super(message, 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
{
/**
* 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)
{
super(message);
}
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.
*/
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.
*/
public MaryConfigurationException(String message, Throwable cause)
{
super(message, cause);
}
/**
* 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) {
super(message, cause);
}
}

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

@ -22,15 +22,15 @@ package marytts.exceptions;
/**
* @author Marc Schr&ouml;der
*
* Thrown by MaryProperties if a property is needed but cannot be found.
* Thrown by MaryProperties if a property is needed but cannot be found.
*/
public class NoSuchPropertyException extends RuntimeException {
public NoSuchPropertyException(String message) {
super(message);
}
public NoSuchPropertyException(String message, Throwable cause) {
super(message, cause);
}
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()
{
super();
}
public SynthesisException(String message)
{
super(message);
}
public SynthesisException(String message, Throwable cause)
{
super(message, cause);
}
public SynthesisException(Throwable cause)
{
super(cause);
}
public class SynthesisException extends Exception {
public SynthesisException() {
super();
}
public SynthesisException(String message) {
super(message);
}
public SynthesisException(String message, Throwable cause) {
super(message, cause);
}
public SynthesisException(Throwable cause) {
super(cause);
}
}

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

@ -29,107 +29,111 @@ 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
{
// The following variables are package-readable, so that they can be
// directly accessed by all classes in this package.
int[] targets;
short[] labels;
boolean[] isLast;
public class FST {
// The following variables are package-readable, so that they can be
// directly accessed by all classes in this package.
int[] targets;
short[] labels;
boolean[] isLast;
short[] offsets;
byte[] bytes;
int[] mapping;
ArrayList strings=new ArrayList();
short[] offsets;
byte[] bytes;
int[] mapping;
ArrayList strings = new ArrayList();
public FST(String fileName) throws IOException
{
FileInputStream fis = new FileInputStream(fileName);
try {
load(fis);
} finally {
fis.close();
}
}
public FST(String fileName) throws IOException {
FileInputStream fis = new FileInputStream(fileName);
try {
load(fis);
} finally {
fis.close();
}
}
/**
* Load the fst from the given input stream. Assumes header.
* @param inStream
* @throws IOException
*/
public FST(InputStream inStream) throws IOException {
load(inStream);
}
/**
* Load the fst from the given input stream. Assumes header.
*
* @param inStream
* @throws IOException
*/
public FST(InputStream inStream) throws IOException {
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.
*/
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.
*/
public FST(String fileName, boolean verbose) throws IOException {
this(fileName, null, verbose);
}
/**
* 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.
*/
public FST(String fileName, String encoding)
throws IOException, UnsupportedEncodingException
{
this(fileName, encoding, false);
}
/**
* 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 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 {
FileInputStream fis = new FileInputStream(fileName);
try {
loadHeaderless(fis, encoding, verbose);
} finally {
fis.close();
}
}
/**
* 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
{
this(fileName, null, verbose);
}
/**
* Load the fst from the given input stream. Assumes headerless legacy file format.
*
* @param inStream
* @param encoding
* @throws IOException
* @throws UnsupportedEncodingException
*/
public FST(InputStream inStream, String encoding) throws IOException, UnsupportedEncodingException {
loadHeaderless(inStream, encoding, false);
}
/**
* 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 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
{
FileInputStream fis = new FileInputStream(fileName);
try {
loadHeaderless(fis, encoding, verbose);
} finally {
fis.close();
}
}
/**
* Load the fst from the given input stream. Assumes headerless legacy file format.
* @param inStream
* @param encoding
* @throws IOException
* @throws UnsupportedEncodingException
*/
public FST(InputStream inStream, String encoding) throws IOException, UnsupportedEncodingException {
loadHeaderless(inStream, encoding, false);
}
private void load(InputStream inStream)
private void load(InputStream inStream)
throws IOException, UnsupportedEncodingException
{
int i;
@ -188,73 +192,64 @@ public class FST
createMapping(mapping, bytes, encoding);
}
private void loadHeaderless(InputStream inStream, String encoding, boolean verbose)
throws IOException, UnsupportedEncodingException
{
int i;
DataInputStream in = new DataInputStream(new BufferedInputStream(inStream));
//int fileSize= (int) f.length();
int fileSize = in.available(); // TODO: how robust is this??
int nArcs=in.readInt();
// arcs = new int[nArcs];
private void loadHeaderless(InputStream inStream, String encoding, boolean verbose) throws IOException,
UnsupportedEncodingException {
int i;
DataInputStream in = new DataInputStream(new BufferedInputStream(inStream));
// int fileSize= (int) f.length();
int fileSize = in.available(); // TODO: how robust is this??
int nArcs = in.readInt();
// arcs = new int[nArcs];
targets = new int[nArcs];
labels = new short[nArcs];
isLast = new boolean[nArcs];
targets = new int[nArcs];
labels = new short[nArcs];
isLast = new boolean[nArcs];
for(i=0; i<nArcs; i++) {
int thisArc = in.readInt();
for (i = 0; i < nArcs; i++) {
int thisArc = in.readInt();
targets[i]= thisArc&1048575;
labels[i]=(short)((thisArc>>20) & 2047);
isLast[i]=((byte)(thisArc >> 31))!=0;
targets[i] = thisArc & 1048575;
labels[i] = (short) ((thisArc >> 20) & 2047);
isLast[i] = ((byte) (thisArc >> 31)) != 0;
}
}
int nPairs=in.readInt();
offsets = new short[2*nPairs];
for(i=0; i<2*nPairs; i++)
offsets[i] = in.readShort();
int nBytes = fileSize - 8 - 4 * (nPairs + nArcs);
mapping=new int[nBytes];
bytes = new byte[nBytes];
in.readFully(bytes);
if(verbose) {
System.err.println("FST ("
+ fileSize + " Bytes, "
+ nArcs + " Arcs, "
+ nPairs + " Labels)"
+ " loaded");
}
in.close();
createMapping(mapping, bytes, encoding);
}
int nPairs = in.readInt();
offsets = new short[2 * nPairs];
for (i = 0; i < 2 * nPairs; i++)
offsets[i] = in.readShort();
int nBytes = fileSize - 8 - 4 * (nPairs + nArcs);
mapping = new int[nBytes];
bytes = new byte[nBytes];
in.readFully(bytes);
if (verbose) {
System.err.println("FST (" + fileSize + " Bytes, " + nArcs + " Arcs, " + nPairs + " Labels)" + " loaded");
}
in.close();
createMapping(mapping, bytes, encoding);
}
private void createMapping(int[] mapping, byte[] bytes, String encoding)
throws UnsupportedEncodingException
{
mapping[0]=0;
int last0=-1;
String s;
int len;
for (int i=0;i<bytes.length;i++) {
if (bytes[i]==0) {
len=i-last0-1;
if (len==0) strings.add("");
else {
String str;
if (encoding != null)
str = new String(bytes, last0+1, len, encoding);
else
str = new String(bytes, last0+1, len);
strings.add(str);
}
mapping[last0+1]=strings.size()-1;
last0=i;
}
}
}
private void createMapping(int[] mapping, byte[] bytes, String encoding) throws UnsupportedEncodingException {
mapping[0] = 0;
int last0 = -1;
String s;
int len;
for (int i = 0; i < bytes.length; i++) {
if (bytes[i] == 0) {
len = i - last0 - 1;
if (len == 0)
strings.add("");
else {
String str;
if (encoding != null)
str = new String(bytes, last0 + 1, len, encoding);
else
str = new String(bytes, last0 + 1, len);
strings.add(str);
}
mapping[last0 + 1] = strings.size() - 1;
last0 = i;
}
}
}
}

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

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

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

@ -23,177 +23,144 @@ package marytts.util;
* @author Oytun T&uumlrk
*
*/
public class ConversionUtils
{
public static byte[] toByteArray(byte byteArray)
{
return new byte[]{byteArray};
}
public class ConversionUtils {
public static byte[] toByteArray(byte byteArray) {
return new byte[] { byteArray };
}
public static byte[] toByteArray(byte[] byteArray)
{
return 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)
{
if (data == null)
return null;
public static byte[] toByteArray(short[] data) {
if (data == null)
return null;
byte[] byts = new byte[data.length * 2];
byte[] byts = new byte[data.length * 2];
for (int i = 0; i < data.length; i++)
System.arraycopy(toByteArray(data[i]), 0, byts, i * 2, 2);
for (int i = 0; i < data.length; i++)
System.arraycopy(toByteArray(data[i]), 0, byts, i * 2, 2);
return byts;
}
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)
{
if (data == null)
return null;
public static byte[] toByteArray(char[] data) {
if (data == null)
return null;
byte[] byts = new byte[data.length * 2];
byte[] byts = new byte[data.length * 2];
for (int i = 0; i < data.length; i++)
System.arraycopy(toByteArray(data[i]), 0, byts, i*2, 2);
for (int i = 0; i < data.length; i++)
System.arraycopy(toByteArray(data[i]), 0, byts, i * 2, 2);
return byts;
}
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)
{
if (data == null)
return null;
public static byte[] toByteArray(int[] data) {
if (data == null)
return null;
byte[] byts = new byte[data.length*4];
byte[] byts = new byte[data.length * 4];
for (int i = 0; i < data.length; i++)
System.arraycopy(toByteArray(data[i]), 0, byts, i*4, 4);
for (int i = 0; i < data.length; i++)
System.arraycopy(toByteArray(data[i]), 0, byts, i * 4, 4);
return byts;
}
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)
{
if (data == null)
return null;
public static byte[] toByteArray(long[] data) {
if (data == null)
return null;
byte[] byts = new byte[data.length*8];
byte[] byts = new byte[data.length * 8];
for (int i = 0; i < data.length; i++)
System.arraycopy(toByteArray(data[i]), 0, byts, i*8, 8);
for (int i = 0; i < data.length; i++)
System.arraycopy(toByteArray(data[i]), 0, byts, i * 8, 8);
return byts;
}
return byts;
}
public static byte[] toByteArray(float data)
{
return toByteArray(Float.floatToRawIntBits(data));
}
public static byte[] toByteArray(float data) {
return toByteArray(Float.floatToRawIntBits(data));
}
public static byte[] toByteArray(float[] data)
{
if (data == null)
return null;
public static byte[] toByteArray(float[] data) {
if (data == null)
return null;
byte[] byts = new byte[data.length*4];
byte[] byts = new byte[data.length * 4];
for (int i = 0; i < data.length; i++)
System.arraycopy(toByteArray(data[i]), 0, byts, i*4, 4);
for (int i = 0; i < data.length; i++)
System.arraycopy(toByteArray(data[i]), 0, byts, i * 4, 4);
return byts;
}
return byts;
}
public static byte[] toByteArray(double data)
{
return toByteArray(Double.doubleToRawLongBits(data));
}
public static byte[] toByteArray(double data) {
return toByteArray(Double.doubleToRawLongBits(data));
}
public static byte[] toByteArray(double[] data)
{
if (data == null)
return null;
public static byte[] toByteArray(double[] data) {
if (data == null)
return null;
byte[] byts = new byte[data.length*8];
byte[] byts = new byte[data.length * 8];
for (int i = 0; i < data.length; i++)
System.arraycopy(toByteArray(data[i]), 0, byts, i*8, 8);
for (int i = 0; i < data.length; i++)
System.arraycopy(toByteArray(data[i]), 0, byts, i * 8, 8);
return byts;
}
return byts;
}
public static byte[] toByteArray(boolean data)
{
return new byte[]{(byte)(data ? 0x01 : 0x00)};
}
public static byte[] toByteArray(boolean data) {
return new byte[] { (byte) (data ? 0x01 : 0x00) };
}
public static byte[] toByteArray(boolean[] data)
{
if (data == null)
return null;
public static byte[] toByteArray(boolean[] data) {
if (data == null)
return null;
int len = data.length;
byte[] lena = toByteArray(len);
byte[] byts = new byte[lena.length + (len / 8) + (len % 8 != 0 ? 1 : 0)];
int len = data.length;
byte[] lena = toByteArray(len);
byte[] byts = new byte[lena.length + (len / 8) + (len % 8 != 0 ? 1 : 0)];
System.arraycopy(lena, 0, byts, 0, lena.length);
System.arraycopy(lena, 0, byts, 0, lena.length);
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; }
}
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;
}
}
return byts;
}
return byts;
}
public static byte[] toByteArray(String data)
{
return (data == null) ? null : data.getBytes();
}
public static byte[] toByteArray(String data) {
return (data == null) ? null : data.getBytes();
}
public static byte[] toByteArray(String[] data)
public static byte[] toByteArray(String[] data)
{
if (data == null)
return null;
@ -240,268 +207,197 @@ public class ConversionUtils
return bytes;
}
public static byte toByte(byte[] byteArray)
{
return (byteArray == null || byteArray.length == 0) ? 0x0 : byteArray[0];
}
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;
// ----------
return (short)(
(0xff & byteArray[0]) << 8 |
(0xff & byteArray[1]) << 0
);
}
public static short toShort(byte[] byteArray) {
if (byteArray == null || byteArray.length != 2)
return 0x0;
// ----------
return (short) ((0xff & byteArray[0]) << 8 | (0xff & byteArray[1]) << 0);
}
public static short[] toShortArray(byte[] byteArray)
{
if (byteArray == null || byteArray.length % 2 != 0)
return null;
public static short[] toShortArray(byte[] byteArray) {
if (byteArray == null || byteArray.length % 2 != 0)
return null;
short[] shts = new short[byteArray.length / 2];
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;
}
return shts;
}
public static char toChar(byte[] byteArray)
{
if (byteArray == null || byteArray.length != 2)
return 0x0;
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)
{
if (byteArray == null || byteArray.length % 2 != 0)
return null;
public static char[] toCharArray(byte[] byteArray) {
if (byteArray == null || byteArray.length % 2 != 0)
return null;
char[] chrs = new char[byteArray.length / 2];
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;
}
return chrs;
}
public static int toInt(byte[] byteArray)
{
if (byteArray == null || byteArray.length != 4)
return 0x0;
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)
{
if (byteArray == null || byteArray.length % 4 != 0)
return null;
public static int[] toIntArray(byte[] byteArray) {
if (byteArray == null || byteArray.length % 4 != 0)
return null;
int[] ints = new int[byteArray.length / 4];
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;
}
return ints;
}
public static long toLong(byte[] byteArray)
{
if (byteArray == null || byteArray.length != 8)
return 0x0;
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)
{
if (byteArray == null || byteArray.length % 8 != 0)
return null;
public static long[] toLongArray(byte[] byteArray) {
if (byteArray == null || byteArray.length % 8 != 0)
return null;
long[] lngs = new long[byteArray.length / 8];
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;
}
return lngs;
}
public static float toFloat(byte[] byteArray)
{
if (byteArray == null || byteArray.length != 4)
return 0x0;
public static float toFloat(byte[] byteArray) {
if (byteArray == null || byteArray.length != 4)
return 0x0;
return Float.intBitsToFloat(toInt(byteArray));
}
return Float.intBitsToFloat(toInt(byteArray));
}
public static float[] toFloatArray(byte[] byteArray)
{
if (byteArray == null || byteArray.length % 4 != 0)
return null;
public static float[] toFloatArray(byte[] byteArray) {
if (byteArray == null || byteArray.length % 4 != 0)
return null;
float[] flts = new float[byteArray.length / 4];
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;
}
return flts;
}
public static double toDouble(byte[] byteArray)
{
if (byteArray == null || byteArray.length != 8)
return 0x0;
public static double toDouble(byte[] byteArray) {
if (byteArray == null || byteArray.length != 8)
return 0x0;
return Double.longBitsToDouble(toLong(byteArray));
}
return Double.longBitsToDouble(toLong(byteArray));
}
public static double[] toDoubleArray(byte[] byteArray)
{
if (byteArray == null)
return null;
public static double[] toDoubleArray(byte[] byteArray) {
if (byteArray == null)
return null;
if (byteArray.length % 8 != 0)
return null;
if (byteArray.length % 8 != 0)
return null;
double[] dbls = new double[byteArray.length / 8];
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;
}
return dbls;
}
public static boolean toBoolean(byte[] byteArray)
{
return (byteArray == null || byteArray.length == 0) ? false : byteArray[0] != 0x00;
}
public static boolean toBoolean(byte[] byteArray) {
return (byteArray == null || byteArray.length == 0) ? false : byteArray[0] != 0x00;
}
public static boolean[] toBooleanArray(byte[] byteArray)
{
if (byteArray == null || byteArray.length < 4)
return null;
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];
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++)
{
bools[i] = ((byteArray[j] >> k--) & 0x01) == 1;
if (k < 0) { j++; k = 7; }
}
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;
}
}
return bools;
}
return bools;
}
public static String toString(byte[] byteArray)
{
return (byteArray == null) ? null : new String(byteArray);
}
public static String toString(byte[] byteArray) {
return (byteArray == null) ? null : new String(byteArray);
}
public static String[] toStringArray(byte[] byteArray)
{
if (byteArray == null || byteArray.length < 4)
return null;
public static String[] toStringArray(byte[] byteArray) {
if (byteArray == null || byteArray.length < 4)
return null;
byte[] bBuff = new byte[4];
byte[] bBuff = new byte[4];
System.arraycopy(byteArray, 0, bBuff, 0, 4);
int saLen = toInt(bBuff);
System.arraycopy(byteArray, 0, bBuff, 0, 4);
int saLen = toInt(bBuff);
if (byteArray.length < (4 + (saLen * 4)))
return null;
if (byteArray.length < (4 + (saLen * 4)))
return null;
bBuff = new byte[saLen*4];
System.arraycopy(byteArray, 4, bBuff, 0, bBuff.length);
int[] sLens = toIntArray(bBuff);
if (sLens == null)
return null;
bBuff = new byte[saLen * 4];
System.arraycopy(byteArray, 4, bBuff, 0, bBuff.length);
int[] sLens = toIntArray(bBuff);
if (sLens == null)
return null;
String[] strs = new String[saLen];
for (int i=0, dataPos=4+(saLen*4); i<saLen; i++)
{
if (sLens[i] > 0)
{
if (byteArray.length >= (dataPos + sLens[i]))
{
bBuff = new byte[sLens[i]];
System.arraycopy(byteArray, dataPos, bBuff, 0, sLens[i]);
dataPos += sLens[i];
strs[i] = toString(bBuff);
}
else
return null;
}
}
return strs;
}
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])) {
bBuff = new byte[sLens[i]];
System.arraycopy(byteArray, dataPos, bBuff, 0, sLens[i]);
dataPos += sLens[i];
strs[i] = toString(bBuff);
} else
return null;
}
}
return strs;
}
}

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

@ -26,18 +26,17 @@ import java.util.TreeSet;
public class PrintSystemProperties {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Properties p = System.getProperties();
SortedSet keys = new TreeSet(p.keySet());
for (Iterator it=keys.iterator(); it.hasNext(); ) {
String key = (String) it.next();
System.out.println(key + " = " + p.getProperty(key));
}
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Properties p = System.getProperties();
SortedSet keys = new TreeSet(p.keySet());
for (Iterator it = keys.iterator(); it.hasNext();) {
String key = (String) it.next();
System.out.println(key + " = " + p.getProperty(key));
}
}
}

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

@ -28,13 +28,11 @@ import java.io.Reader;
* @author Marc Schroeder
*/
public class UncloseableBufferedReader extends BufferedReader
{
public UncloseableBufferedReader(Reader i) {
super(i);
}
public class UncloseableBufferedReader extends BufferedReader {
public UncloseableBufferedReader(Reader i) {
super(i);
}
public void close() {
}
public void close() {
}
}

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

@ -43,80 +43,78 @@ 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
{
/* Global constants */
private final static int MAGIC = 0x4d415259; // "MARY"
private final static int VERSION = 40; // 4.0
public class MaryHeader {
/* Global constants */
private final static int MAGIC = 0x4d415259; // "MARY"
private final static int VERSION = 40; // 4.0
/* List of authorized file type identifier constants */
public final static int UNKNOWN = 0;
public final static int CARTS = 100;
public final static int DIRECTED_GRAPH = 110;
public final static int UNITS = 200;
public final static int LISTENERUNITS = 225;
public final static int UNITFEATS = 300;
public final static int LISTENERFEATS = 325;
public final static int HALFPHONE_UNITFEATS = 301;
public final static int JOINFEATS = 400;
public final static int SCOST = 445;
public final static int PRECOMPUTED_JOINCOSTS = 450;
public final static int TIMELINE = 500;
/* List of authorized file type identifier constants */
public final static int UNKNOWN = 0;
public final static int CARTS = 100;
public final static int DIRECTED_GRAPH = 110;
public final static int UNITS = 200;
public final static int LISTENERUNITS = 225;
public final static int UNITFEATS = 300;
public final static int LISTENERFEATS = 325;
public final static int HALFPHONE_UNITFEATS = 301;
public final static int JOINFEATS = 400;
public final static int SCOST = 445;
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;
/* 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
*/
public static int peekFileType(String fileName) throws IOException {
DataInputStream dis = null;
dis = new DataInputStream(new BufferedInputStream(new FileInputStream(fileName)));
/* Load the Mary header */
try {
MaryHeader hdr = new MaryHeader(dis);
int type = hdr.getType();
return type;
} catch (MaryConfigurationException e) {
// not a valid MARY header
return -1;
} finally {
dis.close();
}
// 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
*/
public static int peekFileType(String fileName) throws IOException
{
DataInputStream dis = null;
dis = new DataInputStream( new BufferedInputStream( new FileInputStream( fileName ) ) );
/* Load the Mary header */
try {
MaryHeader hdr = new MaryHeader( dis );
int type = hdr.getType();
return type;
} catch (MaryConfigurationException e) {
// not a valid MARY header
return -1;
} finally {
dis.close();
}
/****************/
/* CONSTRUCTORS */
/****************/
}
/****************/
/* CONSTRUCTORS */
/****************/
/**
* Consruct a MaryHeader from scratch.
*
* 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.
*
* @throws IllegalArgumentException if the input type is unknown.
*/
public MaryHeader( int newType ) {
/**
* Consruct a MaryHeader from scratch.
*
* 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.
*
* @throws IllegalArgumentException
* if the input type is unknown.
*/
public MaryHeader( int newType ) {
if ( (newType > TIMELINE) || (newType < UNKNOWN) ) {
throw new IllegalArgumentException( "Unauthorized Mary file type [" + type + "]." );
}
@ -128,15 +126,17 @@ public class MaryHeader
assert hasLegalType();
}
/**
* 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.
*
* @throws MaryConfigurationException if no mary header can be read from input.
*/
public MaryHeader( DataInput input ) throws MaryConfigurationException {
/**
* 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.
*
* @throws MaryConfigurationException
* if no mary header can be read from input.
*/
public MaryHeader( DataInput input ) throws MaryConfigurationException {
try {
this.load( input );
} catch (IOException e) {
@ -151,15 +151,17 @@ public class MaryHeader
assert hasLegalType();
}
/**
* 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.
*
* @throws MaryConfigurationException if no mary header can be read from input.
*/
public MaryHeader( ByteBuffer input ) throws MaryConfigurationException {
/**
* 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.
*
* @throws MaryConfigurationException
* if no mary header can be read from input.
*/
public MaryHeader( ByteBuffer input ) throws MaryConfigurationException {
try {
this.load( input );
} catch (BufferUnderflowException e) {
@ -174,19 +176,22 @@ public class MaryHeader
assert hasLegalType();
}
/*****************/
/* OTHER METHODS */
/*****************/
/*****************/
/* OTHER METHODS */
/*****************/
/** Mary header writer
*
* @param output The DataOutputStream or RandomAccessFile to write to
*
* @return the number of written bytes.
*
* @throws IOException if the file type is unknown.
*/
public long writeTo( DataOutput output ) throws IOException {
/**
* Mary header writer
*
* @param output
* The DataOutputStream or RandomAccessFile to write to
*
* @return the number of written bytes.
*
* @throws IOException
* if the file type is unknown.
*/
public long writeTo( DataOutput output ) throws IOException {
long nBytes = 0;
@ -199,43 +204,60 @@ public class MaryHeader
return( nBytes );
}
/** Load a mary header.
*
* @param input The data input (DataInputStream or RandomAccessFile) to read from.
*
* @throws IOException if the header data cannot be read
*/
private void load( DataInput input ) throws IOException {
/**
* Load a mary header.
*
* @param input
* The data input (DataInputStream or RandomAccessFile) to read from.
*
* @throws IOException
* if the header data cannot be read
*/
private void load(DataInput input) throws IOException {
magic = input.readInt();
version = input.readInt();
type = input.readInt();
}
magic = input.readInt();
version = input.readInt();
type = input.readInt();
}
/**
* 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
*/
private void load(ByteBuffer input) {
magic = input.getInt();
version = input.getInt();
type = input.getInt();
}
/**
* 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
*/
private void load(ByteBuffer input) {
magic = input.getInt();
version = input.getInt();
type = input.getInt();
}
/* Accessors */
public int getMagic() { return(magic); }
public int getVersion() { return(version); }
public int getType() { return(type); }
/* Accessors */
public int getMagic() {
return (magic);
}
/* Checkers */
public boolean hasCurrentVersion() { return( version == VERSION ); }
private boolean hasLegalType() {
return (type <= TIMELINE) && (type > UNKNOWN) ;
}
private boolean hasLegalMagic() {
return( magic == MAGIC );
}
public int getVersion() {
return (version);
}
public int getType() {
return (type);
}
/* Checkers */
public boolean hasCurrentVersion() {
return (version == VERSION);
}
private boolean hasLegalType() {
return (type <= TIMELINE) && (type > UNKNOWN);
}
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
{
Logger logger;
public LoggingErrorHandler(String name)
{
logger = MaryUtils.getLogger(name);
}
public class LoggingErrorHandler implements ErrorHandler, ErrorListener {
Logger logger;
public void error(SAXParseException e)
throws SAXParseException
{
logger.warn(e.getMessage());
throw e;
}
public LoggingErrorHandler(String name) {
logger = MaryUtils.getLogger(name);
}
public void error(TransformerException e)
throws TransformerException
{
logger.warn(e.getMessageAndLocation());
throw e;
}
public void error(SAXParseException e) throws SAXParseException {
logger.warn(e.getMessage());
throw e;
}
public void warning(SAXParseException e)
throws SAXParseException
{
logger.warn(e.getMessage());
throw e;
}
public void error(TransformerException e) throws TransformerException {
logger.warn(e.getMessageAndLocation());
throw e;
}
public void warning(TransformerException e)
throws TransformerException
{
logger.warn(e.getMessageAndLocation());
throw e;
}
public void warning(SAXParseException e) throws SAXParseException {
logger.warn(e.getMessage());
throw e;
}
public void fatalError(SAXParseException e)
throws SAXParseException
{
logger.warn(e.getMessage());
throw e;
}
public void fatalError(TransformerException e)
throws TransformerException
{
logger.warn(e.getMessageAndLocation());
throw e;
}
public void warning(TransformerException e) throws TransformerException {
logger.warn(e.getMessageAndLocation());
throw e;
}
public void fatalError(SAXParseException e) throws SAXParseException {
logger.warn(e.getMessage());
throw e;
}
public void fatalError(TransformerException e) throws TransformerException {
logger.warn(e.getMessageAndLocation());
throw e;
}
}

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

@ -46,114 +46,113 @@ 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
*/
public class MaryNormalisedWriter {
private static TransformerFactory tFactory = null;
private static Templates stylesheet = null;
private static TransformerFactory tFactory = null;
private static Templates stylesheet = null;
private static Logger logger; // only used for extensive debug output
private static Logger logger; // only used for extensive debug output
private Transformer transformer;
private Transformer transformer;
/** Default constructor.
* Calls <code>startup()</code> if it has not been called before.
* @see #startup().
*/
public MaryNormalisedWriter()
throws MaryConfigurationException
{
try {
// startup every time:
startup();
transformer = stylesheet.newTransformer();
} catch (Exception e) {
throw new MaryConfigurationException("Cannot initialise XML writing code", e);
}
}
/**
* Default constructor. Calls <code>startup()</code> if it has not been called before.
*
* @see #startup().
*/
public MaryNormalisedWriter() throws MaryConfigurationException {
try {
// startup every time:
startup();
transformer = stylesheet.newTransformer();
} catch (Exception e) {
throw new MaryConfigurationException("Cannot initialise XML writing code", e);
}
}
// Methods
// Methods
/** 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
* if the stylesheet file cannot be found.
* @exception TransformerConfigurationException
* if the templates stylesheet cannot be generated.
*/
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"));
stylesheet = tFactory.newTemplates(stylesheetStream);
}
if (logger == null)
logger = MaryUtils.getLogger("MaryNormalisedWriter");
/**
* 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
* if the stylesheet file cannot be found.
* @exception TransformerConfigurationException
* if the templates stylesheet cannot be generated.
*/
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"));
stylesheet = tFactory.newTemplates(stylesheetStream);
}
if (logger == null)
logger = MaryUtils.getLogger("MaryNormalisedWriter");
}
}
/** The actual output to stdout.
* @param input a DOMSource, a SAXSource or a StreamSource.
* @see javax.xml.transform.Transformer
* @exception TransformerException
* if the transformation cannot be performed.
*/
public void output(Source input, Result destination) throws TransformerException {
//logger.debug("Before transform");
transformer.transform(input, destination);
//logger.debug("After transform");
}
/**
* The actual output to stdout.
*
* @param input
* a DOMSource, a SAXSource or a StreamSource.
* @see javax.xml.transform.Transformer
* @exception TransformerException
* if the transformation cannot be performed.
*/
public void output(Source input, Result destination) throws TransformerException {
// logger.debug("Before transform");
transformer.transform(input, destination);
// logger.debug("After transform");
}
/**
* Output any Source to stdout.
*/
public void output(Source input) throws TransformerException {
output(input, new StreamResult(new PrintStream(System.out, true)));
}
/**
* Output any Source to stdout.
*/
public void output(Source input) throws TransformerException {
output(input, new StreamResult(new PrintStream(System.out, true)));
}
/** Output a DOM node to stdout.
* @see #output(Source)
*/
public void output(Node input) throws TransformerException {
output(new DOMSource(input));
}
/**
* Output a DOM node to stdout.
*
* @see #output(Source)
*/
public void output(Node input) throws TransformerException {
output(new DOMSource(input));
}
/**
* Output a DOM node to a specified destination
*/
public void output(Node input, OutputStream destination) throws TransformerException {
output(new DOMSource(input), new StreamResult(destination));
}
/**
* Output a DOM node to a specified destination
*/
public void output(Node input, OutputStream destination) throws TransformerException {
output(new DOMSource(input), new StreamResult(destination));
}
/**
* 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();
MaryNormalisedWriter writer = new 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.
*/
public static void main(String[] args) throws Throwable {
startup();
MaryNormalisedWriter writer = new MaryNormalisedWriter();
ReaderSplitter splitter = new ReaderSplitter(new InputStreamReader(System.in), "</maryxml>");
ReaderSplitter splitter = new ReaderSplitter(new InputStreamReader(System.in), "</maryxml>");
Reader oneXMLStructure = null;
while ((oneXMLStructure = splitter.nextReader()) != null) {
writer.output(new StreamSource(oneXMLStructure));
}
}
Reader oneXMLStructure = null;
while ((oneXMLStructure = splitter.nextReader()) != null) {
writer.output(new StreamSource(oneXMLStructure));
}
}
}

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

@ -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
{
private Pattern re;
public RENodeFilter(String reString)
{
this.re = Pattern.compile(reString);
}
public class RENodeFilter implements NodeFilter {
private Pattern re;
public RENodeFilter(Pattern re)
{
this.re = re;
}
public RENodeFilter(String reString) {
this.re = Pattern.compile(reString);
}
public short acceptNode(Node n)
{
if (re.matcher(n.getNodeName()).matches())
return NodeFilter.FILTER_ACCEPT;
else
return NodeFilter.FILTER_SKIP;
}
public RENodeFilter(Pattern re) {
this.re = re;
}
public short acceptNode(Node n) {
if (re.matcher(n.getNodeName()).matches())
return NodeFilter.FILTER_ACCEPT;
else
return NodeFilter.FILTER_SKIP;
}
}

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

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

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

@ -44,331 +44,346 @@ 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
{
private Vector bList = null;
private String fromDir = null;
private String fromExt = null;
private boolean hasChanged;
private static final int DEFAULT_INCREMENT = 128;
public class BasenameList {
private Vector bList = null;
private String fromDir = null;
private String fromExt = null;
private boolean hasChanged;
private static final int DEFAULT_INCREMENT = 128;
/****************/
/* CONSTRUCTORS */
/****************/
/****************/
/* CONSTRUCTORS */
/****************/
/**
* Default constructor for an empty list.
*/
public BasenameList() {
fromDir = null;
fromExt = null;
bList = new Vector( DEFAULT_INCREMENT, DEFAULT_INCREMENT );
hasChanged = false;
}
/**
* Default constructor for an empty list.
*/
public BasenameList() {
fromDir = null;
fromExt = null;
bList = new Vector(DEFAULT_INCREMENT, DEFAULT_INCREMENT);
hasChanged = false;
}
/**
* Default constructor from an existing vector and fields.
*/
public BasenameList( String setFromDir, String setFromExt, Vector setVec ) {
fromDir = setFromDir;
fromExt = setFromExt;
bList = setVec;
hasChanged = false;
}
/**
* Default constructor from an existing vector and fields.
*/
public BasenameList(String setFromDir, String setFromExt, Vector setVec) {
fromDir = setFromDir;
fromExt = setFromExt;
bList = setVec;
hasChanged = false;
}
/**
* Constructor from an array of strings.
*/
public BasenameList( String[] str ) {
fromDir = null;
fromExt = null;
bList = new Vector( DEFAULT_INCREMENT, DEFAULT_INCREMENT );
add( str );
hasChanged = false;
}
/**
* Constructor from an array of strings.
*/
public BasenameList(String[] str) {
fromDir = null;
fromExt = null;
bList = new Vector(DEFAULT_INCREMENT, DEFAULT_INCREMENT);
add(str);
hasChanged = false;
}
/**
* This constructor lists the .<extension> files from directory dir,
* and initializes an an array with their list of alphabetically
* sorted basenames.
*
* @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;
/* Turn the directory name into a file, to allow for checking and listing */
File dir = new File( dirName );
/* Check if the directory exists */
if ( !dir.exists() ) {
throw new RuntimeException( "Directory [" + dirName + "] does not exist. Can't find the [" + extension + "] files." );
}
/* List the .extension files */
File[] selectedFiles = dir.listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.endsWith( extension );
}
});
/**
* 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.
*
*/
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;
/* Turn the directory name into a file, to allow for checking and listing */
File dir = new File(dirName);
/* Check if the directory exists */
if (!dir.exists()) {
throw new RuntimeException("Directory [" + dirName + "] does not exist. Can't find the [" + extension + "] files.");
}
/* List the .extension files */
File[] selectedFiles = dir.listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.endsWith(extension);
}
});
/* Sort the file names alphabetically */
Arrays.sort( selectedFiles );
/* Sort the file names alphabetically */
Arrays.sort(selectedFiles);
/* Extract the basenames and store them in a vector of strings */
bList = new Vector( selectedFiles.length, DEFAULT_INCREMENT );
String str = null;
int subtractFromFilename = extension.length();
for ( int i = 0; i < selectedFiles.length; i++ ) {
str = selectedFiles[i].getName().substring( 0, selectedFiles[i].getName().length() - subtractFromFilename );
add( str );
}
hasChanged = false;
}
/* Extract the basenames and store them in a vector of strings */
bList = new Vector(selectedFiles.length, DEFAULT_INCREMENT);
String str = null;
int subtractFromFilename = extension.length();
for (int i = 0; i < selectedFiles.length; i++) {
str = selectedFiles[i].getName().substring(0, selectedFiles[i].getName().length() - subtractFromFilename);
add(str);
}
hasChanged = false;
}
/**
* This constructor loads the basename list from a random access file.
*
* @param fileName The file to read from.
*/
public BasenameList( String fileName ) throws IOException {
load( fileName );
hasChanged = false;
}
/**
* This constructor loads the basename list from a random access file.
*
* @param fileName
* The file to read from.
*/
public BasenameList(String fileName) throws IOException {
load(fileName);
hasChanged = false;
}
/*****************/
/* I/O METHODS */
/*****************/
/*****************/
/* I/O METHODS */
/*****************/
/**
* Write the basenameList to a file, identified by its name.
*/
public void write( String fileName ) throws IOException {
write( new File( fileName ) );
}
/**
* Write the basenameList to a file, identified by its name.
*/
public void write(String fileName) throws IOException {
write(new File(fileName));
}
/**
* Write the basenameList to a File.
*/
public void write( File file ) throws IOException {
PrintWriter pw = new PrintWriter( new OutputStreamWriter( new FileOutputStream( file ), "UTF-8" ), true );
if ( fromDir != null ) {
pw.println( "FROM: " + fromDir + "*" + fromExt );
}
String str = null;
for ( int i = 0; i < bList.size(); i++ ) {
str = (String)(bList.elementAt(i));
pw.println( str );
}
}
/**
* Write the basenameList to a File.
*/
public void write(File file) throws IOException {
PrintWriter pw = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8"), true);
if (fromDir != null) {
pw.println("FROM: " + fromDir + "*" + fromExt);
}
String str = null;
for (int i = 0; i < bList.size(); i++) {
str = (String) (bList.elementAt(i));
pw.println(str);
}
}
/**
* Read the basenameList from a file
*/
public void load( String fileName ) throws IOException {
/* 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 );
/* Check if the first line contains the origin information (directory+ext) */
String line = bfr.readLine();
if ( line.indexOf("FROM: ") != -1 ) {
line = line.substring( 6 );
String[] parts = new String[2];
parts = line.split( "\\*", 2 );
fromDir = parts[0];
fromExt = parts[1];
}
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 );
}
}
/**
* Read the basenameList from a file
*/
public void load(String fileName) throws IOException {
/* 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);
/* Check if the first line contains the origin information (directory+ext) */
String line = bfr.readLine();
if (line.indexOf("FROM: ") != -1) {
line = line.substring(6);
String[] parts = new String[2];
parts = line.split("\\*", 2);
fromDir = parts[0];
fromExt = parts[1];
} 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);
}
}
/*****************/
/* OTHER METHODS */
/*****************/
/*****************/
/* OTHER METHODS */
/*****************/
/**
* Adds a basename to the list.
*/
public void add(String str) {
if (!bList.contains(str))
bList.add(str);
hasChanged = true;
}
/**
* Adds a basename to the list.
*/
public void add( String str ) {
if ( !bList.contains( str ) ) bList.add(str);
hasChanged = true;
}
/**
* Adds an array of basenames to the list.
*/
public void add(String[] str) {
for (int i = 0; i < str.length; i++)
add(str[i]);
hasChanged = true;
}
/**
* Adds an array of basenames to the list.
*/
public void add( String[] str ) {
for ( int i = 0; i < str.length; i++ ) add( str[i] );
hasChanged = true;
}
/**
* Removes a basename from the list, if it was present.
*
* @param str
* The basename to remove.
* @return true if the list was containing the basename.
*/
public boolean remove(String str) {
hasChanged = true;
return (bList.remove(str));
}
/**
* Removes a basename from the list, if it was present.
*
* @param str The basename to remove.
* @return true if the list was containing the basename.
*/
public boolean remove( String str ) {
hasChanged = true;
return( bList.remove( str ) );
}
/**
* Removes a list from another list.
*
* @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) {
boolean ret = true;
for (int i = 0; i < bnl.getLength(); i++) {
bList.remove(bnl.getName(i));
}
hasChanged = true;
return (ret);
}
/**
* Removes a list from another list.
*
* @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 ) {
boolean ret = true;
for ( int i = 0; i < bnl.getLength(); i++ ) {
bList.remove( bnl.getName(i) );
}
hasChanged = true;
return( ret );
}
/**
* Duplicates the list (i.e., emits an autonomous copy of it).
*/
public BasenameList duplicate() {
return (new BasenameList(this.fromDir, this.fromExt, (Vector) (this.bList.clone())));
}
/**
* Duplicates the list (i.e., emits an autonomous copy of it).
*/
public BasenameList duplicate() {
return( new BasenameList( this.fromDir, this.fromExt, (Vector)(this.bList.clone()) ) );
}
/**
* Returns an autonomous sublist between fromIndex, inclusive, and toIndex, exclusive.
*/
public BasenameList subList(int fromIndex, int toIndex) {
Vector subVec = new Vector(toIndex - fromIndex, DEFAULT_INCREMENT);
for (int i = fromIndex; i < toIndex; i++)
subVec.add(this.getName(i));
return (new BasenameList(this.fromDir, this.fromExt, subVec));
}
/**
* Returns an autonomous sublist between fromIndex, inclusive, and toIndex, exclusive.
*/
public BasenameList subList( int fromIndex, int toIndex ) {
Vector subVec = new Vector( toIndex - fromIndex, DEFAULT_INCREMENT );
for ( int i = fromIndex; i < toIndex; i++ ) subVec.add( this.getName(i) );
return( new BasenameList( this.fromDir, this.fromExt, subVec ) );
}
/**
* An accessor for the list of basenames, returned as an array of strings
*/
public String[] getListAsArray() {
String[] ret = new String[this.getLength()];
ret = (String[]) bList.toArray(ret);
return ((String[]) (ret));
}
/**
* An accessor for the list of basenames, returned as an array of strings
*/
public String[] getListAsArray() {
String[] ret = new String[this.getLength()];
ret = (String[]) bList.toArray( ret );
return( (String[])( ret ) );
}
/**
* Another accessor for the list of basenames, returned as a vector of strings
*/
public Vector getListAsVector() {
return (bList);
}
/**
* Another accessor for the list of basenames, returned as a vector of strings
*/
public Vector getListAsVector() {
return( bList );
}
/**
* An accessor for the list's length
*/
public int getLength() {
return (bList.size());
}
/**
* An accessor for the list's length
*/
public int getLength() {
return( bList.size() );
}
/**
* An accessor for the original directory. Returns null if the original directory is undefined.
*/
public String getDir() {
return (fromDir);
}
/**
* 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.
*/
public String getExt() {
return (fromExt);
}
/**
* An accessor for the original extension. Returns null if the original
* extension is undefined.
*/
public String getExt() {
return( fromExt );
}
/**
* Return a copy of the basename at index i.
*
* @param i
* The index of the basename to consider.
* @return The corresponding basename.
*/
public String getName(int i) {
return (String) bList.elementAt(i);
}
/**
* Return a copy of the basename at index i.
*
* @param i The index of the basename to consider.
* @return The corresponding basename.
*/
public String getName( int i ) {
return (String) bList.elementAt(i);
}
/**
* Check if the given basename is part of the list.
*
* @param str
* The basename to check for.
* @return true if yes, false if no.
*/
public boolean contains(String str) {
return (bList.contains(str));
}
/**
* Check if the given basename is part of the list.
*
* @param str The basename to check for.
* @return true if yes, false if no.
*/
public boolean contains( String str ) {
return( bList.contains( str ) );
}
/**
* Check if the list contains another given one.
*
* @param bnl
* The list of basenames to check for.
* @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);
for (int i = 0; i < bnl.getLength(); i++) {
if (!this.contains(bnl.getName(i)))
return (false);
}
return (true);
}
/**
* Check if the list contains another given one.
*
* @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 );
for ( int i = 0; i < bnl.getLength(); i++ ) {
if ( !this.contains( bnl.getName(i) ) ) return( false );
}
return( true );
}
/**
* Check if two lists are equal.
*
* @param bnl
* The list of basenames to check for.
* @return true if yes, false if no.
*/
public boolean equals(BasenameList bnl) {
if (bnl.getLength() != this.getLength())
return (false);
for (int i = 0; i < bnl.getLength(); i++) {
if (!this.contains(bnl.getName(i)))
return (false);
}
return (true);
}
/**
* Check if two lists are equal.
*
* @param bnl The list of basenames to check for.
* @return true if yes, false if no.
*/
public boolean equals( BasenameList bnl ) {
if ( bnl.getLength() != this.getLength() ) return( false );
for ( int i = 0; i < bnl.getLength(); i++ ) {
if ( !this.contains( bnl.getName(i) ) ) return( false );
}
return( true );
}
/**
* Ensure that the list is alphabetically sorted.
*
*/
public void sort() {
String[] str = getListAsArray();
Arrays.sort(str);
bList.removeAllElements();
add(str);
hasChanged = true;
}
/**
* Ensure that the list is alphabetically sorted.
*
*/
public void sort() {
String[] str = getListAsArray();
Arrays.sort( str );
bList.removeAllElements();
add( str );
hasChanged = true;
}
/**
* Clear the list.
*
*/
public void clear() {
fromDir = null;
fromExt = null;
bList.removeAllElements();
hasChanged = true;
}
/**
* Clear the list.
*
*/
public void clear() {
fromDir = null;
fromExt = null;
bList.removeAllElements();
hasChanged = true;
}
public boolean hasChanged(){
return hasChanged;
}
public boolean hasChanged() {
return hasChanged;
}
}

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

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

Разница между файлами не показана из-за своего большого размера Загрузить разницу

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

@ -41,413 +41,385 @@ import java.io.InputStream;
*/
public class LEDataInputStream implements DataInput {
// ------------------------------ FIELDS ------------------------------
// ------------------------------ FIELDS ------------------------------
/**
* undisplayed copyright notice.
*
* @noinspection UnusedDeclaration
*/
private static final String EMBEDDEDCOPYRIGHT =
"copyright (c) 1999-2007 Roedy Green, Canadian Mind Products, http://mindprod.com";
/**
* undisplayed copyright notice.
*
* @noinspection UnusedDeclaration
*/
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
*
* @noinspection WeakerAccess
*/
protected final DataInputStream dis;
/**
* to get at the big-Endian methods of a basic DataInputStream
*
* @noinspection WeakerAccess
*/
protected final DataInputStream dis;
/**
* to get at the a basic readBytes method.
*
* @noinspection WeakerAccess
*/
protected final InputStream is;
/**
* to get at the a basic readBytes method.
*
* @noinspection WeakerAccess
*/
protected final InputStream is;
/**
* work array for buffering input.
*
* @noinspection WeakerAccess
*/
protected final byte[] work;
/**
* work array for buffering input.
*
* @noinspection WeakerAccess
*/
protected final byte[] work;
// -------------------------- PUBLIC STATIC METHODS --------------------------
// -------------------------- PUBLIC STATIC METHODS --------------------------
/**
* Note. This is a STATIC method!
*
* @param in stream to read UTF chars from (endian irrelevant)
*
* @return string from stream
*
* @throws IOException if read fails.
*/
public static String readUTF( DataInput in ) throws IOException
{
return DataInputStream.readUTF( in );
}
/**
* Note. This is a STATIC method!
*
* @param in
* stream to read UTF chars from (endian irrelevant)
*
* @return string from stream
*
* @throws IOException
* if read fails.
*/
public static String readUTF(DataInput in) throws IOException {
return DataInputStream.readUTF(in);
}
// -------------------------- PUBLIC INSTANCE METHODS --------------------------
/**
* constructor.
*
* @param in binary inputstream of little-endian data.
*/
public LEDataInputStream( InputStream in )
{
this.is = in;
this.dis = new DataInputStream( in );
work = new byte[8];
}
// -------------------------- PUBLIC INSTANCE METHODS --------------------------
/**
* constructor.
*
* @param in
* binary inputstream of little-endian data.
*/
public LEDataInputStream(InputStream in) {
this.is = in;
this.dis = new DataInputStream(in);
work = new byte[8];
}
public LEDataInputStream( String filename) throws FileNotFoundException
{
this(new FileInputStream(filename));
}
public LEDataInputStream(String filename) throws FileNotFoundException {
this(new FileInputStream(filename));
}
/**
* close.
*
* @throws IOException if close fails.
*/
public final void close() throws IOException
{
dis.close();
}
/**
* close.
*
* @throws IOException
* if close fails.
*/
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.
*
* @return how many bytes read.
*
* @throws IOException if read fails.
*/
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 );
}
/**
* 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.
*
* @return how many bytes read.
*
* @throws IOException
* if read fails.
*/
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);
}
/**
* read only a one-byte boolean.
*
* @return true or false.
*
* @throws IOException if read fails.
* @see java.io.DataInput#readBoolean()
*/
public final boolean readBoolean() throws IOException
{
return dis.readBoolean();
}
/**
* read only a one-byte boolean.
*
* @return true or false.
*
* @throws IOException
* if read fails.
* @see java.io.DataInput#readBoolean()
*/
public final boolean readBoolean() throws IOException {
return dis.readBoolean();
}
public final boolean [] readBoolean(int len) throws IOException
{
boolean [] ret = new boolean[len];
public final boolean[] readBoolean(int len) throws IOException {
boolean[] ret = new boolean[len];
for (int i=0; i<len; i++)
ret[i] = readBoolean();
for (int i = 0; i < len; i++)
ret[i] = readBoolean();
return ret;
}
return ret;
}
/**
* read byte.
*
* @return the byte read.
*
* @throws IOException if read fails.
* @see java.io.DataInput#readByte()
*/
public final byte readByte() throws IOException
{
return dis.readByte();
}
/**
* read byte.
*
* @return the byte read.
*
* @throws IOException
* if read fails.
* @see java.io.DataInput#readByte()
*/
public final byte readByte() throws IOException {
return dis.readByte();
}
public final byte [] readByte(int len) throws IOException
{
byte [] ret = new byte[len];
public final byte[] readByte(int len) throws IOException {
byte[] ret = new byte[len];
for (int i=0; i<len; i++)
ret[i] = readByte();
for (int i = 0; i < len; i++)
ret[i] = readByte();
return ret;
}
return ret;
}
/**
* Read on char. like DataInputStream.readChar except little endian.
*
* @return little endian 16-bit unicode char from the stream.
*
* @throws IOException if read fails.
*/
public final char readChar() throws IOException
{
dis.readFully( work, 0, 2 );
return (char) ( ( work[ 1 ] & 0xff ) << 8 | ( work[ 0 ] & 0xff ) );
}
/**
* Read on char. like DataInputStream.readChar except little endian.
*
* @return little endian 16-bit unicode char from the stream.
*
* @throws IOException
* if read fails.
*/
public final char readChar() throws IOException {
dis.readFully(work, 0, 2);
return (char) ((work[1] & 0xff) << 8 | (work[0] & 0xff));
}
public final char [] readChar(int len) throws IOException
{
char [] ret = new char[len];
public final char[] readChar(int len) throws IOException {
char[] ret = new char[len];
for (int i=0; i<len; i++)
ret[i] = readChar();
for (int i = 0; i < len; i++)
ret[i] = readChar();
return ret;
}
/**
* Read a double. like DataInputStream.readDouble except little endian.
*
* @return little endian IEEE double from the datastream.
*
* @throws IOException
*/
public final double readDouble() throws IOException
{
return Double.longBitsToDouble( readLong() );
}
return ret;
}
public final double [] readDouble(int len) throws IOException
{
double [] ret = new double[len];
/**
* Read a double. like DataInputStream.readDouble except little endian.
*
* @return little endian IEEE double from the datastream.
*
* @throws IOException
*/
public final double readDouble() throws IOException {
return Double.longBitsToDouble(readLong());
}
for (int i=0; i<len; i++)
ret[i] = readDouble();
public final double[] readDouble(int len) throws IOException {
double[] ret = new double[len];
return ret;
}
for (int i = 0; i < len; i++)
ret[i] = readDouble();
public final int [] readDoubleToInt(int len) throws IOException
{
int [] ret = new int[len];
return ret;
}
for (int i=0; i<len; i++)
ret[i] = (int)readDouble();
public final int[] readDoubleToInt(int len) throws IOException {
int[] ret = new int[len];
return ret;
}
for (int i = 0; i < len; i++)
ret[i] = (int) readDouble();
/**
* Read one float. Like DataInputStream.readFloat except little endian.
*
* @return little endian IEEE float from the datastream.
*
* @throws IOException if read fails.
*/
public final float readFloat() throws IOException
{
return Float.intBitsToFloat( readInt() );
}
return ret;
}
public final float [] readFloat(int len) throws IOException
{
float [] ret = new float[len];
/**
* Read one float. Like DataInputStream.readFloat except little endian.
*
* @return little endian IEEE float from the datastream.
*
* @throws IOException
* if read fails.
*/
public final float readFloat() throws IOException {
return Float.intBitsToFloat(readInt());
}
for (int i=0; i<len; i++)
ret[i] = readFloat();
public final float[] readFloat(int len) throws IOException {
float[] ret = new float[len];
return ret;
}
for (int i = 0; i < len; i++)
ret[i] = readFloat();
/**
* Read bytes until the array is filled.
*
* @see java.io.DataInput#readFully(byte[])
*/
public final void readFully( byte ba[] ) throws IOException
{
dis.readFully( ba, 0, ba.length );
}
return ret;
}
/**
* Read bytes until the count is satisfied.
*
* @throws IOException if read fails.
* @see java.io.DataInput#readFully(byte[],int,int)
*/
public final void readFully( byte ba[],
int off,
int len ) throws IOException
{
dis.readFully( ba, off, len );
}
/**
* Read bytes until the array is filled.
*
* @see java.io.DataInput#readFully(byte[])
*/
public final void readFully(byte ba[]) throws IOException {
dis.readFully(ba, 0, ba.length);
}
/**
* Read an int, 32-bits. Like DataInputStream.readInt except little endian.
*
* @return little-endian binary int from the datastream
*
* @throws IOException if read fails.
*/
public final int readInt() throws IOException
{
dis.readFully( work, 0, 4 );
return ( work[ 3 ] ) << 24
| ( work[ 2 ] & 0xff ) << 16
| ( work[ 1 ] & 0xff ) << 8
| ( work[ 0 ] & 0xff );
}
/**
* Read bytes until the count is satisfied.
*
* @throws IOException
* if read fails.
* @see java.io.DataInput#readFully(byte[],int,int)
*/
public final void readFully(byte ba[], int off, int len) throws IOException {
dis.readFully(ba, off, len);
}
public final int [] readInt(int len) throws IOException
{
int [] ret = new int[len];
/**
* Read an int, 32-bits. Like DataInputStream.readInt except little endian.
*
* @return little-endian binary int from the datastream
*
* @throws IOException
* if read fails.
*/
public final int readInt() throws IOException {
dis.readFully(work, 0, 4);
return (work[3]) << 24 | (work[2] & 0xff) << 16 | (work[1] & 0xff) << 8 | (work[0] & 0xff);
}
for (int i=0; i<len; i++)
ret[i] = readInt();
public final int[] readInt(int len) throws IOException {
int[] ret = new int[len];
return ret;
}
for (int i = 0; i < len; i++)
ret[i] = readInt();
/**
* Read a line.
*
* @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.
*/
public final String readLine() throws IOException
{
return dis.readLine();
}
return ret;
}
/**
* read a long, 64-bits. Like DataInputStream.readLong except little
* endian.
*
* @return little-endian binary long from the datastream.
*
* @throws IOException
*/
public final long readLong() throws IOException
{
dis.readFully( work, 0, 8 );
return (long) ( work[ 7 ] ) << 56
|
/* long cast needed or shift done modulo 32 */
(long) ( work[ 6 ] & 0xff ) << 48
| (long) ( work[ 5 ] & 0xff ) << 40
| (long) ( work[ 4 ] & 0xff ) << 32
| (long) ( work[ 3 ] & 0xff ) << 24
| (long) ( work[ 2 ] & 0xff ) << 16
| (long) ( work[ 1 ] & 0xff ) << 8
| (long) ( work[ 0 ] & 0xff );
}
/**
* Read a line.
*
* @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.
*/
public final String readLine() throws IOException {
return dis.readLine();
}
public final long [] readLong(int len) throws IOException
{
long [] ret = new long[len];
/**
* read a long, 64-bits. Like DataInputStream.readLong except little endian.
*
* @return little-endian binary long from the datastream.
*
* @throws IOException
*/
public final long readLong() throws IOException {
dis.readFully(work, 0, 8);
return (long) (work[7]) << 56 |
/* long cast needed or shift done modulo 32 */
(long) (work[6] & 0xff) << 48 | (long) (work[5] & 0xff) << 40 | (long) (work[4] & 0xff) << 32
| (long) (work[3] & 0xff) << 24 | (long) (work[2] & 0xff) << 16 | (long) (work[1] & 0xff) << 8
| (long) (work[0] & 0xff);
}
for (int i=0; i<len; i++)
ret[i] = readLong();
public final long[] readLong(int len) throws IOException {
long[] ret = new long[len];
return ret;
}
for (int i = 0; i < len; i++)
ret[i] = readLong();
/**
* Read short, 16-bits. Like DataInputStream.readShort except little
* endian.
*
* @return little endian binary short from stream.
*
* @throws IOException if read fails.
*/
public final short readShort() throws IOException
{
dis.readFully( work, 0, 2 );
return (short) ( ( work[ 1 ] & 0xff ) << 8 | ( work[ 0 ] & 0xff ) );
}
return ret;
}
public final short [] readShort(int len) throws IOException
{
short [] ret = new short[len];
/**
* Read short, 16-bits. Like DataInputStream.readShort except little endian.
*
* @return little endian binary short from stream.
*
* @throws IOException
* if read fails.
*/
public final short readShort() throws IOException {
dis.readFully(work, 0, 2);
return (short) ((work[1] & 0xff) << 8 | (work[0] & 0xff));
}
for (int i=0; i<len; i++)
ret[i] = readShort();
public final short[] readShort(int len) throws IOException {
short[] ret = new short[len];
return ret;
}
for (int i = 0; i < len; i++)
ret[i] = readShort();
/**
* Read UTF counted string.
*
* @return String read.
*/
public final String readUTF() throws IOException
{
return dis.readUTF();
}
return ret;
}
/**
* Read an unsigned byte. Note: returns an int, even though says Byte
* (non-Javadoc)
*
* @throws IOException if read fails.
* @see java.io.DataInput#readUnsignedByte()
*/
public final int readUnsignedByte() throws IOException
{
return dis.readUnsignedByte();
}
/**
* Read UTF counted string.
*
* @return String read.
*/
public final String readUTF() throws IOException {
return dis.readUTF();
}
public final int [] readUnsignedByte(int len) throws IOException
{
int [] ret = new int[len];
/**
* Read an unsigned byte. Note: returns an int, even though says Byte (non-Javadoc)
*
* @throws IOException
* if read fails.
* @see java.io.DataInput#readUnsignedByte()
*/
public final int readUnsignedByte() throws IOException {
return dis.readUnsignedByte();
}
for (int i=0; i<len; i++)
ret[i] = readUnsignedByte();
public final int[] readUnsignedByte(int len) throws IOException {
int[] ret = new int[len];
return ret;
}
for (int i = 0; i < len; i++)
ret[i] = readUnsignedByte();
/**
* 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.
*/
public final int readUnsignedShort() throws IOException
{
dis.readFully( work, 0, 2 );
return ( ( work[ 1 ] & 0xff ) << 8 | ( work[ 0 ] & 0xff ) );
}
return ret;
}
public final int [] readUnsignedShort(int len) throws IOException
{
int [] ret = new int[len];
/**
* 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.
*/
public final int readUnsignedShort() throws IOException {
dis.readFully(work, 0, 2);
return ((work[1] & 0xff) << 8 | (work[0] & 0xff));
}
for (int i=0; i<len; i++)
ret[i] = readUnsignedShort();
public final int[] readUnsignedShort(int len) throws IOException {
int[] ret = new int[len];
return ret;
}
for (int i = 0; i < len; i++)
ret[i] = readUnsignedShort();
/**
* 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.
*
* @return the actual number of bytes skipped.
*
* @throws IOException if an I/O error occurs.
*/
public final int skipBytes( int n ) throws IOException
{
return dis.skipBytes( n );
}
return ret;
}
/**
* 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.
*
* @return the actual number of bytes skipped.
*
* @throws IOException
* if an I/O error occurs.
*/
public final int skipBytes(int n) throws IOException {
return dis.skipBytes(n);
}
}// end class LEDataInputStream

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

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

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

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

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

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

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

@ -25,326 +25,291 @@ 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 MaryRandomAccessFile(File arg0, String arg1) throws FileNotFoundException {
super(arg0, arg1);
}
public final class MaryRandomAccessFile extends RandomAccessFile {
public MaryRandomAccessFile(File arg0, String arg1) throws FileNotFoundException {
super(arg0, arg1);
}
public MaryRandomAccessFile(String arg0, String arg1) throws FileNotFoundException {
super(arg0, arg1);
}
public MaryRandomAccessFile(String arg0, String arg1) throws FileNotFoundException {
super(arg0, arg1);
}
public final boolean readBooleanEndian() throws IOException
{
boolean ret = readBoolean();
public final boolean readBooleanEndian() throws IOException {
boolean ret = readBoolean();
return ret;
}
return ret;
}
public final boolean [] readBoolean(int len) throws IOException
{
boolean [] ret = new boolean[len];
public final boolean[] readBoolean(int len) throws IOException {
boolean[] ret = new boolean[len];
for (int i=0; i<len; i++)
ret[i] = readBoolean();
for (int i = 0; i < len; i++)
ret[i] = readBoolean();
return ret;
}
return ret;
}
public final boolean [] readBooleanEndian(int len) throws IOException
{
boolean [] ret = new boolean[len];
public final boolean[] readBooleanEndian(int len) throws IOException {
boolean[] ret = new boolean[len];
for (int i=0; i<len; i++)
ret[i] = readBooleanEndian();
for (int i = 0; i < len; i++)
ret[i] = readBooleanEndian();
return ret;
}
return ret;
}
public final byte readByteEndian() throws IOException
{
byte ret = readByte();
public final byte readByteEndian() throws IOException {
byte ret = readByte();
return ret;
}
return ret;
}
public final byte [] readByte(int len) throws IOException
{
byte [] ret = new byte[len];
public final byte[] readByte(int len) throws IOException {
byte[] ret = new byte[len];
for (int i=0; i<len; i++)
ret[i] = readByte();
for (int i = 0; i < len; i++)
ret[i] = readByte();
return ret;
}
return ret;
}
public final byte [] readByteEndian(int len) throws IOException
{
byte [] ret = new byte[len];
public final byte[] readByteEndian(int len) throws IOException {
byte[] ret = new byte[len];
for (int i=0; i<len; i++)
ret[i] = readByteEndian();
for (int i = 0; i < len; i++)
ret[i] = readByteEndian();
return ret;
}
return ret;
}
public final char readCharEndian() throws IOException
{
char c = (char)readByte();
public final char readCharEndian() throws IOException {
char c = (char) readByte();
return c;
}
return c;
}
public final char [] readChar(int len) throws IOException
{
char [] ret = new char[len];
public final char[] readChar(int len) throws IOException {
char[] ret = new char[len];
for (int i=0; i<len; i++)
ret[i] = readChar();
for (int i = 0; i < len; i++)
ret[i] = readChar();
return ret;
}
return ret;
}
public final char [] readCharEndian(int len) throws IOException
{
char [] ret = new char[len];
public final char[] readCharEndian(int len) throws IOException {
char[] ret = new char[len];
for (int i=0; i<len; i++)
ret[i] = readCharEndian();
for (int i = 0; i < len; i++)
ret[i] = readCharEndian();
return ret;
}
return ret;
}
public final double readDoubleEndian() throws IOException
{
double ret = readDouble();
public final double readDoubleEndian() throws IOException {
double ret = readDouble();
return ret;
}
return ret;
}
public final double [] readDouble(int len) throws IOException
{
double [] ret = new double[len];
public final double[] readDouble(int len) throws IOException {
double[] ret = new double[len];
for (int i=0; i<len; i++)
ret[i] = readDouble();
for (int i = 0; i < len; i++)
ret[i] = readDouble();
return ret;
}
return ret;
}
public final double [] readDoubleEndian(int len) throws IOException
{
double [] ret = new double[len];
public final double[] readDoubleEndian(int len) throws IOException {
double[] ret = new double[len];
for (int i=0; i<len; i++)
ret[i] = readDoubleEndian();
for (int i = 0; i < len; i++)
ret[i] = readDoubleEndian();
return ret;
}
return ret;
}
public final int readDoubleToIntEndian() throws IOException
{
int ret = (int)readDouble();
public final int readDoubleToIntEndian() throws IOException {
int ret = (int) readDouble();
return ret;
}
return ret;
}
public final int [] readDoubleToInt(int len) throws IOException
{
int [] ret = new int[len];
public final int[] readDoubleToInt(int len) throws IOException {
int[] ret = new int[len];
for (int i=0; i<len; i++)
ret[i] = (int)readDouble();
for (int i = 0; i < len; i++)
ret[i] = (int) readDouble();
return ret;
}
return ret;
}
public final int [] readDoubleToIntEndian(int len) throws IOException
{
int [] ret = new int[len];
public final int[] readDoubleToIntEndian(int len) throws IOException {
int[] ret = new int[len];
for (int i=0; i<len; i++)
ret[i] = readDoubleToIntEndian();
for (int i = 0; i < len; i++)
ret[i] = readDoubleToIntEndian();
return ret;
}
return ret;
}
public final float readFloatEndian() throws IOException
{
float ret = readFloat();
public final float readFloatEndian() throws IOException {
float ret = readFloat();
return ret;
}
return ret;
}
public final float [] readFloat(int len) throws IOException
{
float [] ret = new float[len];
public final float[] readFloat(int len) throws IOException {
float[] ret = new float[len];
for (int i=0; i<len; i++)
ret[i] = readFloat();
for (int i = 0; i < len; i++)
ret[i] = readFloat();
return ret;
}
return ret;
}
public final float [] readFloatEndian(int len) throws IOException
{
float [] ret = new float[len];
public final float[] readFloatEndian(int len) throws IOException {
float[] ret = new float[len];
for (int i=0; i<len; i++)
ret[i] = readFloatEndian();
for (int i = 0; i < len; i++)
ret[i] = readFloatEndian();
return ret;
}
return ret;
}
public final int readIntEndian() throws IOException
{
int ret = readInt();
public final int readIntEndian() throws IOException {
int ret = readInt();
return ret;
}
return ret;
}
public final int [] readInt(int len) throws IOException
{
int [] ret = new int[len];
public final int[] readInt(int len) throws IOException {
int[] ret = new int[len];
for (int i=0; i<len; i++)
ret[i] = readInt();
for (int i = 0; i < len; i++)
ret[i] = readInt();
return ret;
}
return ret;
}
public final int [] readIntEndian(int len) throws IOException
{
int [] ret = new int[len];
public final int[] readIntEndian(int len) throws IOException {
int[] ret = new int[len];
for (int i=0; i<len; i++)
ret[i] = readIntEndian();
for (int i = 0; i < len; i++)
ret[i] = readIntEndian();
return ret;
}
return ret;
}
public final long readLongEndian() throws IOException
{
long ret = (long)readInt();
public final long readLongEndian() throws IOException {
long ret = (long) readInt();
return ret;
}
return ret;
}
public final long [] readLong(int len) throws IOException
{
long [] ret = new long[len];
public final long[] readLong(int len) throws IOException {
long[] ret = new long[len];
for (int i=0; i<len; i++)
ret[i] = readLong();
for (int i = 0; i < len; i++)
ret[i] = readLong();
return ret;
}
return ret;
}
public final long [] readLongEndian(int len) throws IOException
{
long [] ret = new long[len];
public final long[] readLongEndian(int len) throws IOException {
long[] ret = new long[len];
for (int i=0; i<len; i++)
ret[i] = readLongEndian();
for (int i = 0; i < len; i++)
ret[i] = readLongEndian();
return ret;
}
return ret;
}
public final short readShortEndian() throws IOException
{
short ret = readShort();
public final short readShortEndian() throws IOException {
short ret = readShort();
return ret;
}
return ret;
}
public final short [] readShort(int len) throws IOException
{
short [] ret = new short[len];
public final short[] readShort(int len) throws IOException {
short[] ret = new short[len];
for (int i=0; i<len; i++)
ret[i] = readShort();
for (int i = 0; i < len; i++)
ret[i] = readShort();
return ret;
}
return ret;
}
public final short [] readShortEndian(int len) throws IOException
{
short [] ret = new short[len];
public final short[] readShortEndian(int len) throws IOException {
short[] ret = new short[len];
for (int i=0; i<len; i++)
ret[i] = readShortEndian();
for (int i = 0; i < len; i++)
ret[i] = readShortEndian();
return ret;
}
return ret;
}
public final int readUnsignedByteEndian() throws IOException
{
int ret = readUnsignedByte();
public final int readUnsignedByteEndian() throws IOException {
int ret = readUnsignedByte();
return ret;
}
return ret;
}
public final int [] readUnsignedByte(int len) throws IOException
{
int [] ret = new int[len];
public final int[] readUnsignedByte(int len) throws IOException {
int[] ret = new int[len];
for (int i=0; i<len; i++)
ret[i] = readUnsignedByte();
for (int i = 0; i < len; i++)
ret[i] = readUnsignedByte();
return ret;
}
return ret;
}
public final int [] readUnsignedByteEndian(int len) throws IOException
{
int [] ret = new int[len];
public final int[] readUnsignedByteEndian(int len) throws IOException {
int[] ret = new int[len];
for (int i=0; i<len; i++)
ret[i] = readUnsignedByteEndian();
for (int i = 0; i < len; i++)
ret[i] = readUnsignedByteEndian();
return ret;
}
return ret;
}
public final int readUnsignedShortEndian() throws IOException
{
int ret = readUnsignedShort();
public final int readUnsignedShortEndian() throws IOException {
int ret = readUnsignedShort();
return ret;
}
return ret;
}
public final int [] readUnsignedShort(int len) throws IOException
{
int [] ret = new int[len];
public final int[] readUnsignedShort(int len) throws IOException {
int[] ret = new int[len];
for (int i=0; i<len; i++)
ret[i] = readUnsignedShort();
for (int i = 0; i < len; i++)
ret[i] = readUnsignedShort();
return ret;
}
return ret;
}
public final int [] readUnsignedShortEndian(int len) throws IOException
{
int [] ret = new int[len];
public final int[] readUnsignedShortEndian(int len) throws IOException {
int[] ret = new int[len];
for (int i=0; i<len; i++)
ret[i] = readUnsignedShortEndian();
for (int i = 0; i < len; i++)
ret[i] = readUnsignedShortEndian();
return ret;
}
return ret;
}
public final void writeBooleanEndian(boolean v) throws IOException
{
writeBoolean(v);
}
public final void writeBooleanEndian(boolean v) throws IOException {
writeBoolean(v);
}
public final void writeBoolean(boolean [] v, int startPos, int len) throws IOException
public final void writeBoolean(boolean [] v, int startPos, int len) throws IOException
{
assert v.length<startPos+len;
@ -352,7 +317,7 @@ public final class MaryRandomAccessFile extends RandomAccessFile
writeBoolean(v[i]);
}
public final void writeBooleanEndian(boolean [] v, int startPos, int len) throws IOException
public final void writeBooleanEndian(boolean [] v, int startPos, int len) throws IOException
{
assert v.length<startPos+len;
@ -360,22 +325,19 @@ public final class MaryRandomAccessFile extends RandomAccessFile
writeBooleanEndian(v[i]);
}
public final void writeBoolean(boolean [] v) throws IOException
{
writeBoolean(v, 0, v.length);
}
public final void writeBoolean(boolean[] v) throws IOException {
writeBoolean(v, 0, v.length);
}
public final void writeBooleanEndian( boolean [] v) throws IOException
{
writeBooleanEndian(v, 0, v.length);
}
public final void writeBooleanEndian(boolean[] v) throws IOException {
writeBooleanEndian(v, 0, v.length);
}
public final void writeByteEndian(byte v) throws IOException
{
writeByte(v);
}
public final void writeByteEndian(byte v) throws IOException {
writeByte(v);
}
public final void writeByte(byte [] v, int startPos, int len) throws IOException
public final void writeByte(byte [] v, int startPos, int len) throws IOException
{
assert v.length<startPos+len;
@ -383,7 +345,7 @@ public final class MaryRandomAccessFile extends RandomAccessFile
writeByte(v[i]);
}
public final void writeByteEndian(byte [] v, int startPos, int len) throws IOException
public final void writeByteEndian(byte [] v, int startPos, int len) throws IOException
{
assert v.length<startPos+len;
@ -391,22 +353,19 @@ public final class MaryRandomAccessFile extends RandomAccessFile
writeByteEndian(v[i]);
}
public final void writeByte(byte [] v) throws IOException
{
writeByte(v, 0, v.length);
}
public final void writeByte(byte[] v) throws IOException {
writeByte(v, 0, v.length);
}
public final void writeByteEndian(byte [] v) throws IOException
{
writeByteEndian(v, 0, v.length);
}
public final void writeByteEndian(byte[] v) throws IOException {
writeByteEndian(v, 0, v.length);
}
public final void writeCharEndian(char c) throws IOException
{
writeByte((byte)c);
}
public final void writeCharEndian(char c) throws IOException {
writeByte((byte) c);
}
public final void writeChar(char [] v, int startPos, int len) throws IOException
public final void writeChar(char [] v, int startPos, int len) throws IOException
{
assert v.length<startPos+len;
@ -414,7 +373,7 @@ public final class MaryRandomAccessFile extends RandomAccessFile
writeChar(v[i]);
}
public final void writeCharEndian(char [] v, int startPos, int len) throws IOException
public final void writeCharEndian(char [] v, int startPos, int len) throws IOException
{
assert v.length<startPos+len;
@ -422,49 +381,41 @@ public final class MaryRandomAccessFile extends RandomAccessFile
writeCharEndian(v[i]);
}
public final void writeChar(char [] v) throws IOException
{
writeChar(v, 0, v.length);
}
public final void writeChar(char[] v) throws IOException {
writeChar(v, 0, v.length);
}
public final void writeCharEndian(char [] v) throws IOException
{
writeCharEndian(v, 0, v.length);
}
public final void writeCharEndian(char[] v) throws IOException {
writeCharEndian(v, 0, v.length);
}
public final void writeDoubleEndian(double v) throws IOException
{
writeDouble(v);
}
public final void writeDoubleEndian(double v) throws IOException {
writeDouble(v);
}
public final void writeDouble(double [] v, int startPos, int len) throws IOException
{
for (int i=startPos; i<startPos+len; i++)
writeDouble(v[i]);
}
public final void writeDouble(double[] v, int startPos, int len) throws IOException {
for (int i = startPos; i < startPos + len; i++)
writeDouble(v[i]);
}
public final void writeDoubleEndian(double [] v, int startPos, int len) throws IOException
{
for (int i=startPos; i<startPos+len; i++)
writeDoubleEndian(v[i]);
}
public final void writeDoubleEndian(double[] v, int startPos, int len) throws IOException {
for (int i = startPos; i < startPos + len; i++)
writeDoubleEndian(v[i]);
}
public final void writeDouble(double [] v) throws IOException
{
writeDouble(v, 0, v.length);
}
public final void writeDouble(double[] v) throws IOException {
writeDouble(v, 0, v.length);
}
public final void writeDoubleEndian(double [] v) throws IOException
{
writeDoubleEndian(v, 0, v.length);
}
public final void writeDoubleEndian(double[] v) throws IOException {
writeDoubleEndian(v, 0, v.length);
}
public final void writeFloatEndian(float v) throws IOException
{
writeFloat(v);
}
public final void writeFloatEndian(float v) throws IOException {
writeFloat(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
{
assert v.length<startPos+len;
@ -472,7 +423,7 @@ public final class MaryRandomAccessFile extends RandomAccessFile
writeFloat(v[i]);
}
public final void writeFloatEndian(float [] v, int startPos, int len) throws IOException
public final void writeFloatEndian(float [] v, int startPos, int len) throws IOException
{
assert v.length<startPos+len;
@ -480,22 +431,19 @@ public final class MaryRandomAccessFile extends RandomAccessFile
writeFloatEndian(v[i]);
}
public final void writeFloat(float [] v) throws IOException
{
writeFloat(v, 0, v.length);
}
public final void writeFloat(float[] v) throws IOException {
writeFloat(v, 0, v.length);
}
public final void writeFloatEndian(float [] v) throws IOException
{
writeFloatEndian(v, 0, v.length);
}
public final void writeFloatEndian(float[] v) throws IOException {
writeFloatEndian(v, 0, v.length);
}
public final void writeIntEndian(int v) throws IOException
{
writeInt(v);
}
public final void writeIntEndian(int v) throws IOException {
writeInt(v);
}
public final void writeInt(int [] v, int startPos, int len) throws IOException
public final void writeInt(int [] v, int startPos, int len) throws IOException
{
assert v.length<startPos+len;
@ -503,7 +451,7 @@ public final class MaryRandomAccessFile extends RandomAccessFile
writeInt(v[i]);
}
public final void writeIntEndian(int [] v, int startPos, int len) throws IOException
public final void writeIntEndian(int [] v, int startPos, int len) throws IOException
{
assert v.length<startPos+len;
@ -511,22 +459,19 @@ public final class MaryRandomAccessFile extends RandomAccessFile
writeIntEndian(v[i]);
}
public final void writeInt(int [] v) throws IOException
{
writeInt(v, 0, v.length);
}
public final void writeInt(int[] v) throws IOException {
writeInt(v, 0, v.length);
}
public final void writeIntEndian(int [] v) throws IOException
{
writeIntEndian(v, 0, v.length);
}
public final void writeIntEndian(int[] v) throws IOException {
writeIntEndian(v, 0, v.length);
}
public final void writeLongEndian(long v) throws IOException
{
writeInt((int)v);
}
public final void writeLongEndian(long v) throws IOException {
writeInt((int) v);
}
public final void writeLong (long [] v, int startPos, int len) throws IOException
public final void writeLong (long [] v, int startPos, int len) throws IOException
{
assert v.length<startPos+len;
@ -534,7 +479,7 @@ public final class MaryRandomAccessFile extends RandomAccessFile
writeLong(v[i]);
}
public final void writeLongEndian(long [] v, int startPos, int len) throws IOException
public final void writeLongEndian(long [] v, int startPos, int len) throws IOException
{
assert v.length<startPos+len;
@ -542,22 +487,19 @@ public final class MaryRandomAccessFile extends RandomAccessFile
writeLongEndian(v[i]);
}
public final void writeLong(long [] v) throws IOException
{
writeLong(v, 0, v.length);
}
public final void writeLong(long[] v) throws IOException {
writeLong(v, 0, v.length);
}
public final void writeLongEndian(long [] v) throws IOException
{
writeLongEndian(v, 0, v.length);
}
public final void writeLongEndian(long[] v) throws IOException {
writeLongEndian(v, 0, v.length);
}
public final void writeShortEndian(short v) throws IOException
{
writeShort(v);
}
public final void writeShortEndian(short v) throws IOException {
writeShort(v);
}
public final void writeShort(short [] v, int startPos, int len) throws IOException
public final void writeShort(short [] v, int startPos, int len) throws IOException
{
assert v.length<startPos+len;
@ -565,7 +507,7 @@ public final class MaryRandomAccessFile extends RandomAccessFile
writeShort(v[i]);
}
public final void writeShortEndian(short [] v, int startPos, int len) throws IOException
public final void writeShortEndian(short [] v, int startPos, int len) throws IOException
{
assert v.length<startPos+len;
@ -573,14 +515,11 @@ public final class MaryRandomAccessFile extends RandomAccessFile
writeShortEndian(v[i]);
}
public final void writeShort(short [] v) throws IOException
{
writeShort(v, 0, v.length);
}
public final void writeShort(short[] v) throws IOException {
writeShort(v, 0, v.length);
}
public final void writeShortEndian(short [] v) throws IOException
{
writeShort(v);
}
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
*
@ -15,19 +14,19 @@ import java.util.Scanner;
*
*/
public class PropertiesTrimTrailingWhitespace extends Properties {
/**
/**
* removes trailing whitespace
*/
public void load(InputStream fis) throws IOException {
Scanner in = new Scanner(fis);
ByteArrayOutputStream out = new ByteArrayOutputStream();
Scanner in = new Scanner(fis);
ByteArrayOutputStream out = new ByteArrayOutputStream();
while(in.hasNext()) {
out.write(in.nextLine().trim().getBytes());
out.write("\n".getBytes());
}
in.close();
InputStream is = new ByteArrayInputStream(out.toByteArray());
super.load(is);
}
while (in.hasNext()) {
out.write(in.nextLine().trim().getBytes());
out.write("\n".getBytes());
}
in.close();
InputStream is = new ByteArrayInputStream(out.toByteArray());
super.load(is);
}
}

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

@ -26,47 +26,40 @@ 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
{
private BufferedReader in;
private StringBuffer buf;
private String endMarker;
public class ReaderSplitter {
private BufferedReader in;
private StringBuffer buf;
private String endMarker;
public ReaderSplitter(Reader in, String endMarker)
{
this.in = new BufferedReader(in);
this.endMarker = endMarker;
buf = new StringBuffer(1000);
}
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.
*/
public Reader nextReader()
throws IOException
{
String line = null;
buf.setLength(0); // start with an empty buffer
while ((line = in.readLine()) != null) {
buf.append(line);
buf.append(System.getProperty("line.separator"));
if (line.indexOf(endMarker) != -1) { // found end marker in line
break;
}
}
if (buf.length() == 0) return null; // nothing more to read.
return (Reader) new StringReader(buf.toString());
}
/**
* 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 {
String line = null;
buf.setLength(0); // start with an empty buffer
while ((line = in.readLine()) != null) {
buf.append(line);
buf.append(System.getProperty("line.separator"));
if (line.indexOf(endMarker) != -1) { // found end marker in line
break;
}
}
if (buf.length() == 0)
return null; // nothing more to read.
return (Reader) new StringReader(buf.toString());
}
}

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

@ -25,34 +25,36 @@ 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
{
String extension;
String description;
public SimpleFileFilter(String extension, String description)
{
this.extension = extension;
this.description = description;
}
public class SimpleFileFilter extends FileFilter {
String extension;
String description;
public boolean accept(File f) {
if (f.isDirectory()) {
return true;
}
String ext = MaryUtils.getExtension(f);
if (ext != null) {
return ext.equals(extension);
}
return false;
}
public SimpleFileFilter(String extension, String description) {
this.extension = extension;
this.description = description;
}
public String getDescription() { return description; }
public boolean accept(File f) {
if (f.isDirectory()) {
return true;
}
String ext = MaryUtils.getExtension(f);
if (ext != null) {
return ext.equals(extension);
}
return false;
}
public String getExtension() { return extension; }
public String getDescription() {
return description;
}
public String getExtension() {
return extension;
}
}

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

@ -8,29 +8,24 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
public class StreamGobbler extends Thread
{
InputStream is;
String type;
public class StreamGobbler extends Thread {
InputStream is;
String type;
public StreamGobbler(InputStream is, String type)
{
this.is = is;
this.type = type;
}
public StreamGobbler(InputStream is, String type) {
this.is = is;
this.type = type;
}
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)
{
ioe.printStackTrace();
}
}
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) {
ioe.printStackTrace();
}
}
}

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

@ -31,73 +31,64 @@ 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
{
private InputStream is;
private PrintStream ps;
private Logger logger;
private Pattern ignorePattern = null;
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.
*/
public StreamLogger(InputStream is, String logCategory, String ignorePattern)
{
this.is = is;
if (logCategory == null)
logger = MaryUtils.getLogger("unnamed");
else
logger = MaryUtils.getLogger(logCategory);
if (ignorePattern != null) {
try {
this.ignorePattern = Pattern.compile(ignorePattern);
} catch (PatternSyntaxException e) {
logger.warn("Problem with regular expression pattern", e);
this.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.
*/
public StreamLogger(InputStream is, String logCategory, String ignorePattern) {
this.is = is;
if (logCategory == null)
logger = MaryUtils.getLogger("unnamed");
else
logger = MaryUtils.getLogger(logCategory);
if (ignorePattern != null) {
try {
this.ignorePattern = Pattern.compile(ignorePattern);
} catch (PatternSyntaxException e) {
logger.warn("Problem with regular expression pattern", e);
this.ignorePattern = null;
}
}
}
public StreamLogger(InputStream is, PrintStream ps) {
this.is = is;
this.ps = ps;
}
public StreamLogger(InputStream is, PrintStream ps) {
this.is = is;
this.ps = ps;
}
public void run()
{
String line = null;
try {
BufferedReader b = new BufferedReader(new InputStreamReader(is));
while ((line = b.readLine()) != null) {
if (ignorePattern != null && ignorePattern.matcher(line).matches())
continue; // do not log
if (ps != null) {
ps.println(line);
} else {
logger.info(line);
}
}
} catch (IOException e) {
try {
logger.warn("Cannot read from stream", e);
} catch (NullPointerException npe) {
e.printStackTrace();
}
}
}
public void run() {
String line = null;
try {
BufferedReader b = new BufferedReader(new InputStreamReader(is));
while ((line = b.readLine()) != null) {
if (ignorePattern != null && ignorePattern.matcher(line).matches())
continue; // do not log
if (ps != null) {
ps.println(line);
} else {
logger.info(line);
}
}
} catch (IOException e) {
try {
logger.warn("Cannot read from stream", e);
} catch (NullPointerException npe) {
e.printStackTrace();
}
}
}
}

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

@ -38,20 +38,18 @@ import java.nio.ByteBuffer;
*/
public class StreamUtils {
public static double[] readDoubleArray(DataInput stream, int len)
throws IOException {
byte[] raw = new byte[len*Double.SIZE/8];
stream.readFully(raw);
DataInputStream in = new DataInputStream(new ByteArrayInputStream(raw));
double[] data = new double[len];
for (int i=0; i<len; i++) {
data[i] = in.readDouble();
}
return data;
}
public static double[] readDoubleArray(DataInput stream, int len) throws IOException {
byte[] raw = new byte[len * Double.SIZE / 8];
stream.readFully(raw);
DataInputStream in = new DataInputStream(new ByteArrayInputStream(raw));
double[] data = new double[len];
for (int i = 0; i < len; i++) {
data[i] = in.readDouble();
}
return data;
}
public static void writeDoubleArray(DataOutput stream, double[] data)
public static void writeDoubleArray(DataOutput stream, double[] data)
throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(baos);
@ -64,107 +62,102 @@ public class StreamUtils {
stream.write(raw);
}
/**
* 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.
* @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.
* @see java.io.DataInputStream#readUnsignedShort()
*/
public static String readUTF(ByteBuffer bb) throws BufferUnderflowException, UTFDataFormatException {
int utflen = readUnsignedShort(bb);
byte[] bytearr = new byte[utflen];
char[] chararr = new char[utflen];
/**
* 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.
* @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.
* @see java.io.DataInputStream#readUnsignedShort()
*/
public static String readUTF(ByteBuffer bb) throws BufferUnderflowException, UTFDataFormatException {
int utflen = readUnsignedShort(bb);
byte[] bytearr = new byte[utflen];
char[] chararr = new char[utflen];
int c, char2, char3;
int count = 0;
int chararr_count=0;
int c, char2, char3;
int count = 0;
int chararr_count = 0;
bb.get(bytearr);
bb.get(bytearr);
while (count < utflen) {
c = (int) bytearr[count] & 0xff;
if (c > 127) break;
count++;
chararr[chararr_count++]=(char)c;
}
while (count < utflen) {
c = (int) bytearr[count] & 0xff;
if (c > 127)
break;
count++;
chararr[chararr_count++] = (char) c;
}
while (count < utflen) {
c = (int) bytearr[count] & 0xff;
switch (c >> 4) {
case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
/* 0xxxxxxx*/
count++;
chararr[chararr_count++]=(char)c;
break;
case 12: case 13:
/* 110x xxxx 10xx xxxx*/
count += 2;
if (count > utflen)
throw new UTFDataFormatException(
"malformed input: partial character at end");
char2 = (int) bytearr[count-1];
if ((char2 & 0xC0) != 0x80)
throw new UTFDataFormatException(
"malformed input around byte " + count);
chararr[chararr_count++]=(char)(((c & 0x1F) << 6) |
(char2 & 0x3F));
break;
case 14:
/* 1110 xxxx 10xx xxxx 10xx xxxx */
count += 3;
if (count > utflen)
throw new UTFDataFormatException(
"malformed input: partial character at end");
char2 = (int) bytearr[count-2];
char3 = (int) bytearr[count-1];
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));
break;
default:
/* 10xx xxxx, 1111 xxxx */
throw new UTFDataFormatException(
"malformed input around byte " + count);
}
}
// The number of chars produced may be less than utflen
return new String(chararr, 0, chararr_count);
}
while (count < utflen) {
c = (int) bytearr[count] & 0xff;
switch (c >> 4) {
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
/* 0xxxxxxx */
count++;
chararr[chararr_count++] = (char) c;
break;
case 12:
case 13:
/* 110x xxxx 10xx xxxx */
count += 2;
if (count > utflen)
throw new UTFDataFormatException("malformed input: partial character at end");
char2 = (int) bytearr[count - 1];
if ((char2 & 0xC0) != 0x80)
throw new UTFDataFormatException("malformed input around byte " + count);
chararr[chararr_count++] = (char) (((c & 0x1F) << 6) | (char2 & 0x3F));
break;
case 14:
/* 1110 xxxx 10xx xxxx 10xx xxxx */
count += 3;
if (count > utflen)
throw new UTFDataFormatException("malformed input: partial character at end");
char2 = (int) bytearr[count - 2];
char3 = (int) bytearr[count - 1];
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));
break;
default:
/* 10xx xxxx, 1111 xxxx */
throw new UTFDataFormatException("malformed input around byte " + count);
}
}
// The number of chars produced may be less than utflen
return new String(chararr, 0, chararr_count);
}
/**
* 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
*
* @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 {
int ch1 = bb.get() & 0xFF; // convert byte to unsigned byte
int ch2 = bb.get() & 0xFF; // convert byte to unsigned byte
return (ch1 << 8) + (ch2 << 0);
}
/**
* 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
*
* @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 {
int ch1 = bb.get() & 0xFF; // convert byte to unsigned byte
int ch2 = bb.get() & 0xFF; // convert byte to unsigned byte
return (ch1 << 8) + (ch2 << 0);
}
}