[cp-patches] RFC: java.io.ObjectOutputStream, etc.

2008-01-24 Thread Ito Kazumitsu
This patch fix the Bub #22941.

ChangeLog:
2008-01-24  Ito Kazumitsu  [EMAIL PROTECTED]

Fixes bug #22941
* java/io/DataInputStream.java(readUTFLong): New method.
(readUTF): New private method.
* java/io/DataOutputStream.java(getUTFlength): Made package-private,
Return type changed to long.
(writeUTF): Use the new method writeUTFShort.
(writeUTFShort): New package-private method.
(writeUTFLong): New package-private method.
(writeUTFBytes): New private method.
* java/io/ObjectInputStream.java(parseContent): Separate the
handling of TC_LONGSTRING from TC_STRING.
* java/io/ObjectOutputStream.java(writeObject): When to write a
String, use writeUTFShort or writeUTFLong depending on the byte length.

Index: classpath/java/io/DataInputStream.java
===
RCS file: /cvsroot/classpath/classpath/java/io/DataInputStream.java,v
retrieving revision 1.31
diff -u -r1.31 DataInputStream.java
--- classpath/java/io/DataInputStream.java  2 Jul 2005 20:32:37 -   
1.31
+++ classpath/java/io/DataInputStream.java  24 Jan 2008 15:03:47 -
@@ -590,13 +590,56 @@
   public static final String readUTF(DataInput in) throws IOException
   {
 final int UTFlen = in.readUnsignedShort ();
-byte[] buf = new byte [UTFlen];
+
+return readUTF(in, UTFlen);
+  }
+
+  /**
+   * This method is similar to codereadUTF/code, but the
+   * UTF-8 byte length is in 64 bits.
+   * This method is not public. It is used by codeObjectInputStream/code.
+   * 
+   * @return The codeString/code read
+   *
+   * @exception EOFException If end of file is reached before reading
+   * the String
+   * @exception UTFDataFormatException If the data is not in UTF-8 format
+   * @exception IOException If any other error occurs
+   *
+   * @see DataOutput#writeUTFLong
+   */
+  final String readUTFLong () throws IOException
+  {
+long l = readLong ();
+if (l  Integer.MAX_VALUE)
+  throw new IOException(The string length  Integer.MAX_VALUE);
+final int UTFlen = (int)l;
+return readUTF (this, UTFlen);
+  }
+
+  /**
+   * This method performs the main task of codereadUTF/code and
+   * codereadUTFLong/code.
+   *
+   * @param in The codeDataInput/code source to read from
+   *
+   * @param len The UTF-8 byte length of the String to be read
+   *
+   * @return The String read from the source
+   *
+   * @exception IOException If an error occurs
+   *
+   * @see DataInput#readUTF
+   */
+  private static final String readUTF(DataInput in, int len) throws IOException
+  {
+byte[] buf = new byte [len];
 
 // This blocks until the entire string is available rather than
 // doing partial processing on the bytes that are available and then
 // blocking.  An advantage of the latter is that Exceptions
 // could be thrown earlier.  The former is a bit cleaner.
-in.readFully (buf, 0, UTFlen);
+in.readFully (buf, 0, len);
 
 return convertFromUTF (buf);
   }
Index: classpath/java/io/DataOutputStream.java
===
RCS file: /cvsroot/classpath/classpath/java/io/DataOutputStream.java,v
retrieving revision 1.23
diff -u -r1.23 DataOutputStream.java
--- classpath/java/io/DataOutputStream.java 12 Apr 2006 16:19:02 -  
1.23
+++ classpath/java/io/DataOutputStream.java 24 Jan 2008 15:03:47 -
@@ -379,19 +379,20 @@
 
   /**
*  Calculate the length, in bytes, of a codeString/code in Utf8 format.
+   *  This method is package-private so that codeObjectOutputStream/code
+   *  may use it.  The return type is long so that a long string whose
+   *  Utf8 byte count is 64 bit long may be handled.
*
*  @param value The codeString/code to measure
*  @param start String index at which to begin count
*  @param sum Starting Utf8 byte count
*
-   *  @throws UTFDataFormatException if result would exceed 65535
*/
-  private int getUTFlength(String value, int start, int sum)
-throws IOException
+  long getUTFlength(String value, int start, long sum)
   {
 int len = value.length();
 
-for (int i = start; i  len  sum = 65535; ++i)
+for (int i = start; i  len; ++i)
   {
char c = value.charAt(i);
if (c = '\u0001'  c = '\u007f')
@@ -402,9 +403,6 @@
  sum += 3;
   }
 
-if (sum  65535)
-  throw new UTFDataFormatException ();
-
 return sum;
   }
   
