You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by te...@apache.org on 2006/06/26 17:05:50 UTC
svn commit: r417205 - in /incubator/harmony/enhanced/classlib/trunk:
modules/luni/src/main/java/java/io/
modules/luni/src/main/java/org/apache/harmony/luni/platform/
native-src/linux.IA32/luni/ native-src/shared/luni/ native-src/win.IA32/luni/
Author: tellison
Date: Mon Jun 26 08:05:49 2006
New Revision: 417205
URL: http://svn.apache.org/viewvc?rev=417205&view=rev
Log:
Fix for HARMONY-648 (Can't read input from the console)
Modified:
incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FileInputStream.java
incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/IFileSystem.java
incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSFileSystem.java
incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/luni/libhyluni.exp
incubator/harmony/enhanced/classlib/trunk/native-src/shared/luni/OSFileSystem.c
incubator/harmony/enhanced/classlib/trunk/native-src/shared/luni/OSFileSystem.h
incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/luni/hyluni.def
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FileInputStream.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FileInputStream.java?rev=417205&r1=417204&r2=417205&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FileInputStream.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FileInputStream.java Mon Jun 26 08:05:49 2006
@@ -123,6 +123,11 @@
public int available() throws IOException {
openCheck();
synchronized (repositioningLock) {
+ // stdin requires special handling
+ 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,
@@ -274,6 +279,10 @@
openCheck();
synchronized (repositioningLock) {
+ // stdin requires special handling
+ if (fd == FileDescriptor.in) {
+ return (int)fileSystem.ttyRead(buffer, offset, count);
+ }
return (int) fileSystem.read(fd.descriptor, buffer, offset, count);
}
}
@@ -282,8 +291,7 @@
* Skips <code>count</code> number of bytes in this FileInputStream.
* Subsequent <code>read()</code>'s will not return these bytes unless
* <code>reset()</code> is used. This method may perform multiple reads to
- * read <code>count</code> bytes. This default implementation reads
- * <code>count</code> bytes into a temporary buffer.
+ * read <code>count</code> bytes.
*
* @param count
* the number of bytes to skip.
@@ -295,6 +303,27 @@
*/
public long skip(long count) throws IOException {
openCheck();
+
+ if (count == 0) {
+ return 0;
+ }
+
+ // stdin requires special handling
+ if (fd == FileDescriptor.in) {
+ // Read and discard count bytes in 8k chunks
+ long skipped = 0, numRead;
+ int chunk = count < 8192 ? (int) count : 8192;
+ byte[] buffer = new byte[chunk];
+ for (long i = count / chunk; i >= 0; i--) {
+ numRead = fileSystem.ttyRead(buffer, 0, chunk);
+ skipped += numRead;
+ if (numRead < chunk) {
+ return skipped;
+ }
+ }
+ return skipped;
+ }
+
synchronized (repositioningLock) {
final long currentPosition = fileSystem.seek(fd.descriptor, 0L,
IFileSystem.SEEK_CUR);
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/IFileSystem.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/IFileSystem.java?rev=417205&r1=417204&r2=417205&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/IFileSystem.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/IFileSystem.java Mon Jun 26 08:05:49 2006
@@ -97,4 +97,7 @@
public long transfer(long fileHandler, FileDescriptor socketDescriptor,
long offset, long count) throws IOException;
+ public long ttyAvailable() throws IOException;
+
+ public long ttyRead(byte[] bytes, int offset, int length) throws IOException;
}
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSFileSystem.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSFileSystem.java?rev=417205&r1=417204&r2=417205&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSFileSystem.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSFileSystem.java Mon Jun 26 08:05:49 2006
@@ -238,4 +238,23 @@
private native long transferImpl(long fileHandler,
FileDescriptor socketDescriptor, long offset, long count);
+ public long ttyAvailable() throws IOException {
+ long nChar = ttyAvailableImpl();
+ if (nChar < 0) {
+ throw new IOException();
+ }
+ return nChar;
+ }
+
+ private native long ttyAvailableImpl();
+
+ public long ttyRead(byte[] bytes, int offset, int length) throws IOException {
+ long nChar = ttyReadImpl(bytes, offset, length);
+ if (nChar < 0) {
+ throw new IOException();
+ }
+ return nChar;
+ }
+
+ private native long ttyReadImpl(byte[] bytes, int offset, int length);
}
Modified: incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/luni/libhyluni.exp
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/luni/libhyluni.exp?rev=417205&r1=417204&r2=417205&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/luni/libhyluni.exp (original)
+++ incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/luni/libhyluni.exp Mon Jun 26 08:05:49 2006
@@ -150,6 +150,8 @@
Java_org_apache_harmony_luni_platform_OSFileSystem_lockImpl;
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_ttyReadImpl
Java_org_apache_harmony_luni_platform_OSMemory_isLoadedImpl;
Java_org_apache_harmony_luni_platform_OSMemory_loadImpl;
Java_org_apache_harmony_luni_platform_OSMemory_mmapImpl;
Modified: incubator/harmony/enhanced/classlib/trunk/native-src/shared/luni/OSFileSystem.c
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/native-src/shared/luni/OSFileSystem.c?rev=417205&r1=417204&r2=417205&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/native-src/shared/luni/OSFileSystem.c (original)
+++ incubator/harmony/enhanced/classlib/trunk/native-src/shared/luni/OSFileSystem.c Mon Jun 26 08:05:49 2006
@@ -236,4 +236,40 @@
return (jlong)portFD;
}
+/*
+ * Answers the number of remaining chars in the stdin.
+ *
+ * Class: org_apache_harmony_luni_platform_OSFileSystem
+ * Method: ttyAvailableImpl
+ * Signature: ()J
+ */
+JNIEXPORT jlong JNICALL Java_org_apache_harmony_luni_platform_OSFileSystem_ttyAvailableImpl
+ (JNIEnv *env, jobject thiz)
+{
+ PORT_ACCESS_FROM_ENV (env);
+ return (jlong)hytty_available();
+}
+
+/*
+ * Reads the number of bytes from stdin.
+ *
+ * Class: org_apache_harmony_luni_platform_OSFileSystem
+ * Method: ttyReadImpl
+ * Signature: ([BII)J
+ */
+JNIEXPORT jlong JNICALL Java_org_apache_harmony_luni_platform_OSFileSystem_ttyReadImpl
+ (JNIEnv *env, jobject thiz, jbyteArray byteArray, jint offset, jint nbytes)
+{
+ PORT_ACCESS_FROM_ENV (env);
+ jboolean isCopy;
+ jbyte *bytes = (*env)->GetByteArrayElements(env, byteArray, &isCopy);
+ jlong result;
+
+ result = (jlong) hytty_get_chars((char *)(bytes + offset), (IDATA) nbytes);
+ if (isCopy == JNI_TRUE) {
+ (*env)->ReleaseByteArrayElements (env, byteArray, bytes, 0);
+ }
+
+ return result;
+}
Modified: incubator/harmony/enhanced/classlib/trunk/native-src/shared/luni/OSFileSystem.h
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/native-src/shared/luni/OSFileSystem.h?rev=417205&r1=417204&r2=417205&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/native-src/shared/luni/OSFileSystem.h (original)
+++ incubator/harmony/enhanced/classlib/trunk/native-src/shared/luni/OSFileSystem.h Mon Jun 26 08:05:49 2006
@@ -136,6 +136,22 @@
JNIEXPORT jlong JNICALL Java_org_apache_harmony_luni_platform_OSFileSystem_transferImpl
(JNIEnv *, jobject, jlong, jobject, jlong, jlong);
+/*
+ * Class: org_apache_harmony_luni_platform_OSFileSystem
+ * Method: ttyAvailableImpl
+ * Signature: ()J
+ */
+JNIEXPORT jlong JNICALL Java_org_apache_harmony_luni_platform_OSFileSystem_ttyAvailableImpl
+ (JNIEnv *, jobject);
+
+/*
+ * Class: org_apache_harmony_luni_platform_OSFileSystem
+ * Method: ttyReadImpl
+ * Signature: ([BII)J
+ */
+JNIEXPORT jlong JNICALL Java_org_apache_harmony_luni_platform_OSFileSystem_ttyReadImpl
+ (JNIEnv *, jobject, jbyteArray, jint, jint);
+
#ifdef __cplusplus
}
#endif
Modified: incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/luni/hyluni.def
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/luni/hyluni.def?rev=417205&r1=417204&r2=417205&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/luni/hyluni.def (original)
+++ incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/luni/hyluni.def Mon Jun 26 08:05:49 2006
@@ -140,6 +140,8 @@
Java_org_apache_harmony_luni_platform_OSFileSystem_lockImpl
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_ttyReadImpl
Java_org_apache_harmony_luni_platform_OSMemory_isLoadedImpl
Java_org_apache_harmony_luni_platform_OSMemory_loadImpl
Java_org_apache_harmony_luni_platform_OSMemory_mmapImpl
Re: svn commit: r417205 - in /incubator/harmony/enhanced/classlib/trunk:
modules/luni/src/main/java/java/io/ modules/luni/src/main/java/org/apache/harmony/luni/platform/
native-src/linux.IA32/luni/ native-src/shared/luni/ native-src/win.IA32/luni/
Posted by Tim Ellison <t....@gmail.com>.
Thanks Gregory, fixed in r417222.
(and left wondering why it didn't fail for me?)
Regards,
Tim
Gregory Shimansky wrote:
> Hello Tim
>
> You've forgot semicolons at the end of lines so linker on Linux complains
> about syntax error in version script.
>
> 2006/6/26, tellison@apache.org <te...@apache.org>:<snip/>
>
>> Modified:
>> incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/luni/libhyluni.exp
>>
>> URL:
>> http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/luni/libhyluni.exp?rev=417205&r1=417204&r2=417205&view=diff
>>
>>
>> ==============================================================================
>>
>> ---
>> incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/luni/libhyluni.exp
>>
>> (original)
>> +++
>> incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/luni/libhyluni.exp
>>
>> Mon Jun 26 08:05:49 2006
>> @@ -150,6 +150,8 @@
>>
>>
>> Java_org_apache_harmony_luni_platform_OSFileSystem_lockImpl;
>>
>>
>> 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_ttyReadImpl
>>
>>
>> Java_org_apache_harmony_luni_platform_OSMemory_isLoadedImpl;
>> Java_org_apache_harmony_luni_platform_OSMemory_loadImpl;
>> Java_org_apache_harmony_luni_platform_OSMemory_mmapImpl;
>>
> <snip/>
>
--
Tim Ellison (t.p.ellison@gmail.com)
IBM Java technology centre, UK.
---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
For additional commands, e-mail: harmony-dev-help@incubator.apache.org
Re: svn commit: r417205 - in /incubator/harmony/enhanced/classlib/trunk: modules/luni/src/main/java/java/io/ modules/luni/src/main/java/org/apache/harmony/luni/platform/ native-src/linux.IA32/luni/ native-src/shared/luni/ native-src/win.IA32/luni/
Posted by Gregory Shimansky <gs...@gmail.com>.
Hello Tim
You've forgot semicolons at the end of lines so linker on Linux complains
about syntax error in version script.
2006/6/26, tellison@apache.org <te...@apache.org>:<snip/>
> Modified:
> incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/luni/libhyluni.exp
> URL:
> http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/luni/libhyluni.exp?rev=417205&r1=417204&r2=417205&view=diff
>
> ==============================================================================
> ---
> incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/luni/libhyluni.exp
> (original)
> +++
> incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/luni/libhyluni.exp
> Mon Jun 26 08:05:49 2006
> @@ -150,6 +150,8 @@
>
> Java_org_apache_harmony_luni_platform_OSFileSystem_lockImpl;
>
> 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_ttyReadImpl
>
> Java_org_apache_harmony_luni_platform_OSMemory_isLoadedImpl;
> Java_org_apache_harmony_luni_platform_OSMemory_loadImpl;
> Java_org_apache_harmony_luni_platform_OSMemory_mmapImpl;
>
<snip/>
--
Gregory Shimansky, Intel Middleware Products Division