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;
}
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;
}
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);
}
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);
}
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)")));
}
Aggregations