I have a method where I am receiving input stream, I need to decrypt that data first then serialize that data. But my data is not getting serialize. My file is a hash file. Please help me. My code is -
private byte[] getSerializeEncryptedBytes(InputStream inputStream,String password)
throws Exception {
byte[] fileBytes = getByteArrayFromInputStream(inputStream);
fileBytes = AESEncrytion.getDecryptedData(fileBytes, password);
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(fileBytes);
ObjectInputStream objectInputStream = objectInputStream = new
ObjectInputStream(byteArrayInputStream);
Object dataObject = objectInputStream.readObject();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutput out = new ObjectOutputStream(bos);
out.writeObject(fileBytes);
out.flush();
byte[] serializeByte = bos.toByteArray();
out.close();
Util.writeFileNewWay(new File("soapSerialized.txt"), serializeByte);
This is my second method -
public byte[] getByteArrayFromInputStream(InputStream inputStream) throws
IOException {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
int nRead;
byte[] data = new byte[16384];
while ((nRead = inputStream.read(data, 0, data.length)) != -1) {
buffer.write(data, 0, nRead);
}
buffer.flush();
return buffer.toByteArray();
}
Can I serialize byte array ?