当前位置: 首页>>代码示例>>Java>>正文


Java HttpConnection.openDataInputStream方法代码示例

本文整理汇总了Java中javax.microedition.io.HttpConnection.openDataInputStream方法的典型用法代码示例。如果您正苦于以下问题:Java HttpConnection.openDataInputStream方法的具体用法?Java HttpConnection.openDataInputStream怎么用?Java HttpConnection.openDataInputStream使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.microedition.io.HttpConnection的用法示例。


在下文中一共展示了HttpConnection.openDataInputStream方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: urlToStream

import javax.microedition.io.HttpConnection; //导入方法依赖的package包/类
/**
 * Reads the content from the specified HTTP URL and returns InputStream
 * where the contents are read.
 * 
 * @return InputStream
 * @throws IOException
 */
private InputStream urlToStream(String url) throws IOException {
    // Open connection to the http url...
    HttpConnection connection = (HttpConnection) Connector.open(url);
    DataInputStream dataIn = connection.openDataInputStream();
    byte[] buffer = new byte[1000];
    int read = -1;
    // Read the content from url.
    ByteArrayOutputStream byteout = new ByteArrayOutputStream();
    while ((read = dataIn.read(buffer)) >= 0) {
        byteout.write(buffer, 0, read);
    }
    dataIn.close();
    // Fill InputStream to return with content read from the URL.
    ByteArrayInputStream byteIn = new ByteArrayInputStream(byteout.toByteArray());
    return byteIn;
}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:24,代码来源:Media.java

示例2: urlToStream

import javax.microedition.io.HttpConnection; //导入方法依赖的package包/类
/**
 * Reads the content from the specified HTTP URL and returns InputStream
 * where the contents are read.
 * 
 * @return InputStream
 * @throws IOException
 */
private InputStream urlToStream(String url) throws IOException {
    // Open connection to the http url...
    HttpConnection connection = (HttpConnection) Connector.open(url);
    DataInputStream dataIn = connection.openDataInputStream();
    byte[] buffer = new byte[1000];
    int read = -1;
    // Read the content from url.
    ByteArrayOutputStream byteout = new ByteArrayOutputStream();
    while ((read = dataIn.read(buffer)) >= 0) {
        byteout.write(buffer, 0, read);
    }
    dataIn.close();
    connection.close();
    // Fill InputStream to return with content read from the URL.
    ByteArrayInputStream byteIn = new ByteArrayInputStream(byteout.toByteArray());
    return byteIn;
}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:25,代码来源:VideoCanvas.java

示例3: submitBug

