2021-09-15
public class SerializableStream implements Serializable {
private final static int LENGTH = 1024;
private byte[] bytes;
public byte[] getBytes() {
return bytes;
}
public void setBytes(byte[] bytes) {
this.bytes = bytes;
}
public InputStream getInputStream() {
InputStream inputStream = IOUtils.toInputStream(Arrays.toString(bytes), Charset.defaultCharset());
return inputStream;
}
private ObjectOutputStream writeObject(InputStream is, ObjectOutputStream oos) {
try {
oos.defaultWriteObject();
byte[] buff = new byte[LENGTH];
int tmp;
while ((tmp = is.read(buff, 0, LENGTH)) != -1) {
oos.write(buff, 0, tmp);
}
return oos;
} catch (Exception e) {
throw new BaseException(e);
}
}
private InputStream readObject(InputSt