You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by hi...@apache.org on 2010/04/22 22:31:30 UTC
svn commit: r937048 [1/2] - in /harmony/enhanced/java/branches/mrh: ./
classlib/ classlib/modules/luni/src/main/java/java/io/
classlib/modules/luni/src/main/java/java/net/
classlib/modules/luni/src/main/java/org/apache/harmony/luni/platform/
classlib/m...
Author: hindessm
Date: Thu Apr 22 20:31:29 2010
New Revision: 937048
URL: http://svn.apache.org/viewvc?rev=937048&view=rev
Log:
Merging from trunk@936843.
Added:
harmony/enhanced/java/branches/mrh/jdktools/modules/jdktools/src/main/java/org/apache/harmony/tools/serialver/ShowGui.java
- copied unchanged from r936843, harmony/enhanced/java/trunk/jdktools/modules/jdktools/src/main/java/org/apache/harmony/tools/serialver/ShowGui.java
Modified:
harmony/enhanced/java/branches/mrh/ (props changed)
harmony/enhanced/java/branches/mrh/build.xml
harmony/enhanced/java/branches/mrh/classlib/ (props changed)
harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/java/io/FileInputStream.java
harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/java/net/URLConnection.java
harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/org/apache/harmony/luni/platform/IFileSystem.java
harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/org/apache/harmony/luni/platform/INetworkSystem.java
harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSFileSystem.java
harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSNetworkSystem.java
harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/native/luni/shared/OSFileSystem.c
harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/native/luni/shared/OSFileSystem.h
harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/native/luni/shared/OSNetworkSystem.h
harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/native/luni/unix/OSFileSystemLinux32.c
harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/native/luni/unix/OSNetworkSystemLinux.c
harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/native/luni/unix/exports.txt
harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/native/luni/windows/OSFileSystemWin32.c
harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/native/luni/windows/OSMemoryWin32.c
harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/native/luni/windows/OSNetworkSystemWin32.c
harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/URLConnectionTest.java
harmony/enhanced/java/branches/mrh/classlib/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/FileChannelImpl.java
harmony/enhanced/java/branches/mrh/classlib/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/SocketChannelImpl.java
harmony/enhanced/java/branches/mrh/classlib/modules/swing/build.xml
harmony/enhanced/java/branches/mrh/common_resources/ (props changed)
harmony/enhanced/java/branches/mrh/drlvm/ (props changed)
harmony/enhanced/java/branches/mrh/jdktools/modules/jdktools/src/main/java/org/apache/harmony/tools/serialver/Clazz.java
harmony/enhanced/java/branches/mrh/jdktools/modules/jdktools/src/main/java/org/apache/harmony/tools/serialver/Main.java
harmony/enhanced/java/branches/mrh/jdktools/modules/jdktools/src/test/java/org/apache/harmony/tests/tools/serialver/NoSerialize.java
harmony/enhanced/java/branches/mrh/jdktools/modules/jdktools/src/test/java/org/apache/harmony/tests/tools/serialver/Point.java
harmony/enhanced/java/branches/mrh/jdktools/modules/jdktools/src/test/java/org/apache/harmony/tests/tools/serialver/Test.java
Propchange: harmony/enhanced/java/branches/mrh/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Apr 22 20:31:29 2010
@@ -1 +1 @@
-/harmony/enhanced/java/trunk:935751-936090
+/harmony/enhanced/java/trunk:935751-936843
Modified: harmony/enhanced/java/branches/mrh/build.xml
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/build.xml?rev=937048&r1=937047&r2=937048&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/build.xml (original)
+++ harmony/enhanced/java/branches/mrh/build.xml Thu Apr 22 20:31:29 2010
@@ -847,7 +847,7 @@ harmony.java.version=${harmony.java.vers
depends="test-classlib,test-jdktools,process-test-output" />
<target name="clean-tests">
- <delete dir="build/test_report" />
+ <delete dir="target/test_report" />
</target>
<target name="test-classlib" depends="clean-tests">
@@ -857,7 +857,7 @@ harmony.java.version=${harmony.java.vers
<property name="svn.info" value="${harmony.long.version}"/>
<property name="svn.revision" value="${harmony.version}"/>
<property name="keep.working" value="true" />
- <property name="tests.output" location="build/test_report" />
+ <property name="tests.output" location="target/test_report" />
<property name="test.jre.home" location="target/hdk/jdk/jre" />
</ant>
</target>
@@ -869,7 +869,7 @@ harmony.java.version=${harmony.java.vers
<property name="svn.info" value="${harmony.long.version}"/>
<property name="svn.revision" value="${harmony.version}"/>
<property name="keep.working" value="true" />
- <property name="tests.output" location="build/test_report" />
+ <property name="tests.output" location="target/test_report" />
<property name="test.jre.home" location="target/hdk/jdk/jre" />
</ant>
</target>
@@ -881,7 +881,7 @@ harmony.java.version=${harmony.java.vers
<property name="svn.info" value="${harmony.long.version}"/>
<property name="svn.revision" value="${harmony.version}"/>
<property name="keep.working" value="true" />
- <property name="tests.output" location="build/test_report" />
+ <property name="tests.output" location="target/test_report" />
<property name="test.jre.home" location="target/hdk/jdk/jre" />
</ant>
</target>
Propchange: harmony/enhanced/java/branches/mrh/classlib/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Apr 22 20:31:29 2010
@@ -1,2 +1,2 @@
/harmony/enhanced/classlib/trunk:926318-926838
-/harmony/enhanced/java/trunk/classlib:935751-936090
+/harmony/enhanced/java/trunk/classlib:935751-936843
Modified: harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/java/io/FileInputStream.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/java/io/FileInputStream.java?rev=937048&r1=937047&r2=937048&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/java/io/FileInputStream.java (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/java/io/FileInputStream.java Thu Apr 22 20:31:29 2010
@@ -148,14 +148,7 @@ public class FileInputStream extends Inp
if (fd == FileDescriptor.in) {
return (int) fileSystem.ttyAvailable();
}
-
- long currentPosition = fileSystem.seek(fd.descriptor, 0L,
- IFileSystem.SEEK_CUR);
- long endOfFilePosition = fileSystem.seek(fd.descriptor, 0L,
- IFileSystem.SEEK_END);
- fileSystem.seek(fd.descriptor, currentPosition,
- IFileSystem.SEEK_SET);
- return (int) (endOfFilePosition - currentPosition);
+ return (int) fileSystem.available(fd.descriptor);
}
}
Modified: harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/java/net/URLConnection.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/java/net/URLConnection.java?rev=937048&r1=937047&r2=937048&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/java/net/URLConnection.java (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/java/net/URLConnection.java Thu Apr 22 20:31:29 2010
@@ -681,6 +681,12 @@ public abstract class URLConnection {
int length = is.read(bytes);
is.reset();
+ // If there is no data from the input stream, can not determine
+ // content-type
+ if (length == -1) {
+ return null;
+ }
+
// Check for Unicode BOM encoding indicators
String encoding = "ASCII";
int start = 0;
Modified: harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/org/apache/harmony/luni/platform/IFileSystem.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/org/apache/harmony/luni/platform/IFileSystem.java?rev=937048&r1=937047&r2=937048&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/org/apache/harmony/luni/platform/IFileSystem.java (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/org/apache/harmony/luni/platform/IFileSystem.java Thu Apr 22 20:31:29 2010
@@ -66,7 +66,7 @@ public interface IFileSystem {
public long readv(long fileDescriptor, long[] addresses, int[] offsets,
int[] lengths, int size) throws IOException;
- public long writev(long fileDescriptor, long[] addresses, int[] offsets,
+ public long writev(long fileDescriptor, Object[] buffers, int[] offsets,
int[] lengths, int size) throws IOException;
// Required to support direct byte buffers
@@ -103,6 +103,8 @@ public interface IFileSystem {
long offset, long count) throws IOException;
public long ttyAvailable() throws IOException;
+
+ public long available(long fileDescriptor) throws IOException;
public long ttyRead(byte[] bytes, int offset, int length) throws IOException;
}
Modified: harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/org/apache/harmony/luni/platform/INetworkSystem.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/org/apache/harmony/luni/platform/INetworkSystem.java?rev=937048&r1=937047&r2=937048&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/org/apache/harmony/luni/platform/INetworkSystem.java (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/org/apache/harmony/luni/platform/INetworkSystem.java Thu Apr 22 20:31:29 2010
@@ -62,8 +62,8 @@ public interface INetworkSystem {
public int writeDirect(FileDescriptor fd, long address, int count)
throws IOException;
- public int writev(FileDescriptor fd, Object[] buffers, int[] offsets,
- int[] counts, int length) throws IOException;
+ public long writev(FileDescriptor fd, Object[] buffers, int[] offsets,
+ int[] lengths, int length) throws IOException;
public void setNonBlocking(FileDescriptor aFD, boolean block)
throws IOException;
Modified: harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSFileSystem.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSFileSystem.java?rev=937048&r1=937047&r2=937048&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSFileSystem.java (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSFileSystem.java Thu Apr 22 20:31:29 2010
@@ -28,6 +28,10 @@ import java.io.UnsupportedEncodingExcept
*/
class OSFileSystem implements IFileSystem {
+ static {
+ oneTimeInitializationImpl();
+ }
+
private static final OSFileSystem singleton = new OSFileSystem();
public static OSFileSystem getOSFileSystem() {
@@ -38,6 +42,8 @@ class OSFileSystem implements IFileSyste
super();
}
+ private native static void oneTimeInitializationImpl();
+
private final void validateLockArgs(int type, long start, long length) {
if ((type != IFileSystem.SHARED_LOCK_TYPE)
&& (type != IFileSystem.EXCLUSIVE_LOCK_TYPE)) {
@@ -194,18 +200,8 @@ class OSFileSystem implements IFileSyste
private native long readvImpl(long fileDescriptor, long[] addresses,
int[] offsets, int[] lengths, int size);
- public long writev(long fileDescriptor, long[] addresses, int[] offsets,
- int[] lengths, int size) throws IOException {
- long bytesWritten = writevImpl(fileDescriptor, addresses, offsets,
- lengths, size);
- if (bytesWritten < 0) {
- throw new IOException();
- }
- return bytesWritten;
- }
-
- private native long writevImpl(long fileDescriptor, long[] addresses,
- int[] offsets, int[] lengths, int size);
+ public native long writev(long fileDescriptor, Object[] buffers,
+ int[] offsets, int[] lengths, int size) throws IOException;
private native int closeImpl(long fileDescriptor);
@@ -271,6 +267,16 @@ class OSFileSystem implements IFileSyste
private native long ttyAvailableImpl();
+ public long available(long fileDescriptor) throws IOException {
+ long nChar = availableImpl(fileDescriptor);
+ if (nChar < 0) {
+ throw new IOException();
+ }
+ return nChar;
+ }
+
+ private native long availableImpl(long fileDescriptor);
+
public long ttyRead(byte[] bytes, int offset, int length) throws IOException {
long nChar = ttyReadImpl(bytes, offset, length);
if (nChar < 0) {
Modified: harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSNetworkSystem.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSNetworkSystem.java?rev=937048&r1=937047&r2=937048&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSNetworkSystem.java (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSNetworkSystem.java Thu Apr 22 20:31:29 2010
@@ -548,6 +548,6 @@ final class OSNetworkSystem implements I
* @throws IOException
* if there is an underlying socket problem
*/
- public native int writev(FileDescriptor fd, Object[] buffers,
- int[] offsets, int[] counts, int length) throws IOException;
+ public native long writev(FileDescriptor fd, Object[] buffers,
+ int[] offsets, int[] lengths, int length) throws IOException;
}
Modified: harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/native/luni/shared/OSFileSystem.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/native/luni/shared/OSFileSystem.c?rev=937048&r1=937047&r2=937048&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/native/luni/shared/OSFileSystem.c (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/native/luni/shared/OSFileSystem.c Thu Apr 22 20:31:29 2010
@@ -23,11 +23,37 @@
#include "iohelp.h"
#include "exceptions.h"
#include "nethelp.h"
+#include "harmonyglob.h"
#include "OSFileSystem.h"
#include "IFileSystem.h"
/*
* Class: org_apache_harmony_luni_platform_OSFileSystem
+ * Method: oneTimeInitializationImpl
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL
+Java_org_apache_harmony_luni_platform_OSFileSystem_oneTimeInitializationImpl
+ (JNIEnv * env, jclass clazz)
+{
+ jclass lookupClass;
+ jobject globalRef;
+
+ if (HARMONY_CACHE_GET (env, CLS_java_nio_DirectByteBuffer)) {
+ /* Cache is already initialized */
+ return;
+ }
+ lookupClass = (*env)->FindClass (env, "java/nio/DirectByteBuffer");
+ if (!lookupClass)
+ return;
+ globalRef = (*env)->NewGlobalRef (env, lookupClass);
+ if (!globalRef)
+ return;
+ HARMONY_CACHE_SET (env, CLS_java_nio_DirectByteBuffer, globalRef);
+}
+
+/*
+ * Class: org_apache_harmony_luni_platform_OSFileSystem
* Method: readDirectImpl
* Signature: (JJI)J
*/
@@ -259,6 +285,33 @@ JNIEXPORT jlong JNICALL Java_org_apache_
}
/*
+ * Answers the number of remaining chars in the stdin.
+ *
+ * Class: org_apache_harmony_luni_platform_OSFileSystem
+ * Method: AvailableImpl
+ * Signature: ()J
+ */
+JNIEXPORT jlong JNICALL Java_org_apache_harmony_luni_platform_OSFileSystem_availableImpl
+(JNIEnv *env, jobject thiz, jlong fd)
+{
+ jlong currentPosition =
+ Java_org_apache_harmony_luni_platform_OSFileSystem_seekImpl(env,
+ thiz, fd, 0,
+ org_apache_harmony_luni_platform_IFileSystem_SEEK_CUR);
+
+ jlong endPosition =
+ Java_org_apache_harmony_luni_platform_OSFileSystem_seekImpl(env,
+ thiz, fd, 0,
+ org_apache_harmony_luni_platform_IFileSystem_SEEK_END);
+
+ Java_org_apache_harmony_luni_platform_OSFileSystem_seekImpl(env,
+ thiz, fd, currentPosition,
+ org_apache_harmony_luni_platform_IFileSystem_SEEK_SET);
+
+ return (jlong) (endPosition - currentPosition);
+}
+
+/*
* Reads the number of bytes from stdin.
*
* Class: org_apache_harmony_luni_platform_OSFileSystem
Modified: harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/native/luni/shared/OSFileSystem.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/native/luni/shared/OSFileSystem.h?rev=937048&r1=937047&r2=937048&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/native/luni/shared/OSFileSystem.h (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/native/luni/shared/OSFileSystem.h Thu Apr 22 20:31:29 2010
@@ -100,10 +100,10 @@ JNIEXPORT jlong JNICALL Java_org_apache_
/*
* Class: org_apache_harmony_luni_platform_OSFileSystem
- * Method: writevImpl
- * Signature: (J[J[I[II)J
+ * Method: writev
+ * Signature: (J[Ljava/lang/Object;[I[II)J
*/
-JNIEXPORT jlong JNICALL Java_org_apache_harmony_luni_platform_OSFileSystem_writevImpl
+JNIEXPORT jlong JNICALL Java_org_apache_harmony_luni_platform_OSFileSystem_writev
(JNIEnv *, jobject, jlong, jlongArray, jintArray, jintArray, jint);
/*
Modified: harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/native/luni/shared/OSNetworkSystem.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/native/luni/shared/OSNetworkSystem.h?rev=937048&r1=937047&r2=937048&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/native/luni/shared/OSNetworkSystem.h (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/native/luni/shared/OSNetworkSystem.h Thu Apr 22 20:31:29 2010
@@ -469,9 +469,9 @@ JNIEXPORT jint JNICALL Java_org_apache_h
/*
* Class: org_apache_harmony_luni_platform_OSNetworkSystem
* Method: writev
- * Signature: (Ljava/io/FileDescriptor;[Ljava/lang/Object;[I[II)I
+ * Signature: (Ljava/io/FileDescriptor;[Ljava/lang/Object;[I[II)J
*/
-JNIEXPORT jint JNICALL Java_org_apache_harmony_luni_platform_OSNetworkSystem_writev
+JNIEXPORT jlong JNICALL Java_org_apache_harmony_luni_platform_OSNetworkSystem_writev
(JNIEnv *, jobject, jobject, jobjectArray, jintArray, jintArray, jint);
#ifdef __cplusplus
Modified: harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/native/luni/unix/OSFileSystemLinux32.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/native/luni/unix/OSFileSystemLinux32.c?rev=937048&r1=937047&r2=937048&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/native/luni/unix/OSFileSystemLinux32.c (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/native/luni/unix/OSFileSystemLinux32.c Thu Apr 22 20:31:29 2010
@@ -32,7 +32,9 @@
#include "vmi.h"
#include "iohelp.h"
#include "nethelp.h"
+#include "harmonyglob.h"
#include "hysock.h"
+#include "exceptions.h"
#include "IFileSystem.h"
#include "OSFileSystem.h"
@@ -190,44 +192,101 @@ JNIEXPORT jlong JNICALL Java_org_apache_
/*
* Class: org_apache_harmony_luni_platform_OSFileSystem
- * Method: writevImpl
- * Signature: (J[J[I[I)J
+ * Method: writev
+ * Signature: (J[Ljava/lang/Object;[I[II)J
*/
-JNIEXPORT jlong JNICALL Java_org_apache_harmony_luni_platform_OSFileSystem_writevImpl
- (JNIEnv *env, jobject thiz, jlong fd, jlongArray jbuffers, jintArray joffsets, jintArray jlengths, jint size){
+JNIEXPORT jlong JNICALL
+Java_org_apache_harmony_luni_platform_OSFileSystem_writev
+ (JNIEnv *env, jobject thiz, jlong fd, jobjectArray buffers, jintArray offset, jintArray counts, jint length){
PORT_ACCESS_FROM_ENV (env);
- jboolean bufsCopied = JNI_FALSE;
- jboolean offsetsCopied = JNI_FALSE;
- jboolean lengthsCopied = JNI_FALSE;
- jlong *bufs;
- jint *offsets;
- jint *lengths;
- int i = 0;
- long totalWritten = 0;
- struct iovec *vectors = (struct iovec *)hymem_allocate_memory(size * sizeof(struct iovec));
- if(vectors == NULL){
- return -1;
- }
- bufs = (*env)->GetLongArrayElements(env, jbuffers, &bufsCopied);
- offsets = (*env)->GetIntArrayElements(env, joffsets, &offsetsCopied);
- lengths = (*env)->GetIntArrayElements(env, jlengths, &lengthsCopied);
- while(i < size){
- vectors[i].iov_base = (void *)((IDATA)(bufs[i]+offsets[i]));
- vectors[i].iov_len = lengths[i];
- i++;
+ jobject buffer;
+ jobject* toBeReleasedBuffers;
+ jint *noffset = NULL;
+ jboolean isDirectBuffer = JNI_FALSE;
+ ssize_t result = 0;
+ jclass byteBufferClass;
+ struct iovec* vect;
+ int i;
+
+ vect = (struct iovec*) hymem_allocate_memory(sizeof(struct iovec) * length);
+ if (vect == NULL) {
+ throwNewOutOfMemoryError(env, "");
+ return (jlong)0;
+ }
+
+ toBeReleasedBuffers =
+ (jobject*) hymem_allocate_memory(sizeof(jobject) * length);
+ if (toBeReleasedBuffers == NULL) {
+ throwNewOutOfMemoryError(env, "");
+ goto free_resources;
+ }
+ memset(toBeReleasedBuffers, 0, sizeof(jobject)*length);
+
+ byteBufferClass = HARMONY_CACHE_GET (env, CLS_java_nio_DirectByteBuffer);
+ noffset = (*env)->GetIntArrayElements(env, offset, NULL);
+ if (noffset == NULL) {
+ throwNewOutOfMemoryError(env, "");
+ goto free_resources;
+ }
+
+ for (i = 0; i < length; ++i) {
+ jint *cts;
+ U_8* base;
+ buffer = (*env)->GetObjectArrayElement(env, buffers, i);
+ isDirectBuffer = (*env)->IsInstanceOf(env, buffer, byteBufferClass);
+ if (isDirectBuffer) {
+ base =
+ (U_8 *)(jbyte *)(IDATA) (*env)->GetDirectBufferAddress(env, buffer);
+ if (base == NULL) {
+ throwNewOutOfMemoryError(env, "");
+ goto free_resources;
+ }
+ toBeReleasedBuffers[i] = NULL;
+ } else {
+ base =
+ (U_8 *)(jbyte *)(IDATA) (*env)->GetByteArrayElements(env, buffer, NULL);
+ if (base == NULL) {
+ throwNewOutOfMemoryError(env, "");
+ goto free_resources;
+ }
+ toBeReleasedBuffers[i] = buffer;
+ }
+ vect[i].iov_base = base + noffset[i];
+
+ cts = (*env)->GetPrimitiveArrayCritical(env, counts, NULL);
+ vect[i].iov_len = cts[i];
+ (*env)->ReleasePrimitiveArrayCritical(env, counts, cts, JNI_ABORT);
}
- totalWritten = writev(fd - FD_BIAS, vectors, size);
- if(bufsCopied){
- (*env)->ReleaseLongArrayElements(env, jbuffers, bufs, JNI_ABORT);
+
+ result = writev(fd - FD_BIAS, vect, length);
+
+ if (0 > result) {
+ if (errno != EAGAIN) {
+ throwJavaIoIOException(env, "");
+ }
+ result = 0;
}
- if(offsetsCopied){
- (*env)->ReleaseIntArrayElements(env, joffsets, offsets, JNI_ABORT);
+
+ free_resources:
+
+ if (toBeReleasedBuffers != NULL) {
+ for (i = 0; i < length; ++i) {
+ if (toBeReleasedBuffers[i] != NULL) {
+ (*env)->ReleaseByteArrayElements(env, toBeReleasedBuffers[i],
+ vect[i].iov_base - noffset[i],
+ JNI_ABORT);
+ }
+ }
}
- if(lengthsCopied){
- (*env)->ReleaseIntArrayElements(env, jlengths, lengths, JNI_ABORT);
+
+ if (noffset != NULL) {
+ (*env)->ReleaseIntArrayElements(env, offset, noffset, JNI_ABORT);
}
- hymem_free_memory(vectors);
- return totalWritten;
+
+ hymem_free_memory(toBeReleasedBuffers);
+ hymem_free_memory(vect);
+
+ return (jlong) result;
}
/*
Modified: harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/native/luni/unix/OSNetworkSystemLinux.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/native/luni/unix/OSNetworkSystemLinux.c?rev=937048&r1=937047&r2=937048&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/native/luni/unix/OSNetworkSystemLinux.c (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/native/luni/unix/OSNetworkSystemLinux.c Thu Apr 22 20:31:29 2010
@@ -727,7 +727,7 @@ pollSelectRead (JNIEnv * env, jobject fi
return result;
}
-JNIEXPORT jint JNICALL
+JNIEXPORT jlong JNICALL
Java_org_apache_harmony_luni_platform_OSNetworkSystem_writev
(JNIEnv *env, jobject thiz, jobject fd, jobjectArray buffers, jintArray offset, jintArray counts, jint length) {
@@ -735,9 +735,9 @@ Java_org_apache_harmony_luni_platform_OS
jobject buffer;
jobject* toBeReleasedBuffers;
- jint *noffset;
+ jint *noffset = NULL;
jboolean isDirectBuffer = JNI_FALSE;
- jint result = 0;
+ ssize_t result = 0;
jclass byteBufferClass;
struct iovec* vect;
int i;
@@ -746,13 +746,13 @@ Java_org_apache_harmony_luni_platform_OS
if (!hysock_socketIsValid(socketP)) {
throwJavaNetSocketException(env, HYPORT_ERROR_SOCKET_BADSOCKET);
- return (jint) 0;
+ return (jlong)0;
}
vect = (struct iovec*) hymem_allocate_memory(sizeof(struct iovec) * length);
if (vect == NULL) {
throwNewOutOfMemoryError(env, "");
- return 0;
+ return (jlong)0;
}
toBeReleasedBuffers =
@@ -799,10 +799,10 @@ Java_org_apache_harmony_luni_platform_OS
(*env)->ReleasePrimitiveArrayCritical(env, counts, cts, JNI_ABORT);
}
-
result = writev(SOCKET_CAST (socketP), vect, length);
if (0 > result) {
+ /* TOFIX? man write(2) on linux implies we should check EWOULDBLOCK too */
if (errno != EAGAIN) {
throwJavaNetSocketException(env, result);
}
@@ -828,5 +828,5 @@ Java_org_apache_harmony_luni_platform_OS
hymem_free_memory(toBeReleasedBuffers);
hymem_free_memory(vect);
- return (jint) result;
+ return (jlong)result;
}
Modified: harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/native/luni/unix/exports.txt
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/native/luni/unix/exports.txt?rev=937048&r1=937047&r2=937048&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/native/luni/unix/exports.txt (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/native/luni/unix/exports.txt Thu Apr 22 20:31:29 2010
@@ -120,9 +120,10 @@ JNI_OnUnload
Java_org_apache_harmony_luni_util_FloatingPointParser_parseDblImpl
Java_org_apache_harmony_luni_util_FloatingPointParser_parseFltImpl
Java_org_apache_harmony_luni_util_NumberConverter_bigIntDigitGeneratorInstImpl
+Java_org_apache_harmony_luni_platform_OSFileSystem_oneTimeInitializationImpl
Java_org_apache_harmony_luni_platform_OSFileSystem_truncateImpl
Java_org_apache_harmony_luni_platform_OSFileSystem_getAllocGranularity
-Java_org_apache_harmony_luni_platform_OSFileSystem_writevImpl
+Java_org_apache_harmony_luni_platform_OSFileSystem_writev
Java_org_apache_harmony_luni_platform_OSFileSystem_readvImpl
Java_org_apache_harmony_luni_platform_OSFileSystem_writeImpl
Java_org_apache_harmony_luni_platform_OSFileSystem_openImpl
@@ -136,6 +137,7 @@ Java_org_apache_harmony_luni_platform_OS
Java_org_apache_harmony_luni_platform_OSFileSystem_unlockImpl
Java_org_apache_harmony_luni_platform_OSFileSystem_transferImpl
Java_org_apache_harmony_luni_platform_OSFileSystem_ttyAvailableImpl
+Java_org_apache_harmony_luni_platform_OSFileSystem_availableImpl
Java_org_apache_harmony_luni_platform_OSFileSystem_ttyReadImpl
Java_org_apache_harmony_luni_platform_OSMemory_isLoadedImpl
Java_org_apache_harmony_luni_platform_OSMemory_loadImpl
Modified: harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/native/luni/windows/OSFileSystemWin32.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/native/luni/windows/OSFileSystemWin32.c?rev=937048&r1=937047&r2=937048&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/native/luni/windows/OSFileSystemWin32.c (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/native/luni/windows/OSFileSystemWin32.c Thu Apr 22 20:31:29 2010
@@ -27,6 +27,7 @@
#include <stdio.h>
#include "IFileSystem.h"
#include "OSFileSystem.h"
+#include "harmonyglob.h"
/**
* Lock the file identified by the given handle.
@@ -170,22 +171,65 @@ JNIEXPORT jlong JNICALL Java_org_apache_
/*
* Class: org_apache_harmony_luni_platform_OSFileSystem
- * Method: writevImpl
- * Signature: (J[J[I[I)J
+ * Method: writev
+ * Signature: (J[Ljava/lang/Object;[I[II)J
*/
-JNIEXPORT jlong JNICALL Java_org_apache_harmony_luni_platform_OSFileSystem_writevImpl
- (JNIEnv *env, jobject thiz, jlong fd, jlongArray jbuffers, jintArray joffsets, jintArray jlengths, jint size){
+JNIEXPORT jlong JNICALL
+Java_org_apache_harmony_luni_platform_OSFileSystem_writev
+ (JNIEnv *env, jobject thiz, jlong fd, jobjectArray buffers, jintArray offset, jintArray counts, jint length){
PORT_ACCESS_FROM_ENV (env);
- jboolean bufsCopied = JNI_FALSE;
- jboolean offsetsCopied = JNI_FALSE;
- jboolean lengthsCopied = JNI_FALSE;
- jlong *bufs = (*env)->GetLongArrayElements(env, jbuffers, &bufsCopied);
- jint *offsets = (*env)->GetIntArrayElements(env, joffsets, &offsetsCopied);
- jint *lengths = (*env)->GetIntArrayElements(env, jlengths, &lengthsCopied);
- long totalWritten = 0;
- int i = 0;
- while(i<size){
- long bytesWritten = hyfile_write ((IDATA) fd, (void *) (*(bufs+i)+*(offsets+i)), (IDATA) *(lengths+i));
+ jint *noffset = NULL;
+ jint *lengths = NULL;
+ jboolean isDirectBuffer = JNI_FALSE;
+ long totalWritten = 0;
+ int i;
+ jclass byteBufferClass;
+
+ byteBufferClass = HARMONY_CACHE_GET (env, CLS_java_nio_DirectByteBuffer);
+
+ noffset = (*env)->GetIntArrayElements(env, offset, NULL);
+ if (noffset == NULL) {
+ throwNewOutOfMemoryError(env, "");
+ goto free_resources;
+ }
+
+ lengths = (*env)->GetIntArrayElements(env, counts, NULL);
+ if (lengths == NULL) {
+ throwNewOutOfMemoryError(env, "");
+ goto free_resources;
+ }
+
+ for (i = 0; i < length; ++i) {
+ long bytesWritten;
+ jobject toRelease = NULL;
+ U_8* buf;
+ jobject buffer = (*env)->GetObjectArrayElement(env, buffers, i);
+ isDirectBuffer = (*env)->IsInstanceOf(env, buffer, byteBufferClass);
+ if (isDirectBuffer) {
+ buf =
+ (U_8 *)(jbyte *)(IDATA) (*env)->GetDirectBufferAddress(env, buffer);
+ if (buf == NULL) {
+ throwNewOutOfMemoryError(env, "Failed to get direct buffer address");
+ goto free_resources;
+ }
+ toRelease = NULL;
+ } else {
+ buf =
+ (U_8 *)(jbyte *)(IDATA) (*env)->GetByteArrayElements(env, buffer, NULL);
+ if (buf == NULL) {
+ throwNewOutOfMemoryError(env, "");
+ goto free_resources;
+ }
+ toRelease = buffer;
+ }
+
+ bytesWritten =
+ hyfile_write ((IDATA) fd,
+ (void *) (buf + noffset[i]), (IDATA) lengths[i]);
+ if (toRelease != NULL) {
+ (*env)->ReleaseByteArrayElements(env, toRelease, buf, JNI_ABORT);
+ }
+
if(bytesWritten == -1 && hyerror_last_error_number() == HYPORT_ERROR_FILE_LOCKED){
throwNewExceptionByName(env, "java/io/IOException", netLookupErrorString(env, HYPORT_ERROR_FILE_LOCKED));
break;
@@ -195,17 +239,19 @@ JNIEXPORT jlong JNICALL Java_org_apache_
break;
}
totalWritten += bytesWritten;
- i++;
+
}
- if(bufsCopied){
- (*env)->ReleaseLongArrayElements(env, jbuffers, bufs, JNI_ABORT);
- }
- if(offsetsCopied){
- (*env)->ReleaseIntArrayElements(env, joffsets, offsets, JNI_ABORT);
+
+ free_resources:
+
+ if (noffset != NULL) {
+ (*env)->ReleaseIntArrayElements(env, offset, noffset, JNI_ABORT);
}
- if(lengthsCopied){
- (*env)->ReleaseIntArrayElements(env, jlengths, lengths, JNI_ABORT);
+
+ if (lengths != NULL) {
+ (*env)->ReleaseIntArrayElements(env, counts, lengths, JNI_ABORT);
}
+
return totalWritten;
}
Modified: harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/native/luni/windows/OSMemoryWin32.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/native/luni/windows/OSMemoryWin32.c?rev=937048&r1=937047&r2=937048&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/native/luni/windows/OSMemoryWin32.c (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/native/luni/windows/OSMemoryWin32.c Thu Apr 22 20:31:29 2010
@@ -80,7 +80,6 @@ JNIEXPORT jint JNICALL Java_org_apache_h
VirtualUnlock((void *)addr, (SIZE_T)size);
return 0;
}else{
- printf("lock error: %d\n", GetLastError());
return -1;
}
}
Modified: harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/native/luni/windows/OSNetworkSystemWin32.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/native/luni/windows/OSNetworkSystemWin32.c?rev=937048&r1=937047&r2=937048&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/native/luni/windows/OSNetworkSystemWin32.c (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/native/luni/windows/OSNetworkSystemWin32.c Thu Apr 22 20:31:29 2010
@@ -435,17 +435,17 @@ pollSelectRead (JNIEnv * env, jobject fi
return result;
}
-JNIEXPORT jint JNICALL
+JNIEXPORT jlong JNICALL
Java_org_apache_harmony_luni_platform_OSNetworkSystem_writev
(JNIEnv *env, jobject thiz, jobject fd, jobjectArray buffers, jintArray offsets, jintArray counts, jint length) {
PORT_ACCESS_FROM_ENV(env);
jobject buffer;
- jobject* toBeReleasedBuffers = NULL;
+ jobject* toBeReleasedBuffers;
jint *noffset = NULL;
jboolean isDirectBuffer = JNI_FALSE;
- jint result = 0;
+ jlong result = 0;
LPWSABUF vect;
int i;
jint sentBytes;
Modified: harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/URLConnectionTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/URLConnectionTest.java?rev=937048&r1=937047&r2=937048&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/URLConnectionTest.java (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/URLConnectionTest.java Thu Apr 22 20:31:29 2010
@@ -1100,6 +1100,10 @@ public class URLConnectionTest extends j
assertEquals(expected[i], URLConnection
.guessContentTypeFromStream(is));
}
+
+ ByteArrayInputStream bais = new ByteArrayInputStream(new byte[0]);
+ assertNull(URLConnection.guessContentTypeFromStream(bais));
+ bais.close();
}
/**
Modified: harmony/enhanced/java/branches/mrh/classlib/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/FileChannelImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/FileChannelImpl.java?rev=937048&r1=937047&r2=937048&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/FileChannelImpl.java (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/FileChannelImpl.java Thu Apr 22 20:31:29 2010
@@ -564,38 +564,43 @@ public abstract class FileChannelImpl ex
return bytesWritten;
}
- public long write(ByteBuffer[] buffers, int offset, int length)
+ public long write(ByteBuffer[] sources, int offset, int length)
throws IOException {
- if (offset < 0 || length < 0 || (offset + length) > buffers.length) {
+ if (offset < 0 || length < 0 || (offset + length) > sources.length) {
throw new IndexOutOfBoundsException();
}
openCheck();
- int count = 0;
+ long count = 0;
for (int i = offset; i < offset + length; i++) {
- count += buffers[i].remaining();
+ count += sources[i].remaining();
}
if (0 == count) {
return 0;
}
- long[] handles = new long[length];
+ Object[] src = new Object[length];
int[] offsets = new int[length];
int[] lengths = new int[length];
- ByteBuffer[] bufferRefs = new ByteBuffer[length];
for (int i = 0; i < length; i++) {
- ByteBuffer buffer = buffers[i + offset];
+ ByteBuffer buffer = sources[i + offset];
if (!buffer.isDirect()) {
- ByteBuffer directBuffer = ByteBuffer.allocateDirect(buffer
- .remaining());
- directBuffer.put(buffer);
- directBuffer.flip();
- buffer = directBuffer;
- offsets[i] = 0;
+ if (buffer.hasArray()) {
+ src[i] = buffer.array();
+ offsets[i] = buffer.position();
+ } else {
+ ByteBuffer directBuffer = ByteBuffer.allocateDirect(buffer
+ .remaining());
+ int oldPosition = buffer.position();
+ directBuffer.put(buffer);
+ buffer.position(oldPosition);
+ directBuffer.flip();
+ src[i] = directBuffer;
+ offsets[i] = 0;
+ }
} else {
+ src[i] = buffer;
offsets[i] = buffer.position();
}
- handles[i] = ((DirectBuffer) buffer).getEffectiveAddress().toLong();
lengths[i] = buffer.remaining();
- bufferRefs[i] = buffer;
}
long bytesWritten = 0;
@@ -603,7 +608,7 @@ public abstract class FileChannelImpl ex
synchronized (repositioningLock) {
try {
begin();
- bytesWritten = fileSystem.writev(handle, handles, offsets,
+ bytesWritten = fileSystem.writev(handle, src, offsets,
lengths, length);
completed = true;
} finally {
@@ -613,13 +618,13 @@ public abstract class FileChannelImpl ex
long bytesRemaining = bytesWritten;
for (int i = offset; i < length + offset; i++) {
- if (bytesRemaining > buffers[i].remaining()) {
- int pos = buffers[i].limit();
- buffers[i].position(pos);
- bytesRemaining -= buffers[i].remaining();
+ if (bytesRemaining > sources[i].remaining()) {
+ int pos = sources[i].limit();
+ sources[i].position(pos);
+ bytesRemaining -= sources[i].remaining();
} else {
- int pos = buffers[i].position() + (int) bytesRemaining;
- buffers[i].position(pos);
+ int pos = sources[i].position() + (int) bytesRemaining;
+ sources[i].position(pos);
break;
}
}
Modified: harmony/enhanced/java/branches/mrh/classlib/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/SocketChannelImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/SocketChannelImpl.java?rev=937048&r1=937047&r2=937048&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/SocketChannelImpl.java (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/SocketChannelImpl.java Thu Apr 22 20:31:29 2010
@@ -491,63 +491,67 @@ class SocketChannelImpl extends SocketCh
}
checkOpenConnected();
+ long count = 0;
+ for (int i = offset; i < offset + length; i++) {
+ count += sources[i].remaining();
+ }
+ if (0 == count) {
+ return 0;
+ }
Object[] src = new Object[length];
int[] offsets = new int[length];
- int[] counts = new int[length];
- for (int i = 0; i < length; ++i) {
+ int[] lengths = new int[length];
+ for (int i = 0; i < length; i++) {
ByteBuffer buffer = sources[i + offset];
if (!buffer.isDirect()) {
if (buffer.hasArray()) {
src[i] = buffer.array();
- counts[i] = buffer.remaining();
offsets[i] = buffer.position();
} else {
- ByteBuffer db = ByteBuffer.allocateDirect(buffer.remaining());
+ ByteBuffer directBuffer = ByteBuffer.allocateDirect(buffer.remaining());
int oldPosition = buffer.position();
- db.put(buffer);
+ directBuffer.put(buffer);
buffer.position(oldPosition);
- db.flip();
- src[i] = db;
- counts[i] = buffer.remaining();
+ directBuffer.flip();
+ src[i] = directBuffer;
offsets[i] = 0;
}
} else {
src[i] = buffer;
- counts[i] = buffer.remaining();
offsets[i] = buffer.position();
}
+ lengths[i] = buffer.remaining();
}
- if (length == 0) {
- return 0;
- }
-
- int result = writevImpl(src, offsets, counts);
- int val = offset;
- int written = result;
- while (result > 0) {
- ByteBuffer source = sources[val];
- int gap = Math.min(result, source.remaining());
- source.position(source.position() + gap);
- val++;
- result -= gap;
+ long bytesWritten = writevImpl(src, offsets, lengths);
+ long bytesRemaining = bytesWritten;
+ for (int i = offset; i < length + offset; i++) {
+ if (bytesRemaining > sources[i].remaining()) {
+ int pos = sources[i].limit();
+ sources[i].position(pos);
+ bytesRemaining -= sources[i].remaining();
+ } else {
+ int pos = sources[i].position() + (int) bytesRemaining;
+ sources[i].position(pos);
+ break;
+ }
}
- return written;
+ return bytesWritten;
}
/*
* Write the source. return the count of bytes written.
*/
- private int writevImpl(Object[] sources, int[] offsets, int[] counts) throws IOException {
- int writeCount = 0;
+ private long writevImpl(Object[] sources, int[] offsets, int[] lengths) throws IOException {
+ long writeCount = 0;
try {
if (isBlocking()) {
begin();
}
synchronized (writeLock) {
- writeCount = networkSystem.writev(fd, sources, offsets, counts, sources.length);
+ writeCount = networkSystem.writev(fd, sources, offsets, lengths, sources.length);
}
} catch (SocketException e) {
if (e.getCause() instanceof ErrorCodeException) {
Modified: harmony/enhanced/java/branches/mrh/classlib/modules/swing/build.xml
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/swing/build.xml?rev=937048&r1=937047&r2=937048&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/swing/build.xml (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/swing/build.xml Thu Apr 22 20:31:29 2010
@@ -116,7 +116,7 @@
<copy file="make/run-test.xml" tofile="${tests.hdk.dir}/build.xml" />
<hy.jar.bin destfile="${tests.hdk.dir}/swing_tests.jar">
- <fileset dir="bin/test" />
+ <fileset dir="bin/test/injected" />
</hy.jar.bin>
<mkdir dir="${tests.excludes.hdk.dir}"/>
@@ -135,7 +135,8 @@
</target>
<target name="compile-tests">
- <compile-tests description="swing tests">
+ <compile-tests description="swing tests"
+ destdir="bin/test/injected">
<javac-elements>
<src>
<pathelement location="src/test/api/java.injected" />
Propchange: harmony/enhanced/java/branches/mrh/common_resources/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Apr 22 20:31:29 2010
@@ -1,3 +1,3 @@
-/harmony/enhanced/java/trunk/common_resources:935751-936090
+/harmony/enhanced/java/trunk/common_resources:935751-936843
/harmony/enhanced/trunk/common_resources:476396-920147
/incubator/harmony/enhanced/trunk/common_resources:423974-476394
Propchange: harmony/enhanced/java/branches/mrh/drlvm/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Apr 22 20:31:29 2010
@@ -1,3 +1,3 @@
-/harmony/enhanced/java/trunk/drlvm:935751-936090
+/harmony/enhanced/java/trunk/drlvm:935751-936843
/harmony/enhanced/trunk/working_vm:476396-920147
/incubator/harmony/enhanced/trunk/working_vm:423974-476394
Modified: harmony/enhanced/java/branches/mrh/jdktools/modules/jdktools/src/main/java/org/apache/harmony/tools/serialver/Clazz.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/jdktools/modules/jdktools/src/main/java/org/apache/harmony/tools/serialver/Clazz.java?rev=937048&r1=937047&r2=937048&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/jdktools/modules/jdktools/src/main/java/org/apache/harmony/tools/serialver/Clazz.java (original)
+++ harmony/enhanced/java/branches/mrh/jdktools/modules/jdktools/src/main/java/org/apache/harmony/tools/serialver/Clazz.java Thu Apr 22 20:31:29 2010
@@ -30,308 +30,308 @@ import org.apache.harmony.tools.ClassPro
/**
* This class is a wrapper of BCEL's Class class.
- *
+ *
* This class depends on Apache Byte Code Engineering Library (BCEL) 5.0 or
* later. Please see http://jakarta.apache.org/bcel for more information about
* this library.
*/
public class Clazz {
- /**
- * A wrapped class.
- */
- private JavaClass wrappedClass;
-
- /**
- * Class fields that will be used to calculate the serialversionUID. All
- * fields except private static and private transient. (SORTED)
- */
- private Vector<Field> fields;
-
- /**
- * Class constructors that will be used to calculate the serialversionUID.
- * Default constructor (if exists) and all non-private constructors.
- * (SORTED)
- */
- private Vector<Method> constructors;
-
- /**
- * Class methods that will be used to calculate the serialversionUID. All
- * non-private methods. (SORTED)
- */
- private Vector<Method> methods;
-
- /**
- * Field that represents existance SUID (if-exists).
- */
- private Field suidField;
-
- /**
- * Constructs a <code>Clazz</code> object.
- *
- * @param classProvider
- * - a helper that provides the class information.
- * @param className
- * - a fully qualified name of a class.
- * @throws ClassNotFoundException
- * - if a give class is not found
- */
- public Clazz(ClassProvider classProvider, String className)
- throws ClassNotFoundException {
- try {
- wrappedClass = classProvider.getJavaClass(className);
-
- // Collect up all valid fields (non transient and private, and non
- // static private) and sort it.
- fields = sortFields(collectValidFields(wrappedClass));
-
- // Collect all valid constructors (non-private) and sort it.
- constructors = sortConstructors(collectConstructors(wrappedClass));
-
- // Collect all valid methods (non-private) and sort it.
- methods = sortMethods(collectMethods(wrappedClass));
- } catch (ClassNotFoundException e) {
- throw new ClassNotFoundException();
- }
- }
-
- /**
- * Returns a name of a wrapped class.
- *
- * @return a class name.
- */
- public String getName() {
- return wrappedClass.getClassName();
- }
-
- /**
- * Returns the {@link Modifiers} of the wrapped class.
- *
- * @return a constant int
- */
- public int getModifiers() {
- return wrappedClass.getModifiers();
- }
-
- /**
- * Get all interfaces names that the wrapped class implement and sort it.
- *
- * @return interfaces names implemented (sorted).
- */
- public String[] getSortedInterfaces() {
- String[] ifNames = wrappedClass.getInterfaceNames();
- Arrays.sort(ifNames);
- return ifNames;
- }
-
- /**
- * Get all valid Fields (i.e., all excluding private static and private
- * transient) of the wrapped class and sort it.
- *
- * @return a Field Vector (Sorted).
- */
- public Vector<Field> getSortedValidFields() {
- return fields;
- }
-
- /**
- * Get all valid Constructors (i.e., non-private) of the wrapped class and
- * sort it.
- *
- * @return a Method Vector (Sorted).
- */
- public Vector<Method> getSortedValidConstructors() {
- return constructors;
- }
-
- /**
- * Get all valid Methods (i.e., non-private) of the wrapped class and sort
- * it.
- *
- * @return a Method Vector (Sorted).
- */
- public Vector<Method> getSortedValidMethods() {
- return methods;
- }
-
- /**
- * Get the existing serialVersionUID of the wrapped class.
- *
- * @return a long that is the serialVersionUID of the wrapped class.
- * @throws NoSuchFieldException
- * if the field doesn't exist.
- */
- public long getExistantSerialVersionUID() throws NoSuchFieldException {
- return Long.parseLong(suidField.getAttributes()[0].toString());
- }
-
- /**
- * Verify if the wrapped class is serializable.
- *
- * @return true - if it's serializable<br />
- * false otherwise.
- * @throws ClassNotFoundException
- * if the wrappedclass isn't found.
- */
- public boolean isSerializable() throws ClassNotFoundException {
- boolean serial = false;
- for (JavaClass clazzInterface : wrappedClass.getAllInterfaces()) {
- if (clazzInterface.getClassName().equals("java.io.Serializable"))
- serial = true;
- }
- return serial;
- }
-
- /**
- * Verify if a give class has a serialVersionUID Field.
- *
- * @return true - if it has this field<br />
- * false otherwise.
- */
- public boolean hasSerialVersionUID() {
- return suidField != null;
- }
-
- /**
- * Collect valid fields of the wrapped class. Valid fields includes all
- * except private static and private transient.
- *
- * @param clazz
- * - the wrapped class.
- * @return a {@link Vector} of valid fields.
- */
- private Vector<Field> collectValidFields(JavaClass clazz) {
- Field[] allFields = clazz.getFields();
- Vector<Field> validFields = new Vector<Field>();
- suidField = null;
-
- int PRIVATE_STATIC = Modifier.PRIVATE | Modifier.STATIC;
- int PRIVATE_TRANSIENT = Modifier.PRIVATE | Modifier.TRANSIENT;
-
- // Excluding all PRIVATE_STATIC and PRIVATE_TRANSIENT fields
- for (int i = 0; i < allFields.length; i++) {
- if ((allFields[i].getModifiers() != PRIVATE_STATIC)
- && (allFields[i].getModifiers() != PRIVATE_TRANSIENT)) {
- // Adding
- validFields.add(allFields[i]);
-
- // Let's check if the Field is a existing SUID
- if (allFields[i].getName().equals("serialVersionUID")) {
- suidField = allFields[i];
- }
- }
- }
- return validFields;
- }
-
- /**
- * Collect valid constructors of the wrapped class. Valid constructors
- * includes all except private.
- *
- * @param clazz
- * - the wrapped class.
- * @return a {@link Vector} of valid constructors.
- */
- private Vector<Method> collectConstructors(JavaClass clazz) {
- Method methods[] = clazz.getMethods();
- Vector<Method> validConstructors = new Vector<Method>();
-
- // Excludes all constructors that are private
- for (int i = 0; i < methods.length; i++) {
- Method m = methods[i];
- String mName = m.getName();
-
- if (mName.equals("<clinit>") || mName.equals("<init>"))
- if (!m.isPrivate())
- validConstructors.add(m);
- }
-
- return validConstructors;
- }
-
- /**
- * Collect valid methods of the wrapped class. Valid methods includes all
- * except private.
- *
- * @param clazz
- * - the wrapped class.
- * @return a {@link Vector} of valid methods.
- */
- private Vector<Method> collectMethods(JavaClass clazz) {
- Method methods[] = clazz.getMethods();
- Vector<Method> validMethods = new Vector<Method>();
-
- // Excludes all methods that are private
- for (int i = 0; i < methods.length; i++) {
- Method m = methods[i];
- String mName = m.getName();
-
- // is not a constructor
- if (!mName.equals("<clinit>") && !mName.equals("<init>")) {
- if (!m.isPrivate()) {
- validMethods.add(m);
- }
- }
- }
-
- return validMethods;
- }
-
- /**
- * Sort the valid fields of the wrapped class.
- *
- * @param vector
- * - to be sorted.
- * @return a Field Vector sorted.
- */
- private Vector<Field> sortFields(Vector<Field> vector) {
- Collections.sort(vector, new Comparator<Field>() {
- public int compare(Field f1, Field f2) {
- return f1.getName().compareTo(f2.getName());
- }
- });
- return vector;
- }
-
- /**
- * Sort the valid constructors of the wrapped class.
- *
- * @param vector
- * - to be sorted.
- * @return a Method Vector sorted.
- */
- private Vector<Method> sortConstructors(Vector<Method> vector) {
- Collections.sort(vector, new Comparator<Method>() {
- public int compare(Method m1, Method m2) {
- if (m1.getName() == "<clinit>")
- return 1;
-
- return m1.getSignature().compareTo(m2.getSignature());
- }
- });
-
- return vector;
- }
-
- /**
- * Sort the valid methods of the wrapped class.
- *
- * @param vector
- * - to be sorted.
- * @return a Method Vector sorted.
- */
- private Vector<Method> sortMethods(Vector<Method> vector) {
- Collections.sort(vector, new Comparator<Method>() {
- public int compare(Method m1, Method m2) {
- int name = m1.getName().compareTo(m2.getName());
- if (name != 0) {
- return name;
- } else {
- return m1.getSignature().compareTo(m2.getSignature());
- }
- }
- });
+ /**
+ * A wrapped class.
+ */
+ private JavaClass wrappedClass;
+
+ /**
+ * Class fields that will be used to calculate the serialversionUID. All
+ * fields except private static and private transient. (SORTED)
+ */
+ private Vector<Field> fields;
+
+ /**
+ * Class constructors that will be used to calculate the serialversionUID.
+ * Default constructor (if exists) and all non-private constructors.
+ * (SORTED)
+ */
+ private Vector<Method> constructors;
+
+ /**
+ * Class methods that will be used to calculate the serialversionUID. All
+ * non-private methods. (SORTED)
+ */
+ private Vector<Method> methods;
+
+ /**
+ * Field that represents existance SUID (if-exists).
+ */
+ private Field suidField;
+
+ /**
+ * Constructs a <code>Clazz</code> object.
+ *
+ * @param classProvider
+ * - a helper that provides the class information from a classpath.
+ * @param className
+ * - a fully qualified name of a class.
+ * @throws ClassNotFoundException
+ * - if a give class is not found
+ */
+ public Clazz(ClassProvider classProvider, String className)
+ throws ClassNotFoundException {
+ try {
+ wrappedClass = classProvider.getJavaClass(className);
+
+ // Collect up all valid fields (non transient and private, and non
+ // static private) and sort it.
+ fields = sortFields(collectValidFields(wrappedClass));
+
+ // Collect all valid constructors (non-private) and sort it.
+ constructors = sortConstructors(collectConstructors(wrappedClass));
+
+ // Collect all valid methods (non-private) and sort it.
+ methods = sortMethods(collectMethods(wrappedClass));
+ } catch (ClassNotFoundException e) {
+ throw new ClassNotFoundException();
+ }
+ }
+
+ /**
+ * Returns a name of a wrapped class.
+ *
+ * @return a class name.
+ */
+ public String getName() {
+ return wrappedClass.getClassName();
+ }
+
+ /**
+ * Returns the {@link Modifiers} of the wrapped class.
+ *
+ * @return a constant int
+ */
+ public int getModifiers() {
+ return wrappedClass.getModifiers();
+ }
+
+ /**
+ * Get all interfaces names that the wrapped class implement and sort it.
+ *
+ * @return interfaces names implemented (sorted).
+ */
+ public String[] getSortedInterfaces() {
+ String[] ifNames = wrappedClass.getInterfaceNames();
+ Arrays.sort(ifNames);
+ return ifNames;
+ }
+
+ /**
+ * Get all valid Fields (i.e., all excluding private static and private
+ * transient) of the wrapped class and sort it.
+ *
+ * @return a Field Vector (Sorted).
+ */
+ public Vector<Field> getSortedValidFields() {
+ return fields;
+ }
+
+ /**
+ * Get all valid Constructors (i.e., non-private) of the wrapped class and
+ * sort it.
+ *
+ * @return a Method Vector (Sorted).
+ */
+ public Vector<Method> getSortedValidConstructors() {
+ return constructors;
+ }
+
+ /**
+ * Get all valid Methods (i.e., non-private) of the wrapped class and sort
+ * it.
+ *
+ * @return a Method Vector (Sorted).
+ */
+ public Vector<Method> getSortedValidMethods() {
+ return methods;
+ }
+
+ /**
+ * Get the existing serialVersionUID of the wrapped class.
+ *
+ * @return a long that is the serialVersionUID of the wrapped class.
+ * @throws NoSuchFieldException
+ * if the field doesn't exist.
+ */
+ public long getExistantSerialVersionUID() throws NoSuchFieldException {
+ return Long.parseLong(suidField.getAttributes()[0].toString());
+ }
+
+ /**
+ * Verify if the wrapped class is serializable.
+ *
+ * @return true - if it's serializable<br />
+ * false otherwise.
+ * @throws ClassNotFoundException
+ * if the wrappedclass isn't found.
+ */
+ public boolean isSerializable() throws ClassNotFoundException {
+ boolean serial = false;
+ for (JavaClass clazzInterface : wrappedClass.getAllInterfaces()) {
+ if (clazzInterface.getClassName().equals("java.io.Serializable"))
+ serial = true;
+ }
+ return serial;
+ }
+
+ /**
+ * Verify if a give class has a serialVersionUID Field.
+ *
+ * @return true - if it has this field<br />
+ * false otherwise.
+ */
+ public boolean hasSerialVersionUID() {
+ return suidField != null;
+ }
+
+ /**
+ * Collect valid fields of the wrapped class. Valid fields includes all
+ * except private static and private transient.
+ *
+ * @param clazz
+ * - the wrapped class.
+ * @return a {@link Vector} of valid fields.
+ */
+ private Vector<Field> collectValidFields(JavaClass clazz) {
+ Field[] allFields = clazz.getFields();
+ Vector<Field> validFields = new Vector<Field>();
+ suidField = null;
+
+ int PRIVATE_STATIC = Modifier.PRIVATE | Modifier.STATIC;
+ int PRIVATE_TRANSIENT = Modifier.PRIVATE | Modifier.TRANSIENT;
+
+ // Excluding all PRIVATE_STATIC and PRIVATE_TRANSIENT fields
+ for (int i = 0; i < allFields.length; i++) {
+ if ((allFields[i].getModifiers() != PRIVATE_STATIC)
+ && (allFields[i].getModifiers() != PRIVATE_TRANSIENT)) {
+ // Adding
+ validFields.add(allFields[i]);
+
+ // Let's check if the Field is a existing SUID
+ if (allFields[i].getName().equals("serialVersionUID")) {
+ suidField = allFields[i];
+ }
+ }
+ }
+ return validFields;
+ }
+
+ /**
+ * Collect valid constructors of the wrapped class. Valid constructors
+ * includes all except private.
+ *
+ * @param clazz
+ * - the wrapped class.
+ * @return a {@link Vector} of valid constructors.
+ */
+ private Vector<Method> collectConstructors(JavaClass clazz) {
+ Method methods[] = clazz.getMethods();
+ Vector<Method> validConstructors = new Vector<Method>();
+
+ // Excludes all constructors that are private
+ for (int i = 0; i < methods.length; i++) {
+ Method m = methods[i];
+ String mName = m.getName();
+
+ if (mName.equals("<clinit>") || mName.equals("<init>"))
+ if (!m.isPrivate())
+ validConstructors.add(m);
+ }
+
+ return validConstructors;
+ }
+
+ /**
+ * Collect valid methods of the wrapped class. Valid methods includes all
+ * except private.
+ *
+ * @param clazz
+ * - the wrapped class.
+ * @return a {@link Vector} of valid methods.
+ */
+ private Vector<Method> collectMethods(JavaClass clazz) {
+ Method methods[] = clazz.getMethods();
+ Vector<Method> validMethods = new Vector<Method>();
+
+ // Excludes all methods that are private
+ for (int i = 0; i < methods.length; i++) {
+ Method m = methods[i];
+ String mName = m.getName();
+
+ // is not a constructor
+ if (!mName.equals("<clinit>") && !mName.equals("<init>")) {
+ if (!m.isPrivate()) {
+ validMethods.add(m);
+ }
+ }
+ }
+
+ return validMethods;
+ }
+
+ /**
+ * Sort the valid fields of the wrapped class.
+ *
+ * @param vector
+ * - to be sorted.
+ * @return a Field Vector sorted.
+ */
+ private Vector<Field> sortFields(Vector<Field> vector) {
+ Collections.sort(vector, new Comparator<Field>() {
+ public int compare(Field f1, Field f2) {
+ return f1.getName().compareTo(f2.getName());
+ }
+ });
+ return vector;
+ }
+
+ /**
+ * Sort the valid constructors of the wrapped class.
+ *
+ * @param vector
+ * - to be sorted.
+ * @return a Method Vector sorted.
+ */
+ private Vector<Method> sortConstructors(Vector<Method> vector) {
+ Collections.sort(vector, new Comparator<Method>() {
+ public int compare(Method m1, Method m2) {
+ if (m1.getName() == "<clinit>")
+ return 1;
+
+ return m1.getSignature().compareTo(m2.getSignature());
+ }
+ });
+
+ return vector;
+ }
+
+ /**
+ * Sort the valid methods of the wrapped class.
+ *
+ * @param vector
+ * - to be sorted.
+ * @return a Method Vector sorted.
+ */
+ private Vector<Method> sortMethods(Vector<Method> vector) {
+ Collections.sort(vector, new Comparator<Method>() {
+ public int compare(Method m1, Method m2) {
+ int name = m1.getName().compareTo(m2.getName());
+ if (name != 0) {
+ return name;
+ } else {
+ return m1.getSignature().compareTo(m2.getSignature());
+ }
+ }
+ });
- return vector;
- }
+ return vector;
+ }
}
Modified: harmony/enhanced/java/branches/mrh/jdktools/modules/jdktools/src/main/java/org/apache/harmony/tools/serialver/Main.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/jdktools/modules/jdktools/src/main/java/org/apache/harmony/tools/serialver/Main.java?rev=937048&r1=937047&r2=937048&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/jdktools/modules/jdktools/src/main/java/org/apache/harmony/tools/serialver/Main.java (original)
+++ harmony/enhanced/java/branches/mrh/jdktools/modules/jdktools/src/main/java/org/apache/harmony/tools/serialver/Main.java Thu Apr 22 20:31:29 2010
@@ -19,13 +19,18 @@ package org.apache.harmony.tools.serialv
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
+
import java.lang.reflect.Modifier;
+
import java.security.MessageDigest;
+
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Vector;
+import javax.swing.JFrame;
+
import org.apache.bcel.classfile.Field;
import org.apache.bcel.classfile.Method;
import org.apache.harmony.tools.ClassProvider;
@@ -35,274 +40,306 @@ import org.apache.harmony.tools.ClassPro
*/
public class Main {
- public static void main(String args[]) {
- if (args.length < 1) {
- usage();
- System.exit(1);
- }
-
- String pathSep = null;
- try {
- pathSep = System.getProperty("path.separator");
- } catch (SecurityException e) {
- // ignore
- }
-
- Vector<String> names = new Vector<String>();
- Map options = new HashMap();
- int i = 0;
- while (i < args.length) {
- if (args[i].equals("-classpath")) {
- try {
- String path = (String) args[i + 1];
-
- // We can concatenate several options, if there is no
- // security restriction; otherwise, the new option replaces
- // the old one.
- if (pathSep != null) {
- String prevPath = (String) options.get(args[i]);
- if (prevPath != null) {
- path = prevPath + pathSep + path;
- }
- }
-
- options.put(args[i], path);
- i++;
- } catch (ArrayIndexOutOfBoundsException ex) {
- System.out
- .println("Missing argument for -classpath option");
- usage();
- System.exit(1);
- }
- } else if (args[i].equals("-show")) {
- options.put(args[i], Boolean.valueOf(true));
- } else if (args[i].charAt(0) == '-') {
- // invalid flag (only allowed -show and -classpath
- System.out.println("Invalid flag " + args[i]);
- usage();
- System.exit(1);
- } else {
- names.add(args[i]);
- }
- i++;
- }
- System.exit(run(options, names));
- }
-
- /**
- * Runs a tool.
- *
- * @param options
- * - a <code>java.util.Map</code> of the following key-value
- * pairs.
- *
- * <li><i>key</i> - "-classpath" <li><i>value</i> - a
- * <code>java.lang.String</code> which is a path where classes
- * are located.
- *
- * <li><i>key</i> - "-show" <li><i>value</i> - display a simple
- * GUI with a textfield, where the user can enter the name of the
- * class he wants to generate the serialversionUID.
- *
- * @param classNames
- * - a vector of the fully qualified class names.
- * @return <code>0</code> if there is no error; <code>1</code> otherwise.
- */
- public static int run(Map options, Vector<String> classNames) {
- int returnValue = 0;
-
- String classpath = getString(options, "-classpath");
- boolean show = getBoolean(options, "-show"); // TODO make show GUI
- Iterator namesIter = classNames.iterator();
-
- // The user can't type -show and put classnames - SUN Spec
- if ((namesIter.hasNext() == true) && (show == true)) {
- System.out.println("Cannot specify class arguments with the -show option");
- return 1;
- }
-
- ClassProvider classProvider = new ClassProvider(null, classpath, false);
- while (namesIter.hasNext()) {
- String className = (String) namesIter.next();
- try {
- // Parse the next class.
- Clazz clazz = new Clazz(classProvider, className);
-
- // Let's check if the class has any 'annoiance'
- if (!isSerializable(clazz)) {
- System.out.println("Class " + clazz.getName() + " is not Serializable.");
- continue;
- }
-
- long hash = calculeSUID(clazz);
- printResult(clazz, hash);
- } catch (Exception e) {
- System.out.println("Class " + className + " not found.");
- returnValue = 1;
- }
- }
- return returnValue;
- }
-
- /**
- * Calculates the serialversionUID for a given {@link Clazz}.
- *
- * @param clazz
- * - wrapped class
- * @return the serialversionUID
- * @throws ClassNotFoundException
- * if a class is not found
- */
- public static long calculeSUID(Clazz clazz) throws ClassNotFoundException {
- try {
- // Let's check if class has already a suid, if yes, we don't need to calculate
- if (clazz.hasSerialVersionUID()) {
- return clazz.getExistantSerialVersionUID();
- }
-
- // Let's compute the serialversionUID
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- DataOutputStream daos = new DataOutputStream(baos);
-
- // Class name
- daos.writeUTF(clazz.getName());
-
- // Class Modifier
- int classMask = Modifier.PUBLIC | Modifier.FINAL
- | Modifier.INTERFACE | Modifier.ABSTRACT;
- daos.writeInt(clazz.getModifiers() & classMask);
-
- // Write all interfaces name (Sorted)
- for (String clazzInterface : clazz.getSortedInterfaces()) {
- daos.writeUTF(clazzInterface);
- }
-
- // We need to write the field/constructor/method information in
- // the following order:
- // 1 - Name
- // 2 - Modifier
- // 3 - Signature
-
- // Only valid fields, i.e. , all fields except
- // static private and transient private
- int fieldMask = Modifier.PUBLIC | Modifier.PRIVATE
- | Modifier.PROTECTED | Modifier.STATIC | Modifier.FINAL
- | Modifier.VOLATILE | Modifier.TRANSIENT;
-
- for (Field field : clazz.getSortedValidFields()) {
- daos.writeUTF(field.getName());
- daos.writeInt(field.getModifiers() & fieldMask);
- daos.writeUTF(field.getSignature());
- }
-
- // Only valid Constructors, i.e., all non-private
- // The first constructor must be the default ()V [if-exists]
- // The method already takes cares of this
- int methodMask = Modifier.PUBLIC | Modifier.PRIVATE
- | Modifier.PROTECTED | Modifier.STATIC | Modifier.FINAL
- | Modifier.SYNCHRONIZED | Modifier.NATIVE
- | Modifier.ABSTRACT | Modifier.STRICT;
-
- for (Method constructor : clazz.getSortedValidConstructors()) {
- daos.writeUTF(constructor.getName());
- daos.writeInt(constructor.getModifiers() & methodMask);
- daos.writeUTF(constructor.getSignature());
- }
-
- // Only valid Methods, i.e., all non-private
- for (Method methods : clazz.getSortedValidMethods()) {
- daos.writeUTF(methods.getName());
- daos.writeInt(methods.getModifiers() & methodMask);
- daos.writeUTF(methods.getSignature().replace('/', '.'));
- }
-
- // Hash is calculated the following way:
- // Get the 8 [0 ... 7] bytes and invert their order, i.e,
- // Suppose bytes are 00110011 ... 11110000, the final order
- // would be:
- // Result: 11110000 ... 00110011
- MessageDigest md = MessageDigest.getInstance("SHA");
- byte[] sha = md.digest(baos.toByteArray());
- long hash = 0;
-
- for (int i = 7; i >= 0; i--) {
- hash = (hash << 8) | (sha[i] & 0xFF);
- }
-
- return hash;
- } catch (Exception e) {
- throw new ClassNotFoundException();
- }
- }
-
- /**
- * Verify if the wrapped class is serializable.
- *
- * @return true - if it's serializable<br />
- * false otherwise.
- * @throws ClassNotFoundException
- * if the wrappedclass isn't found.
- */
- public static boolean isSerializable(Clazz wrappedclazz) throws ClassNotFoundException {
- return wrappedclazz.isSerializable();
- }
-
- /**
- * Prints the usage information.
- */
- public static void usage() {
- System.out.println("Use: serialver [-classpath classpath] [-show] [classname...]");
- }
-
- /**
- * Prints the serialversionUID of a given class.
- *
- * @param clazz
- * the class
- * @param suid
- * the value to be printed
- */
- public static void printResult(Clazz clazz, long suid) {
- System.out.println(clazz.getName() + "\t" + "static final long serialVersionUID = " + suid + "L");
- }
-
- /**
- * Get the options from the Map, string options (-classpath <i>path</i>).
- *
- * @param options
- * map.
- * @param name
- * option.
- * @return value of the option.
- */
- private static String getString(Map options, String name) {
- try {
- return (String) options.get(name);
- } catch (ClassCastException e) {
- throw new RuntimeException("'" + name + "': expected java.lang.String", e);
- }
- }
-
- /**
- * Get the options from the Map, boolean options (<i>-show</i>).
- *
- * @param options
- * map.
- * @param name
- * option.
- * @return true if option was passed as arg<br />
- * false otherwise.
- */
- private static boolean getBoolean(Map options, String name) {
- try {
- Object value = options.get(name);
- if (value != null) {
- return ((Boolean) value).booleanValue();
- }
- } catch (ClassCastException e) {
- throw new RuntimeException("'" + name + "': expected java.lang.Boolean", e);
- }
- return false;
- }
+ public static void main(String args[]) {
+ if (args.length < 1) {
+ usage();
+ System.exit(1);
+ }
+
+ String pathSep = null;
+ try {
+ pathSep = System.getProperty("path.separator");
+ } catch (SecurityException e) {
+ // ignore
+ }
+
+ Vector<String> names = new Vector<String>();
+ Map options = new HashMap();
+ int i = 0;
+ while (i < args.length) {
+ if (args[i].equals("-classpath")) {
+ try {
+ String path = (String) args[i + 1];
+
+ // We can concatenate several options, if there is no
+ // security restriction; otherwise, the new option replaces
+ // the old one.
+ if (pathSep != null) {
+ String prevPath = (String) options.get(args[i]);
+ if (prevPath != null) {
+ path = prevPath + pathSep + path;
+ }
+ }
+
+ options.put(args[i], path);
+ i++;
+ } catch (ArrayIndexOutOfBoundsException ex) {
+ System.out.println("Missing argument for -classpath option");
+ usage();
+ System.exit(1);
+ }
+ } else if (args[i].equals("-show")) {
+ options.put(args[i], Boolean.valueOf(true));
+ } else if (args[i].charAt(0) == '-') {
+ // invalid flag (only allowed -show and -classpath
+ System.out.println("Invalid flag " + args[i]);
+ usage();
+ System.exit(1);
+ } else {
+ names.add(args[i]);
+ }
+ i++;
+ }
+ int runValue = run(options, names);
+ if (runValue != -1) System.exit(runValue);
+ }
+
+ /**
+ * Runs a tool.
+ *
+ * @param options
+ * - a <code>java.util.Map</code> of the following key-value
+ * pairs.
+ *
+ * <li><i>key</i> - "-classpath" <li><i>value</i> - a
+ * <code>java.lang.String</code> which is a path where classes
+ * are located.
+ *
+ * <li><i>key</i> - "-show" <li><i>value</i> - display a simple
+ * GUI with a textfield, where the user can enter the name of the
+ * class he wants to generate the serialversionUID.
+ *
+ * @param classNames
+ * - a vector of the fully qualified class names.
+ * @return <code>0</code> if there is no error; <code>1</code> if there is
+ * error; <code>-1</code> if the runtime has started a GUI.
+ */
+ public static int run(Map options, Vector<String> classNames) {
+ String classpath = getString(options, "-classpath");
+ boolean show = getBoolean(options, "-show");
+ Iterator namesIter = classNames.iterator();
+
+ // Appending the user specified classpath to clasprovider
+ ClassProvider classProvider = new ClassProvider(null, classpath, false);
+
+ // The user can't type -show and put classnames - SUN Spec
+ if ((namesIter.hasNext() == true) && (show == true)) {
+ System.out.println("Cannot specify class arguments with the -show option");
+ return 1;
+ }
+
+ // If the user typed -show let's pass the ClassProvider which contains the
+ // user classpath to the ShowGui, else let's do the default cli run
+ if (show == true) {
+ ShowGui gui = new ShowGui(classProvider);
+ gui.setSize(600, 120);
+ gui.setVisible(true);
+ gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ return -1;
+ } else {
+ return cliRun(classProvider, namesIter);
+ }
+ }
+
+ /**
+ * Cli run of the serialver tool
+ *
+ * @param classProvider
+ * - a helper that provides the class information from a classpath.
+ * @param namesIter
+ * - the list of names to check the serialversionUID.
+ * @return 0 if everything worked fine<br/>
+ * 1 if it has encountered errors while running
+ */
+ public static int cliRun(ClassProvider classProvider, Iterator namesIter) {
+ int runValue = 0;
+ while (namesIter.hasNext()) {
+ String className = (String) namesIter.next();
+ try {
+ // Parse the next class.
+ Clazz clazz = new Clazz(classProvider, className);
+
+ // Let's check if the class has any 'annoiance'
+ if (!isSerializable(clazz)) {
+ System.out.println("Class " + clazz.getName()
+ + " is not Serializable.");
+ continue;
+ }
+
+ long hash = calculeSUID(clazz);
+ printResult(clazz, hash);
+ } catch (Exception e) {
+ System.out.println("Class " + className + " not found.");
+ runValue = 1;
+ }
+ }
+ return runValue;
+ }
+
+ /**
+ * Calculates the serialversionUID for a given {@link Clazz}.
+ *
+ * @param clazz
+ * - wrapped class
+ * @return the serialversionUID
+ * @throws ClassNotFoundException
+ * if a class is not found
+ */
+ public static long calculeSUID(Clazz clazz) throws ClassNotFoundException {
+ try {
+ // Let's check if class has already a suid, if yes, we don't need to
+ // calculate
+ if (clazz.hasSerialVersionUID()) {
+ return clazz.getExistantSerialVersionUID();
+ }
+
+ // Let's compute the serialversionUID
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ DataOutputStream daos = new DataOutputStream(baos);
+
+ // Class name
+ daos.writeUTF(clazz.getName());
+
+ // Class Modifier
+ int classMask = Modifier.PUBLIC | Modifier.FINAL
+ | Modifier.INTERFACE | Modifier.ABSTRACT;
+ daos.writeInt(clazz.getModifiers() & classMask);
+
+ // Write all interfaces name (Sorted)
+ for (String clazzInterface : clazz.getSortedInterfaces()) {
+ daos.writeUTF(clazzInterface);
+ }
+
+ // We need to write the field/constructor/method information in
+ // the following order:
+ // 1 - Name
+ // 2 - Modifier
+ // 3 - Signature
+
+ // Only valid fields, i.e. , all fields except
+ // static private and transient private
+ int fieldMask = Modifier.PUBLIC | Modifier.PRIVATE
+ | Modifier.PROTECTED | Modifier.STATIC | Modifier.FINAL
+ | Modifier.VOLATILE | Modifier.TRANSIENT;
+
+ for (Field field : clazz.getSortedValidFields()) {
+ daos.writeUTF(field.getName());
+ daos.writeInt(field.getModifiers() & fieldMask);
+ daos.writeUTF(field.getSignature());
+ }
+
+ // Only valid Constructors, i.e., all non-private
+ // The first constructor must be the default ()V [if-exists]
+ // The method already takes cares of this
+ int methodMask = Modifier.PUBLIC | Modifier.PRIVATE
+ | Modifier.PROTECTED | Modifier.STATIC | Modifier.FINAL
+ | Modifier.SYNCHRONIZED | Modifier.NATIVE
+ | Modifier.ABSTRACT | Modifier.STRICT;
+
+ for (Method constructor : clazz.getSortedValidConstructors()) {
+ daos.writeUTF(constructor.getName());
+ daos.writeInt(constructor.getModifiers() & methodMask);
+ daos.writeUTF(constructor.getSignature());
+ }
+
+ // Only valid Methods, i.e., all non-private
+ for (Method methods : clazz.getSortedValidMethods()) {
+ daos.writeUTF(methods.getName());
+ daos.writeInt(methods.getModifiers() & methodMask);
+ daos.writeUTF(methods.getSignature().replace('/', '.'));
+ }
+
+ // Hash is calculated the following way:
+ // Get the 8 [0 ... 7] bytes and invert their order, i.e,
+ // Suppose bytes are 00110011 ... 11110000, the final order
+ // would be:
+ // Result: 11110000 ... 00110011
+ MessageDigest md = MessageDigest.getInstance("SHA");
+ byte[] sha = md.digest(baos.toByteArray());
+ long hash = 0;
+
+ for (int i = 7; i >= 0; i--) {
+ hash = (hash << 8) | (sha[i] & 0xFF);
+ }
+
+ return hash;
+ } catch (Exception e) {
+ throw new ClassNotFoundException();
+ }
+ }
+
+ /**
+ * Verify if the wrapped class is serializable.
+ *
+ * @return true - if it's serializable<br />
+ * false otherwise.
+ * @throws ClassNotFoundException
+ * if the wrappedclass isn't found.
+ */
+ public static boolean isSerializable(Clazz wrappedclazz)
+ throws ClassNotFoundException {
+ return wrappedclazz.isSerializable();
+ }
+
+ /**
+ * Prints the usage information.
+ */
+ public static void usage() {
+ System.out.println("Use: serialver [-classpath classpath] [-show] [classname...]");
+ }
+
+ /**
+ * Prints the serialversionUID of a given class.
+ *
+ * @param clazz
+ * the class
+ * @param suid
+ * the value to be printed
+ */
+ public static void printResult(Clazz clazz, long suid) {
+ System.out.println(clazz.getName() + "\t"
+ + "static final long serialVersionUID = " + suid + "L;");
+ }
+
+ /**
+ * Get the options from the Map, string options (-classpath <i>path</i>).
+ *
+ * @param options
+ * map.
+ * @param name
+ * option.
+ * @return value of the option.
+ */
+ private static String getString(Map options, String name) {
+ try {
+ return (String) options.get(name);
+ } catch (ClassCastException e) {
+ throw new RuntimeException("'" + name
+ + "': expected java.lang.String", e);
+ }
+ }
+
+ /**
+ * Get the options from the Map, boolean options (<i>-show</i>).
+ *
+ * @param options
+ * map.
+ * @param name
+ * option.
+ * @return true if option was passed as arg<br />
+ * false otherwise.
+ */
+ private static boolean getBoolean(Map options, String name) {
+ try {
+ Object value = options.get(name);
+ if (value != null) {
+ return ((Boolean) value).booleanValue();
+ }
+ } catch (ClassCastException e) {
+ throw new RuntimeException("'" + name
+ + "': expected java.lang.Boolean", e);
+ }
+ return false;
+ }
}
Modified: harmony/enhanced/java/branches/mrh/jdktools/modules/jdktools/src/test/java/org/apache/harmony/tests/tools/serialver/NoSerialize.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/jdktools/modules/jdktools/src/test/java/org/apache/harmony/tests/tools/serialver/NoSerialize.java?rev=937048&r1=937047&r2=937048&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/jdktools/modules/jdktools/src/test/java/org/apache/harmony/tests/tools/serialver/NoSerialize.java (original)
+++ harmony/enhanced/java/branches/mrh/jdktools/modules/jdktools/src/test/java/org/apache/harmony/tests/tools/serialver/NoSerialize.java Thu Apr 22 20:31:29 2010
@@ -17,8 +17,8 @@
package org.apache.harmony.tests.tools.serialver;
public class NoSerialize {
- private int x;
- private int y;
-
- public String lol;
+ private int x;
+ private int y;
+
+ public String lol;
}
Modified: harmony/enhanced/java/branches/mrh/jdktools/modules/jdktools/src/test/java/org/apache/harmony/tests/tools/serialver/Point.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/jdktools/modules/jdktools/src/test/java/org/apache/harmony/tests/tools/serialver/Point.java?rev=937048&r1=937047&r2=937048&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/jdktools/modules/jdktools/src/test/java/org/apache/harmony/tests/tools/serialver/Point.java (original)
+++ harmony/enhanced/java/branches/mrh/jdktools/modules/jdktools/src/test/java/org/apache/harmony/tests/tools/serialver/Point.java Thu Apr 22 20:31:29 2010
@@ -19,16 +19,16 @@ package org.apache.harmony.tests.tools.s
import java.io.Serializable;
public class Point implements Serializable {
-
- //private static final long serialVersionUID = -2044326457932868113L;
- private int x;
- private int y;
- private Point p;
-
- public Point(int x, int y) {
- }
- public void setP(Point p) {
- this.p = p;
- }
+ //private static final long serialVersionUID = -2044326457932868113L;
+ private int x;
+ private int y;
+ private Point p;
+
+ public Point(int x, int y) {
+ }
+
+ public void setP(Point p) {
+ this.p = p;
+ }
}