StreamGobbler.java 1.59 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.pdfg.logging.PDFGLogger
 */
package com.adobe.pdfg.common;

import com.adobe.pdfg.logging.PDFGLogger;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class StreamGobbler
extends Thread {
    private final int BUFLEN = 512;
    private byte[] buffer = new byte[512];
    private PDFGLogger pdfgLogger = PDFGLogger.getPDFGLogger(StreamGobbler.class);
    final InputStream is;
    final OutputStream copyTo;

    public StreamGobbler(String name, InputStream is, OutputStream copyTo) {
        super(name);
        this.setDaemon(true);
        this.is = is;
        this.copyTo = copyTo;
    }

    public void run() {
        try {
            int bytesRead;
            while (!StreamGobbler.interrupted() && (bytesRead = this.is.read(this.buffer)) != -1) {
                if (this.copyTo == null) continue;
                this.copyTo.write(this.buffer, 0, bytesRead);
            }
        }
        catch (IOException e) {
            this.pdfgLogger.trace(e.getMessage(), null, (Throwable)e);
        }
        try {
            this.is.close();
        }
        catch (IOException e) {
            this.pdfgLogger.trace(e.getMessage(), null, (Throwable)e);
        }
    }

    public void collectThread() {
        this.interrupt();
        try {
            this.join(1000);
        }
        catch (InterruptedException e) {
            this.pdfgLogger.trace(e.getMessage(), null, (Throwable)e);
        }
        if (this.isAlive()) {
            this.interrupt();
        }
    }
}