Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ public void close() {
// swallow it.
}
}

channel = null;
stream = null;
}

/** {@inheritDoc} */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,31 @@ void shouldReadThenClose() throws Exception {
location.close();
}

@Test
void shouldReopenAfterClose() throws Exception {
File file = Files.createTempFile("test.", ".file-location").toFile();
file.deleteOnExit();

String testStr = "This is a test";

FileUtils.writeStringToFile(file, testStr, "US-ASCII");

FileLocation location = new FileLocation(file, file.getAbsolutePath());

location.open();
byte[] buffer = new byte[testStr.length()];
location.read(buffer);
assertEquals(testStr, new String(buffer, StandardCharsets.US_ASCII));
location.close();

// read again after close should re-open
location.open();
buffer = new byte[testStr.length()];
location.read(buffer);
assertEquals(testStr, new String(buffer, StandardCharsets.US_ASCII));
location.close();
}

@Test
void shouldOpenThenFailToSetFile() throws Exception {
File file = Files.createTempFile("test.", ".file-location").toFile();
Expand Down
Loading