Skip to content

Commit

Permalink
Merge pull request #2 from rchodava/sf-issue-43
Browse files Browse the repository at this point in the history
Allow truncation
  • Loading branch information
rchodava committed Feb 25, 2016
2 parents de29c63 + 4a88c3d commit 5b15ac0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/main/java/com/chodavarapu/io/ReadWriteBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ public OutputStream openOutputStream() {
return new BufferOutputStream();
}

public void truncate() {
synchronized (bufferMonitor) {
writtenPosition = 0;
}
}

private class BufferInputStream extends InputStream {
private int readPosition = 0;
private long waitStart;
Expand Down
18 changes: 18 additions & 0 deletions src/test/java/com/chodavarapu/io/ReadWriteBufferTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,24 @@ public void basicReadWrite() throws Exception {
assertEquals("Another String", reader.readLine());
}

@Test
public void truncation() throws Exception {
ReadWriteBuffer buffer = new ReadWriteBuffer();

OutputStreamWriter writer = new OutputStreamWriter(buffer.openOutputStream());
writer.write("Test String\n");
writer.flush();

buffer.truncate();

BufferedReader reader = new BufferedReader(new InputStreamReader(buffer.openInputStream()));

writer.write("Another String\n");
writer.flush();

assertEquals("Another String", reader.readLine());
}

@Test
public void outputCompletionNotification() throws Exception {
ArrayList<byte[]> completionNotificationBytes = new ArrayList<>();
Expand Down

0 comments on commit 5b15ac0

Please sign in to comment.