Can I serialize an array of bytes in java?

I have a method in which I get an input stream, I need to first decrypt this data serialize this data. But my data is not serialized. 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 an array of bytes?

+4
source share
1 answer

The answer to your question:

Can I serialize an array of bytes?

This is actually “you don't need to do this”. Your code appears to write bytes to disk and then read bytes from disk; everything is transparent, you are doing quite nicely.

Does your code generate any errors?

+2
source

Source: https://habr.com/ru/post/1527908/


All Articles