當前位置: 首頁>>代碼示例>>Java>>正文


Java BufferedInputStream類代碼示例

本文整理匯總了Java中org.javarosa.core.io.BufferedInputStream的典型用法代碼示例。如果您正苦於以下問題:Java BufferedInputStream類的具體用法?Java BufferedInputStream怎麽用?Java BufferedInputStream使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


BufferedInputStream類屬於org.javarosa.core.io包,在下文中一共展示了BufferedInputStream類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: downloadToTemp

import org.javarosa.core.io.BufferedInputStream; //導入依賴的package包/類
private String downloadToTemp(String resource) {
    try{
        URL url = new URL(resource);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setInstanceFollowRedirects(true);  //you still need to handle redirect manully.
        HttpURLConnection.setFollowRedirects(true);

        File file = File.createTempFile("commcare_", ".ccz");

        FileOutputStream fos = new FileOutputStream(file);
        StreamsUtil.writeFromInputToOutput(new BufferedInputStream(conn.getInputStream()), fos);
        return file.getAbsolutePath();
    } catch(IOException e) {
        print.println("Issue downloading or create stream for " +resource);
        e.printStackTrace(print);
        System.exit(-1);
        return null;
    }
}
 
開發者ID:dimagi,項目名稱:commcare-j2me,代碼行數:20,代碼來源:CommCareConfigEngine.java

示例2: getStream

import org.javarosa.core.io.BufferedInputStream; //導入依賴的package包/類
public InputStream getStream() throws IOException {
    try {
        final HttpConnection connection = (HttpConnection)Connector.open(URI);
        connection.setRequestMethod(HttpConnection.GET);

        InputStream httpStream = connection.openInputStream();

        //Buffer our stream, since reading small units at a time from the network
        //increases the likelihood of network errors
        return new BufferedInputStream(httpStream) {
            /* (non-Javadoc)
             * @see java.io.InputStream#close()
             */
            public void close() throws IOException {
                //Some platforms were having issues with the connection close semantics
                //where it was supposed to close the connection when the stream was closed,
                //so we'll go ahead and move this here.
                connection.close();

                super.close();
            }
        };
    } catch(SecurityException se) {
        if(this.listener != null) {
            listener.onSecurityException(se);
        }
        throw new IOException("Couldn't retrieve data from " + this.getLocalURI() + " due to lack of permissions.");
    }
}
 
開發者ID:dimagi,項目名稱:commcare-j2me,代碼行數:30,代碼來源:HttpReference.java

示例3: testBuffered

import org.javarosa.core.io.BufferedInputStream; //導入依賴的package包/類
@Test
public void testBuffered() {
    //TODO: Test on this axis too?
    byte[] testBuffer = new byte[256];

    for (byte[] bytes : arraysToTest) {
        try {
            BufferedInputStream bis = new BufferedInputStream(new ByteArrayInputStream(bytes));
            ByteArrayOutputStream baos = new ByteArrayOutputStream();

            boolean done = false;
            while (!done) {
                int read = bis.read(testBuffer);
                if (read == -1) {
                    break;
                } else {
                    baos.write(testBuffer, 0, read);
                }
            }


            if (!ArrayUtilities.arraysEqual(bytes, baos.toByteArray())) {
                fail("Bulk BufferedInputStream read failed at size " + bytes.length);
            }
        } catch (Exception e) {
            fail("Exception while testing bulk read for " + bytes.length + " size: " + e.getMessage());
            continue;
        }
    }
}
 
開發者ID:dimagi,項目名稱:commcare-j2me,代碼行數:31,代碼來源:BufferedInputStreamTests.java

示例4: testIndividual

import org.javarosa.core.io.BufferedInputStream; //導入依賴的package包/類
@Test
public void testIndividual() {
    //TODO: Almost identical to above
    for (byte[] bytes : arraysToTest) {
        try {
            BufferedInputStream bis = new BufferedInputStream(new ByteArrayInputStream(bytes));
            int position = 0;

            boolean done = false;
            while (!done) {
                int read = bis.read();
                if (read == -1) {
                    break;
                } else {
                    if (bytes[position] != (byte)read) {
                        fail("one-by-one BIS read failed at size " + bytes.length + " at position " + position);
                    }
                }
                position++;
            }
            if (position != bytes.length) {
                fail("one-by-one BIS read failed to read full array of size " + bytes.length + " only read " + position);
            }
        } catch (Exception e) {
            fail("Exception while testing buffered read for " + bytes.length + " size: " + e.getMessage());
            continue;
        }
    }
}
 
開發者ID:dimagi,項目名稱:commcare-j2me,代碼行數:30,代碼來源:BufferedInputStreamTests.java

示例5: getResponse

import org.javarosa.core.io.BufferedInputStream; //導入依賴的package包/類
/**
 * @return The stream provided from the http connection
 * from the previous deliver attempt
 */
public InputStream getResponse() {
    return new BufferedInputStream(response);
}
 
開發者ID:dimagi,項目名稱:commcare-j2me,代碼行數:8,代碼來源:AuthenticatedHttpTransportMessage.java


注:本文中的org.javarosa.core.io.BufferedInputStream類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。