113 lines
3.2 KiB
Java
113 lines
3.2 KiB
Java
/* */ package kong.unirest.cosmetics;
|
|
/* */
|
|
/* */ import java.io.IOException;
|
|
/* */ import java.io.InputStream;
|
|
/* */ import java.nio.file.Path;
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */ class MonitoringInputStream
|
|
/* */ extends InputStream
|
|
/* */ {
|
|
/* */ private final InputStream content;
|
|
/* */ private final ProgressMonitor downloadMonitor;
|
|
/* */ private long totalSize;
|
|
/* 36 */ private long byteCount = 0L;
|
|
/* */ private String fileName;
|
|
/* */
|
|
/* */ MonitoringInputStream(InputStream content, ProgressMonitor downloadMonitor, Path target, RawResponse contentSize) {
|
|
/* 40 */ this.content = content;
|
|
/* 41 */ this.downloadMonitor = downloadMonitor;
|
|
/* 42 */ this.fileName = target.getFileName().toString();
|
|
/* 43 */ this.totalSize = getBodySize(contentSize).longValue();
|
|
/* */ }
|
|
/* */
|
|
/* */ private Long getBodySize(RawResponse r) {
|
|
/* 47 */ String header = r.getHeaders().getFirst("Content-Length");
|
|
/* 48 */ if (header != null && header.length() > 0) {
|
|
/* 49 */ return Long.valueOf(header);
|
|
/* */ }
|
|
/* 51 */ return Long.valueOf(0L);
|
|
/* */ }
|
|
/* */
|
|
/* */
|
|
/* */ public int read() throws IOException {
|
|
/* 56 */ return this.content.read();
|
|
/* */ }
|
|
/* */
|
|
/* */
|
|
/* */ public int read(byte[] b) throws IOException {
|
|
/* 61 */ int read = super.read(b);
|
|
/* 62 */ monitor(read);
|
|
/* 63 */ return read;
|
|
/* */ }
|
|
/* */
|
|
/* */
|
|
/* */ public int read(byte[] b, int off, int len) throws IOException {
|
|
/* 68 */ int read = super.read(b, off, len);
|
|
/* 69 */ monitor(read);
|
|
/* 70 */ return read;
|
|
/* */ }
|
|
/* */
|
|
/* */ private void monitor(int bytesRead) {
|
|
/* 74 */ this.byteCount += bytesRead;
|
|
/* 75 */ this.downloadMonitor.accept("body", this.fileName, Long.valueOf(this.byteCount), Long.valueOf(this.totalSize));
|
|
/* */ }
|
|
/* */
|
|
/* */
|
|
/* */ public void close() throws IOException {
|
|
/* 80 */ this.content.close();
|
|
/* */ }
|
|
/* */
|
|
/* */
|
|
/* */ public long skip(long n) throws IOException {
|
|
/* 85 */ return this.content.skip(n);
|
|
/* */ }
|
|
/* */
|
|
/* */
|
|
/* */ public int available() throws IOException {
|
|
/* 90 */ return this.content.available();
|
|
/* */ }
|
|
/* */
|
|
/* */
|
|
/* */ public synchronized void mark(int readlimit) {
|
|
/* 95 */ this.content.mark(readlimit);
|
|
/* */ }
|
|
/* */
|
|
/* */
|
|
/* */ public boolean markSupported() {
|
|
/* 100 */ return this.content.markSupported();
|
|
/* */ }
|
|
/* */
|
|
/* */
|
|
/* */ public synchronized void reset() throws IOException {
|
|
/* 105 */ this.content.reset();
|
|
/* */ }
|
|
/* */ }
|
|
|
|
|
|
/* Location: C:\Users\Xiao\Downloads\MinehutCosmetics.jar!\kon\\unirest\cosmetics\MonitoringInputStream.class
|
|
* Java compiler version: 11 (55.0)
|
|
* JD-Core Version: 1.1.3
|
|
*/ |