Commit Graph

904 Commits

Author SHA1 Message Date
Joshua Warner
2b68815636 Merge pull request #103 from dscho/data-input-stream
Data input stream
2013-11-12 10:46:10 -08:00
Johannes Schindelin
209f2a3aff Fix DataOutputStream#writeUTF
This developer did not read the specs closely enough and missed that
the length of the byte array needs to be written out first, so that
DataInputStream#readUTF has a chance of reading the string back.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2013-11-08 17:42:14 -06:00
Johannes Schindelin
759a08bb54 Implement DataInputStream
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2013-11-08 17:42:14 -06:00
Ilya Mizus
45ee25f68c Implement socket API 2013-11-08 09:55:43 -07:00
Joshua Warner
fd81e126ef fix Dates test for openjdk and stub out java.util.TimeZone 2013-11-07 20:44:02 -07:00
Joshua Warner
76b0bb4872 remove non-conforming ZipEntry.getJavaTime API and associated tests (which failed the openjdk build) 2013-11-07 19:13:13 -07:00
Joshua Warner
dd460ab55e Merge pull request #99 from dscho/fix-get-annotation
Fix NPE in Field#getAnnotation
2013-11-06 09:03:45 -08:00
Joshua Warner
42651da0b2 Merge pull request #96 from dscho/filter-input-stream
Filter input stream
2013-11-06 09:02:57 -08:00
Joshua Warner
4cf3d9de88 Merge pull request #95 from dscho/compatible-serialization
Java-compatible (de)serialization of TreeMap, ArrayList and Number
2013-11-06 09:02:12 -08:00
Joshua Warner
d0d4f600dc Merge pull request #94 from dscho/serialization
Implement Java-compatible serialization
2013-11-06 08:49:14 -08:00
Johannes Schindelin
ff50034206 Fix NPE in Field#getAnnotation
When the class whose field is to be inspected has no annotations at all,
at least my javac here (1.6.0_51 on MacOSX) does not produce any class
addendum.

Therefore, let's verify that the addendum is not null before proceeding.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2013-11-06 09:46:56 -06:00
Johannes Schindelin
6ea017eb86 Mark java.lang.Number as serializable
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2013-11-06 09:12:18 -06:00
Johannes Schindelin
2a9ab48137 Make ArrayList's serialization compatible with OpenJDK's
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2013-11-06 09:12:18 -06:00
Johannes Schindelin
a90b3ae574 Make TreeMap (de)serialization compatible with Java
This is done by implementing the readObject()/writeObject() method
pair as demanded by the serialization specification. The specifics
were reverse-engineered from serializing trivial TreeMap instances
with OpenJDK.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2013-11-06 09:12:18 -06:00
Johannes Schindelin
afe09e32de Add a 'comparator' field to TreeMap
This will be needed for Java-compatible serialization of tree maps.

Note that the field should be null when the TreeMap uses the default
comparator.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2013-11-06 09:12:17 -06:00
Johannes Schindelin
884d0979a9 ObjectInputStream: handle super class descriptors correctly
We punted previously on any serializable super class' descriptor and
simply expected the super class not to be serializable (and consequently,
we expected the respective descriptor to be null). However, for quite
common classes, e.g. OpenJDK's Double class, this is not true.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2013-11-06 09:10:51 -06:00
Johannes Schindelin
ff45f452da ObjectInputStream: handle TC_REFERENCE
There are serialized objects out in the wild which make heavy use of
TC_REFERENCE: for example when an object has a reference to itself.

Therefore we need to support that, too.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2013-11-06 09:10:51 -06:00
Johannes Schindelin
b6d3caf458 ObjectInputStream: refactor class desc parsing
We punted previously on any serializable super class' descriptor and
simply expected the super class not to be serializable (and consequently,
we expected the respective descriptor to be null).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2013-11-06 09:10:51 -06:00
Johannes Schindelin
25ed2965e7 ObjectInputStream: use private readObject() methods
The specification of the Java deserialization demands that a private
readObject(ObjectOutputStream) method is used -- if it exists. In
that case, ObjectInputStream must not initialize the contents of the
fields (called 'classdata[]' in the documentation) but offer that
functionality via the defaultReadObject() method.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2013-11-06 09:10:51 -06:00
Johannes Schindelin
931617a787 ObjectOutputStream: use private writeObject() methods
The specification of the Java serialization demands that a private
writeObject(ObjectOutputStream) method is used -- if it exists. In that
case, ObjectOutputStream must not write the contents of the fields
(called 'classdata[]' in the documentation) but offer that via the
defaultWriteObject() method.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2013-11-06 09:10:51 -06:00
Johannes Schindelin
f3189bc79d ObjectOutputStream: optimize String serialization
The serialization protocol specifies a quick method to serialize
a String (because that is so common an operation): TC_STRING +
(short)length + bytes. Let's use that, also to make it easier to test
the upcoming changes to TreeMap harmonizing that Avian's serialization
of said class with OpenJDK's.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2013-11-06 09:10:51 -06:00
Johannes Schindelin
bba0d25ba5 ObjectInputStream: handle fields of type String
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2013-11-06 09:10:51 -06:00
Johannes Schindelin
c78923d717 ObjectInputStream: add rudimentary support for objects
This is by no means a complete support for the deserialization compliant
to the Java Language Specification, but it is better to add the support
incrementally, for better readability of the commits.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2013-11-06 09:10:51 -06:00
Johannes Schindelin
4b8285e597 Implement a rudimentary Java-compatible ObjectInputStream
The Java Language Specification documents the serialization protocol
implemented by this change set:

