本文整理汇总了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;
}
}
示例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.");
}
}
示例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;
}
}
}
示例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;
}
}
}
示例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);
}