Search in sources :

Example 61 with EOFException

use of java.io.EOFException in project android_frameworks_base by DirtyUnicorns.

the class AccountSyncSettingsBackupHelper method readOldMd5Checksum.

/**
     * Read the MD5 checksum from the old state.
     *
     * @return the old MD5 checksum
     */
private byte[] readOldMd5Checksum(ParcelFileDescriptor oldState) throws IOException {
    DataInputStream dataInput = new DataInputStream(new FileInputStream(oldState.getFileDescriptor()));
    byte[] oldMd5Checksum = new byte[MD5_BYTE_SIZE];
    try {
        int stateVersion = dataInput.readInt();
        if (stateVersion <= STATE_VERSION) {
            // backup.
            for (int i = 0; i < MD5_BYTE_SIZE; i++) {
                oldMd5Checksum[i] = dataInput.readByte();
            }
        } else {
            Log.i(TAG, "Backup state version is: " + stateVersion + " (support only up to version " + STATE_VERSION + ")");
        }
    } catch (EOFException eof) {
    // Initial state may be empty.
    }
    // We explicitly don't close 'dataInput' because we must not close the backing fd.
    return oldMd5Checksum;
}
Also used : EOFException(java.io.EOFException) DataInputStream(java.io.DataInputStream) BackupDataInputStream(android.app.backup.BackupDataInputStream) FileInputStream(java.io.FileInputStream)

Example 62 with EOFException

use of java.io.EOFException in project dubbo by alibaba.

the class GenericDataInput method read0.

protected byte[] read0(int len) throws IOException {
    int rem = mRead - mPosition;
    byte[] ret = new byte[len];
    if (len <= rem) {
        System.arraycopy(mBuffer, mPosition, ret, 0, len);
        mPosition += len;
    } else {
        System.arraycopy(mBuffer, mPosition, ret, 0, rem);
        mPosition = mRead;
        len -= rem;
        int read, pos = rem;
        while (len > 0) {
            read = mInput.read(ret, pos, len);
            if (read == -1)
                throw new EOFException();
            pos += read;
            len -= read;
        }
    }
    return ret;
}
Also used : EOFException(java.io.EOFException)

Example 63 with EOFException

use of java.io.EOFException in project android_frameworks_base by AOSPA.

the class BackupManagerService method initPackageTracking.

private void initPackageTracking() {
    if (MORE_DEBUG)
        Slog.v(TAG, "` tracking");
    // Remember our ancestral dataset
    mTokenFile = new File(mBaseStateDir, "ancestral");
    try {
        RandomAccessFile tf = new RandomAccessFile(mTokenFile, "r");
        int version = tf.readInt();
        if (version == CURRENT_ANCESTRAL_RECORD_VERSION) {
            mAncestralToken = tf.readLong();
            mCurrentToken = tf.readLong();
            int numPackages = tf.readInt();
            if (numPackages >= 0) {
                mAncestralPackages = new HashSet<String>();
                for (int i = 0; i < numPackages; i++) {
                    String pkgName = tf.readUTF();
                    mAncestralPackages.add(pkgName);
                }
            }
        }
        tf.close();
    } catch (FileNotFoundException fnf) {
        // Probably innocuous
        Slog.v(TAG, "No ancestral data");
    } catch (IOException e) {
        Slog.w(TAG, "Unable to read token file", e);
    }
    // Keep a log of what apps we've ever backed up.  Because we might have
    // rebooted in the middle of an operation that was removing something from
    // this log, we sanity-check its contents here and reconstruct it.
    mEverStored = new File(mBaseStateDir, "processed");
    File tempProcessedFile = new File(mBaseStateDir, "processed.new");
    // Ignore it -- we'll validate "processed" against the current package set.
    if (tempProcessedFile.exists()) {
        tempProcessedFile.delete();
    }
    // file to continue the recordkeeping.
    if (mEverStored.exists()) {
        RandomAccessFile temp = null;
        RandomAccessFile in = null;
        try {
            temp = new RandomAccessFile(tempProcessedFile, "rws");
            in = new RandomAccessFile(mEverStored, "r");
            // Loop until we hit EOF
            while (true) {
                String pkg = in.readUTF();
                try {
                    // is this package still present?
                    mPackageManager.getPackageInfo(pkg, 0);
                    // if we get here then yes it is; remember it
                    mEverStoredApps.add(pkg);
                    temp.writeUTF(pkg);
                    if (MORE_DEBUG)
                        Slog.v(TAG, "   + " + pkg);
                } catch (NameNotFoundException e) {
                    // nope, this package was uninstalled; don't include it
                    if (MORE_DEBUG)
                        Slog.v(TAG, "   - " + pkg);
                }
            }
        } catch (EOFException e) {
            // old one with the new one then reopen the file for continuing use.
            if (!tempProcessedFile.renameTo(mEverStored)) {
                Slog.e(TAG, "Error renaming " + tempProcessedFile + " to " + mEverStored);
            }
        } catch (IOException e) {
            Slog.e(TAG, "Error in processed file", e);
        } finally {
            try {
                if (temp != null)
                    temp.close();
            } catch (IOException e) {
            }
            try {
                if (in != null)
                    in.close();
            } catch (IOException e) {
            }
        }
    }
    synchronized (mQueueLock) {
        // Resume the full-data backup queue
        mFullBackupQueue = readFullBackupSchedule();
    }
    // Register for broadcasts about package install, etc., so we can
    // update the provider list.
    IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_PACKAGE_ADDED);
    filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
    filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
    filter.addDataScheme("package");
    mContext.registerReceiver(mBroadcastReceiver, filter);
    // Register for events related to sdcard installation.
    IntentFilter sdFilter = new IntentFilter();
    sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE);
    sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE);
    mContext.registerReceiver(mBroadcastReceiver, sdFilter);
}
Also used : IntentFilter(android.content.IntentFilter) RandomAccessFile(java.io.RandomAccessFile) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) FileNotFoundException(java.io.FileNotFoundException) EOFException(java.io.EOFException) IOException(java.io.IOException) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) AtomicFile(android.util.AtomicFile)

