-
Notifications
You must be signed in to change notification settings - Fork 244
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is more complicated than originally described because the file encoding isn't really described and java bytes include negative values. EOF is triggered correctly, but it's also triggered on various potential characters which become negative values when they are truncated to byte. It's unclear if this is meant to only read ASCII, ISO 8859-1, or UTF-8 but nothing outside of the ascii space works correctly.
- Loading branch information
1 parent
f684576
commit 1239e98
Showing
2 changed files
with
49 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/test/java/htsjdk/tribble/util/LittleEndianInputStreamTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package htsjdk.tribble.util; | ||
|
||
import com.google.common.io.LittleEndianDataOutputStream; | ||
import htsjdk.HtsjdkTest; | ||
import org.testng.Assert; | ||
import org.testng.annotations.Test; | ||
|
||
import java.io.BufferedInputStream; | ||
import java.io.BufferedOutputStream; | ||
import java.io.EOFException; | ||
import java.io.FileInputStream; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.nio.file.Files; | ||
|
||
import static org.testng.Assert.*; | ||
|
||
public class LittleEndianInputStreamTest extends HtsjdkTest { | ||
|
||
@Test(expectedExceptions = EOFException.class) | ||
public void testReadStringEOF() throws IOException { | ||
final String emptyFile = "src/test/resources/htsjdk/tribble/util/string_with_extended_ascii_no_terminator.bin"; | ||
try(final LittleEndianInputStream in = new LittleEndianInputStream(new BufferedInputStream(new FileInputStream(emptyFile)))){ | ||
in.readString(); | ||
} | ||
} | ||
|
||
@Test | ||
public void testReadStringWithExtendedCharacters() throws IOException { | ||
final String emptyFile = "src/test/resources/htsjdk/tribble/util/string_with_extended_ascii_and_null_terminator.bin"; | ||
try(final LittleEndianInputStream in = new LittleEndianInputStream(new BufferedInputStream(new FileInputStream(emptyFile)))){ | ||
Assert.assertEquals(in.readString(), "very dràààààmatic and null terminated"); | ||
} | ||
} | ||
|
||
|
||
@Test(expectedExceptions = EOFException.class) | ||
public void write() throws IOException { | ||
final String emptyFile = "src/test/resources/htsjdk/tribble/util/string_with_extended_ascii_and_null_terminator.bin"; | ||
try(final LittleEndianDataOutputStream out = new LittleEndianDataOutputStream(new FileOutputStream(emptyFile))){ | ||
out.writeBytes("very dràààààmatic and null terminated\0"); | ||
} | ||
} | ||
} |