Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
1.1.5
-----
* [Removed direct reference to Unix TMP-path](https://github.com/iipc/webarchive-commons/issues/2)

1.1.4
-----
* [All dates should be independent of locale settings](https://github.com/iipc/webarchive-commons/pull/22)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
public class GZIPMemberWriterTest extends TestCase {

public void testWrite() throws IOException {
String outPath = "/tmp/tmp.gz";
GZIPMemberWriter gzw = new GZIPMemberWriter(new FileOutputStream(new File(outPath)));
File outFile = File.createTempFile("tmp", ".gz");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it make more sense to use java.io.tmpdir env. variable than relying on the current directory being suitable for tmp files?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the javadoc of File.createTempFile():
"Creates an empty file in the default temporary-file directory, using the given prefix and suffix to generate its name."

The default temporary-file dir should equal java.io.tmpdir which can be extracted using System.getProperty(). This could have been used, but then you would have construct a file using this string + file name. The current approach just gives fewer lines of code.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough.

GZIPMemberWriter gzw = new GZIPMemberWriter(new FileOutputStream(outFile));
gzw.write(new ByteArrayInputStream("Here is record 1".getBytes(IAUtils.UTF8)));
gzw.write(new ByteArrayInputStream("Here is record 2".getBytes(IAUtils.UTF8)));
}
Expand Down
38 changes: 19 additions & 19 deletions src/test/java/org/archive/net/PublicSuffixesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
*/
public class PublicSuffixesTest extends TestCase {
// test of low level implementation
private final String NL = System.lineSeparator();

public void testCompare() {
Node n = new Node("hoge");
Expand Down Expand Up @@ -78,27 +79,26 @@ public void testTrie1() {
Node alt = new Node(null, new ArrayList<Node>());
alt.addBranch("ac,");
// specifically, should not have empty string as match.
assertEquals("(null)\n" +
" \"ac,\"\n", dump(alt));
assertEquals("(null)" + NL + " \"ac,\"" + NL, dump(alt));
alt.addBranch("ac,com,");
assertEquals("(null)\n" +
" \"ac,\"\n" +
" \"com,\"\n" +
" \"\"\n", dump(alt));
assertEquals("(null)" + NL +
" \"ac,\"" + NL +
" \"com,\"" + NL +
" \"\"" + NL, dump(alt));
alt.addBranch("ac,edu,");
assertEquals("(null)\n" +
" \"ac,\"\n" +
" \"com,\"\n" +
" \"edu,\"\n" +
" \"\"\n", dump(alt));
assertEquals("(null)" + NL +
" \"ac,\"" + NL +
" \"com,\"" + NL +
" \"edu,\"" + NL +
" \"\"" + NL, dump(alt));
}
public void testTrie2() {
Node alt = new Node(null, new ArrayList<Node>());
alt.addBranch("ac,");
alt.addBranch("*,");
assertEquals("(null)\n" +
" \"ac,\"\n" +
" \"*,\"\n", dump(alt));
assertEquals("(null)" + NL +
" \"ac,\"" + NL +
" \"*,\"" + NL, dump(alt));
}

public void testTrie3() {
Expand All @@ -107,11 +107,11 @@ public void testTrie3() {
alt.addBranch("ac,!hoge,");
alt.addBranch("ac,*,");
// exception goes first.
assertEquals("(null)\n" +
" \"ac,\"\n" +
" \"!hoge,\"\n" +
" \"*,\"\n" +
" \"\"\n", dump(alt));
assertEquals("(null)" + NL +
" \"ac,\"" + NL +
" \"!hoge,\"" + NL +
" \"*,\"" + NL +
" \"\"" + NL, dump(alt));
}

// test of higher-level functionality
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ private void createFile(File target, int max) throws FileNotFoundException {


public void testGetRecordIteratorStringBoolean() throws IOException {
File test = new File("/tmp/test.tmp");
File test = File.createTempFile("test", null);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, why not java.io.tmpdir?

int max = 1000000;
createFile(test,max);
RandomAccessFileSeekableLineReaderFactory factory =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,19 @@
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Comparator;

import junit.framework.TestCase;

public class SortedCompositeIteratorTest extends TestCase {

public void testHasNext() throws FileNotFoundException {
public void testHasNext() throws FileNotFoundException, IOException {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where these lines non-functional?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the only use of "long t", "long c" and "float f" were to output the "System.err". An estimated guess is that the original writer for some reason needed to calculate "134/210000" and put it into the code, then forgot about it.

long t = 210000;
long c = 134;
float f = (float)c / (float)t;
System.err.format("F(%f)\n",f);
File a = File.createTempFile("filea", null);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

java.io.tmpdir?

File b = File.createTempFile("fileb", null);

File a = new File("/tmp/a");
File b = new File("/tmp/b");
if(a.isFile()) {
a.delete();
}
if(b.isFile()) {
b.delete();
}
PrintWriter apw = new PrintWriter(a);
PrintWriter bpw = new PrintWriter(b);
apw.println("1");
Expand All @@ -38,6 +29,7 @@ public void testHasNext() throws FileNotFoundException {
BufferedReader bbr = new BufferedReader(new FileReader(b));
SortedCompositeIterator<String> sci = new SortedCompositeIterator<String>(new Comparator<String>() {

@Override
public int compare(String o1, String o2) {
return o1.compareTo(o2);
}
Expand Down