Java Examples for java.io.BufferedInputStream
The following java examples will help you to understand the usage of java.io.BufferedInputStream. These source code samples are taken from different open source projects.
Example 1
| Project: CPP-Programs-master File: FileDownloader.java View source code |
public static void main(String args[]) throws IOException {
java.io.BufferedInputStream in = new java.io.BufferedInputStream(new java.net.URL("http://cl.thapar.edu/qp/CH016.pdf").openStream());
java.io.FileOutputStream fos = new java.io.FileOutputStream("t est.pdf");
java.io.BufferedOutputStream bout = new BufferedOutputStream(fos, 1024);
byte[] data = new byte[1024];
int x = 0;
while ((x = in.read(data, 0, 1024)) >= 0) {
bout.write(data, 0, x);
}
bout.close();
in.close();
}Example 2
| Project: aetheria-master File: Downloader.java View source code |
/**
* Downloads file from an URL and saves it to a path in the local machine
* @throws FileNotFoundException, IOException
*/
public static void urlToFile(URL url, File path) throws FileNotFoundException, IOException {
java.io.BufferedInputStream in = new java.io.BufferedInputStream(url.openStream());
java.io.FileOutputStream fos = new java.io.FileOutputStream(path);
java.io.BufferedOutputStream bout = new BufferedOutputStream(fos, 1024);
byte[] data = new byte[1024];
int x = 0;
while ((x = in.read(data, 0, 1024)) >= 0) {
bout.write(data, 0, x);
}
bout.close();
in.close();
}Example 3
| Project: android-ssl-master File: IOUtil.java View source code |
public static String readFully(InputStream inputStream) throws IOException {
if (inputStream == null) {
return "";
}
BufferedInputStream bufferedInputStream = null;
ByteArrayOutputStream byteArrayOutputStream = null;
try {
bufferedInputStream = new BufferedInputStream(inputStream);
byteArrayOutputStream = new ByteArrayOutputStream();
final byte[] buffer = new byte[1024];
int available = 0;
while ((available = bufferedInputStream.read(buffer)) >= 0) {
byteArrayOutputStream.write(buffer, 0, available);
}
return byteArrayOutputStream.toString();
} finally {
if (bufferedInputStream != null) {
bufferedInputStream.close();
}
}
}Example 4
| Project: eclipse-commons-master File: FileUtils.java View source code |
public static String readFileAsString(String filePath) throws IOException {
byte[] buffer = new byte[(int) new File(filePath).length()];
BufferedInputStream stream = null;
try {
stream = new BufferedInputStream(new FileInputStream(filePath));
stream.read(buffer);
} finally {
if (stream != null) {
stream.close();
}
}
return new String(buffer);
}Example 5
| Project: JAVA-KOANS-master File: FileUtils.java View source code |
public static String readFileAsString(File file) {
byte[] buffer = new byte[(int) file.length()];
BufferedInputStream f = null;
try {
f = new BufferedInputStream(new FileInputStream(file));
f.read(buffer);
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
if (f != null)
try {
f.close();
} catch (IOException ignored) {
}
}
return new String(buffer);
}Example 6
| Project: Java_Training-master File: HttpTest.java View source code |
/**
* @param args
*/
public static void main(String[] args) {
URL url = null;
HttpURLConnection http = null;
BufferedInputStream bis = null;
try {
url = new URL("http://yahoo.co.jp");
http = (HttpURLConnection) url.openConnection();
http.setRequestMethod("GET");
http.connect();
bis = new BufferedInputStream(http.getInputStream());
int data;
while ((data = bis.read()) != -1) {
System.out.write(data);
}
} catch (Exception e) {
System.out.println(e);
}
}Example 7
| Project: kannel-java-master File: Utils.java View source code |
public static String getFileContent(String fileName) throws Exception {
File file = new File(fileName);
FileInputStream fis = new FileInputStream(file);
BufferedInputStream bis = new BufferedInputStream(fis);
DataInputStream dis = new DataInputStream(bis);
StringBuffer content = new StringBuffer();
while (dis.available() != 0) {
content.append(dis.readLine());
}
fis.close();
bis.close();
dis.close();
return content.toString();
}Example 8
| Project: koa-master File: FileUtils.java View source code |
public static String readFileAsString(File file) {
byte[] buffer = new byte[(int) file.length()];
BufferedInputStream f = null;
try {
f = new BufferedInputStream(new FileInputStream(file));
f.read(buffer);
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
if (f != null)
try {
f.close();
} catch (IOException ignored) {
}
}
return new String(buffer);
}Example 9
| Project: LimeWire-Pirate-Edition-master File: ProcessUtils.java View source code |
/**
* Consumes all input from a Process. See also
* ProcessBuilder.redirectErrorStream()
*/
public static void consumeAllInput(Process p) throws IOException {
InputStream in = null;
try {
in = new BufferedInputStream(p.getInputStream());
byte[] buf = new byte[1024];
while (in.read(buf, 0, buf.length) >= 0) ;
} finally {
try {
if (in != null) {
in.close();
}
} catch (IOException ignored) {
}
}
}Example 10
| Project: limewire5-ruby-master File: ProcessUtils.java View source code |
/**
* Consumes all input from a Process. See also
* ProcessBuilder.redirectErrorStream()
*/
public static void consumeAllInput(Process p) throws IOException {
InputStream in = null;
try {
in = new BufferedInputStream(p.getInputStream());
byte[] buf = new byte[1024];
while (in.read(buf, 0, buf.length) >= 0) ;
} finally {
try {
if (in != null) {
in.close();
}
} catch (IOException ignored) {
}
}
}Example 11
| Project: lumify-master File: TikaMimeTypeMapper.java View source code |
public String guessMimeType(InputStream in, String fileName) throws Exception {
Metadata metadata = new Metadata();
metadata.set(LumifyMimeTypeDetector.METADATA_FILENAME, fileName);
MediaType mediaType = detector.detect(new BufferedInputStream(in), metadata);
String mimeType = mediaType.toString();
if (mimeType != null) {
return mimeType;
}
return "application/octet-stream";
}Example 12
| Project: android-sdk-sources-for-api-level-23-master File: BufferedInputStreamTest.java View source code |
/*
* java.io.BufferedInputStream(InputStream)
*/
public void test_ConstructorLjava_io_InputStreamI() throws IOException {
try {
BufferedInputStream str = new BufferedInputStream(null, 1);
str.read();
fail("Expected an IOException");
} catch (IOException e) {
}
// Test for method java.io.BufferedInputStream(java.io.InputStream, int)
// Create buffer with hald size of file and fill it.
int bufferSize = INPUT.length() / 2;
is = new BufferedInputStream(isBytes, bufferSize);
// Ensure buffer gets filled by evaluating one read
is.read();
// Close underlying FileInputStream, all but 1 buffered bytes should
// still be available.
isBytes.close();
// Read the remaining buffered characters, no IOException should
// occur.
is.skip(bufferSize - 2);
is.read();
try {
// is.read should now throw an exception because it will have to
// be filled.
is.read();
fail("Exception should have been triggered by read()");
} catch (IOException e) {
}
// regression test for harmony-2407
new MockBufferedInputStream(null);
assertNotNull(MockBufferedInputStream.buf);
MockBufferedInputStream.buf = null;
new MockBufferedInputStream(null, 100);
assertNotNull(MockBufferedInputStream.buf);
}Example 13
| Project: ARTPart-master File: BufferedInputStreamTest.java View source code |
/*
* java.io.BufferedInputStream(InputStream)
*/
public void test_ConstructorLjava_io_InputStreamI() throws IOException {
try {
BufferedInputStream str = new BufferedInputStream(null, 1);
str.read();
fail("Expected an IOException");
} catch (IOException e) {
}
// Test for method java.io.BufferedInputStream(java.io.InputStream, int)
// Create buffer with hald size of file and fill it.
int bufferSize = INPUT.length() / 2;
is = new BufferedInputStream(isBytes, bufferSize);
// Ensure buffer gets filled by evaluating one read
is.read();
// Close underlying FileInputStream, all but 1 buffered bytes should
// still be available.
isBytes.close();
// Read the remaining buffered characters, no IOException should
// occur.
is.skip(bufferSize - 2);
is.read();
try {
// is.read should now throw an exception because it will have to
// be filled.
is.read();
fail("Exception should have been triggered by read()");
} catch (IOException e) {
}
// regression test for harmony-2407
new MockBufferedInputStream(null);
assertNotNull(MockBufferedInputStream.buf);
MockBufferedInputStream.buf = null;
new MockBufferedInputStream(null, 100);
assertNotNull(MockBufferedInputStream.buf);
}Example 14
| Project: AllArkhamPlugins-master File: PacketUtils.java View source code |
public static void saveUrl(final String filename, final String urlString) throws MalformedURLException, IOException {
NetworkManager.log.debug("Downloading " + filename + " from " + urlString + "...", PacketUtils.class);
BufferedInputStream in = null;
FileOutputStream fout = null;
try {
in = new BufferedInputStream(new URL(urlString).openStream());
fout = new FileOutputStream(filename);
final byte data[] = new byte[1024];
int count;
while ((count = in.read(data, 0, 1024)) != -1) {
fout.write(data, 0, count);
}
} finally {
if (in != null) {
in.close();
}
if (fout != null) {
fout.close();
}
}
NetworkManager.log.debug("Download of " + filename + " complete!", PacketUtils.class);
}Example 15
| Project: Bayesian-Nonparametric-Ontology-Learning-master File: AIW.java View source code |
public static int[] aiw() throws IOException {
File f = new File("/Users/nicholasbartlett/Documents/np_bayes/data/alice_in_wonderland/alice_in_wonderland.txt");
int[] aiw = new int[(int) f.length()];
BufferedInputStream bis = null;
try {
bis = new BufferedInputStream(new FileInputStream(f));
int b;
int index = 0;
while ((b = bis.read()) > -1) {
aiw[index++] = b;
}
} finally {
if (bis != null) {
bis.close();
}
}
return aiw;
}Example 16
| Project: BBC-News-Reader-master File: ImageDownloader.java View source code |
public static byte[] getImage(URL url) throws Exception {
URLConnection connection = url.openConnection();
InputStream stream = connection.getInputStream();
BufferedInputStream inputbuffer = new BufferedInputStream(stream, 8000);
ByteArrayBuffer arraybuffer = new ByteArrayBuffer(50);
int current = 0;
while ((current = inputbuffer.read()) != -1) {
arraybuffer.append((byte) current);
}
byte[] image = arraybuffer.toByteArray();
return image;
}Example 17
| Project: droiddraw-master File: FileCopier.java View source code |
public static void copy(File file, File dir, boolean overwrite) throws IOException {
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
File out = new File(dir, file.getName());
if (out.exists() && !overwrite) {
throw new IOException("File: " + out + " already exists.");
}
FileOutputStream fos = new FileOutputStream(out, false);
byte[] block = new byte[4096];
int read = bis.read(block);
while (read != -1) {
fos.write(block, 0, read);
read = bis.read(block);
}
}Example 18
| Project: dtangler-master File: FileUtil.java View source code |
public static String readFile(String fileName) {
try {
File file = new File(fileName);
BufferedInputStream stream = new BufferedInputStream(new FileInputStream(file));
byte[] bytes = new byte[(int) file.length()];
stream.read(bytes);
return new String(bytes);
} catch (Exception e) {
throw new RuntimeException(e);
}
}Example 19
| Project: embeddedlinux-jvmdebugger-intellij-master File: UrlDownloader.java View source code |
/**
* Saves a file to a path
*
* @param filename
* @param urlString
* @throws IOException
*/
public static void saveUrl(final String filename, final String urlString) throws IOException {
BufferedInputStream in = null;
FileOutputStream fout = null;
try {
in = new BufferedInputStream(new URL(urlString).openStream());
fout = new FileOutputStream(filename);
final byte data[] = new byte[1024];
int count;
while ((count = in.read(data, 0, 1024)) != -1) {
fout.write(data, 0, count);
}
} catch (Exception e) {
} finally {
if (in != null) {
in.close();
}
if (fout != null) {
fout.close();
}
}
}Example 20
| Project: ggp-base-master File: BaseHashing.java View source code |
// Computes the SHA1 hash of a given input string, and represents
// that hash as a hexadecimal string.
public static String computeSHA1Hash(String theData) {
try {
MessageDigest SHA1 = MessageDigest.getInstance("SHA1");
DigestInputStream theDigestStream = new DigestInputStream(new BufferedInputStream(new ByteArrayInputStream(theData.getBytes("UTF-8"))), SHA1);
while (theDigestStream.read() != -1) ;
byte[] theHash = SHA1.digest();
Formatter hexFormat = new Formatter();
for (byte x : theHash) {
hexFormat.format("%02x", x);
}
String theHex = hexFormat.toString();
hexFormat.close();
return theHex;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}Example 21
| Project: graphchi-java-master File: DegreeFileReader.java View source code |
public static void main(String[] args) throws Exception {
String degreeFile = args[0];
DataInputStream dis = new DataInputStream(new BufferedInputStream(new FileInputStream(degreeFile)));
int j = 0;
long totIn = 0;
long totOut = 0;
try {
while (true) {
int inDeg = Integer.reverseBytes(dis.readInt());
int outDeg = Integer.reverseBytes(dis.readInt());
j++;
totIn += inDeg;
totOut += outDeg;
if (j >= 100000 && j < 200000) {
System.out.println(j + ", " + inDeg + ", " + outDeg);
}
}
} catch (EOFException e) {
}
System.out.println(j + " in=" + totIn + " out=" + totOut);
}Example 22
| Project: IronCount-master File: ObjectSerializerTest.java View source code |
@Test
public void writeHandlerToDisk() throws Exception {
SerializedHandler h = new SerializedHandler();
ObjectSerializer instance = new ObjectSerializer();
byte[] result = instance.serializeObject(h);
java.io.BufferedOutputStream bi = new BufferedOutputStream(new FileOutputStream(new File("/tmp/abd")));
bi.write(result);
bi.close();
BufferedInputStream in = new BufferedInputStream(new FileInputStream(new File("/tmp/abd")));
}Example 23
| Project: ismp_manager-master File: ReadFile.java View source code |
public static void readFileToOutputStream(OutputStream out, String filePath) throws Exception {
BufferedInputStream inputstream = new BufferedInputStream(new FileInputStream(filePath));
byte[] b = new byte[100];
int len;
try {
while ((len = inputstream.read(b)) > 0) {
out.write(b, 0, len);
}
inputstream.close();
out.close();
} catch (Exception e) {
e.printStackTrace();
out.close();
throw new Exception("下载文件时出错�");
}
}Example 24
| Project: jumbodb-master File: BufTestIn.java View source code |
public static void main(String[] args) throws Exception {
FileInputStream fis = new FileInputStream("/Users/carsten/bla.buf");
BufferedInputStream bis = new BufferedInputStream(fis);
long start = System.currentTimeMillis();
long l = 24l * 1024l * 1024l * 1024l;
bis.skip(l);
byte[] b = new byte[128];
bis.read(b);
System.out.println(new String(b));
System.out.println("Time: " + (System.currentTimeMillis() - start));
bis.close();
bis.close();
fis.close();
}Example 25
| Project: LiveDroid-master File: Network.java View source code |
public static Bitmap loadBitmap(String url, AQuery aq) {
Bitmap bm = null;
InputStream is = null;
BufferedInputStream bis = null;
try {
URLConnection conn = new URL(url).openConnection();
conn.connect();
is = conn.getInputStream();
bis = new BufferedInputStream(is, 8192);
bm = BitmapFactory.decodeStream(bis);
aq.cache(url, 0).image(bm);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (bis != null) {
try {
bis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (is != null) {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return bm;
}Example 26
| Project: Makelangelo-master File: SoundSystem.java View source code |
public static void playSound(String url) {
if (url.isEmpty())
return;
try {
Clip clip = AudioSystem.getClip();
BufferedInputStream x = new BufferedInputStream(new FileInputStream(url));
AudioInputStream inputStream = AudioSystem.getAudioInputStream(x);
clip.open(inputStream);
clip.start();
} catch (Exception e) {
Log.error(e.getMessage());
}
}Example 27
| Project: Makelangelo-software-master File: SoundSystem.java View source code |
public static void playSound(String url) {
if (url.isEmpty())
return;
try {
Clip clip = AudioSystem.getClip();
BufferedInputStream x = new BufferedInputStream(new FileInputStream(url));
AudioInputStream inputStream = AudioSystem.getAudioInputStream(x);
clip.open(inputStream);
clip.start();
} catch (Exception e) {
Log.error(e.getMessage());
}
}Example 28
| Project: map-engine-master File: Main.java View source code |
public static void main(String[] args) throws Exception {
Engine engine = new Engine(Engine.class.getClassLoader().getResourceAsStream("create_catalog_directives.xml"));
StringBuilder xml = new StringBuilder();
byte[] buffer = new byte[4096];
int readed = 0;
try (BufferedInputStream bis = new BufferedInputStream(Main.class.getClassLoader().getResourceAsStream("in.xml"))) {
while ((readed = bis.read(buffer)) != -1) {
xml.append(new String(buffer, 0, readed));
}
}
@SuppressWarnings("unchecked") List<Catalog> result = (List<Catalog>) engine.run(new ByteArrayInputStream(xml.toString().getBytes()));
for (Catalog catalog : result) {
System.out.println(catalog);
}
engine.shutdown();
}Example 29
| Project: OCRaptor-master File: PropertiesManager.java View source code |
/**
*
*
* @return
*
* @throws IOException
*/
public Properties getProperties() throws IOException {
if (configFile != null) {
this.properties = new Properties();
BufferedInputStream stream = new BufferedInputStream(new FileInputStream(configFile));
InputStreamReader in = new InputStreamReader(stream, "UTF-8");
BufferedReader buf = new BufferedReader(in);
this.properties.load(buf);
stream.close();
return properties;
}
return null;
}Example 30
| Project: ode-master File: SerializerTest.java View source code |
@Test
public void testBasicSerialize() throws IOException {
OmSerdeFactory serdeFactory = new OmSerdeFactory();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
OProcess original = new OProcess("0");
original.setProcessName("process1");
DeSerializer serializer = new DeSerializer();
serializer.serialize(baos, original);
InputStream is = new BufferedInputStream(new ByteArrayInputStream(baos.toByteArray()));
DeSerializer deSerializer = new DeSerializer(is);
OProcess desered = deSerializer.deserialize();
assertEquals(original.getFieldContainer(), desered.getFieldContainer());
}Example 31
| Project: openrocket-master File: OpenRocketComponentLoader.java View source code |
@Override
public Collection<ComponentPreset> load(InputStream stream, String filename) {
log.debug("Loading presets from file " + filename);
if (!(stream instanceof BufferedInputStream)) {
stream = new BufferedInputStream(stream);
}
try {
List<ComponentPreset> presets;
presets = (new OpenRocketComponentSaver().unmarshalFromOpenRocketComponent(new InputStreamReader(stream))).asComponentPresets();
log.debug("ComponentPreset file " + filename + " contained " + presets.size() + " presets");
return presets;
} catch (JAXBException e) {
throw new BugException("Unable to parse file: " + filename, e);
} catch (InvalidComponentPresetException e) {
throw new BugException("Unable to parse file: " + filename, e);
}
}Example 32
| Project: StarMod-master File: FileUtil.java View source code |
public static byte[] createChecksum(File file) throws IOException, NoSuchAlgorithmException {
byte[] bytes = new byte[1024];
BufferedInputStream in = new BufferedInputStream(new FileInputStream(file));
MessageDigest sha1 = MessageDigest.getInstance("SHA1");
int i;
do {
if ((i = in.read(bytes)) > 0) {
sha1.update(bytes, 0, i);
}
} while (i != -1);
in.close();
return sha1.digest();
}Example 33
| Project: swing-minizoo-master File: Audio.java View source code |
public void play() {
try {
FileInputStream fis = new FileInputStream(filename);
BufferedInputStream bis = new BufferedInputStream(fis);
player = new Player(bis);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (JavaLayerException e) {
e.printStackTrace();
}
new Thread() {
public void run() {
try {
player.play();
} catch (JavaLayerException e) {
e.printStackTrace();
}
}
}.start();
}Example 34
| Project: teamengine-master File: CachedHttpURLConnection.java View source code |
public void connect() throws IOException {
super.connect();
BufferedInputStream bis = new BufferedInputStream(uc.getInputStream());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int i = bis.read();
while (i >= 0) {
baos.write(i);
i = bis.read();
}
bis.close();
baos.close();
content = baos.toByteArray();
}Example 35
| Project: TheMinecraft-master File: TexturePackFolder.java View source code |
/**
* Gives a texture resource as InputStream.
*/
public InputStream getResourceAsStream(String par1Str) {
try {
File var2 = new File(this.texturePackFile, par1Str.substring(1));
if (var2.exists()) {
return new BufferedInputStream(new FileInputStream(var2));
}
} catch (IOException var3) {
;
}
return super.getResourceAsStream(par1Str);
}Example 36
| Project: usercenter-master File: XmlSerializer.java View source code |
public Object deserialize(byte[] serialized) {
if (serialized == null) {
throw new IllegalArgumentException("Argument cannot be null.");
}
ByteArrayInputStream bis = new ByteArrayInputStream(serialized);
XMLDecoder decoder = new XMLDecoder(new BufferedInputStream(bis));
Object o = decoder.readObject();
decoder.close();
return o;
}Example 37
| Project: AmDroid-master File: ImageDownloader.java View source code |
public static Bitmap getImageBitmap(String url) {
Bitmap bm = null;
try {
URL aURL = new URL(url);
URLConnection conn = aURL.openConnection();
conn.connect();
InputStream is = conn.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
bm = BitmapFactory.decodeStream(bis);
bis.close();
is.close();
} catch (IOException e) {
Log.e(LOG_TAG, "Error getting bitmap from URL: " + url, e);
amdroid.logger.logWarning("Could not download image", "URL: " + url + "\nDetails: " + e.getLocalizedMessage());
}
return bm;
}Example 38
| Project: android-bankdroid-master File: CertificateReader.java View source code |
public static Certificate[] getCertificates(Context context, int... rawResCerts) {
List<Certificate> certificates = new ArrayList<>();
try {
CertificateFactory cf = CertificateFactory.getInstance("X.509");
for (int resId : rawResCerts) {
InputStream is = new BufferedInputStream(context.getResources().openRawResource(resId));
try {
X509Certificate cert = (X509Certificate) cf.generateCertificate(is);
certificates.add(cert);
} finally {
try {
is.close();
} catch (IOException e) {
Timber.w(e, "Failed to close input stream");
}
}
}
} catch (CertificateException e) {
Timber.w(e, "Generating certificate failed");
}
return certificates.toArray(new Certificate[certificates.size()]);
}Example 39
| Project: android-gif-drawable-master File: InputStreamTest.java View source code |
@Test
public void gifDrawableCreatedFromInputStream() throws Exception {
final InputStream originalStream = InstrumentationRegistry.getContext().getResources().openRawResource(R.raw.test);
mMockWebServer.enqueue(new MockResponse().setChunkedBody(new Buffer().readFrom(originalStream), 1 << 8));
final URL url = new URL(mMockWebServer.url("/").toString());
final BufferedInputStream responseStream = new BufferedInputStream(url.openConnection().getInputStream(), 1 << 16);
final GifDrawable gifDrawable = new GifDrawable(responseStream);
assertThat(gifDrawable.getError()).isEqualTo(GifError.NO_ERROR);
assertThat(gifDrawable.getIntrinsicWidth()).isEqualTo(278);
assertThat(gifDrawable.getIntrinsicHeight()).isEqualTo(183);
}Example 40
| Project: AndroidArch-master File: AbstractCheckTest.java View source code |
@Override
protected InputStream getTestResource(String relativePath, boolean expectExists) {
String path = "demo/src/main/" + relativePath;
File root = getTestDataRootDir();
assertNotNull(root);
File f = new File(root, path);
System.out.println("test file: " + f.getAbsolutePath());
if (f.exists()) {
try {
return new BufferedInputStream(new FileInputStream(f));
} catch (FileNotFoundException e) {
if (expectExists) {
fail("Could not find file " + relativePath);
}
}
}
return null;
}Example 41
| Project: AndroidPirataEs-master File: CtrlNet.java View source code |
// ----- PRIVATE
private String downloadBody(String urlString) {
Log.d("downloadBody", urlString);
try {
URL myURL = new URL(urlString);
URLConnection ucon = myURL.openConnection();
ucon.setConnectTimeout(10000);
InputStream is = ucon.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is, 65535);
ByteArrayBuffer baf = new ByteArrayBuffer(65535);
int current = 0;
while ((current = bis.read()) != -1) {
baf.append((byte) current);
}
return new String(baf.toByteArray());
} catch (IOException e) {
e.printStackTrace();
return new String();
}
}Example 42
| Project: android_explore-master File: Activity01.java View source code |
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView tv = new TextView(this);
String myString = null;
try {
/* ¶¨ÒåÎÒÃÇÒª·ÃÎʵĵØÖ·url */
URL uri = new URL("http://192.168.1.110:8080/android.txt");
/* ´ò¿ªÕâ¸öurlÁ¬½Ó */
URLConnection ucon = uri.openConnection();
/* ´ÓÉÏÃæµÄÁ´½ÓÖÐÈ¡µÃInputStream */
InputStream is = ucon.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
ByteArrayBuffer baf = new ByteArrayBuffer(100);
int current = 0;
/* Ò»Ö±¶Áµ½Îļþ½áÊø */
while ((current = bis.read()) != -1) {
baf.append((byte) current);
}
myString = new String(baf.toByteArray());
} catch (Exception e) {
myString = e.getMessage();
}
/* ½«ÐÅÏ¢ÉèÖõ½TextView */
tv.setText(myString);
/* ½«TextViewÏÔʾµ½ÆÁÄ»ÉÏ */
this.setContentView(tv);
}Example 43
| Project: android_libcore-master File: BufferedInputStreamTest.java View source code |
/**
* @throws IOException
* @tests java.io.BufferedInputStream#BufferedInputStream(java.io.InputStream,
* int)
*/
@TestTargetNew(level = TestLevel.COMPLETE, method = "BufferedInputStream", args = { java.io.InputStream.class, int.class })
public void test_ConstructorLjava_io_InputStreamI() throws IOException {
// Test for method java.io.BufferedInputStream(java.io.InputStream, int)
boolean exceptionFired = false;
try {
is = new BufferedInputStream(isFile, -1);
fail("IllegalArgumentException expected.");
} catch (IllegalArgumentException e) {
}
try {
// Create buffer with exact size of file
is = new BufferedInputStream(isFile, this.fileString.length());
// Ensure buffer gets filled by evaluating one read
is.read();
// Close underlying FileInputStream, all but 1 buffered bytes should
// still be available.
isFile.close();
// Read the remaining buffered characters, no IOException should
// occur.
is.skip(this.fileString.length() - 2);
is.read();
try {
// is.read should now throw an exception because it will have to
// be filled.
is.read();
} catch (IOException e) {
exceptionFired = true;
}
assertTrue("Exception should have been triggered by read()", exceptionFired);
} catch (IOException e) {
fail("Exception during test_1_Constructor");
}
// regression test for harmony-2407
new testBufferedInputStream(null);
assertNotNull(testBufferedInputStream.buf);
testBufferedInputStream.buf = null;
new testBufferedInputStream(null, 100);
assertNotNull(testBufferedInputStream.buf);
}Example 44
| Project: apptoolkit-master File: Compress.java View source code |
public void zip(String location) {
try {
BufferedInputStream origin = null;
FileOutputStream dest = new FileOutputStream(_zipFile);
ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(dest));
byte data[] = new byte[BUFFER];
for (int i = 0; i < _files.length; i++) {
Log.v("Compress", "Adding: " + _files[i]);
FileInputStream fi = new FileInputStream(_files[i]);
origin = new BufferedInputStream(fi, BUFFER);
ZipEntry entry = new ZipEntry(_files[i].substring(_files[i].lastIndexOf(location) + 1));
out.putNextEntry(entry);
int count;
while ((count = origin.read(data, 0, BUFFER)) != -1) {
out.write(data, 0, count);
}
origin.close();
}
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}Example 45
| Project: Aspose_Cells_Java-master File: InsertWebImageFromURL.java View source code |
public static void main(String[] args) throws Exception {
// The path to the documents directory.
String dataDir = Utils.getSharedDataDir(InsertWebImageFromURL.class) + "articles/";
// Download image and store it in an object of InputStream
URL url = new URL("https://www.google.com/images/nav_logo100633543.png");
InputStream inStream = new BufferedInputStream(url.openStream());
// Create a new workbook
Workbook book = new Workbook();
// Get the first worksheet in the book
Worksheet sheet = book.getWorksheets().get(0);
// Get the first worksheet pictures collection
PictureCollection pictures = sheet.getPictures();
// Insert the picture from the stream to B2 cell
pictures.add(1, 1, inStream);
// Save the excel file
book.save(dataDir + "IWebImageFromURL_out.xls");
}Example 46
| Project: AsyncHttpClient-master File: StreamResponseHandler.java View source code |
@Override
public void onReceiveStream(InputStream stream, final ClientTaskImpl client, final long totalLength) throws Exception {
if (reader == null) {
reader = new InputStreamReader(new BufferedInputStream(stream, 8192) {
private long total = 0;
@Override
public synchronized int read(byte[] buffer, int byteOffset, int byteCount) throws IOException {
int len = super.read(buffer, byteOffset, byteCount);
onByteChunkReceived(buffer, len, total, totalLength);
client.transferProgress(new Packet(total, totalLength, true));
total += byteCount;
return len;
}
});
}
if (!client.isCancelled()) {
getConnectionInfo().responseLength = totalLength;
// we fake the content length, because it can be -1
onByteChunkReceived(null, totalLength, totalLength, totalLength);
client.transferProgress(new Packet(totalLength, totalLength, true));
}
}Example 47
| Project: brouter-master File: WayIterator.java View source code |
public void processFile(File wayfile) throws Exception {
System.out.println("*** WayIterator reading: " + wayfile);
if (!listener.wayFileStart(wayfile)) {
return;
}
DataInputStream di = new DataInputStream(new BufferedInputStream(new FileInputStream(wayfile)));
try {
for (; ; ) {
WayData w = new WayData(di);
listener.nextWay(w);
}
} catch (EOFException eof) {
di.close();
}
listener.wayFileEnd(wayfile);
if (delete && "true".equals(System.getProperty("deletetmpfiles"))) {
wayfile.delete();
}
}Example 48
| Project: butter-master File: LintDetectorTestBase.java View source code |
@Override
protected InputStream getTestResource(String relativePath, boolean expectExists) {
String path = (getTestResourcesPath() + relativePath).replace('/', File.separatorChar);
File file = new File(getTestDataRootDir(), path);
if (file.exists()) {
try {
return new BufferedInputStream(new FileInputStream(file));
} catch (FileNotFoundException e) {
if (expectExists) {
fail("Could not find file " + relativePath);
}
}
}
return null;
}Example 49
| Project: butterknife-master File: LintDetectorTestBase.java View source code |
@Override
protected InputStream getTestResource(String relativePath, boolean expectExists) {
String path = (getTestResourcesPath() + relativePath).replace('/', File.separatorChar);
File file = new File(getTestDataRootDir(), path);
if (file.exists()) {
try {
return new BufferedInputStream(new FileInputStream(file));
} catch (FileNotFoundException e) {
if (expectExists) {
fail("Could not find file " + relativePath);
}
}
}
return null;
}Example 50
| Project: CIMTool-master File: Convert.java View source code |
/**
* Convert an RDF file from one syntax to another.
* @throws IOException
*/
public static void main(String[] args) throws IOException {
if (args.length < 2 || args.length > 5) {
System.err.println("arguments: input_file output_file [input_lang [output_lang [base_uri]]]");
return;
}
String input = args[0];
String output = args[1];
String inputLang = args.length > 2 ? args[2] : "TTL";
String outputLang = args.length > 3 ? args[3] : "RDF/XML";
String base = args.length > 4 ? args[4] : "http://langdale.com.au/2008/network#";
Model model = ModelFactory.createDefaultModel();
model.read(new BufferedInputStream(new FileInputStream(input)), base, inputLang);
model.write(new BufferedOutputStream(new FileOutputStream(output)), outputLang, base);
}Example 51
| Project: cloudstore-master File: GZIPReaderInterceptor.java View source code |
@Override
public Object aroundReadFrom(ReaderInterceptorContext context) throws IOException, WebApplicationException {
InputStream originalInputStream = context.getInputStream();
if (!originalInputStream.markSupported())
originalInputStream = new BufferedInputStream(originalInputStream);
// Test, if it contains data. We only try to unzip, if it is not empty.
originalInputStream.mark(5);
int read = originalInputStream.read();
originalInputStream.reset();
if (read > -1)
context.setInputStream(new GZIPInputStream(originalInputStream));
else {
// We might have wrapped it with our BufferedInputStream!
context.setInputStream(originalInputStream);
logger.debug("aroundReadFrom: originalInputStream is empty! Skipping GZIP.");
}
return context.proceed();
}Example 52
| Project: codeine-master File: SerializationUtils.java View source code |
@SuppressWarnings("unchecked")
public static <T> T fromFile(String file) {
try (InputStream f = new FileInputStream(file);
InputStream buffer = new BufferedInputStream(f);
ObjectInput input = new ObjectInputStream(buffer)) {
return (T) input.readObject();
} catch (ClassNotFoundException ex) {
throw ExceptionUtils.asUnchecked(ex);
} catch (IOException ex) {
throw ExceptionUtils.asUnchecked(ex);
}
}Example 53
| Project: coding2017-master File: ClassFileLoader.java View source code |
public byte[] readBinaryCode(String className) throws IOException {
File f = new File(clzPaths.get(0) + File.separatorChar + className + ".class");
if (!f.exists()) {
throw new FileNotFoundException("File not found");
}
ByteArrayOutputStream bos = new ByteArrayOutputStream((int) f.length());
BufferedInputStream in = null;
try {
in = new BufferedInputStream(new FileInputStream(f));
int buf_size = 1024;
byte[] buffer = new byte[buf_size];
int len = 0;
while (-1 != (len = in.read(buffer, 0, buf_size))) {
bos.write(buffer, 0, len);
}
return bos.toByteArray();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
in.close();
} catch (Exception e2) {
e2.printStackTrace();
}
bos.close();
}
return null;
}Example 54
| Project: CoreNLP-master File: ExtractQuotesUtil.java View source code |
public static Annotation readSerializedProtobufFile(File fileIn) {
Annotation annotation;
try {
ProtobufAnnotationSerializer pas = new ProtobufAnnotationSerializer();
InputStream is = new BufferedInputStream(new FileInputStream(fileIn));
Pair<Annotation, InputStream> pair = pas.read(is);
pair.second.close();
annotation = pair.first;
IOUtils.closeIgnoringExceptions(is);
return annotation;
} catch (Exception e) {
throw new RuntimeException(e);
}
}Example 55
| Project: cramtools-master File: DetectMultiref.java View source code |
public static void main(String[] args) throws IOException, IllegalArgumentException, IllegalAccessException {
Log.setGlobalLogLevel(LogLevel.INFO);
File cramFile = new File(args[0]);
InputStream is = new BufferedInputStream(new FileInputStream(cramFile));
CramHeader header = CramIO.readCramHeader(is);
Container c = null;
while ((c = ContainerIO.readContainer(header.getVersion(), is)) != null && !c.isEOF()) {
for (Slice slice : c.slices) {
if (slice.sequenceId == Slice.MULTI_REFERENCE) {
System.out.println("Read feature B detected.");
System.exit(1);
}
}
}
}Example 56
| Project: dropwizard-orient-server-master File: StudioVirtualFolder.java View source code |
@Override
public Object call(final String iArgument) {
final String fileName = STUDIO_PATH + MoreObjects.firstNonNull(Strings.emptyToNull(iArgument), STUDIO_INDEX);
final URL url = getClass().getResource(fileName);
if (url != null) {
final OServerCommandGetStaticContent.OStaticContent content = new OServerCommandGetStaticContent.OStaticContent();
content.is = new BufferedInputStream(getClass().getResourceAsStream(fileName));
content.contentSize = -1;
content.type = OServerCommandGetStaticContent.getContentType(url.getFile());
return content;
}
return null;
}Example 57
| Project: easy-httpserver-master File: PropertyUtil.java View source code |
public static Map<String, String> analysisProperties(String path) {
Map<String, String> map = new HashMap<String, String>();
Properties props = new Properties();
try {
InputStream in = new BufferedInputStream(new FileInputStream(path));
props.load(in);
for (String key : props.stringPropertyNames()) {
map.put(key, props.get(key).toString());
}
} catch (Exception e) {
log.error("�置文件解�错误:", e);
}
return map;
}Example 58
| Project: eclipse-license-management-tools-master File: VerSig.java View source code |
public static void main(String[] args) throws Exception {
if (args.length != 2) {
System.out.println("Usage: VerSig " + "publickeyfile signaturefile " + "datafile");
System.exit(1);
}
PublicKey pubKey = Utils.readPublicKeyFromBytes(PUBLIC_KEY);
byte[] sigToVerify = Utils.readFile(args[0]);
Signature sig = Signature.getInstance("SHA1withDSA", "SUN");
sig.initVerify(pubKey);
FileInputStream datafis = new FileInputStream(args[1]);
BufferedInputStream bufin = new BufferedInputStream(datafis);
byte[] buffer = new byte[1024];
int len;
while (bufin.available() != 0) {
len = bufin.read(buffer);
sig.update(buffer, 0, len);
}
bufin.close();
boolean verifies = sig.verify(sigToVerify);
System.out.println("signature verifies: " + verifies);
}Example 59
| Project: elexis-3-base-master File: VacdocServiceTest.java View source code |
@SuppressWarnings("unchecked")
@Test
public void testImport() throws Exception {
BufferedInputStream input = new BufferedInputStream(getClass().getResourceAsStream("/rsc/test.xml"));
assertNotNull(input);
ServiceReference<VacdocService> serviceRef = (ServiceReference<VacdocService>) AllTests.getService(VacdocService.class);
VacdocService service = AllTests.context.getService(serviceRef);
Optional<CdaChVacd> document = service.loadVacdocDocument(input);
assertNotNull(document);
assertTrue(document.isPresent());
List<Immunization> immunizations = document.get().getImmunizations();
assertNotNull(immunizations);
assertEquals(3, immunizations.size());
AllTests.ungetService(serviceRef);
}Example 60
| Project: Europeana-Cloud-master File: ContentStreamDetectorTest.java View source code |
@Test
@Parameters({ "example_metadata.xml, application/xml", "example_jpg2000.jp2, image/jp2" })
public void shouldProperlyGuessMimeType_Xml(String fileName, String expectedMimeType) throws IOException {
//given
URL resource = Resources.getResource(fileName);
byte[] expected = Resources.toByteArray(resource);
BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream(resource.getFile()));
//when
String mimeType = detectMediaType(inputStream).toString();
//then
assertThat(mimeType, is(expectedMimeType));
byte[] actual = readFully(inputStream, expected.length);
assertThat(actual, is(expected));
}Example 61
| Project: fdroidclient-master File: BluetoothConnection.java View source code |
@TargetApi(14)
public void open() throws IOException {
if (Build.VERSION.SDK_INT >= 14 && !socket.isConnected()) {
// Server sockets will already be connected when they are passed to us,
// client sockets require us to call connect().
socket.connect();
}
input = new BufferedInputStream(socket.getInputStream());
output = new BufferedOutputStream(socket.getOutputStream());
Utils.debugLog(TAG, "Opened connection to Bluetooth device");
}Example 62
| Project: freeline-master File: FileUtils.java View source code |
public static void unzip(File zipFile, File targetDirectory) throws IOException {
ZipInputStream zis = new ZipInputStream(new BufferedInputStream(new FileInputStream(zipFile)));
try {
ZipEntry ze;
int count;
byte[] buffer = new byte[8192];
while ((ze = zis.getNextEntry()) != null) {
File file = new File(targetDirectory, ze.getName());
File dir = ze.isDirectory() ? file : file.getParentFile();
if (!dir.isDirectory() && !dir.mkdirs())
throw new FileNotFoundException("Failed to ensure directory: " + dir.getAbsolutePath());
if (ze.isDirectory())
continue;
FileOutputStream fout = new FileOutputStream(file);
try {
while ((count = zis.read(buffer)) != -1) fout.write(buffer, 0, count);
} finally {
fout.close();
}
}
} finally {
zis.close();
}
}Example 63
| Project: geoserver-2.0.x-master File: FlatFileStorage.java View source code |
public List<String> handleUpload(String contentType, File content, UniqueIDGenerator generator, File uploadDirectory) throws IOException {
String originalName = "";
String name = generator.generate(originalName);
InputStream in = new BufferedInputStream(new FileInputStream(content));
File storedFile = new File(uploadDirectory, name);
OutputStream out = new BufferedOutputStream(new FileOutputStream(storedFile));
copyStream(in, out);
in.close();
out.flush();
out.close();
List<String> result = new ArrayList<String>();
result.add(name);
return result;
}Example 64
| Project: gh4a-master File: FeedLoader.java View source code |
@Override
public List<Feed> doLoadInBackground() throws Exception {
BufferedInputStream bis = null;
try {
URL url = new URL(mUrl);
URLConnection request = url.openConnection();
bis = new BufferedInputStream(request.getInputStream());
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser parser = factory.newSAXParser();
FeedHandler handler = new FeedHandler();
parser.parse(bis, handler);
return handler.getFeeds();
} finally {
if (bis != null) {
try {
bis.close();
} catch (IOException e) {
}
}
}
}Example 65
| Project: GigaGet-master File: DownloadRunnableFallback.java View source code |
@Override
public void run() {
try {
URL url = new URL(mMission.url);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
if (conn.getResponseCode() != 200 && conn.getResponseCode() != 206) {
notifyError(DownloadMission.ERROR_SERVER_UNSUPPORTED);
} else {
RandomAccessFile f = new RandomAccessFile(mMission.location + "/" + mMission.name, "rw");
f.seek(0);
BufferedInputStream ipt = new BufferedInputStream(conn.getInputStream());
byte[] buf = new byte[512];
int len = 0;
while ((len = ipt.read(buf, 0, 512)) != -1 && mMission.running) {
f.write(buf, 0, len);
notifyProgress(len);
if (Thread.currentThread().interrupted()) {
break;
}
}
f.close();
ipt.close();
}
} catch (Exception e) {
notifyError(DownloadMission.ERROR_UNKNOWN);
}
if (mMission.errCode == -1 && mMission.running) {
notifyFinished();
}
}Example 66
| Project: GPT-Organize-master File: TGSongLoader.java View source code |
/**
* @return TGSong
* @throws TGFileFormatException
*/
public TGSong load(TGFactory factory, InputStream is) throws TGFileFormatException {
try {
BufferedInputStream stream = new BufferedInputStream(is);
stream.mark(1);
Iterator it = TGFileFormatManager.instance().getInputStreams();
while (it.hasNext()) {
TGInputStreamBase reader = (TGInputStreamBase) it.next();
reader.init(factory, stream);
if (reader.isSupportedVersion()) {
return reader.readSong();
}
stream.reset();
}
stream.close();
} catch (Throwable t) {
throw new TGFileFormatException(t);
}
throw new TGFileFormatException("Unsupported file format");
}Example 67
| Project: grails-lightweight-deploy-master File: Utils.java View source code |
public static void unzip(ZipEntry entry, ZipFile zipfile, File explodedDir) throws IOException {
if (entry.isDirectory()) {
new File(explodedDir, entry.getName()).mkdirs();
return;
}
File outputFile = new File(explodedDir, entry.getName());
if (!outputFile.getParentFile().exists()) {
outputFile.getParentFile().mkdirs();
}
BufferedInputStream inputStream = new BufferedInputStream(zipfile.getInputStream(entry));
BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(outputFile));
try {
ByteStreams.copy(inputStream, outputStream);
} finally {
outputStream.close();
inputStream.close();
}
}Example 68
| Project: hdt-java-master File: TarTest.java View source code |
public static void main(String[] args) throws Throwable {
InputStream input = new ExternalDecompressStream(new File("/Users/mck/rdf/dataset/tgztest.tar.gz"), ExternalDecompressStream.GZIP);
// InputStream input = new CountInputStream(new BufferedInputStream(new GZIPInputStream(new FileInputStream("/Users/mck/rdf/dataset/tgztest.tar.gz"))));
// InputStream input = new CountInputStream(new BufferedInputStream(new FileInputStream("/Users/mck/rdf/dataset/tgztest.tar")));
final TarArchiveInputStream debInputStream = new TarArchiveInputStream(input);
TarArchiveEntry entry = null;
NonCloseInputStream nonCloseIn = new NonCloseInputStream(debInputStream);
while ((entry = (TarArchiveEntry) debInputStream.getNextEntry()) != null) {
System.out.println(entry.getName());
}
debInputStream.close();
}Example 69
| Project: HotFix-master File: Utils.java View source code |
public static boolean prepareDex(Context context, File dexInternalStoragePath, String dex_file) {
BufferedInputStream bis = null;
OutputStream dexWriter = null;
try {
bis = new BufferedInputStream(context.getAssets().open(dex_file));
dexWriter = new BufferedOutputStream(new FileOutputStream(dexInternalStoragePath));
byte[] buf = new byte[BUF_SIZE];
int len;
while ((len = bis.read(buf, 0, BUF_SIZE)) > 0) {
dexWriter.write(buf, 0, len);
}
dexWriter.close();
bis.close();
return true;
} catch (IOException e) {
if (dexWriter != null) {
try {
dexWriter.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
if (bis != null) {
try {
bis.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
return false;
}
}Example 70
| Project: java-weboslib-master File: JarResource.java View source code |
public File extract(File dest) {
try {
if (dest.exists())
dest.delete();
InputStream in = null;
if (specific == null) {
in = new BufferedInputStream(this.getClass().getResourceAsStream(path));
} else {
in = new BufferedInputStream(specific.getResourceAsStream(path));
}
OutputStream out = new BufferedOutputStream(new FileOutputStream(dest));
byte[] buffer = new byte[2048];
for (; ; ) {
int nBytes = in.read(buffer);
if (nBytes <= 0)
break;
out.write(buffer, 0, nBytes);
}
out.flush();
out.close();
in.close();
return dest;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}Example 71
| Project: javacuriosities-master File: Step1ServerSocketTCP.java View source code |
public static void main(String[] args) {
try (ServerSocket serverSocket = new ServerSocket(9500)) {
while (true) {
System.out.println("Waiting client...");
Socket clientSocket = serverSocket.accept();
System.out.println("Accepted connection : " + clientSocket.getInetAddress());
// Creamos un array de bytes para ir leyendo el file, acá creamos un array pequeño para el ejemplo
byte[] bytes = new byte[10];
// Pedimos el output stream
OutputStream os = clientSocket.getOutputStream();
InputStream resourceAsStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("data.txt");
BufferedInputStream bis = new BufferedInputStream(resourceAsStream);
int bytesRead = 0;
while ((bytesRead = bis.read(bytes)) != -1) {
System.out.println("Sending file (" + bytesRead + " bytes)");
os.write(bytes, 0, bytesRead);
}
os.close();
bis.close();
System.out.println("Done.");
}
} catch (IOException e) {
e.printStackTrace();
}
}Example 72
| Project: jdk7u-jdk-master File: OptionTest.java View source code |
/**
* Run an arbitrary command and return the results to caller.
*
* @param an array of String containing the command
* to run and any flags or parameters to the command.
*
* @return completion status, stderr and stdout as array of String
* Look for:
* return status in result[OptionTest.RETSTAT]
* standard out in result[OptionTest.STDOUT]
* standard err in result[OptionTest.STDERR]
*
*/
public String[] run(String[] cmdStrings) {
StringBuffer stdoutBuffer = new StringBuffer();
StringBuffer stderrBuffer = new StringBuffer();
System.out.print(CR + "runCommand method about to execute: ");
for (int iNdx = 0; iNdx < cmdStrings.length; iNdx++) {
System.out.print(" ");
System.out.print(cmdStrings[iNdx]);
}
System.out.println(CR);
try {
Process process = Runtime.getRuntime().exec(cmdStrings);
/*
* Gather up the output of the subprocess using non-blocking
* reads so we can get both the subprocess stdout and the
* subprocess stderr without overfilling any buffers.
*/
java.io.BufferedInputStream is = new java.io.BufferedInputStream(process.getInputStream());
int isLen = 0;
byte[] isBuf = new byte[BUFFERSIZE];
java.io.BufferedInputStream es = new java.io.BufferedInputStream(process.getErrorStream());
int esLen = 0;
byte[] esBuf = new byte[BUFFERSIZE];
do {
isLen = is.read(isBuf);
if (isLen > 0) {
stdoutBuffer.append(new String(isBuf, 0, isLen));
}
esLen = es.read(esBuf);
if (esLen > 0) {
stderrBuffer.append(new String(esBuf, 0, esLen));
}
} while ((isLen > -1) || (esLen > -1));
try {
process.waitFor();
subprocessStatus = process.exitValue();
process = null;
} catch (java.lang.InterruptedException e) {
System.err.println("InterruptedException: " + e);
}
} catch (java.io.IOException ex) {
System.err.println("IO error: " + ex);
}
String[] result = new String[] { Integer.toString(subprocessStatus), stdoutBuffer.toString(), stderrBuffer.toString() };
System.out.println(CR + "--- Return code was: " + CR + result[RETSTAT]);
System.out.println(CR + "--- Return stdout was: " + CR + result[STDOUT]);
System.out.println(CR + "--- Return stderr was: " + CR + result[STDERR]);
return result;
}Example 73
| Project: JMediaPlayer-master File: MP3.java View source code |
// play the MP3 file to the sound card
public void play() {
try {
FileInputStream fis = new FileInputStream(filename);
BufferedInputStream bis = new BufferedInputStream(fis);
player = new Player(bis);
} catch (Exception e) {
System.out.println("Problem playing file " + filename);
System.out.println(e);
}
// run in new thread to play in background
new Thread() {
public void run() {
try {
player.play();
} catch (Exception e) {
System.out.println(e);
}
}
}.start();
}Example 74
| Project: jml-master File: GenerateCppEnumWriter.java View source code |
public static void main(String[] args) {
try {
Scanner reader = new Scanner(new BufferedInputStream(new FileInputStream("enum_lines")));
Pattern enumNamePatter = Pattern.compile("([A-Z_0-9]+)");
Set<String> enumValues = new HashSet<>();
while (reader.hasNext()) {
String line = reader.nextLine();
if (line.length() == 0 || line.charAt(0) == '#' || !line.contains("_")) {
continue;
}
Matcher matcher = enumNamePatter.matcher(line);
if (matcher.find()) {
enumValues.add(matcher.group(0));
}
}
for (String enumValue : enumValues) {
System.out.println("out << \"" + enumValue + " : \" << " + enumValue + " << std::endl;");
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}Example 75
| Project: JodaEngine-master File: FormStreamHandler.java View source code |
@Override
public void processSingleDarFileEntry(ZipFile darFile, ZipEntry entry, DeploymentBuilder builder) {
if (entry.getName().startsWith(FORMS_SUBDIR) && !entry.isDirectory()) {
try {
BufferedInputStream inputStream = new BufferedInputStream(darFile.getInputStream(entry));
int lastDelimiter = entry.getName().lastIndexOf(DELIMITER);
String formName = entry.getName().substring(lastDelimiter + 1);
builder.addInputStreamForm(formName, inputStream);
inputStream.close();
} catch (IOException e) {
logger.error("Could not read file {} from archive", entry.getName());
}
}
}Example 76
| Project: Joker-master File: HttpGet.java View source code |
public static String getResultString(String urlString) {
String result = "";
URL url;
try {
url = new URL(urlString);
URLConnection conn = url.openConnection();
int reCode = ((HttpURLConnection) conn).getResponseCode();
if (reCode == 200) {
InputStream is = conn.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
ByteArrayBuffer buffer = new ByteArrayBuffer(32);
int read;
while ((read = bis.read()) != -1) {
buffer.append((char) read);
}
result = EncodingUtils.getString(buffer.toByteArray(), HTTP.UTF_8);
Log.d("TTT HttpGet getResultString", "result = " + result);
}
} catch (Exception e) {
e.printStackTrace();
result = "";
}
return result;
}Example 77
| Project: jop-master File: DirectInterfaceHost.java View source code |
/**
* @param args
*/
public static void main(String[] args) throws Exception {
SerialInterface serialInterface = new SerialInterface("COM1");
final yaffs_Device dev = DebugDevice.getDebugDevice();
// MS: uncomment it to avoid syntx errors.
// Shall we really include a reference to joptraget in pc?
// I don't think that makes sense.
// new DirectInterfaceServerStub(dev, port_fileem2k_C.instance,
// new BufferedInputStream(serialInterface.getInputStream()),
// serialInterface.getOutputStream(), "PC").receive(true, new byte[dev.subField1.nDataBytesPerChunk], 0, new byte[yaffs_Spare.SERIALIZED_LENGTH], 0);
}Example 78
| Project: josm-older-master File: OsmBzip2Importer.java View source code |
@Override
public void importData(File file, ProgressMonitor progressMonitor) throws IOException, IllegalDataException {
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
int b = bis.read();
if (b != 'B')
throw new IOException(tr("Invalid bz2 file."));
b = bis.read();
if (b != 'Z')
throw new IOException(tr("Invalid bz2 file."));
CBZip2InputStream in = new CBZip2InputStream(bis);
importData(in, file);
}Example 79
| Project: Just-Another-Android-App-master File: AbstractDetectorTest.java View source code |
@Override
protected InputStream getTestResource(String relativePath, boolean expectExists) {
String path = (PATH_TEST_RESOURCES + getTestResourceDirectory() + File.separatorChar + relativePath).replace('/', File.separatorChar);
File file = new File(getTestDataRootDir(), path);
if (file.exists()) {
try {
return new BufferedInputStream(new FileInputStream(file));
} catch (FileNotFoundException ignored) {
if (expectExists) {
fail("Could not find file " + relativePath);
}
}
}
return null;
}Example 80
| Project: jxls-master File: ReadFormulasTest.java View source code |
public void testReadFormulas() throws IOException, SAXException, InvalidFormatException {
InputStream inputXML = new BufferedInputStream(getClass().getResourceAsStream(xmlConfig));
XLSReader reader = ReaderBuilder.buildFromXML(inputXML);
assertNotNull(reader);
InputStream inputXLS = new BufferedInputStream(getClass().getResourceAsStream(formulasXLS));
List employees = new ArrayList();
SimpleBean bean = new SimpleBean();
Map beans = new HashMap();
beans.put("employees", employees);
beans.put("bean", bean);
reader.read(inputXLS, beans);
assertNotNull(employees);
assertEquals(4, employees.size());
assertEquals("Value or formula is incorrect ", new Integer(5), bean.getIntValue1());
assertEquals("Value or formula is incorrect ", new Double(9805), bean.getDoubleValue());
assertEquals("Value or formula is incorrect ", "Age&Payment", bean.getStr());
inputXLS.close();
}Example 81
| Project: linette-master File: AbstractDetectorTest.java View source code |
@Override
protected InputStream getTestResource(String relativePath, boolean expectExists) {
String path = (PATH_TEST_RESOURCES + getTestResourceDirectory() + File.separatorChar + relativePath).replace('/', File.separatorChar);
File file = new File(getTestDataRootDir(), path);
if (file.exists()) {
try {
return new BufferedInputStream(new FileInputStream(file));
} catch (FileNotFoundException e) {
if (expectExists) {
fail("Could not find file " + relativePath);
}
}
}
return null;
}Example 82
| Project: logback-beagle-master File: LoggingEventSocketReader.java View source code |
@Override
public void run() {
try {
ObjectInputStream ois = new ObjectInputStream(new BufferedInputStream(socket.getInputStream()));
while (started) {
// read an event from the wire
LoggingEventVO event = (LoggingEventVO) ois.readObject();
// add event
blockingQueue.put(event);
}
} catch (EOFException eofException) {
} catch (Exception ex) {
logException(ex);
}
}Example 83
| Project: logdb-master File: JmapCommand.java View source code |
@Override
public void run() {
HprofParser parser = new HprofParser(new JmapRecordHandler(this));
FileInputStream fs = null;
DataInputStream in = null;
try {
fs = new FileInputStream(path);
in = new DataInputStream(new BufferedInputStream(fs));
parser.parse(in);
} catch (IOException e) {
throw new IllegalStateException(e);
} finally {
if (in != null) {
try {
in.close();
} catch (Throwable t) {
}
}
if (fs != null) {
try {
fs.close();
} catch (Throwable t) {
}
}
}
}Example 84
| Project: LunarTabsAndroid-master File: TGSongLoader.java View source code |
/**
* @return TGSong
* @throws TGFileFormatException
*/
public TGSong load(TGFactory factory, InputStream is) throws TGFileFormatException {
try {
BufferedInputStream stream = new BufferedInputStream(is);
stream.mark(1);
Iterator it = TGFileFormatManager.instance().getInputStreams();
while (it.hasNext()) {
TGInputStreamBase reader = (TGInputStreamBase) it.next();
reader.init(factory, stream);
if (reader.isSupportedVersion()) {
return reader.readSong();
}
stream.reset();
}
stream.close();
} catch (Throwable t) {
throw new TGFileFormatException(t);
}
throw new TGFileFormatException("Unsupported file format");
}Example 85
| Project: ManagedRuntimeInitiative-master File: OptionTest.java View source code |
/**
* Run an arbitrary command and return the results to caller.
*
* @param an array of String containing the command
* to run and any flags or parameters to the command.
*
* @return completion status, stderr and stdout as array of String
* Look for:
* return status in result[OptionTest.RETSTAT]
* standard out in result[OptionTest.STDOUT]
* standard err in result[OptionTest.STDERR]
*
*/
public String[] run(String[] cmdStrings) {
StringBuffer stdoutBuffer = new StringBuffer();
StringBuffer stderrBuffer = new StringBuffer();
System.out.print(CR + "runCommand method about to execute: ");
for (int iNdx = 0; iNdx < cmdStrings.length; iNdx++) {
System.out.print(" ");
System.out.print(cmdStrings[iNdx]);
}
System.out.println(CR);
try {
Process process = Runtime.getRuntime().exec(cmdStrings);
/*
* Gather up the output of the subprocess using non-blocking
* reads so we can get both the subprocess stdout and the
* subprocess stderr without overfilling any buffers.
*/
java.io.BufferedInputStream is = new java.io.BufferedInputStream(process.getInputStream());
int isLen = 0;
byte[] isBuf = new byte[BUFFERSIZE];
java.io.BufferedInputStream es = new java.io.BufferedInputStream(process.getErrorStream());
int esLen = 0;
byte[] esBuf = new byte[BUFFERSIZE];
do {
isLen = is.read(isBuf);
if (isLen > 0) {
stdoutBuffer.append(new String(isBuf, 0, isLen));
}
esLen = es.read(esBuf);
if (esLen > 0) {
stderrBuffer.append(new String(esBuf, 0, esLen));
}
} while ((isLen > -1) || (esLen > -1));
try {
process.waitFor();
subprocessStatus = process.exitValue();
process = null;
} catch (java.lang.InterruptedException e) {
System.err.println("InterruptedException: " + e);
}
} catch (java.io.IOException ex) {
System.err.println("IO error: " + ex);
}
String[] result = new String[] { Integer.toString(subprocessStatus), stdoutBuffer.toString(), stderrBuffer.toString() };
System.out.println(CR + "--- Return code was: " + CR + result[RETSTAT]);
System.out.println(CR + "--- Return stdout was: " + CR + result[STDOUT]);
System.out.println(CR + "--- Return stderr was: " + CR + result[STDERR]);
return result;
}Example 86
| Project: mathematorium-master File: ActionScriptLoadUtilities.java View source code |
/**
* Saves the current model of the history
*
* @param outputFile
* @return the ExpressionConsoleHistory object loaded from the file, or null
* if unsuccessful.
*/
public static ExpressionConsoleHistory loadScript(File inputFile) {
ExpressionConsoleHistory expressionHistory = null;
try {
XMLDecoder d = new XMLDecoder(new BufferedInputStream(new FileInputStream(inputFile)));
expressionHistory = (ExpressionConsoleHistory) d.readObject();
d.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
return expressionHistory;
}Example 87
| Project: MiBandDecompiled-master File: WebServiceClient$DomXMLHandler.java View source code |
public Element parseXml(InputStream inputstream) {
Element element;
try {
if (a == null) {
a = a();
}
element = a.parse(new BufferedInputStream(inputstream)).getDocumentElement();
} catch (ParserConfigurationException parserconfigurationexception) {
parserconfigurationexception.printStackTrace();
return null;
} catch (SAXException saxexception) {
saxexception.printStackTrace();
return null;
} catch (IOException ioexception) {
ioexception.printStackTrace();
return null;
}
return element;
}Example 88
| Project: mini-blog-master File: FileUtil.java View source code |
public static byte[] readFileImage(String filename) throws IOException {
BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(filename));
int len = bufferedInputStream.available();
byte[] bytes = new byte[len];
int r = bufferedInputStream.read(bytes);
if (len != r) {
bytes = null;
throw new IOException("读å?–文件ä¸?æ£ç¡®");
}
bufferedInputStream.close();
return bytes;
}Example 89
| Project: NativeFmod-master File: Medias.java View source code |
public static ByteBuffer loadMediaIntoMemory(String media) {
try {
InputStream is = new Medias().getClass().getResourceAsStream(media);
BufferedInputStream bis = new BufferedInputStream(is);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] bytes = new byte[4 * 1024];
int read;
while ((read = bis.read(bytes, 0, bytes.length)) != -1) {
baos.write(bytes, 0, read);
}
bis.close();
ByteBuffer buffer = BufferUtils.newByteBuffer(baos.size());
buffer.put(baos.toByteArray());
buffer.rewind();
lastError = "";
return buffer;
} catch (IOException e) {
lastError = e.getMessage();
return null;
}
}Example 90
| Project: NIM_Android_Demo-master File: MD5.java View source code |
public static String getStreamMD5(String filePath) {
String hash = null;
byte[] buffer = new byte[4096];
BufferedInputStream in = null;
try {
MessageDigest md5 = MessageDigest.getInstance("MD5");
in = new BufferedInputStream(new FileInputStream(filePath));
int numRead = 0;
while ((numRead = in.read(buffer)) > 0) {
md5.update(buffer, 0, numRead);
}
in.close();
hash = HexDump.toHex(md5.digest());
} catch (Exception e) {
e.printStackTrace();
} finally {
if (in != null) {
try {
in.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
return hash;
}Example 91
| Project: NIM_Android_UIKit-master File: MD5.java View source code |
public static String getStreamMD5(String filePath) {
String hash = null;
byte[] buffer = new byte[4096];
BufferedInputStream in = null;
try {
MessageDigest md5 = MessageDigest.getInstance("MD5");
in = new BufferedInputStream(new FileInputStream(filePath));
int numRead = 0;
while ((numRead = in.read(buffer)) > 0) {
md5.update(buffer, 0, numRead);
}
in.close();
hash = HexDump.toHex(md5.digest());
} catch (Exception e) {
e.printStackTrace();
} finally {
if (in != null) {
try {
in.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
return hash;
}Example 92
| Project: NoSQLBenchmark-master File: PropertiesBasedConfiguration.java View source code |
private void loadProperties(String filePath) {
Properties props = new Properties();
InputStream in = null;
try {
in = new BufferedInputStream(new FileInputStream(filePath));
props.load(in);
Enumeration<?> en = props.propertyNames();
while (en.hasMoreElements()) {
String key = (String) en.nextElement();
String Property = props.getProperty(key);
store.put(key, Property);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}Example 93
| Project: OG-Platform-master File: RecordNetworkStream.java View source code |
public static void main(final String[] args) throws IOException {
// CSIGNORE
final String host = args[0];
final Integer port = Integer.parseInt(args[1]);
final String file = args[2];
try (Socket socket = new Socket(host, port)) {
try (BufferedOutputStream output = new BufferedOutputStream(new FileOutputStream(file))) {
final BufferedInputStream input = new BufferedInputStream(socket.getInputStream());
try {
final byte[] buffer = new byte[4096];
final long start = System.nanoTime();
while (System.nanoTime() - start < 300000000000L) {
final int bytes = input.read(buffer);
if (bytes < 0) {
return;
}
output.write(buffer, 0, bytes);
}
} finally {
input.close();
}
}
}
}Example 94
| Project: omc-lib-master File: NBTUtil.java View source code |
public static CompoundTag readFromFile(final File file, final boolean compressed) throws IOException {
DataInputStream in;
if (compressed) {
in = new DataInputStream(new BufferedInputStream(new GZIPInputStream(new FileInputStream(file))));
} else {
in = new DataInputStream(new BufferedInputStream(new FileInputStream(file)));
}
final CompoundTag tag = (CompoundTag) NBTTag.readTag(in);
in.close();
return tag;
}Example 95
| Project: openjdk8-jdk-master File: OptionTest.java View source code |
/**
* Run an arbitrary command and return the results to caller.
*
* @param an array of String containing the command
* to run and any flags or parameters to the command.
*
* @return completion status, stderr and stdout as array of String
* Look for:
* return status in result[OptionTest.RETSTAT]
* standard out in result[OptionTest.STDOUT]
* standard err in result[OptionTest.STDERR]
*
*/
public String[] run(String[] cmdStrings) {
StringBuffer stdoutBuffer = new StringBuffer();
StringBuffer stderrBuffer = new StringBuffer();
System.out.print(CR + "runCommand method about to execute: ");
for (int iNdx = 0; iNdx < cmdStrings.length; iNdx++) {
System.out.print(" ");
System.out.print(cmdStrings[iNdx]);
}
System.out.println(CR);
try {
Process process = Runtime.getRuntime().exec(cmdStrings);
/*
* Gather up the output of the subprocess using non-blocking
* reads so we can get both the subprocess stdout and the
* subprocess stderr without overfilling any buffers.
*/
java.io.BufferedInputStream is = new java.io.BufferedInputStream(process.getInputStream());
int isLen = 0;
byte[] isBuf = new byte[BUFFERSIZE];
java.io.BufferedInputStream es = new java.io.BufferedInputStream(process.getErrorStream());
int esLen = 0;
byte[] esBuf = new byte[BUFFERSIZE];
do {
isLen = is.read(isBuf);
if (isLen > 0) {
stdoutBuffer.append(new String(isBuf, 0, isLen));
}
esLen = es.read(esBuf);
if (esLen > 0) {
stderrBuffer.append(new String(esBuf, 0, esLen));
}
} while ((isLen > -1) || (esLen > -1));
try {
process.waitFor();
subprocessStatus = process.exitValue();
process = null;
} catch (java.lang.InterruptedException e) {
System.err.println("InterruptedException: " + e);
}
} catch (java.io.IOException ex) {
System.err.println("IO error: " + ex);
}
String[] result = new String[] { Integer.toString(subprocessStatus), stdoutBuffer.toString(), stderrBuffer.toString() };
System.out.println(CR + "--- Return code was: " + CR + result[RETSTAT]);
System.out.println(CR + "--- Return stdout was: " + CR + result[STDOUT]);
System.out.println(CR + "--- Return stderr was: " + CR + result[STDERR]);
return result;
}Example 96
| Project: oryx-engine-master File: FormStreamHandler.java View source code |
@Override
public void processSingleDarFileEntry(ZipFile darFile, ZipEntry entry, DeploymentBuilder builder) {
if (entry.getName().startsWith(FORMS_SUBDIR) && !entry.isDirectory()) {
try {
BufferedInputStream inputStream = new BufferedInputStream(darFile.getInputStream(entry));
int lastDelimiter = entry.getName().lastIndexOf(DELIMITER);
String formName = entry.getName().substring(lastDelimiter + 1);
builder.addInputStreamForm(formName, inputStream);
inputStream.close();
} catch (IOException e) {
logger.error("Could not read file {} from archive", entry.getName());
}
}
}Example 97
| Project: PeripheralsPlusPlus-master File: Audio.java View source code |
public InputStream getAudio(String text, String languageOutput) throws IOException {
//See http://stackoverflow.com/questions/32053442/google-translate-tts-api-blocked
URL url = new URL("http://translate.google.com/translate_tts?q=" + text.replace(" ", "%20") + "&tl=" + languageOutput + "&client=tw-ob");
URLConnection urlConn = url.openConnection();
urlConn.addRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
InputStream audioSrc = urlConn.getInputStream();
return new BufferedInputStream(audioSrc);
}Example 98
| Project: pitest-master File: ClassUtils.java View source code |
public static byte[] classAsBytes(final String className) throws ClassNotFoundException {
try {
final URL resource = ClassUtils.class.getClassLoader().getResource(convertClassNameToFileName(className));
final BufferedInputStream stream = new BufferedInputStream(resource.openStream());
final byte[] result = new byte[resource.openConnection().getContentLength()];
int i;
int counter = 0;
while ((i = stream.read()) != -1) {
result[counter] = (byte) i;
counter++;
}
stream.close();
return result;
} catch (final IOException e) {
throw new ClassNotFoundException("", e);
}
}Example 99
| Project: polyglot-maven-master File: Util.java View source code |
/**
* Read resource form classpath
* @param theName - the resource name
*/
public static String getLocalResource(String theName) {
try {
InputStream input;
input = Thread.currentThread().getContextClassLoader().getResourceAsStream(theName);
if (input == null) {
throw new RuntimeException("Can not find " + theName);
}
BufferedInputStream is = new BufferedInputStream(input);
StringBuilder buf = new StringBuilder(3000);
int i;
try {
while ((i = is.read()) != -1) {
buf.append((char) i);
}
} finally {
is.close();
}
String resource = buf.toString();
// convert EOLs
String[] lines = resource.split("\\r?\\n");
StringBuilder buffer = new StringBuilder();
for (int j = 0; j < lines.length; j++) {
buffer.append(lines[j]);
buffer.append("\n");
}
return buffer.toString();
} catch (IOException e) {
throw new RuntimeException(e);
}
}Example 100
| Project: projecteuler-master File: Decompress.java View source code |
public static void unzip(InputStream fin, String location) {
dirChecker(location, "");
try {
ZipInputStream zin = new ZipInputStream(new BufferedInputStream(fin));
ZipEntry ze = null;
while ((ze = zin.getNextEntry()) != null) {
if (ze.isDirectory())
dirChecker(location, ze.getName());
else {
File f = new File(location + ze.getName());
f.getParentFile().mkdirs();
BufferedOutputStream fout = new BufferedOutputStream(new FileOutputStream(location + ze.getName()));
int BUFFER_SIZE = 2048;
byte b[] = new byte[BUFFER_SIZE];
int n;
while ((n = zin.read(b, 0, BUFFER_SIZE)) >= 0) fout.write(b, 0, n);
zin.closeEntry();
fout.close();
}
}
zin.close();
} catch (Exception e) {
String s = e.getMessage();
Log.e("DB Error", s);
}
}Example 101
| Project: project_open-master File: Bimp.java View source code |
public static Bitmap revitionImageSize(String path) throws IOException {
BufferedInputStream in = new BufferedInputStream(new FileInputStream(new File(path)));
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeStream(in, null, options);
in.close();
int i = 0;
Bitmap bitmap = null;
while (true) {
if ((options.outWidth >> i <= 1000) && (options.outHeight >> i <= 1000)) {
in = new BufferedInputStream(new FileInputStream(new File(path)));
options.inSampleSize = (int) Math.pow(2.0D, i);
options.inJustDecodeBounds = false;
bitmap = BitmapFactory.decodeStream(in, null, options);
break;
}
i += 1;
}
max += 1;
return bitmap;
}