diff options
author | The Android Open Source Project <initial-contribution@android.com> | 2009-03-18 22:20:24 -0700 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2009-03-18 22:20:24 -0700 |
commit | 5d287a9d9768195f53e244414b465ec4a6f72625 (patch) | |
tree | 32ff909271b0a01bc62e2b661321958cad5fe6c8 | |
parent | 9fdda7315a733131bc1b6b5e08535d1199113be0 (diff) | |
download | libcore-5d287a9d9768195f53e244414b465ec4a6f72625.zip libcore-5d287a9d9768195f53e244414b465ec4a6f72625.tar.gz libcore-5d287a9d9768195f53e244414b465ec4a6f72625.tar.bz2 |
auto import //branches/master/...@140412
6 files changed, 120 insertions, 27 deletions
diff --git a/dalvik/src/main/java/dalvik/system/PathClassLoader.java b/dalvik/src/main/java/dalvik/system/PathClassLoader.java index c80aef8..55e61a9 100644 --- a/dalvik/src/main/java/dalvik/system/PathClassLoader.java +++ b/dalvik/src/main/java/dalvik/system/PathClassLoader.java @@ -56,8 +56,8 @@ public class PathClassLoader extends ClassLoader { /** * Creates a {@code PathClassLoader} that operates on a given list of files * and directories. This method is equivalent to calling - * {@link #PathClassLoader(String, String, ClassLoader) with a {@code null} - * value for the second argument (see description there). + * {@link #PathClassLoader(String, String, ClassLoader)} with a + * {@code null} value for the second argument (see description there). * * @param path * the list of files and directories diff --git a/dalvik/src/main/java/dalvik/system/VMDebug.java b/dalvik/src/main/java/dalvik/system/VMDebug.java index 023cd6a..ee0847d 100644 --- a/dalvik/src/main/java/dalvik/system/VMDebug.java +++ b/dalvik/src/main/java/dalvik/system/VMDebug.java @@ -153,6 +153,12 @@ public final class VMDebug { int bufferSize, int flags); /** + * Determine whether method tracing is currently active. + * @hide + */ + public static native boolean isMethodTracingActive(); + + /** * Stops method tracing. */ public static native void stopMethodTracing(); diff --git a/luni/src/main/native/org_apache_harmony_luni_platform_OSNetworkSystem.cpp b/luni/src/main/native/org_apache_harmony_luni_platform_OSNetworkSystem.cpp index de01295..348041e 100755 --- a/luni/src/main/native/org_apache_harmony_luni_platform_OSNetworkSystem.cpp +++ b/luni/src/main/native/org_apache_harmony_luni_platform_OSNetworkSystem.cpp @@ -1379,7 +1379,7 @@ static jint osNetworkSystem_readSocketDirectImpl(JNIEnv* env, jclass clazz, // LOGD("ENTER readSocketDirectImpl"); int handle; - jbyte *message = (jbyte *)address; + jbyte *message = (jbyte *)address + offset; int result, ret, localCount; handle = jniGetFDFromFileDescriptor(env, fileDescriptor); @@ -1437,7 +1437,7 @@ static jint osNetworkSystem_readSocketImpl(JNIEnv* env, jclass clazz, } result = osNetworkSystem_readSocketDirectImpl(env, clazz, fileDescriptor, - (jint) message, offset, count, timeout); + (jint) message, 0, localCount, timeout); if (result > 0) { env->SetByteArrayRegion(data, offset, result, (jbyte *)message); @@ -1455,7 +1455,7 @@ static jint osNetworkSystem_writeSocketDirectImpl(JNIEnv* env, jclass clazz, // LOGD("ENTER writeSocketDirectImpl"); int handle; - jbyte *message = (jbyte *)address; + jbyte *message = (jbyte *)address + offset; int result = 0, sent = 0; if (count <= 0) { @@ -1499,7 +1499,7 @@ static jint osNetworkSystem_writeSocketDirectImpl(JNIEnv* env, jclass clazz, if (!socketExConstructor) { return 0; } - socketEx = env->NewObject(socketExClass, socketExConstructor, errorMessageString); + socketEx = env->NewObject(socketExClass, socketExConstructor, errorMessageString); socketExCauseMethod = env->GetMethodID(socketExClass,"initCause","(Ljava/lang/Throwable;)Ljava/lang/Throwable;"); env->CallObjectMethod(socketEx,socketExCauseMethod,errorCodeEx); env->Throw((jthrowable)socketEx); @@ -1539,13 +1539,13 @@ static jint osNetworkSystem_writeSocketImpl(JNIEnv* env, jclass clazz, env->GetByteArrayRegion(data, offset, count, message); result = osNetworkSystem_writeSocketDirectImpl(env, clazz, fileDescriptor, - (jint) message, offset, count); + (jint) message, 0, count); if (( jbyte *)message != internalBuffer) { - free(( jbyte *)message); + free(( jbyte *)message); } #undef INTERNAL_SEND_BUFFER_MAX - return result; + return result; } static void osNetworkSystem_setNonBlockingImpl(JNIEnv* env, jclass clazz, @@ -2256,7 +2256,7 @@ static jint osNetworkSystem_receiveDatagramImpl(JNIEnv* env, jclass clazz, } int actualLength = osNetworkSystem_receiveDatagramDirectImpl(env, clazz, fd, - packet, (jint)bytes, offset, localLength, receiveTimeout, peek); + packet, (jint)bytes, 0, localLength, receiveTimeout, peek); if (actualLength > 0) { env->SetByteArrayRegion(data, offset, actualLength, bytes); @@ -2315,7 +2315,7 @@ static jint osNetworkSystem_recvConnectedDatagramImpl(JNIEnv* env, jclass clazz, } int actualLength = osNetworkSystem_recvConnectedDatagramDirectImpl(env, - clazz, fd, packet, (jint)bytes, offset, localLength, + clazz, fd, packet, (jint)bytes, 0, localLength, receiveTimeout, peek); if (actualLength > 0) { @@ -2757,10 +2757,10 @@ static jint osNetworkSystem_selectImpl(JNIEnv* env, jclass clazz, } if (0 < result) { - /*output the result to a int array*/ - flagArray = env->GetIntArrayElements(outFlags, &isCopy); + /*output the result to a int array*/ + flagArray = env->GetIntArrayElements(outFlags, &isCopy); - for (val=0; val<countReadC; val++) { + for (val=0; val<countReadC; val++) { gotFD = env->GetObjectArrayElement(readFDArray,val); handle = jniGetFDFromFileDescriptor(env, gotFD); @@ -3056,7 +3056,7 @@ static void osNetworkSystem_setSocketOptionImpl(JNIEnv* env, jclass clazz, break; } - case JAVASOCKOPT_MCAST_TTL: { + case JAVASOCKOPT_MCAST_TTL: { if ((anOption >> 16) & BROKEN_MULTICAST_TTL) { return; } @@ -3071,13 +3071,13 @@ static void osNetworkSystem_setSocketOptionImpl(JNIEnv* env, jclass clazz, case JAVASOCKOPT_MCAST_ADD_MEMBERSHIP: { mcastAddDropMembership(env, handle, optVal, (anOption >> 16) & BROKEN_MULTICAST_IF, IP_ADD_MEMBERSHIP); - return; + break; } case JAVASOCKOPT_MCAST_DROP_MEMBERSHIP: { mcastAddDropMembership(env, handle, optVal, (anOption >> 16) & BROKEN_MULTICAST_IF, IP_DROP_MEMBERSHIP); - return; + break; } case JAVASOCKOPT_MCAST_INTERFACE: { diff --git a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/SocketChannelTest.java b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/SocketChannelTest.java index e1f5e86..015a1d0 100755 --- a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/SocketChannelTest.java +++ b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/SocketChannelTest.java @@ -28,6 +28,8 @@ import java.io.InputStream; import java.io.OutputStream; import java.net.BindException; import java.net.ConnectException; +import java.net.Inet4Address; +import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.ServerSocket; import java.net.Socket; @@ -4112,6 +4114,95 @@ public class SocketChannelTest extends TestCase { } } + /** + * @throws IOException + * @tests java.nio.channels.SocketChannel#read(ByteBuffer) + */ + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "", + method = "read", + args = {java.nio.ByteBuffer[].class} + ) + public void test_socketChannel_read_DirectByteBuffer() throws InterruptedException, IOException { + + ServerThread server = new ServerThread(); + server.start(); + Thread.currentThread().sleep(1000); + + InetSocketAddress address = new InetSocketAddress(InetAddress + .getByName("localhost"), port); + + // First test with array based byte buffer + SocketChannel sc = SocketChannel.open(); + sc.connect(address); + + ByteBuffer buf = ByteBuffer.allocate(data.length); + buf.limit(data.length / 2); + sc.read(buf); + + buf.limit(buf.capacity()); + sc.read(buf); + sc.close(); + + // Make sure the buffer is filled correctly + buf.rewind(); + assertSameContent(data, buf); + + // Now test with direct byte buffer + sc = SocketChannel.open(); + sc.connect(address); + + buf = ByteBuffer.allocateDirect(data.length); + buf.limit(data.length / 2); + sc.read(buf); + + buf.limit(buf.capacity()); + sc.read(buf); + sc.close(); + + // Make sure the buffer is filled correctly + buf.rewind(); + assertSameContent(data, buf); + } + + private void assertSameContent(byte[] data, ByteBuffer buf) { + for (byte b : data) { + if (b != buf.get()) { + int pos = buf.position() - 1; + fail("Content not equal. Buffer position: " + + (pos) + " expected: " + b + " was: " + buf.get(pos)); + } + } + } + + public static boolean done = false; + public static int port = Support_PortManager.getNextPort(); + public static byte[] data = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + + static class ServerThread extends Thread { + @Override + public void run() { + try { + ServerSocketChannel ssc = ServerSocketChannel.open(); + InetSocketAddress addr = new InetSocketAddress(InetAddress + .getByAddress(new byte[] {0, 0, 0, 0}), port); + ssc.socket().bind(addr, 0); + + ByteBuffer buf = ByteBuffer.allocate(10); + buf.put(data); + + while (!done) { + SocketChannel sc = ssc.accept(); + buf.rewind(); + sc.write(buf); + } + } catch (Exception e) { + // ignore + } + } + } + class MockSocketChannel extends SocketChannel { private boolean isWriteCalled = false; diff --git a/prefs/src/main/java/java/util/prefs/Preferences.java b/prefs/src/main/java/java/util/prefs/Preferences.java index b7a0c70..719c89a 100644 --- a/prefs/src/main/java/java/util/prefs/Preferences.java +++ b/prefs/src/main/java/java/util/prefs/Preferences.java @@ -1006,15 +1006,11 @@ public abstract class Preferences { //parse node's absolute path from class instance private static String getNodeName(Class<?> c){ - // ??? PREFS TODO change back to harmony code once getPackage - // delivers the correct results - // Package p = c.getPackage(); - // if(null == p){ - // return "/<unnamed>"; //$NON-NLS-1$ - // } - // return "/"+p.getName().replace('.', '/'); //$NON-NLS-1$ - int dotIndex = c.getName().lastIndexOf("."); - return "/" + c.getName().substring(0, dotIndex).replace(".", "/"); + Package p = c.getPackage(); + if(null == p){ + return "/<unnamed>"; //$NON-NLS-1$ + } + return "/"+p.getName().replace('.', '/'); //$NON-NLS-1$ } /** diff --git a/text/src/main/java/java/text/RuleBasedCollator.java b/text/src/main/java/java/text/RuleBasedCollator.java index 41a51e2..6418962 100644 --- a/text/src/main/java/java/text/RuleBasedCollator.java +++ b/text/src/main/java/java/text/RuleBasedCollator.java @@ -390,7 +390,7 @@ public class RuleBasedCollator extends Collator { /** * Returns the collation rules of this collator. These {@code rules} can be - * fed into the {@link #RuleBasedCollator(String)} constructor. + * fed into the {@code RuleBasedCollator(String)} constructor. * <p> * Note that the {@code rules} are actually interpreted as a delta to the * standard Unicode Collation Algorithm (UCA). Hence, an empty {@code rules} |