mirror of
https://github.com/VibedByKaKi/alexandroid.git
synced 2026-11-29 09:13:24 +01:00
76 lines
2.2 KiB
Java
76 lines
2.2 KiB
Java
package org.apache.http.entity;
|
|
|
|
import java.io.File;
|
|
import java.io.FileInputStream;
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.io.OutputStream;
|
|
import org.apache.http.util.Args;
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
/* loaded from: classes11.dex */
|
|
public class FileEntity extends AbstractHttpEntity implements Cloneable {
|
|
protected final File file;
|
|
|
|
public FileEntity(File file, ContentType contentType) {
|
|
this.file = (File) Args.notNull(file, "File");
|
|
if (contentType != null) {
|
|
setContentType(contentType.toString());
|
|
}
|
|
}
|
|
|
|
public Object clone() throws CloneNotSupportedException {
|
|
return super.clone();
|
|
}
|
|
|
|
@Override // org.apache.http.HttpEntity
|
|
public InputStream getContent() throws IOException {
|
|
return new FileInputStream(this.file);
|
|
}
|
|
|
|
@Override // org.apache.http.HttpEntity
|
|
public long getContentLength() {
|
|
return this.file.length();
|
|
}
|
|
|
|
@Override // org.apache.http.HttpEntity
|
|
public boolean isRepeatable() {
|
|
return true;
|
|
}
|
|
|
|
@Override // org.apache.http.HttpEntity
|
|
public boolean isStreaming() {
|
|
return false;
|
|
}
|
|
|
|
@Override // org.apache.http.HttpEntity
|
|
public void writeTo(OutputStream outputStream) throws IOException {
|
|
Args.notNull(outputStream, "Output stream");
|
|
FileInputStream fileInputStream = new FileInputStream(this.file);
|
|
try {
|
|
byte[] bArr = new byte[4096];
|
|
while (true) {
|
|
int read = fileInputStream.read(bArr);
|
|
if (read == -1) {
|
|
outputStream.flush();
|
|
fileInputStream.close();
|
|
return;
|
|
}
|
|
outputStream.write(bArr, 0, read);
|
|
}
|
|
} catch (Throwable th) {
|
|
fileInputStream.close();
|
|
throw th;
|
|
}
|
|
}
|
|
|
|
@Deprecated
|
|
public FileEntity(File file, String str) {
|
|
this.file = (File) Args.notNull(file, "File");
|
|
setContentType(str);
|
|
}
|
|
|
|
public FileEntity(File file) {
|
|
this.file = (File) Args.notNull(file, "File");
|
|
}
|
|
}
|