@Test public void testReadFileContent() throws Throwable { ova = OvaTestModule.generateOva("ovf content"); inputStream = ova.getOvaStream(); TarFileStreamReader tarFile = new TarFileStreamReader(inputStream); TarFileStreamReader.TarFile file = tarFile.iterator().next(); assertNotNull(file); String content = OvaTestModule.readStringFromStream(file.content); assertEquals(content, ova.ovfContent); file = tarFile.iterator().next(); assertNotNull(file); content = OvaTestModule.readStringFromStream(file.content); assertEquals(content, ova.vmdkContent); }
@Override public Iterator<TarFile> iterator() { return new Iterator<TarFile>() { @Override public boolean hasNext() { try { if (lastFile != null) { lastFile.content.close(); lastFile = null; } if (nextFile == null) { nextFile = decodeNextFile(); } } catch (IOException e) { return false; } return nextFile != null; } @Override public TarFile next() { TarFile next = null; if (hasNext()) { next = nextFile; lastFile = nextFile; nextFile = null; } return next; } }; }
TarFileStreamReader implements Iterable<TarFileStreamReader.TarFile> { @Override public Iterator<TarFile> iterator() { return new Iterator<TarFile>() { @Override public boolean hasNext() { try { if (lastFile != null) { lastFile.content.close(); lastFile = null; } if (nextFile == null) { nextFile = decodeNextFile(); } } catch (IOException e) { return false; } return nextFile != null; } @Override public TarFile next() { TarFile next = null; if (hasNext()) { next = nextFile; lastFile = nextFile; nextFile = null; } return next; } }; } }
TarFileStreamReader implements Iterable<TarFileStreamReader.TarFile> { @Override public Iterator<TarFile> iterator() { return new Iterator<TarFile>() { @Override public boolean hasNext() { try { if (lastFile != null) { lastFile.content.close(); lastFile = null; } if (nextFile == null) { nextFile = decodeNextFile(); } } catch (IOException e) { return false; } return nextFile != null; } @Override public TarFile next() { TarFile next = null; if (hasNext()) { next = nextFile; lastFile = nextFile; nextFile = null; } return next; } }; } TarFileStreamReader(InputStream inputStream); }
TarFileStreamReader implements Iterable<TarFileStreamReader.TarFile> { @Override public Iterator<TarFile> iterator() { return new Iterator<TarFile>() { @Override public boolean hasNext() { try { if (lastFile != null) { lastFile.content.close(); lastFile = null; } if (nextFile == null) { nextFile = decodeNextFile(); } } catch (IOException e) { return false; } return nextFile != null; } @Override public TarFile next() { TarFile next = null; if (hasNext()) { next = nextFile; lastFile = nextFile; nextFile = null; } return next; } }; } TarFileStreamReader(InputStream inputStream); @Override Iterator<TarFile> iterator(); }
TarFileStreamReader implements Iterable<TarFileStreamReader.TarFile> { @Override public Iterator<TarFile> iterator() { return new Iterator<TarFile>() { @Override public boolean hasNext() { try { if (lastFile != null) { lastFile.content.close(); lastFile = null; } if (nextFile == null) { nextFile = decodeNextFile(); } } catch (IOException e) { return false; } return nextFile != null; } @Override public TarFile next() { TarFile next = null; if (hasNext()) { next = nextFile; lastFile = nextFile; nextFile = null; } return next; } }; } TarFileStreamReader(InputStream inputStream); @Override Iterator<TarFile> iterator(); static final int TAR_FILE_GRANULARITY; }