Example 64 with EOFException

use of java.io.EOFException in project android_frameworks_base by AOSPA.

the class OMAConstants method deserializeString.

public static String deserializeString(InputStream in) throws IOException {
    StringBuilder prefix = new StringBuilder();
    for (; ; ) {
        byte b = (byte) in.read();
        if (b == '.')
            return null;
        else if (b == ':')
            break;
        else if (b > ' ')
            prefix.append((char) b);
    }
    int length = Integer.parseInt(prefix.toString(), 16);
    byte[] octets = new byte[length];
    int offset = 0;
    while (offset < octets.length) {
        int amount = in.read(octets, offset, octets.length - offset);
        if (amount <= 0)
            throw new EOFException();
        offset += amount;
    }
    return new String(octets, StandardCharsets.UTF_8);
}
Also used : EOFException(java.io.EOFException)

Example 65 with EOFException

use of java.io.EOFException in project mobile-center-sdk-android by Microsoft.

the class HttpUtilsAndroidTest method isRecoverableErrorTest.

@Test
public void isRecoverableErrorTest() {
    assertTrue(isRecoverableError(new EOFException()));
    assertTrue(isRecoverableError(new InterruptedIOException()));
    assertTrue(isRecoverableError(new SocketTimeoutException()));
    assertTrue(isRecoverableError(new SocketException()));
    assertTrue(isRecoverableError(new PortUnreachableException()));
    assertTrue(isRecoverableError(new UnknownHostException()));
    assertTrue(isRecoverableError(new RejectedExecutionException()));
    assertFalse(isRecoverableError(new MalformedURLException()));
    assertFalse(isRecoverableError(new IOException()));
    assertTrue(isRecoverableError(new IOException(new EOFException())));
    assertFalse(isRecoverableError(new IOException(new Exception())));
    for (int i = 0; i <= 4; i++) assertTrue(isRecoverableError(new HttpException(500 + i)));
    for (int i = 0; i <= 6; i++) assertFalse(isRecoverableError(new HttpException(400 + i)));
    assertTrue(isRecoverableError(new HttpException(408)));
    assertFalse(isRecoverableError(new HttpException(413)));
    assertTrue(isRecoverableError(new HttpException(429)));
    assertTrue(isRecoverableError(new SSLException("Write error: ssl=0x59c28f90: I/O error during system call, Connection timed out")));
    assertFalse(isRecoverableError(new SSLHandshakeException("java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.")));
    assertFalse(isRecoverableError(new SSLException(null, new CertPathValidatorException("Trust anchor for certification path not found."))));
    assertFalse(isRecoverableError(new SSLException("java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty")));
    assertTrue(isRecoverableError(new SSLException("Read error: ssl=0x9dd07200: I/O error during system call, Connection reset by peer")));
    assertTrue(isRecoverableError(new SSLException("SSL handshake aborted: ssl=0x1cc160: I/O error during system call, Connection reset by peer")));
    assertTrue(isRecoverableError(new SSLHandshakeException("javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0x870c918: Failure in SSL library, usually a protocol error\nerror:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure (external/openssl/ssl/s23_clnt.c:658 0xb7c393a1:0x00000000)")));
}
Also used : InterruptedIOException(java.io.InterruptedIOException) SocketException(java.net.SocketException) PortUnreachableException(java.net.PortUnreachableException) MalformedURLException(java.net.MalformedURLException) UnknownHostException(java.net.UnknownHostException) IOException(java.io.IOException) InterruptedIOException(java.io.InterruptedIOException) SSLException(javax.net.ssl.SSLException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) MalformedURLException(java.net.MalformedURLException) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) IOException(java.io.IOException) EOFException(java.io.EOFException) InterruptedIOException(java.io.InterruptedIOException) UnknownHostException(java.net.UnknownHostException) SocketException(java.net.SocketException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) SSLException(javax.net.ssl.SSLException) SocketTimeoutException(java.net.SocketTimeoutException) PortUnreachableException(java.net.PortUnreachableException) CertPathValidatorException(java.security.cert.CertPathValidatorException) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) CertPathValidatorException(java.security.cert.CertPathValidatorException) SocketTimeoutException(java.net.SocketTimeoutException) EOFException(java.io.EOFException) Test(org.junit.Test)

Aggregations

EOFException (java.io.EOFException)1149 IOException (java.io.IOException)508 DataInputStream (java.io.DataInputStream)139 FileInputStream (java.io.FileInputStream)124 InputStream (java.io.InputStream)100 ByteArrayInputStream (java.io.ByteArrayInputStream)95 ArrayList (java.util.ArrayList)84 Test (org.junit.Test)84 ByteBuffer (java.nio.ByteBuffer)75 File (java.io.File)74 FileNotFoundException (java.io.FileNotFoundException)61 BufferedInputStream (java.io.BufferedInputStream)56 RandomAccessFile (java.io.RandomAccessFile)46 SocketTimeoutException (java.net.SocketTimeoutException)43 HashMap (java.util.HashMap)38 ByteArrayOutputStream (java.io.ByteArrayOutputStream)32 SocketException (java.net.SocketException)31 Map (java.util.Map)30 InterruptedIOException (java.io.InterruptedIOException)29 Path (org.apache.hadoop.fs.Path)29