我有一个接收输入流的方法,我需要先解密该数据然后 序列化该数据。但是我的数据没有序列化。我的文件是一个哈希文件。 请帮我。我的代码是 -
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);
这是我的第二种方法-
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 ?
其实就是“你不需要这样做”。您的代码显然将字节写入磁盘,然后从磁盘读取字节;一切都是透明的,你做得很好。
您的代码会产生任何错误吗?
关于java - 我可以在java中序列化字节数组吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21910144/