import javax.microedition.io.HttpConnection; //导入方法依赖的package包/类
public static void submitBug(Location location, String text, String user) {
    String url = API_URL + "addPOIexec?lat=" + location.getY() + "&lon=" + location.getX()
            + "&text=" + urlEncode(text) + "&format=js";
    try {
        HttpConnection httpConn = (HttpConnection) Connector.open(url);
        ByteArrayOutputStream reply = new ByteArrayOutputStream();
        InputStream in = httpConn.openDataInputStream();
        for (int b = in.read(); b != -1; b = in.read()) {
            reply.write(b);
        }
        in.close();
        System.out.println("OpenStreetBugs reply: " + reply.toString());
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}
 
开发者ID:cli,项目名称:worldmap-classic,代码行数:17,代码来源:OpenStreetBugs.java

示例4: processResponse

import javax.microedition.io.HttpConnection; //导入方法依赖的package包/类
private long processResponse(HttpConnection conn, long[] responseRead) throws IOException {
    responseProperties = HttpRequestProperties.HttpResponsePropertyFactory(conn);

    long responseLength = -1;

    DataInputStream is = null;

    try {
        responseLength = conn.getLength();

        is = (DataInputStream) conn.openDataInputStream();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        StreamsUtil.writeFromInputToOutput(is, baos, responseRead);

        // set return information in the message
        this.setResponseBody(baos.toByteArray());
        this.setResponseCode(conn.getResponseCode());
        if (responseCode >= 200 && responseCode <= 299) {
            this.setStatus(TransportMessageStatus.SENT);
        } else {
            Logger.log("send", this.getTag() + " http resp code: " + responseCode);
        }
        return responseLength;
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (IOException e) {
                // do nothing
            }
        }

    }
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:35,代码来源:SimpleHttpTransportMessage.java

示例5: readConnection

import javax.microedition.io.HttpConnection; //导入方法依赖的package包/类
private byte[] readConnection(HttpConnection c) throws IOException {
	InputStream is = c.openDataInputStream();;
	try {
		byte[] data;
	    // Get the length and process the data
	    int len = (int)c.getLength();
	    if (len > 0) {
	        int actual = 0;
	        int bytesread = 0 ;
	        data = new byte[len];
	        while ((bytesread != len) && (actual != -1)) {
	           actual = is.read(data, bytesread, len - bytesread);
	           bytesread += actual;
	        }
	    } else {
	        int bytesread = 0, lastread;
	        data = new byte[1024];
	        while ((lastread = is.read(data, bytesread, Math.min(1024, data.length - bytesread))) != -1) {
	        	bytesread += lastread;
	        	if(data.length <= bytesread) {
	        		byte[] newData = new byte[data.length * 2];
	        		for(int i = 0; i < data.length; i++)
	        			newData[i] = data[i];
	        		data = newData;
	        	}
	        }
	    }
	    return data;
	} finally { is.close(); }
}
 
开发者ID:wvdschel,项目名称:twitsy,代码行数:31,代码来源:TweetUpdateRunnable.java

示例6: readConnection

import javax.microedition.io.HttpConnection; //导入方法依赖的package包/类
private static byte[] readConnection(HttpConnection c) throws IOException {
	InputStream is = c.openDataInputStream();;
	try {
		byte[] data;
	    // Get the length and process the data
	    int len = (int)c.getLength();
	    if (len > 0) {
	        int actual = 0;
	        int bytesread = 0 ;
	        data = new byte[len];
	        while ((bytesread != len) && (actual != -1)) {
	           actual = is.read(data, bytesread, len - bytesread);
	           bytesread += actual;
	        }
	    } else {
	        int bytesread = 0, lastread;
	        data = new byte[1024];
	        while ((lastread = is.read(data, bytesread, Math.min(1024, data.length - bytesread))) != -1) {
	        	bytesread += lastread;
	        	if(data.length <= bytesread) {
	        		byte[] newData = new byte[data.length * 2];
	        		for(int i = 0; i < data.length; i++)
	        			newData[i] = data[i];
	        		data = newData;
	        	}
	        }
	    }
	    return data;
	} finally { is.close(); }
}
 
开发者ID:wvdschel,项目名称:twitsy,代码行数:31,代码来源:HttpFetcher.java

示例7: run

import javax.microedition.io.HttpConnection; //导入方法依赖的package包/类
public void run() {
    // Call to
    // /api/0.1/getBugs?b=36.17496&t=61.03797&l=-9.9793&r=31.54902&ucid=1
    // Reply is something like: putAJAXMarker(552542, 6.971592, 50.810296,
    // 'Strassensystem auf Friedhof fehlt [TobiR, 2010-08-09 23:30:37
    // CEST]', 0);
    try {
        String url = OpenStreetBugs.API_URL + "getBugs?b=" + ymin + "&t=" + ymax + "&l=" + xmin
                + "&r=" + xmax;
        HttpConnection httpConn = (HttpConnection) Connector.open(url);
        DataInputStream in = httpConn.openDataInputStream();
        ByteArrayOutputStream buf = new ByteArrayOutputStream();

        int openbrackets = 0;
        for (int b = in.read(); b != -1; b = in.read()) {
            char c = (char) b;
            if (c == ')') {
                openbrackets--;
                if (openbrackets == 0) {
                    Bug bug = Bug.parse(buf.toString());
                    buf.reset();
                    if (bug != null) {
                        rec.receiveBug(bug);
                        if (++receivedBugs >= MAX_BUGS) {
                            break;
                        }
                    }
                }
            } else if (c == '(') {
                openbrackets++;
            } else if (openbrackets > 0) { // only store bytes between '('
                                           // ')'
                buf.write(b);
            }
        }

        in.close();
        httpConn.close();
    } catch (IOException ex) {
        ex.printStackTrace();
    } catch (Throwable t) {
        t.printStackTrace();
    }
}
 
开发者ID:cli,项目名称:worldmap-classic,代码行数:45,代码来源:BugLoader.java


注:本文中的javax.microedition.io.HttpConnection.openDataInputStream方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。