mirror of
https://github.com/VibedByKaKi/alexandroid.git
synced 2026-11-29 09:13:24 +01:00
79 lines
2.5 KiB
Java
79 lines
2.5 KiB
Java
package org.apache.http.entity;
|
|
|
|
import java.io.ByteArrayInputStream;
|
|
import java.io.ByteArrayOutputStream;
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.io.ObjectOutputStream;
|
|
import java.io.OutputStream;
|
|
import java.io.Serializable;
|
|
import org.apache.http.util.Args;
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
/* loaded from: classes11.dex */
|
|
public class SerializableEntity extends AbstractHttpEntity {
|
|
private Serializable objRef;
|
|
private byte[] objSer;
|
|
|
|
public SerializableEntity(Serializable serializable, boolean z) throws IOException {
|
|
Args.notNull(serializable, "Source object");
|
|
if (z) {
|
|
createBytes(serializable);
|
|
} else {
|
|
this.objRef = serializable;
|
|
}
|
|
}
|
|
|
|
private void createBytes(Serializable serializable) throws IOException {
|
|
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
|
|
objectOutputStream.writeObject(serializable);
|
|
objectOutputStream.flush();
|
|
this.objSer = byteArrayOutputStream.toByteArray();
|
|
}
|
|
|
|
@Override // org.apache.http.HttpEntity
|
|
public InputStream getContent() throws IOException, IllegalStateException {
|
|
if (this.objSer == null) {
|
|
createBytes(this.objRef);
|
|
}
|
|
return new ByteArrayInputStream(this.objSer);
|
|
}
|
|
|
|
@Override // org.apache.http.HttpEntity
|
|
public long getContentLength() {
|
|
if (this.objSer == null) {
|
|
return -1L;
|
|
}
|
|
return r2.length;
|
|
}
|
|
|
|
@Override // org.apache.http.HttpEntity
|
|
public boolean isRepeatable() {
|
|
return true;
|
|
}
|
|
|
|
@Override // org.apache.http.HttpEntity
|
|
public boolean isStreaming() {
|
|
return this.objSer == null;
|
|
}
|
|
|
|
@Override // org.apache.http.HttpEntity
|
|
public void writeTo(OutputStream outputStream) throws IOException {
|
|
Args.notNull(outputStream, "Output stream");
|
|
byte[] bArr = this.objSer;
|
|
if (bArr != null) {
|
|
outputStream.write(bArr);
|
|
outputStream.flush();
|
|
} else {
|
|
ObjectOutputStream objectOutputStream = new ObjectOutputStream(outputStream);
|
|
objectOutputStream.writeObject(this.objRef);
|
|
objectOutputStream.flush();
|
|
}
|
|
}
|
|
|
|
public SerializableEntity(Serializable serializable) {
|
|
Args.notNull(serializable, "Source object");
|
|
this.objRef = serializable;
|
|
}
|
|
}
|