try (InputStream stream = new MyInputStream(...)){ // ... use stream } catch(IOException e) { // handle exception }
InputStream stream = new MyInputStream(...); try { // ... use stream } catch(IOException e) { // handle exception } finally { try { if(stream != null) { stream.close(); } } catch(IOException e) { // handle yet another possible exception } }
final InputStream slowIS = new ThrottledInputStream(new BufferedInputStream(new FileInputStream("c:\\file.txt"),8000),300);
try (InputStream stream = new MyInputStream(...)){ // ... use stream } catch(IOException e) { // handle exception }
InputStream is = new InputStream( ... ) try { is.read(...); return is; } catch ( IOException ioe ) { is.close(); throw ioe; }
public void doStuff() throws IOException { InputStream in = new InputStream(...); // do stuff in.close(); }
InputStream stream = null; try { stream = new InputStream(); yourMethod(stream); } catch (...) { } finally { try { stream.close() } catch (IOException ioe) { // can throw IOException while closing closed stream } }
byte[] b = byteBuffer.array(); ByteArrayInputStream bais = new ByteArrayInputStream(b); InputStream is = new InputStream(bais); AudioInputStrream aisOgg = AudioSystem.getAudioInputStream(is); AudioInputStrream aisPcm = AudioSystem. getAudioInputStream(pcmAudioFormat, aisOgg);
is = new InputStream(...); Helper.getInstance().setInputStreamer(is); Intent i = new Intent(MainActivity.this, ChildActivity.class); startActivity(i);
InputStream in = new java.util.GZIPInputStream(new FileInputStream(file)); byte[] buffer = new byte[1024]; int read = 0; while (( read = in.read(buffer, 0, 1024)) > 0) { // do sth }
File transferFile = new File(file); InputStream in = new InputStream(transferFile); // Create connection Socket conn = new Socket(address, port); OutputStream out = conn.getOutputStream(); copyStream(in,out); in.close(); out.close(); conn.close();
//Don't forget the manifest permission to write files final FileOutputStream fos = new FileOutputStream(yourFileHere); bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos); fos.close(); final InputStream is = new Base64InputStream( new FileInputStream(yourFileHere) ); //Now that we have the InputStream, we can read it and put it into the String final StringWriter writer = new StringWriter(); IOUtils.copy(is , writer, encoding); final String yourBase64String = writer.toString();
String text = "this is text"; // It can be Unicode text ByteBuffer buffer = ByteBuffer.wrap(text.getBytes("UTF-8")); InputStream is = new ByteBufferBackedInputStream(buffer); InputStreamReader r = new InputStreamReader(is, "UTF-8"); BufferedReader br = new BufferedReader(r); BufferedReader br = new BufferedReader(r);
FileInputStream fis = new FileInputStream( new File( "thefile.cfg.Z" ) ); InputStream is = new UncompressInputStream( new BufferedInputStream( fis ) ); BufferedReader reader = new BufferedReader(new InputStreamReader( is ) ); String line = null; while ( ( line = reader.readLine() ) != null ) { System.out.println( "line = " + line ); }
try{ MultipartFile newFile=multiPartRequest.getFile("newFileUpload"); InputStream is = new newFile.getInputStream(); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(is); } catch (SAXException | IOException | ParserConfigurationException ex) { Logger.getLogger(JavaApplication4.class.getName()).log(Level.SEVERE, null, ex); }
InputSource is = new InputSource(new InputStream(xml_file)); SAXParserFactory spf = SAXParserFactory.newInstance(); SAXParser sp = spf.newSAXParser(); XMLReader xr = sp.getXMLReader(); dataHandler = new UIXMLHandler(); xr.setContentHandler(dataHandler); xr.parse(is);
List<InputStream> list = new ArrayList<InputStream>(3); list.add(new FileInputStream("head.xml")); list.add(new FileInputStream("body.xml")); list.add(new FileInputStream("tail.xml")); InputStream xmlStream = new SequentialInputStream(Collections.enumeration(list));
URL url = new URL("http://10.10.1.154" + GETIMAGESCR()); InputStream is = new InputStream(url.openStream()); FileOutputStream out = new FileOutputStream("D:\\alphas\\proba.jpg"); byte[] data = new byte[1024]; int readBytes = 0; while ((readBytes = is.read(data)) > 0) { out.write(data,0,readBytes); } out.flush(); out.close(); is.close()
try (InputStream is = new InputStream(socket); OutputStream os = new OutputStream(socket); ObjectInputStream ois = new ObjectInputStream(is) ObjectOutputStream oos = new ObjectInputStream(os)) { // Do stuff here }
Environment env = new Environment(); env.setInitialContextFactory(Environment.DEFAULT_INITIAL_CONTEXT_FACTORY); // env.setSecurityPrincipal("user"); // env.setSecurityCredentials("pass"); env.setProviderUrl("t3s://localhost:7002"); InputStream key = new PEMInputStream(new FileInputStream(CERT_KEYFILE)); InputStream cert = new PEMInputStream(new FileInputStream(CERT_CERTFILE)); env.setSSLClientCertificate(new InputStream[] {key, cert}); env.setSSLClientKeyPassword(CERT_KEYPASSWORD);