Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1921eab4 authored by Bjorn Bringert's avatar Bjorn Bringert Committed by Android (Google) Code Review
Browse files

Merge "Only decrement mRemaining once in read()."

parents d8591020 21279933
Loading
Loading
Loading
Loading
+4 −20
Original line number Original line Diff line number Diff line
@@ -16,7 +16,6 @@


package android.content.res;
package android.content.res;


import android.os.MemoryFile;
import android.os.Parcel;
import android.os.Parcel;
import android.os.ParcelFileDescriptor;
import android.os.ParcelFileDescriptor;
import android.os.Parcelable;
import android.os.Parcelable;
@@ -184,14 +183,9 @@ public class AssetFileDescriptor implements Parcelable {


        @Override
        @Override
        public int read() throws IOException {
        public int read() throws IOException {
            if (mRemaining >= 0) {
            byte[] buffer = new byte[1];
                if (mRemaining == 0) return -1;
            int result = read(buffer, 0, 1);
                int res = super.read();
            return result == -1 ? -1 : buffer[0] & 0xff;
                if (res >= 0) mRemaining--;
                return res;
            }
            
            return super.read();
        }
        }


        @Override
        @Override
@@ -209,16 +203,7 @@ public class AssetFileDescriptor implements Parcelable {


        @Override
        @Override
        public int read(byte[] buffer) throws IOException {
        public int read(byte[] buffer) throws IOException {
            if (mRemaining >= 0) {
            return read(buffer, 0, buffer.length);
                if (mRemaining == 0) return -1;
                int count = buffer.length;
                if (count > mRemaining) count = (int)mRemaining;
                int res = super.read(buffer, 0, count);
                if (res >= 0) mRemaining -= res;
                return res;
            }
            
            return super.read(buffer);
        }
        }


        @Override
        @Override
@@ -231,7 +216,6 @@ public class AssetFileDescriptor implements Parcelable {
                return res;
                return res;
            }
            }
            
            
            // TODO Auto-generated method stub
            return super.skip(count);
            return super.skip(count);
        }
        }