harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hinde...@apache.org
Subject svn commit: r936298 - in /harmony/enhanced/java/trunk/classlib/modules/luni/src/main: java/java/io/ java/org/apache/harmony/luni/platform/ native/luni/shared/ native/luni/unix/
Date Wed, 21 Apr 2010 13:36:51 GMT
Author: hindessm
Date: Wed Apr 21 13:36:51 2010
New Revision: 936298

URL: http://svn.apache.org/viewvc?rev=936298&view=rev
Log:
Add available call to IFileSystem to squash three JNI calls down to one.

Modified:
    harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/io/FileInputStream.java
    harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/org/apache/harmony/luni/platform/IFileSystem.java
    harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSFileSystem.java
    harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/shared/OSFileSystem.c
    harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/unix/exports.txt

Modified: harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/io/FileInputStream.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/io/FileInputStream.java?rev=936298&r1=936297&r2=936298&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/io/FileInputStream.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/io/FileInputStream.java
Wed Apr 21 13:36:51 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/trunk/classlib/modules/luni/src/main/java/org/apache/harmony/luni/platform/IFileSystem.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/org/apache/harmony/luni/platform/IFileSystem.java?rev=936298&r1=936297&r2=936298&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/org/apache/harmony/luni/platform/IFileSystem.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/org/apache/harmony/luni/platform/IFileSystem.java
Wed Apr 21 13:36:51 2010
@@ -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/trunk/classlib/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSFileSystem.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSFileSystem.java?rev=936298&r1=936297&r2=936298&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSFileSystem.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSFileSystem.java
Wed Apr 21 13:36:51 2010
@@ -267,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/trunk/classlib/modules/luni/src/main/native/luni/shared/OSFileSystem.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/shared/OSFileSystem.c?rev=936298&r1=936297&r2=936298&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/shared/OSFileSystem.c
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/shared/OSFileSystem.c
Wed Apr 21 13:36:51 2010
@@ -285,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/trunk/classlib/modules/luni/src/main/native/luni/unix/exports.txt
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/unix/exports.txt?rev=936298&r1=936297&r2=936298&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/unix/exports.txt
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/unix/exports.txt
Wed Apr 21 13:36:51 2010
@@ -137,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



Mime
View raw message