@@ -442,10 +440,70 @@
*/
   public final synchronized void writeUTF(String value) throws IOException
   {
+long l = getUTFlength(value, 0, 0);
+if (l  65535)
+  throw new UTFDataFormatException ();
+writeUTFShort(value, (int)l);
+  }
+
+  /**
+   * This method performs the main task of codewriteUTF/code.
+   * This method is package-private because ObjectOutputStream uses it.
+   *
+   * @param value The codeString/code to write to the output 

[cp-patches] RFC: adding -reverse to gnative2ascii

2008-01-24 Thread Mario Torre
This patch adds the -reverse option to gnative2ascii as described here:

http://icedtea.classpath.org/bugzilla/show_bug.cgi?id=103

The user can pass either option, if both are present one is simply
ignored, I first added an exception, but I guess it's better to just
ignore the redundant option rather that stop the application.

Mark told me that Tom Tromey is already working on it too, so feel free
to ignore this one.

Thanks,
Mario

2008-01-24  Mario Torre  [EMAIL PROTECTED]

* tools/gnu/classpath/tools/native2ascii/Native2ASCII.java
(createParser): 
added new option for compatibility with OpenJDK.
* resource/gnu/classpath/tools/native2ascii/messages.properties: Help
string for new option.

-- 
Lima Software - http://www.limasoftware.net/
GNU Classpath Developer - http://www.classpath.org/
Fedora Ambassador - http://fedoraproject.org/wiki/MarioTorre
Jabber: [EMAIL PROTECTED]
pgp key: http://subkeys.pgp.net/ PGP Key ID: 80F240CF
Fingerprint: BA39 9666 94EC 8B73 27FA  FC7C 4086 63E3 80F2 40CF

Please, support open standards:
http://opendocumentfellowship.org/petition/
http://www.nosoftwarepatents.com/
### Eclipse Workspace Patch 1.0
#P classpath
Index: tools/gnu/classpath/tools/native2ascii/Native2ASCII.java
===
RCS file: /sources/classpath/classpath/tools/gnu/classpath/tools/native2ascii/Native2ASCII.java,v
retrieving revision 1.5
diff -u -r1.5 Native2ASCII.java
--- tools/gnu/classpath/tools/native2ascii/Native2ASCII.java	8 Jan 2007 17:00:49 -	1.5
+++ tools/gnu/classpath/tools/native2ascii/Native2ASCII.java	24 Jan 2008 17:14:49 -
@@ -68,7 +68,7 @@
   String encoding;
   // True for reverse operation.
   boolean reversed;
-
+  
   private class HandleFile extends FileArgumentCallback
   {
 public HandleFile()
@@ -101,10 +101,18 @@
 encoding = argument;
   }
 });
+
 result.add(new Option(reversed, Messages.getString(Native2ASCII.ReversedHelp)) //$NON-NLS-1$ //$NON-NLS-2$
 {
   public void parsed(String argument) throws OptionException
-  {
+  {   
+reversed = true;
+  }
+});
+result.add(new Option(reverse, Messages.getString(Native2ASCII.ReverseHelp)) //$NON-NLS-1$ //$NON-NLS-2$
+{
+  public void parsed(String argument) throws OptionException
+  { 
 reversed = true;
   }
 });
Index: resource/gnu/classpath/tools/native2ascii/messages.properties
===
RCS file: /sources/classpath/classpath/resource/gnu/classpath/tools/native2ascii/messages.properties,v
retrieving revision 1.1
diff -u -r1.1 messages.properties
--- resource/gnu/classpath/tools/native2ascii/messages.properties	20 May 2006 22:10:31 -	1.1
+++ resource/gnu/classpath/tools/native2ascii/messages.properties	24 Jan 2008 17:14:49 -
@@ -41,3 +41,4 @@
 Native2ASCII.EncodingArgName=NAME
 Native2ASCII.EncodingSpecified=encoding already specified
 Native2ASCII.ReversedHelp=convert from encoding to native
+Native2ASCII.ReverseHelp=convert from encoding to native, this option has the same effect of \reversed\


[cp-patches] Patch: FYI: -reverse argument for native2ascii

2008-01-24 Thread Tom Tromey
I'm checking this in to Classpath and libgcj.

Sun's native2ascii accepts -reverse, while we accept -reversed.
This changes Classpath to conform.

This bug came from the IcedTea build:

http://icedtea.classpath.org/bugzilla/show_bug.cgi?id=103

Tom

ChangeLog:
2008-01-24  Tom Tromey  [EMAIL PROTECTED]

* resource/gnu/classpath/tools/native2ascii/messages.properties
(Native2ASCII.ReversedHelpCompat): New.
* tools/gnu/classpath/tools/native2ascii/Native2ASCII.java
(createParser): Add -reverse.  Update -reversed.

Index: resource/gnu/classpath/tools/native2ascii/messages.properties
===
RCS file: 
/cvsroot/classpath/classpath/resource/gnu/classpath/tools/native2ascii/messages.properties,v
retrieving revision 1.1
diff -u -r1.1 messages.properties
--- resource/gnu/classpath/tools/native2ascii/messages.properties   20 May 
2006 22:10:31 -  1.1
+++ resource/gnu/classpath/tools/native2ascii/messages.properties   24 Jan 
2008 14:27:37 -
@@ -1,5 +1,5 @@
 # messages.properties -- English language messages
-# Copyright (C) 2006  Free Software Foundation, Inc.
+# Copyright (C) 2006, 2008  Free Software Foundation, Inc.
 #
 # This file is part of GNU Classpath.
 #
@@ -41,3 +41,4 @@
 Native2ASCII.EncodingArgName=NAME
 Native2ASCII.EncodingSpecified=encoding already specified
 Native2ASCII.ReversedHelp=convert from encoding to native
+Native2ASCII.ReversedHelpCompat=alias for -reverse (deprecated)
Index: tools/gnu/classpath/tools/native2ascii/Native2ASCII.java
===
RCS file: 
/cvsroot/classpath/classpath/tools/gnu/classpath/tools/native2ascii/Native2ASCII.java,v
retrieving revision 1.5
diff -u -r1.5 Native2ASCII.java
--- tools/gnu/classpath/tools/native2ascii/Native2ASCII.java8 Jan 2007 
17:00:49 -   1.5
+++ tools/gnu/classpath/tools/native2ascii/Native2ASCII.java24 Jan 2008 
14:27:37 -
@@ -1,5 +1,5 @@
 /* Native2ASCII.java - native2ascii program
- Copyright (C) 2003, 2007 Free Software Foundation, Inc.
+ Copyright (C) 2003, 2007, 2008 Free Software Foundation, Inc.
 
  This file is part of GNU Classpath.
 
@@ -101,7 +101,17 @@
 encoding = argument;
   }
 });
-result.add(new Option(reversed, 
Messages.getString(Native2ASCII.ReversedHelp)) //$NON-NLS-1$ //$NON-NLS-2$
+result.add(new Option(reverse, 
Messages.getString(Native2ASCII.ReversedHelp)) //$NON-NLS-1$ //$NON-NLS-2$
+{
+  public void parsed(String argument) throws OptionException
+  {
+reversed = true;
+  }
+});
+
+// We mistakenly added the extra d in reversed; now we don't
+// want to remove it, for backward compatibility.
+result.add(new Option(reversed, 
Messages.getString(Native2ASCII.ReversedHelpCompat)) //$NON-NLS-1$ 
//$NON-NLS-2$
 {
   public void parsed(String argument) throws OptionException
   {



Re: [cp-patches] RFC: adding -reverse to gnative2ascii

2008-01-24 Thread Dalibor Topic

Mario Torre wrote:

This patch adds the -reverse option to gnative2ascii as described here:

http://icedtea.classpath.org/bugzilla/show_bug.cgi?id=103

The user can pass either option, if both are present one is simply
ignored, I first added an exception, but I guess it's better to just
ignore the redundant option rather that stop the application.



I'd suggest removing the redundant option. The official docs at 
http://java.sun.com/javase/6/docs/technotes/tools/solaris/native2ascii.html 
don't have a -reversed, just a -reverse, so I assume it was a typo anyway.


cheers,
dalibor topic



Re: [cp-patches] RFC: adding -reverse to gnative2ascii

2008-01-24 Thread Mario Torre
Il giorno gio, 24/01/2008 alle 19.30 +0100, Dalibor Topic ha scritto:

 I'd suggest removing the redundant option. The official docs at 
 http://java.sun.com/javase/6/docs/technotes/tools/solaris/native2ascii.html 
 don't have a -reversed, just a -reverse, so I assume it was a typo anyway.
 
 cheers,
 dalibor topic

Agree, but not needed anymore :)

Anyway, I was thinking that someone could use that option in scripts,
that's why I left it in place.

Cheers,
Mario
-- 
Lima Software - http://www.limasoftware.net/
GNU Classpath Developer - http://www.classpath.org/
Fedora Ambassador - http://fedoraproject.org/wiki/MarioTorre
Jabber: [EMAIL PROTECTED]
pgp key: http://subkeys.pgp.net/ PGP Key ID: 80F240CF
Fingerprint: BA39 9666 94EC 8B73 27FA  FC7C 4086 63E3 80F2 40CF

Please, support open standards:
http://opendocumentfellowship.org/petition/
http://www.nosoftwarepatents.com/


signature.asc
Description: Questa รจ una parte del messaggio	firmata digitalmente


Re: [cp-patches] Patch: FYI: -reverse argument for native2ascii

2008-01-24 Thread Dalibor Topic

Tom Tromey wrote:

I'm checking this in to Classpath and libgcj.

Sun's native2ascii accepts -reverse, while we accept -reversed.
This changes Classpath to conform.

This bug came from the IcedTea build:

http://icedtea.classpath.org/bugzilla/show_bug.cgi?id=103

Tom

ChangeLog:
2008-01-24  Tom Tromey  [EMAIL PROTECTED]

* resource/gnu/classpath/tools/native2ascii/messages.properties
(Native2ASCII.ReversedHelpCompat): New.
* tools/gnu/classpath/tools/native2ascii/Native2ASCII.java
(createParser): Add -reverse.  Update -reversed.



Please remove it instead, as no one is using it according to google or 
Koders. 0 hits for gnative2ascii reversed on Google, and Ant does not 
support reversion with the Kaffe/Classpath native2ascii.


cheers,
dalibor topic



Re: [cp-patches] RFC: adding -reverse to gnative2ascii

2008-01-24 Thread Dalibor Topic

Mario Torre wrote:

Il giorno gio, 24/01/2008 alle 19.30 +0100, Dalibor Topic ha scritto:

I'd suggest removing the redundant option. The official docs at 
http://java.sun.com/javase/6/docs/technotes/tools/solaris/native2ascii.html 
don't have a -reversed, just a -reverse, so I assume it was a typo anyway.


cheers,
dalibor topic


Agree, but not needed anymore :)

Anyway, I was thinking that someone could use that option in scripts,
that's why I left it in place.


According to Google and Koders, no one is. There is no point in crufting 
up Classpath when there are no documented users, in my opinion.


cheers,
dalibor topic