Search in sources :

Example 6 with BufferedInputStream

use of com.codename1.io.BufferedInputStream in project CodenameOne by codenameone.

the class AndroidImplementation method openInputStream.

/**
 * @inheritDoc
 */
public InputStream openInputStream(Object connection) throws IOException {
    if (connection instanceof String) {
        String con = (String) connection;
        if (con.startsWith("file://")) {
            con = con.substring(7);
        }
        InputStream fc = createFileInputStream(con);
        BufferedInputStream o = new BufferedInputStream(fc, con);
        return o;
    }
    if (connection instanceof HttpURLConnection) {
        HttpURLConnection ht = (HttpURLConnection) connection;
        if (ht.getResponseCode() < 400) {
            return new BufferedInputStream(ht.getInputStream());
        }
        return new BufferedInputStream(ht.getErrorStream());
    } else {
        return new BufferedInputStream(((URLConnection) connection).getInputStream());
    }
}
Also used : HttpURLConnection(java.net.HttpURLConnection) BufferedInputStream(com.codename1.io.BufferedInputStream) BufferedInputStream(com.codename1.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream)

Example 7 with BufferedInputStream

use of com.codename1.io.BufferedInputStream in project CodenameOne by codenameone.

the class GameCanvasImplementation method openInputStream.

/**
 * @inheritDoc
 */
public InputStream openInputStream(Object connection) throws IOException {
    if (connection instanceof String) {
        FileConnection fc = (FileConnection) Connector.open((String) connection, Connector.READ);
        BufferedInputStream o = new BufferedInputStream(fc.openInputStream(), (String) connection);
        o.setConnection(fc);
        return o;
    }
    return new BufferedInputStream(((HttpConnection) connection).openInputStream(), ((HttpConnection) connection).getURL());
}
Also used : BufferedInputStream(com.codename1.io.BufferedInputStream) FileConnection(javax.microedition.io.file.FileConnection)

Aggregations

BufferedInputStream (com.codename1.io.BufferedInputStream)6 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 FileConnection (javax.microedition.io.file.FileConnection)2 CodenameOneImplementation (com.codename1.impl.CodenameOneImplementation)1 NetworkEvent (com.codename1.io.NetworkEvent)1 FontFormatException (java.awt.FontFormatException)1 Point (java.awt.Point)1 EOFException (java.io.EOFException)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 OutputStream (java.io.OutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 HttpURLConnection (java.net.HttpURLConnection)1 SQLException (java.sql.SQLException)1 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Vector (java.util.Vector)1