http://docs.oracle.com/javase/7/docs/platform/serialization/spec/protocol.html#10258

This change is intended to make it easier to use Avian VM as a drop-in
replacement for the Oracle JVM when serializing objects.

The previous serialization code is still available as
avian.LegacyObjectInputStream.

This commit only implements the non-object parts of the deserialization
specification.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2013-11-06 09:10:51 -06:00
Johannes Schindelin
35ecf5025c Make ObjectOutputStream's constants available to java.io
We will reuse the constants in the upcoming deserialization counterpart.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2013-11-06 09:10:50 -06:00
Johannes Schindelin
3dccd68fe7 Implement the Field#set<PrimitiveType> method family
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2013-11-06 09:10:50 -06:00
Johannes Schindelin
c2a6f4a726 Implement a Java-compatible ObjectOutputStream
The Java Language Specification documents the serialization protocol
implemented by this change set:

http://docs.oracle.com/javase/7/docs/platform/serialization/spec/protocol.html#10258

This change is intended to make it easier to use Avian VM as a drop-in
replacement for the Oracle JVM when serializing objects.

The previous serialization code is still available as
avian.LegacyObjectOutputStream.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2013-11-06 09:10:50 -06:00
Johannes Schindelin
f2dd4add26 Implement FilterReader
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2013-11-06 09:10:50 -06:00
Johannes Schindelin
2904dd738e Fix java.lang.reflect.Field.getLong()
The bug was that the long was cast to an int, cutting off the most
significant bytes.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2013-11-06 09:10:50 -06:00
Johannes Schindelin
6a7c03aef9 Implement the Math#signum method
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2013-11-06 09:07:58 -06:00
Johannes Schindelin
f8028c9864 Add a dummy implementation of EmptyStackException
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2013-11-06 09:07:58 -06:00
Johannes Schindelin
6159f5cd3c Support Logger#log(Level,String,Object)
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2013-11-06 09:07:58 -06:00
Johannes Schindelin
874bf4ef4c Initialize Logger instances to the 'INFO' level by default
... otherwise, logging would throw an exception when trying to
determine whether the current level allows the message to be logged.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2013-11-06 09:07:58 -06:00
Johannes Schindelin
dba8d39e63 Implement Class#getDeclaredClasses
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2013-11-06 09:07:58 -06:00
Simon Ochsenreither
5827c450c9 Adds separatorChar and pathSeparatorChar fields to File ...
... and fixes a bug which caused path.separator to always return null.
2013-11-06 14:05:25 +01:00
Johannes Schindelin
26c90170a6 Add a minimal FilterInputStream
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2013-11-05 14:36:16 -06:00
Joshua Warner
da69b735f4 Merge branch 'addzip' of git://github.com/CUBoulderBoy/avian into CUBoulderBoy-addzip 2013-11-04 17:38:27 -07:00
Joshua Warner
d128838617 Merge pull request #92 from dscho/collections
Various improvements regarding Collections
2013-11-04 16:33:06 -08:00
Joshua Warner
ac32e0de39 Merge pull request #91 from dscho/intro-sort
Replace Arrays.sort() with an efficient sort algorithm
2013-11-04 16:31:08 -08:00
Johannes Schindelin
002b0db43a Do not report jar: URLs as jar://file:...
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2013-11-04 16:55:07 -06:00
Johannes Schindelin
167688eabd Teach SystemClassLoader#getResources to not stop at the first match
The getResources method can be used to find all matches in the class
path for a given path, e.g. to seek out all the META-INF/MANIFEST.MF
files contained in all of the .jar files in the class path.

We just taught the findResources() method to return all matches (rather
than only the first), so let's use that method to get all the matches
from the current class loader's class path elements.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2013-11-04 16:49:34 -06:00
Johannes Schindelin
0602d4a447 Consider all class path elements in SystemClassLoader#findResources
The findResources method is supposed to enumerate all the class path
elements' matching paths' URLs, but we used to stop at the first one.

While this is good enough when the system class path contains only a
single .jar file, since b88438d2(sketch of JAR support in Finder)
supports more than a single .jar file in the class path.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2013-11-04 16:49:31 -06:00
Johannes Schindelin
7fe3979280 Implement LinkedHashSet
This implementation is intentionally simple. If and when the need arises,
we can always implement a more performant version.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2013-11-04 15:11:19 -06:00
Johannes Schindelin
58ea1442fd Implement LinkedHashMap
This implementation is intentionally simple. If and when the need arises,
we can always implement a more performant version.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2013-11-04 15:11:19 -06:00
Johannes Schindelin
c023bd8654 Implement TreeSet#descendingIterator
If need be, this functionality can be sped up by implementing a
descending iterator on the tree without copying it into an ArrayList.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2013-11-04 15:11:19 -06:00
Johannes Schindelin
1ed90c38ab Implement rest of the Arrays#fill family
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2013-11-04 15:11:19 -06:00
Johannes Schindelin
6a81623690 Implement the Arrays#copyOf family
... as introduced in Java 6.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2013-11-04 15:11:00 -06:00
Johannes Schindelin
46a55bd024 Implement ArrayList#ensureCapacity
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2013-11-04 14:33:25 -06:00
Johannes Schindelin
eab3b8e448 Implement Collections#reverse
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2013-11-04 14:33:25 -06:00
Johannes Schindelin
a61bcf824f Implement Collections#binarySearch
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2013-11-04 14:33:25 -06:00