@Test public void testGetNextInputStream() { writeSimpleFiles(BASE_DIR,"txt",NUM_FILES_IN_DIR); streamSource.init(BASE_DIR, "txt"); Set<String> contents = new HashSet<String>(); for (int i=1; i<=NUM_FILES_IN_DIR; i++) { contents.add(Integer.toString(i)); } for (int i=0; i< NUM_FILES_IN_DIR; i++) { InputStream inStream = streamSource.getNextInputStream(); assertNotNull("Unexpected end of input stream list.",inStream); BufferedReader rd = new BufferedReader(new InputStreamReader(inStream)); String inputRead = null; try { inputRead = rd.readLine(); } catch (IOException ioe) { fail("Fail reading from stream at index:"+i + ioe.getMessage()); } assertTrue("File content is incorrect.",contents.contains(inputRead)); Iterator<String> it = contents.iterator(); while (it.hasNext()) { if (it.next().equals(inputRead)) { it.remove(); break; } } } assertNull("Call getNextInputStream after the last file did not return null.",streamSource.getNextInputStream()); }
public InputStream getNextInputStream() { this.closeFileStream(); if (this.currentIndex >= (this.filePaths.size()-1)) return null; this.currentIndex++; String filePath = this.filePaths.get(currentIndex); File file = new File(filePath); try { fileStream = new FileInputStream(file); } catch(IOException ioe) { this.closeFileStream(); throw new RuntimeException("Failed opening file:"+filePath,ioe); } return fileStream; }
LocalFileStreamSource implements FileStreamSource { public InputStream getNextInputStream() { this.closeFileStream(); if (this.currentIndex >= (this.filePaths.size()-1)) return null; this.currentIndex++; String filePath = this.filePaths.get(currentIndex); File file = new File(filePath); try { fileStream = new FileInputStream(file); } catch(IOException ioe) { this.closeFileStream(); throw new RuntimeException("Failed opening file:"+filePath,ioe); } return fileStream; } }
LocalFileStreamSource implements FileStreamSource { public InputStream getNextInputStream() { this.closeFileStream(); if (this.currentIndex >= (this.filePaths.size()-1)) return null; this.currentIndex++; String filePath = this.filePaths.get(currentIndex); File file = new File(filePath); try { fileStream = new FileInputStream(file); } catch(IOException ioe) { this.closeFileStream(); throw new RuntimeException("Failed opening file:"+filePath,ioe); } return fileStream; } LocalFileStreamSource(); }
LocalFileStreamSource implements FileStreamSource { public InputStream getNextInputStream() { this.closeFileStream(); if (this.currentIndex >= (this.filePaths.size()-1)) return null; this.currentIndex++; String filePath = this.filePaths.get(currentIndex); File file = new File(filePath); try { fileStream = new FileInputStream(file); } catch(IOException ioe) { this.closeFileStream(); throw new RuntimeException("Failed opening file:"+filePath,ioe); } return fileStream; } LocalFileStreamSource(); void init(String path, String ext); void reset(); InputStream getNextInputStream(); InputStream getCurrentInputStream(); }
LocalFileStreamSource implements FileStreamSource { public InputStream getNextInputStream() { this.closeFileStream(); if (this.currentIndex >= (this.filePaths.size()-1)) return null; this.currentIndex++; String filePath = this.filePaths.get(currentIndex); File file = new File(filePath); try { fileStream = new FileInputStream(file); } catch(IOException ioe) { this.closeFileStream(); throw new RuntimeException("Failed opening file:"+filePath,ioe); } return fileStream; } LocalFileStreamSource(); void init(String path, String ext); void reset(); InputStream getNextInputStream(); InputStream getCurrentInputStream();  }