Popular Posts
Enable SSL connection for Jsoup import org.jsoup.Connection; import org.jsoup.Jsoup; import javax.net.ssl.*; import java.io.IOException; import java.security.KeyManagement... javax.net.ssl.SSLHandshakeException: Connection closed by peer in Android 5.0 Lollipop Recently, there is a error occurs when access website via ssl connection like below although it worked fine several days ago. // Enable SSL... Tired of Hibernate? Try JDBI in your code JDBI Quick sample ICategoryDAO.java : create a data access interface (implement is not required) package com.prhythm.erotic.task.data....
Stats
StreamReader
package bruce.lib.io;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * @author Bruce Tsai
 * 
 */
public class StreamReader {

    private InputStream stream;
    public String encoding;

    /**
     * @param stream
     */
    public StreamReader(InputStream stream) {
        this.stream = stream;
    }

    /**
     * @param stream
     * @param encoding
     */
    public StreamReader(InputStream stream, String encoding) {
        this.stream = stream;
        this.encoding = encoding;
    }

    /**
     * @return
     * @throws IOException
     */
    public String readAllText() throws IOException {
        return this.encoding == null || this.encoding.length() == 0 ? new String(readAllBytes()) : new String(readAllBytes(), this.encoding);
    }

    /**
     * @return
     * @throws IOException
     */
    public byte[] readAllBytes() throws IOException {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        byte[] buffer = new byte[128];
        int readed = -1;
        while ((readed = this.stream.read(buffer)) > -1) {
            baos.write(buffer, 0, readed);
        }
        baos.close();
        this.stream.close();
        return baos.toByteArray();
    }
}