Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: tebeka/zipstream
base: 40c05709e3
...
head fork: tebeka/zipstream
compare: 04cd2d3a72
  • 2 commits
  • 4 files changed
  • 0 commit comments
  • 1 contributor
Commits on Mar 12, 2013
@tebeka Ignore eclipse
--HG--
branch : multi
c53ac13
@tebeka works with many files
--HG--
branch : multi
04cd2d3
View
2  .hgignore
@@ -1,4 +1,6 @@
syntax: glob
+.classpath
+.project
target
README.html
View
16 src/main/java/com/mikitebeka/mapred/ZipLineIterator.java
@@ -13,7 +13,7 @@
public class ZipLineIterator implements Iterator<String> {
private ZipInputStream zin = null;
- private String name = null;
+ ZipEntry entry = null;
private String nextLine = null;
private BufferedReader reader = null;
private int pos = 0;
@@ -24,7 +24,7 @@ public ZipLineIterator(InputStream in) throws IOException {
nextEntry();
}
- private void nextEntry() {
+ private void nextEntry() throws IOException {
nextLine = null;
if (entry != null) {
@@ -36,7 +36,6 @@ private void nextEntry() {
return;
}
- name = entry.getName();
reader = new BufferedReader(new InputStreamReader(zin));
nextLine = reader.readLine();
}
@@ -59,12 +58,15 @@ public boolean hasNext() {
@Override
public String next() {
String line = nextLine;
- pos += line.length();
+ pos += (line == null) ? 0 : line.length();
try {
nextLine = reader.readLine();
+ if (nextLine == null) {
+ nextEntry();
+ }
} catch (IOException e) {
- nextEntry();
+ nextLine = null;
}
return line;
@@ -84,7 +86,7 @@ public void remove() {
* @return the name
*/
public String getName() {
- return name;
+ return (entry == null) ? null : entry.getName();
}
public void close() throws IOException {
@@ -95,7 +97,7 @@ public void close() throws IOException {
}
public float getProgress() {
- // FIXME
+ // FIXME: Find a good way to get total zip size from ZipInputStream
return 0.5f;
}
View
29 src/test/java/com/mikitebeka/mapred/ZipLineReaderTest.java
@@ -15,19 +15,44 @@ private ZipLineIterator getZip(String file) throws IOException {
return new ZipLineIterator(in);
}
- public void TestSmallFile() throws IOException {
- ZipLineIterator it = getZip("3.zip");
+ private ArrayList<String> readLines(ZipLineIterator it) {
ArrayList<String> lines = new ArrayList<String>();
while (it.hasNext()) {
lines.add(it.next());
}
+ return lines;
+ }
+
+ public void TestSmallFile() throws IOException {
+ ZipLineIterator it = getZip("3.zip");
+ ArrayList<String> lines = readLines(it);
+
+ @SuppressWarnings("serial")
+ ArrayList<String> expected = new ArrayList<String>() {
+ {
+ add("1");
+ add("2");
+ add("3");
+ }
+ };
+
+ Assert.assertTrue(lines.equals(expected));
+ }
+
+ public void TestMultiFiles() throws IOException {
+ ZipLineIterator it = getZip("2.zip");
+ ArrayList<String> lines = readLines(it);
+
@SuppressWarnings("serial")
ArrayList<String> expected = new ArrayList<String>() {
{
add("1");
add("2");
add("3");
+ add("a");
+ add("b");
+ add("c");
}
};
View
BIN  src/test/resources/2.zip
Binary file not shown

No commit comments for this range

Something went wrong with that request. Please try again.