use of java.io.StreamCorruptedException in project connect-sdk-client-android by Ingenico-ePayments.
the class WriteInternalStorage method storeIinResponseInCache.
/**
* Stores the given iinResponses in the cache on disk
*
* @param context, used for writing files
* @param partialCreditCardNumber, entered partial creditcardnumber
* @param IinDetailsResponse, the IinDetailsResponse which is added to the current cache
*/
public void storeIinResponseInCache(String partialCreditCardNumber, IinDetailsResponse iinResponse) {
if (partialCreditCardNumber == null) {
throw new InvalidParameterException("Error storing response in partialCreditCardNumber, context may not be null");
}
if (iinResponse == null) {
throw new InvalidParameterException("Error storing response in iinResponse, iinResponse may not be null");
}
// Retrieve the currenct cached items and add the new one to it
Map<String, IinDetailsResponse> currentCachedIinResponses = storage.getIinResponsesFromCache();
// Overwrite old value if it exists
if (currentCachedIinResponses.containsKey(partialCreditCardNumber)) {
currentCachedIinResponses.remove(partialCreditCardNumber);
}
currentCachedIinResponses.put(partialCreditCardNumber, iinResponse);
// Then write the currentCachedIinResponses to disk
String directory = context.getFilesDir() + Constants.DIRECTORY_IINRESPONSES;
File file = new File(directory, Constants.FILENAME_IINRESPONSE_CACHE);
file.getParentFile().mkdirs();
FileOutputStream fileOutputStream = null;
ObjectOutputStream objectOutputStream = null;
try {
fileOutputStream = new FileOutputStream(file);
objectOutputStream = new ObjectOutputStream(fileOutputStream);
objectOutputStream.writeObject(currentCachedIinResponses);
} catch (StreamCorruptedException e) {
Log.e(TAG, "Error storing BasicPaymentProducts on internal device storage", e);
} catch (IOException e) {
Log.e(TAG, "Error storing BasicPaymentProducts on internal device storage", e);
} finally {
try {
objectOutputStream.close();
fileOutputStream.close();
} catch (IOException e) {
}
}
}
use of java.io.StreamCorruptedException in project motech by motech.
the class MdsLongVarBinaryRDBMSMapping method deserialize.
private Object deserialize(byte[] bytes) {
BundleContext bundleContext = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
Bundle mdsEntitiesBundle = MdsBundleHelper.findMdsBundle(bundleContext);
Bundle jodaTimeBundle = OsgiBundleUtils.findBundleBySymbolicName(bundleContext, "joda-time");
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
try (ObjectInputStream ois = new MdsObjectInputStream(bais, mdsEntitiesBundle, jodaTimeBundle)) {
return ois.readObject();
} catch (StreamCorruptedException e) {
String msg = "StreamCorruptedException: object is corrupted";
NucleusLogger.DATASTORE.error(msg);
throw new NucleusUserException(msg, e).setFatal();
} catch (IOException e) {
String msg = "IOException: error when reading object";
NucleusLogger.DATASTORE.error(msg);
throw new NucleusUserException(msg, e).setFatal();
} catch (ClassNotFoundException e) {
String msg = "ClassNotFoundException: error when creating object";
NucleusLogger.DATASTORE.error(msg);
throw new NucleusUserException(msg, e).setFatal();
}
}
use of java.io.StreamCorruptedException in project wifilibrary by LiShiHui24740.
the class SPUtils method readObject.
/**
* 读取数据
*
* @param tag
* @return
*/
public static Object readObject(SharedPreferences sharedPrefs, String tag) {
Object object = null;
String productBase64 = sharedPrefs.getString(tag, "");
// 读取字节
byte[] base64 = Base64.decode(productBase64, Base64.DEFAULT);
// 封装到字节流
ByteArrayInputStream bais = new ByteArrayInputStream(base64);
try {
// 再次封装
ObjectInputStream bis = new ObjectInputStream(bais);
try {
// 读取对象
object = bis.readObject();
} catch (ClassNotFoundException e) {
Log.d("AppConfig", e.toString());
}
} catch (StreamCorruptedException e) {
Log.d("AppConfig", e.toString());
} catch (IOException e) {
Log.d("AppConfig", e.toString());
}
return object;
}
use of java.io.StreamCorruptedException in project teiid by teiid.
the class PgBackendProtocol method getContent.
private void getContent(ResultSet rs, PgColInfo col, int column) throws SQLException, TeiidSQLException, IOException {
switch(col.type) {
case PG_TYPE_BOOL:
boolean b = rs.getBoolean(column);
if (!rs.wasNull()) {
// $NON-NLS-1$ //$NON-NLS-2$
writer.write(b ? "t" : "f");
}
break;
case PG_TYPE_BPCHAR:
case PG_TYPE_DATE:
case PG_TYPE_FLOAT4:
case PG_TYPE_FLOAT8:
case PG_TYPE_INT2:
case PG_TYPE_INT4:
case PG_TYPE_INT8:
case PG_TYPE_NUMERIC:
case PG_TYPE_TIME:
case PG_TYPE_TIMESTAMP_NO_TMZONE:
case PG_TYPE_VARCHAR:
String value = rs.getString(column);
if (value != null) {
writer.write(value);
}
break;
case PG_TYPE_GEOMETRY:
Object val = rs.getObject(column);
if (val != null) {
Blob blob = GeometryUtils.geometryToEwkb((GeometryType) rs.unwrap(ResultSetImpl.class).getRawCurrentValue());
String hexewkb = PropertiesUtils.toHex(blob.getBytes(1, (int) blob.length()));
writer.write(hexewkb);
}
break;
case PG_TYPE_XML:
case PG_TYPE_TEXT:
Reader r = rs.getCharacterStream(column);
if (r != null) {
try {
ObjectConverterUtil.write(writer, r, this.maxLobSize, false);
} finally {
r.close();
}
}
break;
case PG_TYPE_BYTEA:
Blob blob = rs.getBlob(column);
if (blob != null) {
try {
String blobString = PGbytea.toPGString(ObjectConverterUtil.convertToByteArray(blob.getBinaryStream(), this.maxLobSize));
writer.write(blobString);
} catch (OutOfMemoryError e) {
// $NON-NLS-1$
throw new StreamCorruptedException("data too big: " + e.getMessage());
}
}
break;
case PG_TYPE_CHARARRAY:
case PG_TYPE_TEXTARRAY:
case PG_TYPE_OIDARRAY:
case PG_TYPE_BOOLARRAY:
case PG_TYPE_INT2ARRAY:
case PG_TYPE_INT4ARRAY:
case PG_TYPE_INT8ARRAY:
case PG_TYPE_FLOAT4ARRAY:
case PG_TYPE_FLOAT8ARRAY:
case PG_TYPE_NUMERICARRAY:
case PG_TYPE_DATEARRAY:
case PG_TYPE_TIMEARRAY:
case PG_TYPE_TIMESTAMP_NO_TMZONEARRAY:
{
Array obj = rs.getArray(column);
if (obj != null) {
writer.append("{");
boolean first = true;
Object array = obj.getArray();
int length = java.lang.reflect.Array.getLength(array);
for (int i = 0; i < length; i++) {
if (!first) {
writer.append(",");
} else {
first = false;
}
Object o = java.lang.reflect.Array.get(array, i);
if (o != null) {
if (col.type == PG_TYPE_TEXTARRAY) {
escapeQuote(writer, o.toString());
} else {
writer.append(o.toString());
}
}
}
writer.append("}");
}
}
break;
case PG_TYPE_INT2VECTOR:
case PG_TYPE_OIDVECTOR:
{
ArrayImpl obj = (ArrayImpl) rs.getObject(column);
if (obj != null) {
boolean first = true;
for (Object o : obj.getValues()) {
if (!first) {
writer.append(" ");
} else {
first = false;
}
if (o != null) {
writer.append(o.toString());
} else {
writer.append('0');
}
}
}
}
break;
default:
Object obj = rs.getObject(column);
if (obj != null) {
throw new TeiidSQLException("unknown datatype " + col.type + " failed to convert");
}
break;
}
}
use of java.io.StreamCorruptedException in project teiid by teiid.
the class PgBackendProtocol method getBinaryContent.
private void getBinaryContent(ResultSet rs, PgColInfo col, int column) throws SQLException, TeiidSQLException, IOException {
switch(col.type) {
case PG_TYPE_INT2:
short sval = rs.getShort(column);
if (!rs.wasNull()) {
dataOut.writeShort(sval);
}
break;
case PG_TYPE_INT4:
int ival = rs.getInt(column);
if (!rs.wasNull()) {
dataOut.writeInt(ival);
}
break;
case PG_TYPE_INT8:
long lval = rs.getLong(column);
if (!rs.wasNull()) {
dataOut.writeLong(lval);
}
break;
case PG_TYPE_FLOAT4:
float fval = rs.getFloat(column);
if (!rs.wasNull()) {
dataOut.writeInt(Float.floatToIntBits(fval));
}
break;
case PG_TYPE_FLOAT8:
double dval = rs.getDouble(column);
if (!rs.wasNull()) {
dataOut.writeLong(Double.doubleToLongBits(dval));
}
break;
case PG_TYPE_BYTEA:
Blob blob = rs.getBlob(column);
if (blob != null) {
try {
byte[] bytes = ObjectConverterUtil.convertToByteArray(blob.getBinaryStream(), this.maxLobSize);
write(bytes);
} catch (OutOfMemoryError e) {
// $NON-NLS-1$
throw new StreamCorruptedException("data too big: " + e.getMessage());
}
}
break;
case PG_TYPE_DATE:
Date d = rs.getDate(column);
if (d != null) {
long millis = d.getTime();
millis += TimestampWithTimezone.getCalendar().getTimeZone().getOffset(millis);
long secs = TimestampUtils.toPgSecs(millis / 1000);
dataOut.writeInt((int) (secs / 86400));
}
break;
default:
throw new AssertionError();
}
}
Aggregations