List of usage examples for java.io FilterInputStream close
public void close() throws IOException
From source file:Main.java
public static void main(String[] args) throws Exception { // create input streams InputStream is = new FileInputStream("C://test.txt"); FilterInputStream fis = new BufferedInputStream(is); // closes and releases the associated system resources fis.close(); // read is called after close() invocation fis.read();/*from www . j a va2 s . co m*/ }
From source file:org.alfresco.repo.imap.RemoteLoadTester.java
public void testMailbox() { logger.info("Getting folder..."); long t = System.currentTimeMillis(); // Create empty properties Properties props = new Properties(); props.setProperty("mail.imap.partialfetch", "false"); // Get session Session session = Session.getDefaultInstance(props, null); Store store = null;/*from w w w .j ava 2s .c o m*/ Folder folder = null; try { // Get the store store = session.getStore("imap"); store.connect(REMOTE_HOST, USER_NAME, USER_PASSWORD); // Get folder folder = store.getFolder(TEST_FOLDER_NAME); folder.open(Folder.READ_ONLY); // Get directory Message message[] = folder.getMessages(); for (int i = 0, n = message.length; i < n; i++) { message[i].getAllHeaders(); Address[] from = message[i].getFrom(); System.out.print(i + ": "); if (from != null) { System.out.print(message[i].getFrom()[0] + "\t"); } System.out.println(message[i].getSubject()); Object content = message[i].getContent(); if (content instanceof MimeMultipart) { for (int j = 0, m = ((MimeMultipart) content).getCount(); j < m; j++) { BodyPart part = ((MimeMultipart) content).getBodyPart(j); Object partContent = part.getContent(); if (partContent instanceof String) { String body = (String) partContent; } else if (partContent instanceof FilterInputStream) { FilterInputStream fis = (FilterInputStream) partContent; BufferedInputStream bis = new BufferedInputStream(fis); /* while (bis.available() > 0) { bis.read(); }*/ byte[] bytes = new byte[524288]; while (bis.read(bytes) != -1) { } bis.close(); fis.close(); } } } int nn = 0; } t = System.currentTimeMillis() - t; logger.info("Time: " + t + " ms (" + t / 1000 + " s)"); logger.info("Length: " + message.length); } catch (Exception e) { logger.error(e.getMessage(), e); fail(e.getMessage()); } finally { // Close connection try { if (folder != null) { folder.close(false); } } catch (MessagingException e) { logger.error(e.getMessage(), e); fail(e.getMessage()); } try { if (store != null) { store.close(); } } catch (MessagingException e) { logger.error(e.getMessage(), e); fail(e.getMessage()); } } }