From 80ec3282a476cd90257aa827330d54182690968c Mon Sep 17 00:00:00 2001 From: yeom Date: Tue, 12 Jul 2011 20:09:54 +0000 Subject: [PATCH] try to make mp3decoder compile --- .../SSJava/ByteArrayInputStream.java | 251 ++++++ Robust/src/ClassLibrary/SSJava/Cloneable.java | 78 ++ .../ClassLibrary/SSJava/FileDescriptor.java | 144 +++ .../ClassLibrary/SSJava/FileOutputStream.java | 63 ++ Robust/src/ClassLibrary/SSJava/Float.java | 630 +++++++++++++ Robust/src/ClassLibrary/SSJava/Integer.java | 6 + Robust/src/ClassLibrary/SSJava/Long.java | 832 ++++++++++++++++++ Robust/src/ClassLibrary/SSJava/String.java | 110 +++ .../src/ClassLibrary/SSJava/StringBuffer.java | 142 +++ .../Tests/ssJava/mp3decoder/Bitstream.java | 6 - .../ssJava/mp3decoder/BitstreamException.java | 3 +- .../src/Tests/ssJava/mp3decoder/Decoder.java | 21 +- .../ssJava/mp3decoder/DecoderException.java | 3 +- .../src/Tests/ssJava/mp3decoder/Header.java | 4 +- .../ssJava/mp3decoder/JavaLayerException.java | 158 ++-- .../ssJava/mp3decoder/LayerIDecoder.java | 76 +- .../ssJava/mp3decoder/LayerIIDecoder.java | 12 +- .../ssJava/mp3decoder/LayerIIIDecoder.java | 9 +- .../src/Tests/ssJava/mp3decoder/Obuffer.java | 4 +- .../src/Tests/ssJava/mp3decoder/Player.java | 2 +- .../src/Tests/ssJava/mp3decoder/Subband.java | 39 + .../ssJava/mp3decoder/SynthesisFilter.java | 6 +- 22 files changed, 2445 insertions(+), 154 deletions(-) create mode 100644 Robust/src/ClassLibrary/SSJava/ByteArrayInputStream.java create mode 100644 Robust/src/ClassLibrary/SSJava/Cloneable.java create mode 100644 Robust/src/ClassLibrary/SSJava/FileDescriptor.java create mode 100644 Robust/src/ClassLibrary/SSJava/FileOutputStream.java create mode 100644 Robust/src/ClassLibrary/SSJava/Float.java create mode 100644 Robust/src/ClassLibrary/SSJava/Long.java create mode 100644 Robust/src/ClassLibrary/SSJava/StringBuffer.java create mode 100644 Robust/src/Tests/ssJava/mp3decoder/Subband.java diff --git a/Robust/src/ClassLibrary/SSJava/ByteArrayInputStream.java b/Robust/src/ClassLibrary/SSJava/ByteArrayInputStream.java new file mode 100644 index 00000000..eb05a83a --- /dev/null +++ b/Robust/src/ClassLibrary/SSJava/ByteArrayInputStream.java @@ -0,0 +1,251 @@ +/* ByteArrayInputStream.java -- Read an array as a stream + Copyright (C) 1998, 1999, 2001, 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +//package java.io; + +/** + * This class permits an array of bytes to be read as an input stream. + * + * @author Warren Levy (warrenl@cygnus.com) + * @author Aaron M. Renn (arenn@urbanophile.com) + */ +public class ByteArrayInputStream extends InputStream +{ + /** + * The array that contains the data supplied during read operations + */ + protected byte[] buf; + + /** + * The array index of the next byte to be read from the buffer + * buf + */ + protected int pos; + + /** + * The currently marked position in the stream. This defaults to 0, so a + * reset operation on the stream resets it to read from array index 0 in + * the buffer - even if the stream was initially created with an offset + * greater than 0 + */ + protected int mark; + + /** + * This indicates the maximum number of bytes that can be read from this + * stream. It is the array index of the position after the last valid + * byte in the buffer buf + */ + protected int count; + + /** + * Create a new ByteArrayInputStream that will read bytes from the passed + * in byte array. This stream will read from the beginning to the end + * of the array. It is identical to calling an overloaded constructor + * as ByteArrayInputStream(buf, 0, buf.length). + *

+ * Note that this array is not copied. If its contents are changed + * while this stream is being read, those changes will be reflected in the + * bytes supplied to the reader. Please use caution in changing the + * contents of the buffer while this stream is open. + * + * @param buffer The byte array buffer this stream will read from. + */ + public ByteArrayInputStream(byte[] buffer) + { + this(buffer, 0, buffer.length); + } + + /** + * Create a new ByteArrayInputStream that will read bytes from the + * passed in byte array. This stream will read from position + * offset in the array for a length of + * length bytes past offset. If the + * stream is reset to a position before offset then + * more than length bytes can be read from the stream. + * The length value should be viewed as the array index + * one greater than the last position in the buffer to read. + *

+ * Note that this array is not copied. If its contents are changed + * while this stream is being read, those changes will be reflected in the + * bytes supplied to the reader. Please use caution in changing the + * contents of the buffer while this stream is open. + * + * @param buffer The byte array buffer this stream will read from. + * @param offset The index into the buffer to start reading bytes from + * @param length The number of bytes to read from the buffer + */ + public ByteArrayInputStream(byte[] buffer, int offset, int length) + { + if (offset < 0 || length < 0 || offset > buffer.length) + throw new IllegalArgumentException(); + + buf = buffer; + + count = offset + length; + if (count > buf.length) + count = buf.length; + + pos = offset; + mark = pos; + } + + /** + * This method returns the number of bytes available to be read from this + * stream. The value returned will be equal to count - pos. + * + * @return The number of bytes that can be read from this stream + * before blocking, which is all of them + */ + public synchronized int available() + { + return count - pos; + } + + /** + * This method sets the mark position in this stream to the current + * position. Note that the readlimit parameter in this + * method does nothing as this stream is always capable of + * remembering all the bytes int it. + *

+ * Note that in this class the mark position is set by default to + * position 0 in the stream. This is in constrast to some other + * stream types where there is no default mark position. + * + * @param readLimit The number of bytes this stream must remember. + * This parameter is ignored. + */ + public synchronized void mark(int readLimit) + { + // readLimit is ignored per Java Class Lib. book, p.220. + mark = pos; + } + + /** + * This method overrides the markSupported method in + * InputStream in order to return true - + * indicating that this stream class supports mark/reset + * functionality. + * + * @return true to indicate that this class supports + * mark/reset. + */ + public boolean markSupported() + { + return true; + } + + /** + * This method reads one byte from the stream. The pos + * counter is advanced to the next byte to be read. The byte read is + * returned as an int in the range of 0-255. If the stream position + * is already at the end of the buffer, no byte is read and a -1 is + * returned in order to indicate the end of the stream. + * + * @return The byte read, or -1 if end of stream + */ + public synchronized int read() + { + if (pos < count) + return ((int) buf[pos++]) & 0xFF; + return -1; + } + + /** + * This method reads bytes from the stream and stores them into a + * caller supplied buffer. It starts storing the data at index + * offset into the buffer and attempts to read + * len bytes. This method can return before reading + * the number of bytes requested if the end of the stream is + * encountered first. The actual number of bytes read is returned. + * If no bytes can be read because the stream is already at the end + * of stream position, a -1 is returned. + *

+ * This method does not block. + * + * @param buffer The array into which the bytes read should be stored. + * @param offset The offset into the array to start storing bytes + * @param length The requested number of bytes to read + * + * @return The actual number of bytes read, or -1 if end of stream. + */ + public synchronized int read(byte[] buffer, int offset, int length) + { + if (pos >= count) + return -1; + + int numBytes = Math.min(count - pos, length); + System.arraycopy(buf, pos, buffer, offset, numBytes); + pos += numBytes; + return numBytes; + } + + /** + * This method sets the read position in the stream to the mark + * point by setting the pos variable equal to the + * mark variable. Since a mark can be set anywhere in + * the array, the mark/reset methods int this class can be used to + * provide random search capabilities for this type of stream. + */ + public synchronized void reset() + { + pos = mark; + } + + /** + * This method attempts to skip the requested number of bytes in the + * input stream. It does this by advancing the pos + * value by the specified number of bytes. It this would exceed the + * length of the buffer, then only enough bytes are skipped to + * position the stream at the end of the buffer. The actual number + * of bytes skipped is returned. + * + * @param num The requested number of bytes to skip + * + * @return The actual number of bytes skipped. + */ + public synchronized long skip(long num) + { + // Even though the var numBytes is a long, in reality it can never + // be larger than an int since the result of subtracting 2 positive + // ints will always fit in an int. Since we have to return a long + // anyway, numBytes might as well just be a long. + long numBytes = Math.min((long) (count - pos), num < 0 ? 0L : num); + pos += numBytes; + return numBytes; + } +} \ No newline at end of file diff --git a/Robust/src/ClassLibrary/SSJava/Cloneable.java b/Robust/src/ClassLibrary/SSJava/Cloneable.java new file mode 100644 index 00000000..2f51beed --- /dev/null +++ b/Robust/src/ClassLibrary/SSJava/Cloneable.java @@ -0,0 +1,78 @@ +/* Cloneable.java -- Interface for marking objects cloneable by Object.clone() + Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +//package java.lang; + +/** + * This interface should be implemented by classes wishing to + * support of override Object.clone(). The default + * behaviour of clone() performs a shallow copy, but + * subclasses often change this to perform a deep copy. Therefore, + * it is a good idea to document how deep your clone will go. + * If clone() is called on an object which does not + * implement this interface, a CloneNotSupportedException + * will be thrown. + * + *

This interface is simply a tagging interface; it carries no + * requirements on methods to implement. However, it is typical for + * a Cloneable class to implement at least equals, + * hashCode, and clone, sometimes + * increasing the accessibility of clone to be public. The typical + * implementation of clone invokes super.clone() + * rather than a constructor, but this is not a requirement. + * + *

If an object that implement Cloneable should not be cloned, + * simply override the clone method to throw a + * CloneNotSupportedException. + * + *

All array types implement Cloneable, and have a public + * clone method that will never fail with a + * CloneNotSupportedException. + * + * @author Paul Fisher + * @author Eric Blake (ebb9@email.byu.edu) + * @author Warren Levy (warrenl@cygnus.com) + * @see Object#clone() + * @see CloneNotSupportedException + * @since 1.0 + * @status updated to 1.4 + */ +public interface Cloneable +{ + // Tagging interface only. +} diff --git a/Robust/src/ClassLibrary/SSJava/FileDescriptor.java b/Robust/src/ClassLibrary/SSJava/FileDescriptor.java new file mode 100644 index 00000000..3e46732d --- /dev/null +++ b/Robust/src/ClassLibrary/SSJava/FileDescriptor.java @@ -0,0 +1,144 @@ +/* FileDescriptor.java -- Opaque file handle class + Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004 + Free Software Foundation, Inc. + + This file is part of GNU Classpath. + + GNU Classpath is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + GNU Classpath 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 + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNU Classpath; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. + + Linking this library statically or dynamically with other modules is + making a combined work based on this library. Thus, the terms and + conditions of the GNU General Public License cover the whole + combination. + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent + modules, and to copy and distribute the resulting executable under + terms of your choice, provided that you also meet, for each linked + independent module, the terms and conditions of the license of that + module. An independent module is a module which is not derived from + or based on this library. If you modify this library, you may extend + this exception to your version of the library, but you are not + obligated to do so. If you do not wish to do so, delete this + exception statement from your version. */ + + +//package java.io; + +/*import gnu.java.nio.FileChannelImpl; + + import java.nio.channels.ByteChannel; + import java.nio.channels.FileChannel; + */ +/** + * This class represents an opaque file handle as a Java class. It should + * be used only to pass to other methods that expect an object of this + * type. No system specific information can be obtained from this object. + * + * @author Aaron M. Renn (arenn@urbanophile.com) + * @author Tom Tromey (tromey@cygnus.com) + * @date September 24, 1998 + */ +public final class FileDescriptor +{ + /** + * A FileDescriptor representing the system standard input + * stream. This will usually be accessed through the + * System.invariable. + */ + public static final FileDescriptor in + = new FileDescriptor ("System.in" /*FileChannelImpl.in*/); + + /** + * A FileDescriptor representing the system standard output + * stream. This will usually be accessed through the + * System.outvariable. + */ + public static final FileDescriptor out + = new FileDescriptor ("System.out" /*FileChannelImpl.out*/); + + /** + * A FileDescriptor representing the system standard error + * stream. This will usually be accessed through the + * System.errvariable. + */ + public static final FileDescriptor err + = new FileDescriptor ("System.err" /*FileChannelImpl.err*/); + + //final ByteChannel channel; + final String channel; + + /** + * This method is used to initialize an invalid FileDescriptor object. + */ + public FileDescriptor() { + channel = null; + } + + /** + * This method is used to initialize a FileDescriptor object. + */ + /*FileDescriptor(ByteChannel channel) + { + this.channel = channel; + }*/ + + FileDescriptor(String channel) { + this.channel = channel; + } + + + /** + * This method forces all data that has not yet been physically written to + * the underlying storage medium associated with this + * FileDescriptor + * to be written out. This method will not return until all data has + * been fully written to the underlying device. If the device does not + * support this functionality or if an error occurs, then an exception + * will be thrown. + */ + /*public void sync () throws SyncFailedException + { + if (channel instanceof FileChannel) + { + try + { + ((FileChannel) channel).force(true); + } + catch (IOException ex) + { + if (ex instanceof SyncFailedException) + throw (SyncFailedException) ex; + else + throw new SyncFailedException(ex.toString()); + } + } + }*/ + + /** + * This methods tests whether or not this object represents a valid open + * native file handle. + * + * @return true if this object represents a valid + * native file handle, false otherwise + */ + /*public boolean valid () + { + ByteChannel c = channel; + return (c != null) && (c.isOpen()); + }*/ +} diff --git a/Robust/src/ClassLibrary/SSJava/FileOutputStream.java b/Robust/src/ClassLibrary/SSJava/FileOutputStream.java new file mode 100644 index 00000000..78fe1bb9 --- /dev/null +++ b/Robust/src/ClassLibrary/SSJava/FileOutputStream.java @@ -0,0 +1,63 @@ +//import java.io.FileDescriptor; + +public class FileOutputStream extends OutputStream { + private int fd; + + public FileOutputStream(String pathname) { + fd=nativeOpen(pathname.getBytes()); + } + + public FileOutputStream(String pathname, boolean append) { + if(append) + fd=nativeAppend(pathname.getBytes()); + else + fd=nativeOpen(pathname.getBytes()); + } + + public FileOutputStream(String pathname, int mode) { + if(mode==0) + fd=nativeAppend(pathname.getBytes()); + if(mode==1) + fd=nativeOpen(pathname.getBytes()); + } + + public FileOutputStream(File path) { + fd=nativeOpen(path.getPath().getBytes()); + } + + public FileOutputStreamOpen(String pathname) { + fd = nativeOpen(pathname.getBytes()); + } + + public FileOutputStream(FileDescriptor fdObj) { + fd = nativeOpen(fdObj.channel.getBytes()); + } + + private static native int nativeOpen(byte[] filename); + private static native int nativeAppend(byte[] filename); + private static native void nativeWrite(int fd, byte[] array, int off, int len); + private static native void nativeClose(int fd); + private static native void nativeFlush(int fd); + + public void write(int ch) { + byte b[]=new byte[1]; + b[0]=(byte)ch; + write(b); + } + + public void write(byte[] b) { + nativeWrite(fd, b, 0, b.length); + } + + public void write(byte[] b, int index, int len) { + nativeWrite(fd, b, index, len); + } + + public void flush() { + nativeFlush(fd); + } + + public void close() { + nativeClose(fd); + } +} diff --git a/Robust/src/ClassLibrary/SSJava/Float.java b/Robust/src/ClassLibrary/SSJava/Float.java new file mode 100644 index 00000000..360145af --- /dev/null +++ b/Robust/src/ClassLibrary/SSJava/Float.java @@ -0,0 +1,630 @@ +/* Float.java -- object wrapper for float + Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 + Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +/** + * Instances of class Float represent primitive + * float values. + * + * Additionally, this class provides various helper functions and variables + * related to floats. + * + * @author Paul Fisher + * @author Andrew Haley (aph@cygnus.com) + * @author Eric Blake (ebb9@email.byu.edu) + * @author Tom Tromey (tromey@redhat.com) + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.0 + * @status partly updated to 1.5 + */ +public final class Float +{ + /** + * Compatible with JDK 1.0+. + */ + private static final long serialVersionUID = -2671257302660747028L; + + /** + * The maximum positive value a double may represent + * is 3.4028235e+38f. + */ + public static final float MAX_VALUE = 3.4028235e+38f; + + /** + * The minimum positive value a float may represent + * is 1.4e-45. + */ + public static final float MIN_VALUE = 1.4e-45f; + + /** + * The value of a float representation -1.0/0.0, negative infinity. + */ + public static final float NEGATIVE_INFINITY = -1.0f / 0.0f; + + /** + * The value of a float representation 1.0/0.0, positive infinity. + */ + public static final float POSITIVE_INFINITY = 1.0f / 0.0f; + + /** + * All IEEE 754 values of NaN have the same value in Java. + */ + public static final float NaN = 0.0f / 0.0f; + + /** + * The primitive type float is represented by this + * Class object. + * @since 1.1 + */ + //public static final Class TYPE = (Class) VMClassLoader.getPrimitiveClass('F'); + + /** + * The number of bits needed to represent a float. + * @since 1.5 + */ + public static final int SIZE = 32; + + /** + * Cache representation of 0 + */ + private static final Float ZERO = new Float(0.0f); + + /** + * Cache representation of 1 + */ + private static final Float ONE = new Float(1.0f); + + /** + * The immutable value of this Float. + * + * @serial the wrapped float + */ + private final float value; + + /** + * Create a Float from the primitive float + * specified. + * + * @param value the float argument + */ + public Float(float value) + { + this.value = value; + } + + /** + * Create a Float from the primitive double + * specified. + * + * @param value the double argument + */ + public Float(double value) + { + this.value = (float) value; + } + + /** + * Create a Float from the specified String. + * This method calls Float.parseFloat(). + * + * @param s the String to convert + * @throws NumberFormatException if s cannot be parsed as a + * float + * @throws NullPointerException if s is null + * @see #parseFloat(String) + */ + public Float(String s) + { + value = parseFloat(s); + } + + /** + * Convert the float to a String. + * Floating-point string representation is fairly complex: here is a + * rundown of the possible values. "[-]" indicates that a + * negative sign will be printed if the value (or exponent) is negative. + * "<number>" means a string of digits ('0' to '9'). + * "<digit>" means a single digit ('0' to '9').
+ * + * + * + * + * + * + * + * + * + * + *
Value of FloatString Representation
[+-] 0 [-]0.0
Between [+-] 10-3 and 107, exclusive[-]number.number
Other numeric value[-]<digit>.<number> + * E[-]<number>
[+-] infinity [-]Infinity
NaN NaN
+ * + * Yes, negative zero is a possible value. Note that there is + * always a . and at least one digit printed after + * it: even if the number is 3, it will be printed as 3.0. + * After the ".", all digits will be printed except trailing zeros. The + * result is rounded to the shortest decimal number which will parse back + * to the same float. + * + *

To create other output formats, use {@link java.text.NumberFormat}. + * + * @XXX specify where we are not in accord with the spec. + * + * @param f the float to convert + * @return the String representing the float + */ + /*public static String toString(float f) + { + return VMFloat.toString(f); + }*/ + + /** + * Convert a float value to a hexadecimal string. This converts as + * follows: + *

+ * @param f the float value + * @return the hexadecimal string representation + * @since 1.5 + */ + /*public static String toHexString(float f) + { + if (isNaN(f)) + return "NaN"; + if (isInfinite(f)) + return f < 0 ? "-Infinity" : "Infinity"; + + int bits = floatToIntBits(f); + CPStringBuilder result = new CPStringBuilder(); + + if (bits < 0) + result.append('-'); + result.append("0x"); + + final int mantissaBits = 23; + final int exponentBits = 8; + int mantMask = (1 << mantissaBits) - 1; + int mantissa = bits & mantMask; + int expMask = (1 << exponentBits) - 1; + int exponent = (bits >>> mantissaBits) & expMask; + + result.append(exponent == 0 ? '0' : '1'); + result.append('.'); + // For Float only, we have to adjust the mantissa. + mantissa <<= 1; + result.append(Integer.toHexString(mantissa)); + if (exponent == 0 && mantissa != 0) + { + // Treat denormal specially by inserting '0's to make + // the length come out right. The constants here are + // to account for things like the '0x'. + int offset = 4 + ((bits < 0) ? 1 : 0); + // The silly +3 is here to keep the code the same between + // the Float and Double cases. In Float the value is + // not a multiple of 4. + int desiredLength = offset + (mantissaBits + 3) / 4; + while (result.length() < desiredLength) + result.insert(offset, '0'); + } + result.append('p'); + if (exponent == 0 && mantissa == 0) + { + // Zero, so do nothing special. + } + else + { + // Apply bias. + boolean denormal = exponent == 0; + exponent -= (1 << (exponentBits - 1)) - 1; + // Handle denormal. + if (denormal) + ++exponent; + } + + result.append(Integer.toString(exponent)); + return result.toString(); + }*/ + + /** + * Creates a new Float object using the String. + * + * @param s the String to convert + * @return the new Float + * @throws NumberFormatException if s cannot be parsed as a + * float + * @throws NullPointerException if s is null + * @see #parseFloat(String) + */ + public static Float valueOf(String s) + { + return valueOf(parseFloat(s)); + } + + /** + * Returns a Float object wrapping the value. + * In contrast to the Float constructor, this method + * may cache some values. It is used by boxing conversion. + * + * @param val the value to wrap + * @return the Float + * @since 1.5 + */ + public static Float valueOf(float val) + { + if ((val == 0.0)/* && (floatToRawIntBits(val) == 0)*/) + return ZERO; + else if (val == 1.0) + return ONE; + else + return new Float(val); + } + + /** + * Parse the specified String as a float. The + * extended BNF grammar is as follows:
+ *
+   * DecodableString:
+   *      ( [ - | + ] NaN )
+   *    | ( [ - | + ] Infinity )
+   *    | ( [ - | + ] FloatingPoint
+   *              [ f | F | d
+   *                | D] )
+   * FloatingPoint:
+   *      ( { Digit }+ [ . { Digit } ]
+   *              [ Exponent ] )
+   *    | ( . { Digit }+ [ Exponent ] )
+   * Exponent:
+   *      ( ( e | E )
+   *              [ - | + ] { Digit }+ )
+   * Digit: '0' through '9'
+   * 
+ * + *

NaN and infinity are special cases, to allow parsing of the output + * of toString. Otherwise, the result is determined by calculating + * n * 10exponent to infinite precision, then rounding + * to the nearest float. Remember that many numbers cannot be precisely + * represented in floating point. In case of overflow, infinity is used, + * and in case of underflow, signed zero is used. Unlike Integer.parseInt, + * this does not accept Unicode digits outside the ASCII range. + * + *

If an unexpected character is found in the String, a + * NumberFormatException will be thrown. Leading and trailing + * 'whitespace' is ignored via String.trim(), but spaces + * internal to the actual number are not allowed. + * + *

To parse numbers according to another format, consider using + * {@link java.text.NumberFormat}. + * + * @XXX specify where/how we are not in accord with the spec. + * + * @param str the String to convert + * @return the float value of s + * @throws NumberFormatException if str cannot be parsed as a + * float + * @throws NullPointerException if str is null + * @see #MIN_VALUE + * @see #MAX_VALUE + * @see #POSITIVE_INFINITY + * @see #NEGATIVE_INFINITY + * @since 1.2 + */ + public static float parseFloat(String str) + { + //return VMFloat.parseFloat(str); + return (float)(Long.parseLong(str)); + } + + /** + * Return true if the float has the same + * value as NaN, otherwise return false. + * + * @param v the float to compare + * @return whether the argument is NaN + */ + public static boolean isNaN(float v) + { + // This works since NaN != NaN is the only reflexive inequality + // comparison which returns true. + return v != v; + } + + /** + * Return true if the float has a value + * equal to either NEGATIVE_INFINITY or + * POSITIVE_INFINITY, otherwise return false. + * + * @param v the float to compare + * @return whether the argument is (-/+) infinity + */ + public static boolean isInfinite(float v) + { + return v == POSITIVE_INFINITY || v == NEGATIVE_INFINITY; + } + + /** + * Return true if the value of this Float + * is the same as NaN, otherwise return false. + * + * @return whether this Float is NaN + */ + public boolean isNaN() + { + return isNaN(value); + } + + /** + * Return true if the value of this Float + * is the same as NEGATIVE_INFINITY or + * POSITIVE_INFINITY, otherwise return false. + * + * @return whether this Float is (-/+) infinity + */ + public boolean isInfinite() + { + return isInfinite(value); + } + + /** + * Convert the float value of this Float + * to a String. This method calls + * Float.toString(float) to do its dirty work. + * + * @return the String representation + * @see #toString(float) + */ + /*public String toString() + { + return toString(value); + }*/ + + /** + * Return the value of this Float as a byte. + * + * @return the byte value + * @since 1.1 + */ + public byte byteValue() + { + return (byte) value; + } + + /** + * Return the value of this Float as a short. + * + * @return the short value + * @since 1.1 + */ + public short shortValue() + { + return (short) value; + } + + /** + * Return the value of this Integer as an int. + * + * @return the int value + */ + public int intValue() + { + return (int) value; + } + + /** + * Return the value of this Integer as a long. + * + * @return the long value + */ + public long longValue() + { + return (long) value; + } + + /** + * Return the value of this Float. + * + * @return the float value + */ + public float floatValue() + { + return value; + } + + /** + * Return the value of this Float as a double + * + * @return the double value + */ + public double doubleValue() + { + return value; + } + + /** + * Return a hashcode representing this Object. Float's hash + * code is calculated by calling floatToIntBits(floatValue()). + * + * @return this Object's hash code + * @see #floatToIntBits(float) + */ + /*public int hashCode() + { + return floatToIntBits(value); + }*/ + + /** + * Returns true if obj is an instance of + * Float and represents the same float value. Unlike comparing + * two floats with ==, this treats two instances of + * Float.NaN as equal, but treats 0.0 and + * -0.0 as unequal. + * + *

Note that f1.equals(f2) is identical to + * floatToIntBits(f1.floatValue()) == + * floatToIntBits(f2.floatValue()). + * + * @param obj the object to compare + * @return whether the objects are semantically equal + */ + /*public boolean equals(Object obj) + { + if (obj instanceof Float) + { + float f = ((Float) obj).value; + return (floatToRawIntBits(value) == floatToRawIntBits(f)) || + (isNaN(value) && isNaN(f)); + } + return false; + }*/ + + /** + * Convert the float to the IEEE 754 floating-point "single format" bit + * layout. Bit 31 (the most significant) is the sign bit, bits 30-23 + * (masked by 0x7f800000) represent the exponent, and bits 22-0 + * (masked by 0x007fffff) are the mantissa. This function collapses all + * versions of NaN to 0x7fc00000. The result of this function can be used + * as the argument to Float.intBitsToFloat(int) to obtain the + * original float value. + * + * @param value the float to convert + * @return the bits of the float + * @see #intBitsToFloat(int) + */ + /*public static int floatToIntBits(float value) + { + if (isNaN(value)) + return 0x7fc00000; + else + return VMFloat.floatToRawIntBits(value); + }*/ + + /** + * Convert the float to the IEEE 754 floating-point "single format" bit + * layout. Bit 31 (the most significant) is the sign bit, bits 30-23 + * (masked by 0x7f800000) represent the exponent, and bits 22-0 + * (masked by 0x007fffff) are the mantissa. This function leaves NaN alone, + * rather than collapsing to a canonical value. The result of this function + * can be used as the argument to Float.intBitsToFloat(int) to + * obtain the original float value. + * + * @param value the float to convert + * @return the bits of the float + * @see #intBitsToFloat(int) + */ + /*public static int floatToRawIntBits(float value) + { + return VMFloat.floatToRawIntBits(value); + }*/ + + /** + * Convert the argument in IEEE 754 floating-point "single format" bit + * layout to the corresponding float. Bit 31 (the most significant) is the + * sign bit, bits 30-23 (masked by 0x7f800000) represent the exponent, and + * bits 22-0 (masked by 0x007fffff) are the mantissa. This function leaves + * NaN alone, so that you can recover the bit pattern with + * Float.floatToRawIntBits(float). + * + * @param bits the bits to convert + * @return the float represented by the bits + * @see #floatToIntBits(float) + * @see #floatToRawIntBits(float) + */ + /*public static float intBitsToFloat(int bits) + { + return VMFloat.intBitsToFloat(bits); + }*/ + + /** + * Compare two Floats numerically by comparing their float + * values. The result is positive if the first is greater, negative if the + * second is greater, and 0 if the two are equal. However, this special + * cases NaN and signed zero as follows: NaN is considered greater than + * all other floats, including POSITIVE_INFINITY, and positive + * zero is considered greater than negative zero. + * + * @param f the Float to compare + * @return the comparison + * @since 1.2 + */ + /*public int compareTo(Float f) + { + return compare(value, f.value); + }*/ + + /** + * Behaves like new Float(x).compareTo(new Float(y)); in + * other words this compares two floats, special casing NaN and zero, + * without the overhead of objects. + * + * @param x the first float to compare + * @param y the second float to compare + * @return the comparison + * @since 1.4 + */ + /*public static int compare(float x, float y) + { + // handle the easy cases: + if (x < y) + return -1; + if (x > y) + return 1; + + // handle equality respecting that 0.0 != -0.0 (hence not using x == y): + int ix = floatToRawIntBits(x); + int iy = floatToRawIntBits(y); + if (ix == iy) + return 0; + + // handle NaNs: + if (x != x) + return (y != y) ? 0 : 1; + else if (y != y) + return -1; + + // handle +/- 0.0 + return (ix < iy) ? -1 : 1; + }*/ +} diff --git a/Robust/src/ClassLibrary/SSJava/Integer.java b/Robust/src/ClassLibrary/SSJava/Integer.java index bfed63aa..7c51d4ed 100644 --- a/Robust/src/ClassLibrary/SSJava/Integer.java +++ b/Robust/src/ClassLibrary/SSJava/Integer.java @@ -3,6 +3,12 @@ public class Integer { @LOC("V") private int value; + + /** + * The maximum value an int can represent is 2147483647 (or + * 231 - 1). + */ + public static final int MAX_VALUE = 0x7fffffff; public Integer(int value) { this.value = value; diff --git a/Robust/src/ClassLibrary/SSJava/Long.java b/Robust/src/ClassLibrary/SSJava/Long.java new file mode 100644 index 00000000..e0e06cf5 --- /dev/null +++ b/Robust/src/ClassLibrary/SSJava/Long.java @@ -0,0 +1,832 @@ +/* Long.java -- object wrapper for long + Copyright (C) 1998, 1999, 2001, 2002, 2004, 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package java.lang; + +/** + * Instances of class Long represent primitive + * long values. + * + * Additionally, this class provides various helper functions and variables + * related to longs. + * + * @author Paul Fisher + * @author John Keiser + * @author Warren Levy + * @author Eric Blake (ebb9@email.byu.edu) + * @author Tom Tromey (tromey@redhat.com) + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @author Ian Rogers + * @since 1.0 + * @status updated to 1.5 + */ +public final class Long //extends Number implements Comparable +{ + /** + * Compatible with JDK 1.0.2+. + */ + private static final long serialVersionUID = 4290774380558885855L; + + /** + * The minimum value a long can represent is + * -9223372036854775808L (or -263). + */ + public static final long MIN_VALUE = 0x8000000000000000L; + + /** + * The maximum value a long can represent is + * 9223372036854775807 (or 263 - 1). + */ + public static final long MAX_VALUE = 0x7fffffffffffffffL; + + /** + * The primitive type long is represented by this + * Class object. + * @since 1.1 + */ + //public static final Class TYPE = (Class) VMClassLoader.getPrimitiveClass ('J'); + + /** + * The number of bits needed to represent a long. + * @since 1.5 + */ + public static final int SIZE = 64; + + // This caches some Long values, and is used by boxing + // conversions via valueOf(). We cache at least -128..127; + // these constants control how much we actually cache. + private static final int MIN_CACHE = -128; + private static final int MAX_CACHE = 127; + private static final Long[] longCache = new Long[MAX_CACHE - MIN_CACHE + 1]; + static + { + for (int i=MIN_CACHE; i <= MAX_CACHE; i++) + longCache[i - MIN_CACHE] = new Long(i); + } + + /** + * The immutable value of this Long. + * + * @serial the wrapped long + */ + private final long value; + + /** + * Create a Long object representing the value of the + * long argument. + * + * @param value the value to use + */ + public Long(long value) + { + this.value = value; + } + + /** + * Create a Long object representing the value of the + * argument after conversion to a long. + * + * @param s the string to convert + * @throws NumberFormatException if the String does not contain a long + * @see #valueOf(String) + */ + public Long(String s) + { + value = parseLong(s, 10, false); + } + + /** + * Return the size of a string large enough to hold the given number + * + * @param num the number we want the string length for (must be positive) + * @param radix the radix (base) that will be used for the string + * @return a size sufficient for a string of num + */ + private static int stringSize(long num, int radix) { + int exp; + if (radix < 4) + { + exp = 1; + } + else if (radix < 8) + { + exp = 2; + } + else if (radix < 16) + { + exp = 3; + } + else if (radix < 32) + { + exp = 4; + } + else + { + exp = 5; + } + int size=0; + do + { + num >>>= exp; + size++; + } + while(num != 0); + return size; + } + + /** + * Converts the long to a String using + * the specified radix (base). If the radix exceeds + * Character.MIN_RADIX or Character.MAX_RADIX, 10 + * is used instead. If the result is negative, the leading character is + * '-' ('\\u002D'). The remaining characters come from + * Character.forDigit(digit, radix) ('0'-'9','a'-'z'). + * + * @param num the long to convert to String + * @param radix the radix (base) to use in the conversion + * @return the String representation of the argument + */ + /*public static String toString(long num, int radix) + { + if (radix < Character.MIN_RADIX || radix > Character.MAX_RADIX) + radix = 10; + + // Is the value negative? + boolean isNeg = num < 0; + + // Is the string a single character? + if (!isNeg && num < radix) + return new String(digits, (int)num, 1, true); + + // Compute string size and allocate buffer + // account for a leading '-' if the value is negative + int size; + int i; + char[] buffer; + if (isNeg) + { + num = -num; + + // When the value is MIN_VALUE, it overflows when made positive + if (num < 0) + { + i = size = stringSize(MAX_VALUE, radix) + 2; + buffer = new char[size]; + buffer[--i] = digits[(int) (-(num + radix) % radix)]; + num = -(num / radix); + } + else + { + i = size = stringSize(num, radix) + 1; + buffer = new char[size]; + } + } + else + { + i = size = stringSize(num, radix); + buffer = new char[size]; + } + + do + { + buffer[--i] = digits[(int) (num % radix)]; + num /= radix; + } + while (num > 0); + + if (isNeg) + buffer[--i] = '-'; + + // Package constructor avoids an array copy. + return new String(buffer, i, size - i, true); + }*/ + + /** + * Converts the long to a String assuming it is + * unsigned in base 16. + * + * @param l the long to convert to String + * @return the String representation of the argument + */ + /*public static String toHexString(long l) + { + return toUnsignedString(l, 4); + }*/ + + /** + * Converts the long to a String assuming it is + * unsigned in base 8. + * + * @param l the long to convert to String + * @return the String representation of the argument + */ + /*public static String toOctalString(long l) + { + return toUnsignedString(l, 3); + }*/ + + /** + * Converts the long to a String assuming it is + * unsigned in base 2. + * + * @param l the long to convert to String + * @return the String representation of the argument + */ + /*public static String toBinaryString(long l) + { + return toUnsignedString(l, 1); + }*/ + + /** + * Converts the long to a String and assumes + * a radix of 10. + * + * @param num the long to convert to String + * @return the String representation of the argument + * @see #toString(long, int) + */ + public static String toString(long num) + { + //return toString(num, 10); + return String.valueOf(num); + } + + /** + * Converts the specified String into an int + * using the specified radix (base). The string must not be null + * or empty. It may begin with an optional '-', which will negate the answer, + * provided that there are also valid digits. Each digit is parsed as if by + * Character.digit(d, radix), and must be in the range + * 0 to radix - 1. Finally, the result must be + * within MIN_VALUE to MAX_VALUE, inclusive. + * Unlike Double.parseDouble, you may not have a leading '+'; and 'l' or + * 'L' as the last character is only valid in radices 22 or greater, where + * it is a digit and not a type indicator. + * + * @param str the String to convert + * @param radix the radix (base) to use in the conversion + * @return the String argument converted to long + * @throws NumberFormatException if s cannot be parsed as a + * long + */ + public static long parseLong(String str, int radix) + { + return parseLong(str, radix, false); + } + + /** + * Converts the specified String into a long. + * This function assumes a radix of 10. + * + * @param s the String to convert + * @return the int value of s + * @throws NumberFormatException if s cannot be parsed as a + * long + * @see #parseLong(String, int) + */ + public static long parseLong(String s) + { + return parseLong(s, 10, false); + } + + /** + * Creates a new Long object using the String + * and specified radix (base). + * + * @param s the String to convert + * @param radix the radix (base) to convert with + * @return the new Long + * @throws NumberFormatException if s cannot be parsed as a + * long + * @see #parseLong(String, int) + */ + public static Long valueOf(String s, int radix) + { + return valueOf(parseLong(s, radix, false)); + } + + /** + * Creates a new Long object using the String, + * assuming a radix of 10. + * + * @param s the String to convert + * @return the new Long + * @throws NumberFormatException if s cannot be parsed as a + * long + * @see #Long(String) + * @see #parseLong(String) + */ + public static Long valueOf(String s) + { + return valueOf(parseLong(s, 10, false)); + } + + /** + * Returns a Long object wrapping the value. + * + * @param val the value to wrap + * @return the Long + * @since 1.5 + */ + public static Long valueOf(long val) + { + if (val < MIN_CACHE || val > MAX_CACHE) + return new Long(val); + else + return longCache[((int)val) - MIN_CACHE]; + } + + /** + * Convert the specified String into a Long. + * The String may represent decimal, hexadecimal, or + * octal numbers. + * + *

The extended BNF grammar is as follows:
+ *

+   * DecodableString:
+   *      ( [ - ] DecimalNumber )
+   *    | ( [ - ] ( 0x | 0X
+   *              | # ) HexDigit { HexDigit } )
+   *    | ( [ - ] 0 { OctalDigit } )
+   * DecimalNumber:
+   *        DecimalDigit except '0' { DecimalDigit }
+   * DecimalDigit:
+   *        Character.digit(d, 10) has value 0 to 9
+   * OctalDigit:
+   *        Character.digit(d, 8) has value 0 to 7
+   * DecimalDigit:
+   *        Character.digit(d, 16) has value 0 to 15
+   * 
+ * Finally, the value must be in the range MIN_VALUE to + * MAX_VALUE, or an exception is thrown. Note that you cannot + * use a trailing 'l' or 'L', unlike in Java source code. + * + * @param str the String to interpret + * @return the value of the String as a Long + * @throws NumberFormatException if s cannot be parsed as a + * long + * @throws NullPointerException if s is null + * @since 1.2 + */ + public static Long decode(String str) + { + return valueOf(parseLong(str, 10, true)); + } + + /** + * Return the value of this Long as a byte. + * + * @return the byte value + */ + public byte byteValue() + { + return (byte) value; + } + + /** + * Return the value of this Long as a short. + * + * @return the short value + */ + public short shortValue() + { + return (short) value; + } + + /** + * Return the value of this Long as an int. + * + * @return the int value + */ + public int intValue() + { + return (int) value; + } + + /** + * Return the value of this Long. + * + * @return the long value + */ + public long longValue() + { + return value; + } + + /** + * Return the value of this Long as a float. + * + * @return the float value + */ + public float floatValue() + { + return value; + } + + /** + * Return the value of this Long as a double. + * + * @return the double value + */ + public double doubleValue() + { + return value; + } + + /** + * Converts the Long value to a String and + * assumes a radix of 10. + * + * @return the String representation + */ + public String toString() + { + //return toString(value, 10); + return String.valueOf(value); + } + + /** + * Return a hashcode representing this Object. Long's hash + * code is calculated by (int) (value ^ (value >> 32)). + * + * @return this Object's hash code + */ + public int hashCode() + { + return (int) (value ^ (value >>> 32)); + } + + /** + * Returns true if obj is an instance of + * Long and represents the same long value. + * + * @param obj the object to compare + * @return whether these Objects are semantically equal + */ + public boolean equals(Object obj) + { + return obj instanceof Long && value == ((Long) obj).value; + } + + /** + * Get the specified system property as a Long. The + * decode() method will be used to interpret the value of + * the property. + * + * @param nm the name of the system property + * @return the system property as a Long, or null if the + * property is not found or cannot be decoded + * @throws SecurityException if accessing the system property is forbidden + * @see System#getProperty(String) + * @see #decode(String) + */ + public static Long getLong(String nm) + { + return getLong(nm, null); + } + + /** + * Get the specified system property as a Long, or use a + * default long value if the property is not found or is not + * decodable. The decode() method will be used to interpret + * the value of the property. + * + * @param nm the name of the system property + * @param val the default value + * @return the value of the system property, or the default + * @throws SecurityException if accessing the system property is forbidden + * @see System#getProperty(String) + * @see #decode(String) + */ + public static Long getLong(String nm, long val) + { + Long result = getLong(nm, null); + return result == null ? valueOf(val) : result; + } + + /** + * Get the specified system property as a Long, or use a + * default Long value if the property is not found or is + * not decodable. The decode() method will be used to + * interpret the value of the property. + * + * @param nm the name of the system property + * @param def the default value + * @return the value of the system property, or the default + * @throws SecurityException if accessing the system property is forbidden + * @see System#getProperty(String) + * @see #decode(String) + */ + public static Long getLong(String nm, Long def) + { + if (nm == null || "".equals(nm)) + return def; + nm = null;//System.getProperty(nm); + if (nm == null) + return def; + /*try + { + return decode(nm); + } + catch (NumberFormatException e) + { + return def; + }*/ + } + + /** + * Compare two Longs numerically by comparing their long + * values. The result is positive if the first is greater, negative if the + * second is greater, and 0 if the two are equal. + * + * @param l the Long to compare + * @return the comparison + * @since 1.2 + */ + public int compareTo(Long l) + { + if (value == l.value) + return 0; + // Returns just -1 or 1 on inequality; doing math might overflow the long. + return value > l.value ? 1 : -1; + } + + /** + * Return the number of bits set in x. + * @param x value to examine + * @since 1.5 + */ + public static int bitCount(long x) + { + // Successively collapse alternating bit groups into a sum. + x = ((x >> 1) & 0x5555555555555555L) + (x & 0x5555555555555555L); + x = ((x >> 2) & 0x3333333333333333L) + (x & 0x3333333333333333L); + int v = (int) ((x >>> 32) + x); + v = ((v >> 4) & 0x0f0f0f0f) + (v & 0x0f0f0f0f); + v = ((v >> 8) & 0x00ff00ff) + (v & 0x00ff00ff); + return ((v >> 16) & 0x0000ffff) + (v & 0x0000ffff); + } + + /** + * Rotate x to the left by distance bits. + * @param x the value to rotate + * @param distance the number of bits by which to rotate + * @since 1.5 + */ + public static long rotateLeft(long x, int distance) + { + // This trick works because the shift operators implicitly mask + // the shift count. + return (x << distance) | (x >>> - distance); + } + + /** + * Rotate x to the right by distance bits. + * @param x the value to rotate + * @param distance the number of bits by which to rotate + * @since 1.5 + */ + public static long rotateRight(long x, int distance) + { + // This trick works because the shift operators implicitly mask + // the shift count. + return (x << - distance) | (x >>> distance); + } + + /** + * Find the highest set bit in value, and return a new value + * with only that bit set. + * @param value the value to examine + * @since 1.5 + */ + public static long highestOneBit(long value) + { + value |= value >>> 1; + value |= value >>> 2; + value |= value >>> 4; + value |= value >>> 8; + value |= value >>> 16; + value |= value >>> 32; + return value ^ (value >>> 1); + } + + /** + * Return the number of leading zeros in value. + * @param value the value to examine + * @since 1.5 + */ + public static int numberOfLeadingZeros(long value) + { + value |= value >>> 1; + value |= value >>> 2; + value |= value >>> 4; + value |= value >>> 8; + value |= value >>> 16; + value |= value >>> 32; + return bitCount(~value); + } + + /** + * Find the lowest set bit in value, and return a new value + * with only that bit set. + * @param value the value to examine + * @since 1.5 + */ + public static long lowestOneBit(long value) + { + // Classic assembly trick. + return value & - value; + } + + /** + * Find the number of trailing zeros in value. + * @param value the value to examine + * @since 1.5 + */ + public static int numberOfTrailingZeros(long value) + { + return bitCount((value & -value) - 1); + } + + /** + * Return 1 if x is positive, -1 if it is negative, and 0 if it is + * zero. + * @param x the value to examine + * @since 1.5 + */ + public static int signum(long x) + { + return (int) ((x >> 63) | (-x >>> 63)); + + // The LHS propagates the sign bit through every bit in the word; + // if X < 0, every bit is set to 1, else 0. if X > 0, the RHS + // negates x and shifts the resulting 1 in the sign bit to the + // LSB, leaving every other bit 0. + + // Hacker's Delight, Section 2-7 + } + + /** + * Reverse the bytes in val. + * @since 1.5 + */ + /*public static long reverseBytes(long val) + { + int hi = Integer.reverseBytes((int) val); + int lo = Integer.reverseBytes((int) (val >>> 32)); + return (((long) hi) << 32) | lo; + }*/ + + /** + * Reverse the bits in val. + * @since 1.5 + */ + /*public static long reverse(long val) + { + long hi = Integer.reverse((int) val) & 0xffffffffL; + long lo = Integer.reverse((int) (val >>> 32)) & 0xffffffffL; + return (hi << 32) | lo; + }*/ + + /** + * Helper for converting unsigned numbers to String. + * + * @param num the number + * @param exp log2(digit) (ie. 1, 3, or 4 for binary, oct, hex) + */ + /*private static String toUnsignedString(long num, int exp) + { + // Compute string length + int size = 1; + long copy = num >>> exp; + while (copy != 0) + { + size++; + copy >>>= exp; + } + // Quick path for single character strings + if (size == 1) + return new String(digits, (int)num, 1, true); + + // Encode into buffer + int mask = (1 << exp) - 1; + char[] buffer = new char[size]; + int i = size; + do + { + buffer[--i] = digits[(int) num & mask]; + num >>>= exp; + } + while (num != 0); + + // Package constructor avoids an array copy. + return new String(buffer, i, size - i, true); + }*/ + + /** + * Helper for parsing longs. + * + * @param str the string to parse + * @param radix the radix to use, must be 10 if decode is true + * @param decode if called from decode + * @return the parsed long value + * @throws NumberFormatException if there is an error + * @throws NullPointerException if decode is true and str is null + * @see #parseLong(String, int) + * @see #decode(String) + */ + private static long parseLong(String str, int radix, boolean decode) + { + if (! decode && str == null) + throw new /*NumberFormat*/Exception("NumberFormatException"); + int index = 0; + int len = str.length(); + boolean isNeg = false; + if (len == 0) + throw new /*NumberFormat*/Exception("NumberFormatException"); + int ch = str.charAt(index); + if (ch == '-') + { + if (len == 1) + throw new /*NumberFormat*/Exception("NumberFormatException"); + isNeg = true; + ch = str.charAt(++index); + } + if (decode) + { + if (ch == '0') + { + if (++index == len) + return 0; + if ((str.charAt(index) & ~('x' ^ 'X')) == 'X') + { + radix = 16; + index++; + } + else + radix = 8; + } + else if (ch == '#') + { + radix = 16; + index++; + } + } + if (index == len) + throw new /*NumberFormat*/Exception("NumberFormatException"); + + long max = MAX_VALUE / radix; + // We can't directly write `max = (MAX_VALUE + 1) / radix'. + // So instead we fake it. + if (isNeg && MAX_VALUE % radix == radix - 1) + ++max; + + long val = 0; + while (index < len) + { + if (val < 0 || val > max) + throw new /*NumberFormat*/Exception("NumberFormatException"); + + ch = Character.digit(str.charAt(index++), radix); + val = val * radix + ch; + if (ch < 0 || (val < 0 && (! isNeg || val != MIN_VALUE))) + throw new /*NumberFormat*/Exception("NumberFormatException"); + } + return isNeg ? -val : val; + } +} diff --git a/Robust/src/ClassLibrary/SSJava/String.java b/Robust/src/ClassLibrary/SSJava/String.java index 2710ebdb..d5f98219 100644 --- a/Robust/src/ClassLibrary/SSJava/String.java +++ b/Robust/src/ClassLibrary/SSJava/String.java @@ -13,6 +13,28 @@ public class String { private String() { } + public String(byte str[]) { + char charstr[]=new char[str.length]; + for(int i=0; i(str.length)) + length=str.length; + char charstr[]=new char[length]; + for(int i=0; ivalue.length) { + // Need to allocate + char newvalue[]=new char[s.count+count+16]; //16 is DEFAULTSIZE + for(int i=0; isize) + size=i; + if (i>value.length) { + char newvalue[]=new char[i]; + for(int ii=0; iivalue.length) { + // Need to allocate + char newvalue[]=new char[s.count+count+16]; //16 is DEFAULTSIZE + for(int i=0; i count) { + // FIXME + System.printString("StringIndexOutOfBoundsException: start > length()\n"); + } + if (start > end) { + // FIXME + System.printString("StringIndexOutOfBoundsException: start > end\n"); + } + if (end > count) + end = count; + + if (end > count) + end = count; + int len = str.length(); + int newCount = count + len - (end - start); + if (newCount > value.length) + expandCapacity(newCount); + + System.arraycopy(value, end, value, start + len, count - end); + str.getChars(value, start); + count = newCount; + return this; + } + + void expandCapacity(int minimumCapacity) { + int newCapacity = (value.length + 1) * 2; + if (newCapacity < 0) { + newCapacity = 0x7fffffff /*Integer.MAX_VALUE*/; + } else if (minimumCapacity > newCapacity) { + newCapacity = minimumCapacity; + } + char newValue[] = new char[newCapacity]; + System.arraycopy(value, 0, newValue, 0, count); + value = newValue; + } +} diff --git a/Robust/src/Tests/ssJava/mp3decoder/Bitstream.java b/Robust/src/Tests/ssJava/mp3decoder/Bitstream.java index b0493045..7fd9be88 100644 --- a/Robust/src/Tests/ssJava/mp3decoder/Bitstream.java +++ b/Robust/src/Tests/ssJava/mp3decoder/Bitstream.java @@ -33,12 +33,6 @@ *---------------------------------------------------------------------- */ -import java.io.BufferedInputStream; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.PushbackInputStream; - /** * The Bistream class is responsible for parsing diff --git a/Robust/src/Tests/ssJava/mp3decoder/BitstreamException.java b/Robust/src/Tests/ssJava/mp3decoder/BitstreamException.java index ba005809..07aa18fb 100644 --- a/Robust/src/Tests/ssJava/mp3decoder/BitstreamException.java +++ b/Robust/src/Tests/ssJava/mp3decoder/BitstreamException.java @@ -62,7 +62,8 @@ public class BitstreamException extends JavaLayerException // REVIEW: use resource bundle to map error codes // to locale-sensitive strings. - return "Bitstream errorcode "+Integer.toHexString(errorcode); +// return "Bitstream errorcode "+Integer.toHexString(errorcode); + return "Bitstream errorcode "+errorcode; } diff --git a/Robust/src/Tests/ssJava/mp3decoder/Decoder.java b/Robust/src/Tests/ssJava/mp3decoder/Decoder.java index 4d064359..19b20507 100644 --- a/Robust/src/Tests/ssJava/mp3decoder/Decoder.java +++ b/Robust/src/Tests/ssJava/mp3decoder/Decoder.java @@ -319,14 +319,19 @@ public class Decoder implements DecoderErrors public Object clone() { - try - { - return super.clone(); - } - catch (CloneNotSupportedException ex) - { - throw new InternalError(this+": "+ex); - } + //TODO: need to have better clone method + Params clone=new Params(); + clone.outputChannels=outputChannels; + clone.equalizer=equalizer; + return clone; +// try +// { +// return super.clone(); +// } +// catch (CloneNotSupportedException ex) +// { +// throw new InternalError(this+": "+ex); +// } } public void setOutputChannels(OutputChannels out) diff --git a/Robust/src/Tests/ssJava/mp3decoder/DecoderException.java b/Robust/src/Tests/ssJava/mp3decoder/DecoderException.java index a00a20b5..d33b0f09 100644 --- a/Robust/src/Tests/ssJava/mp3decoder/DecoderException.java +++ b/Robust/src/Tests/ssJava/mp3decoder/DecoderException.java @@ -52,7 +52,8 @@ public class DecoderException extends JavaLayerException // REVIEW: use resource file to map error codes // to locale-sensitive strings. - return "Decoder errorcode "+Integer.toHexString(errorcode); +// return "Decoder errorcode "+Integer.toHexString(errorcode); + return "Decoder errorcode "+errorcode; } diff --git a/Robust/src/Tests/ssJava/mp3decoder/Header.java b/Robust/src/Tests/ssJava/mp3decoder/Header.java index 09f1b231..456161f2 100644 --- a/Robust/src/Tests/ssJava/mp3decoder/Header.java +++ b/Robust/src/Tests/ssJava/mp3decoder/Header.java @@ -72,9 +72,9 @@ public final class Header @LOC("HNS") private int h_number_of_subbands; @LOC("HI") private int h_intensity_stereo_bound; @LOC("H") private boolean h_copyright; - @LOC("H") private int h_original; + @LOC("H") private boolean h_original; // VBR support added by E.B - @LOC("T") private double[] h_vbr_time_per_frame = {-1, 384, 1152, 1152}; + @LOC("T") private double[] h_vbr_time_per_frame = {-1.0, 384.0, 1152.0, 1152.0}; @LOC("T") private boolean h_vbr; @LOC("T") private int h_vbr_frames; @LOC("T") private int h_vbr_scale; diff --git a/Robust/src/Tests/ssJava/mp3decoder/JavaLayerException.java b/Robust/src/Tests/ssJava/mp3decoder/JavaLayerException.java index 2d47f5cd..2759a9a8 100644 --- a/Robust/src/Tests/ssJava/mp3decoder/JavaLayerException.java +++ b/Robust/src/Tests/ssJava/mp3decoder/JavaLayerException.java @@ -1,79 +1,79 @@ -/* - * 11/19/04 1.0 moved to LGPL. - * 12/12/99 Initial version. mdm@techie.com - *----------------------------------------------------------------------- - * This program 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 of the License, or - * (at your option) any later version. - * - * This program 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. - * - * You should have received a copy of the GNU Library General Public - * License along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - *---------------------------------------------------------------------- - */ - - -import java.io.PrintStream; - - -/** - * The JavaLayerException is the base class for all API-level - * exceptions thrown by JavaLayer. To facilitate conversion and - * common handling of exceptions from other domains, the class - * can delegate some functionality to a contained Throwable instance. - *

- * - * @author MDM - */ -public class JavaLayerException extends Exception -{ - - private Throwable exception; - - - public JavaLayerException() - { - } - - public JavaLayerException(String msg) - { - super(msg); - } - - public JavaLayerException(String msg, Throwable t) - { - super(msg); - exception = t; - } - - public Throwable getException() - { - return exception; - } - - - public void printStackTrace() - { - printStackTrace(System.err); - } - - public void printStackTrace(PrintStream ps) - { - if (this.exception==null) - { - super.printStackTrace(ps); - } - else - { - exception.printStackTrace(); - } - } - - -} +/* + * 11/19/04 1.0 moved to LGPL. + * 12/12/99 Initial version. mdm@techie.com + *----------------------------------------------------------------------- + * This program 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 of the License, or + * (at your option) any later version. + * + * This program 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. + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + *---------------------------------------------------------------------- + */ + + +//import java.io.PrintStream; + + +/** + * The JavaLayerException is the base class for all API-level + * exceptions thrown by JavaLayer. To facilitate conversion and + * common handling of exceptions from other domains, the class + * can delegate some functionality to a contained Throwable instance. + *

+ * + * @author MDM + */ +public class JavaLayerException extends Exception +{ + + private Throwable exception; + + + public JavaLayerException() + { + } + + public JavaLayerException(String msg) + { + super(msg); + } + + public JavaLayerException(String msg, Throwable t) + { + super(msg); + exception = t; + } + + public Throwable getException() + { + return exception; + } + + + public void printStackTrace() + { +// printStackTrace(System.err); + } + + public void printStackTrace(PrintStream ps) + { +// if (this.exception==null) +// { +// super.printStackTrace(ps); +// } +// else +// { +// exception.printStackTrace(); +// } + } + + +} diff --git a/Robust/src/Tests/ssJava/mp3decoder/LayerIDecoder.java b/Robust/src/Tests/ssJava/mp3decoder/LayerIDecoder.java index 89eb5dec..fbbdd278 100644 --- a/Robust/src/Tests/ssJava/mp3decoder/LayerIDecoder.java +++ b/Robust/src/Tests/ssJava/mp3decoder/LayerIDecoder.java @@ -30,7 +30,7 @@ */ @LATTICE("L 32767.0f) ? 32767 : - ((sample < -32768.0f) ? -32768 : + return ((sample > 32767.0f) ? (short) 32767 : + ((sample < -32768.0f) ? (short) -32768 : (short) sample)); } diff --git a/Robust/src/Tests/ssJava/mp3decoder/Player.java b/Robust/src/Tests/ssJava/mp3decoder/Player.java index b4048110..3acb03c0 100644 --- a/Robust/src/Tests/ssJava/mp3decoder/Player.java +++ b/Robust/src/Tests/ssJava/mp3decoder/Player.java @@ -19,7 +19,7 @@ */ -import java.io.InputStream; +//import java.io.InputStream; /** diff --git a/Robust/src/Tests/ssJava/mp3decoder/Subband.java b/Robust/src/Tests/ssJava/mp3decoder/Subband.java new file mode 100644 index 00000000..dbfcd873 --- /dev/null +++ b/Robust/src/Tests/ssJava/mp3decoder/Subband.java @@ -0,0 +1,39 @@ +//package ssJava.mp3decoder; + +/** + * Abstract base class for subband classes of layer I and II + */ + @LATTICE("L