Search in sources :

Example 51 with StreamCorruptedException

use of java.io.StreamCorruptedException in project mailim by zengsn.

the class InputUtil method readObjectFromLocal.

/**
 * 读取本地对象
 * @param context
 * @param fielName 文件名
 * @return
 */
@SuppressWarnings("unchecked")
public T readObjectFromLocal(Context context, String fielName) {
    T bean;
    try {
        // 获得输入流
        FileInputStream fis = context.openFileInput(fielName);
        ObjectInputStream ois = new ObjectInputStream(fis);
        bean = (T) ois.readObject();
        fis.close();
        ois.close();
        return bean;
    } catch (StreamCorruptedException e) {
        // Toast.makeText(ShareTencentActivity.this,"出现异常3",Toast.LENGTH_LONG).show();//弹出Toast消息
        e.printStackTrace();
        return null;
    } catch (OptionalDataException e) {
        // Toast.makeText(ShareTencentActivity.this,"出现异常4",Toast.LENGTH_LONG).show();//弹出Toast消息
        e.printStackTrace();
        return null;
    } catch (FileNotFoundException e) {
        // Toast.makeText(ShareTencentActivity.this,"出现异常5",Toast.LENGTH_LONG).show();//弹出Toast消息
        e.printStackTrace();
        return null;
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    } catch (ClassNotFoundException e) {
        // Toast.makeText(ShareTencentActivity.this,"出现异常6",Toast.LENGTH_LONG).show();//弹出Toast消息
        e.printStackTrace();
        return null;
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) StreamCorruptedException(java.io.StreamCorruptedException) IOException(java.io.IOException) OptionalDataException(java.io.OptionalDataException) FileInputStream(java.io.FileInputStream) ObjectInputStream(java.io.ObjectInputStream)

Example 52 with StreamCorruptedException

use of java.io.StreamCorruptedException in project mailim by zengsn.

the class InputUtil method readObjectFromSdCard.

/**
 * 读取sd卡对象
 * @param fileName 文件名
 * @return
 */
@SuppressWarnings("unchecked")
public T readObjectFromSdCard(String fileName) {
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        // 检测sd卡是否存在
        T bean;
        File sdCardDir = Environment.getExternalStorageDirectory();
        File sdFile = new File(sdCardDir, fileName);
        try {
            FileInputStream fis = new FileInputStream(sdFile);
            ObjectInputStream ois = new ObjectInputStream(fis);
            bean = (T) ois.readObject();
            fis.close();
            ois.close();
            return bean;
        } catch (StreamCorruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return null;
        } catch (OptionalDataException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return null;
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return null;
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return null;
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return null;
        }
    } else {
        return null;
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) StreamCorruptedException(java.io.StreamCorruptedException) IOException(java.io.IOException) File(java.io.File) OptionalDataException(java.io.OptionalDataException) FileInputStream(java.io.FileInputStream) ObjectInputStream(java.io.ObjectInputStream)

Example 53 with StreamCorruptedException

use of java.io.StreamCorruptedException in project carat by amplab.

the class CaratSampleDB method fillSample.

/*
     * Read a sample from the current position of the cursor. TODO: Needs to be
     * updated when fields update.
     */
private Sample fillSample(Cursor cursor) {
    Sample s = null;
    byte[] sampleB = cursor.getBlob(cursor.getColumnIndex(CaratSampleDB.COLUMN_SAMPLE));
    if (sampleB != null) {
        ObjectInputStream oi;
        try {
            oi = new ObjectInputStream(new ByteArrayInputStream(sampleB));
            Object o = oi.readObject();
            if (o != null)
                s = SampleReader.readSample(o);
        } catch (StreamCorruptedException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
    return s;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Sample(edu.berkeley.cs.amplab.carat.thrift.Sample) StreamCorruptedException(java.io.StreamCorruptedException) IOException(java.io.IOException) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

StreamCorruptedException (java.io.StreamCorruptedException)53 IOException (java.io.IOException)35 ObjectInputStream (java.io.ObjectInputStream)30 ByteArrayInputStream (java.io.ByteArrayInputStream)22 OptionalDataException (java.io.OptionalDataException)11 File (java.io.File)8 FileInputStream (java.io.FileInputStream)7 FileNotFoundException (java.io.FileNotFoundException)7 InvalidClassException (java.io.InvalidClassException)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 ObjectOutputStream (java.io.ObjectOutputStream)6 NucleusUserException (org.datanucleus.exceptions.NucleusUserException)5 EOFException (java.io.EOFException)4 NotSerializableException (java.io.NotSerializableException)4 Serializable (java.io.Serializable)4 Blob (java.sql.Blob)4 SSLException (javax.net.ssl.SSLException)4 FileOutputStream (java.io.FileOutputStream)3 SocketTimeoutException (java.net.SocketTimeoutException)3 InvalidParameterException (java.security.InvalidParameterException)3