- Notifications
You must be signed in to change notification settings - Fork 44
add BufferedFileDataOutput and BufferedFileDataInput #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Codecov Report
@@ Coverage Diff @@ ## master #15 +/- ## ============================================ + Coverage 77.83% 80.31% +2.47% - Complexity 631 746 +115 ============================================ Files 68 72 +4 Lines 2148 2474 +326 Branches 176 216 +40 ============================================ + Hits 1672 1987 +315 - Misses 370 371 +1 - Partials 106 116 +10
Continue to review full report at Codecov.
|
int readLen = (int) Math.min(bufferSize, this.fileLength); | ||
this.file.readFully(this.buffer(), 0, readLen); | ||
this.fileOffset = readLen; | ||
super.limit(readLen); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
call fillBuffer
int remaining = this.remaining(); | ||
if (remaining > 0) { | ||
System.arraycopy(this.buffer, this.position, | ||
this.buffer,0, remaining); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a space before 0
* Cut the content from 0 to position and copy the content from position | ||
* to the end to 0. | ||
*/ | ||
protected void cutReadBuffer() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shiftBuffer() is ok
super.write(b, off, len); | ||
return; | ||
} | ||
this.writeBuffer(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename to flushBuffer()
int remaining = super.remaining(); | ||
super.readFully(b, off, remaining); | ||
this.file.readFully(b, off + remaining, len - remaining); | ||
this.fileOffset += len; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a method fillBuffer()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
part of the data needed is in buffer, the other part is in file, and the length of data is beyond the buffer size, so read from two places.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can add length parameter to fillBuffer()
import com.baidu.hugegraph.util.E; | ||
| ||
public class BufferedFileDataInput extends UnsafeByteArrayInput | ||
implements RandomAccessInput { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't implement RandomAccessInput, since UnsafeByteArrayInput implements RandomAccessInput
E.checkArgument(bufferSize >= 8, | ||
"The parameter bufferSize must be >= 8"); | ||
this.file = file; | ||
this.fileLength = file.length(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this field
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fileLength is used several time, we call file.length() every time?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems the fileLength is not used everywhere after added fillBuffer() method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is used in seek(long position). The position may be far from the current position
private final RandomAccessFile file; | ||
private final long fileLength; | ||
| ||
public BufferedFileDataInput(File file) throws IOException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add RandomAccessInputStream class to support InputStream as parameter
import com.baidu.hugegraph.computer.core.common.exception.ComputerException; | ||
import com.baidu.hugegraph.util.E; | ||
| ||
public class BufferedFileDataInput extends UnsafeByteArrayInput |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename to BufferedFileInput
int remaining = super.remaining(); | ||
super.readFully(b, off, remaining); | ||
this.file.readFully(b, off + remaining, len - remaining); | ||
this.fileOffset += len; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can add length parameter to fillBuffer()
super.seek(0L); | ||
this.file.readFully(this.buffer(), 0, readLen); | ||
super.limit(readLen); | ||
this.fileOffset = position + readLen; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also call fillBuffer()
} | ||
| ||
@Override | ||
public void readFully(byte[] b, int off, int len) throws IOException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should also deal with buffer overflow for other read* methods like readLong?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need, since the buffer size must be >=8, and if there is no enough data in the buffer, the overwritten require method will fillBuffer again.
computer-core/src/main/java/com/baidu/hugegraph/computer/core/io/BufferedFileOutput.java Show resolved Hide resolved
long bufferAvailable = this.bufferSize - position; | ||
if (bufferAvailable >= size) { | ||
super.require(size); | ||
long available = this.bufferSize - position; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
long available = this.bufferSize - super.position();
} | ||
| ||
public BufferedInputStream(InputStream in, int bufferSize) | ||
throws IOException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
align
| ||
public class BufferedInputStream extends UnsafeByteArrayInput { | ||
| ||
private long inOffset; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inputOffset
if (this.remaining() >= size) { | ||
return; | ||
} | ||
shiftAndFillBuffer(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add this
} | ||
| ||
@Test | ||
public void testInt() throws IOException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
testWriteInt
computer-test/src/main/java/com/baidu/hugegraph/computer/core/io/BufferedStreamTest.java Show resolved Hide resolved
computer-test/src/main/java/com/baidu/hugegraph/computer/core/io/BufferedStreamTest.java Show resolved Hide resolved
output.writeInt(Integer.MAX_VALUE); | ||
output.writeInt(Integer.MIN_VALUE); | ||
} | ||
LOG.info("file.length:{}", file.length()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove it
} | ||
} | ||
| ||
private File createTempFile() throws IOException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
set static
(this.osOffset + this.bufferSize) + ")"); | ||
"of range [" + this.outputOffset + ", " + | ||
(this.outputOffset + this.bufferSize) + | ||
")"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prefer to use String.format()
} | ||
| ||
private BufferedFileOutput createOutput(File file) | ||
private static BufferedFileOutput createOutput(File file) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
align
computer-test/src/main/java/com/baidu/hugegraph/computer/core/io/BufferedFileTest.java Show resolved Hide resolved
Assert.assertThrows(IOException.class, () -> { | ||
input.seek(size * 4 + 1); | ||
}, e -> { | ||
Assert.assertContains("Can't seek at position ", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove space
Assert.assertThrows(IOException.class, () -> { | ||
output.seek(output.position() - BUFFER_SIZE - 2); | ||
}, e -> { | ||
Assert.assertContains("out of range ", e.getMessage()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
} | ||
| ||
@Test | ||
public void testLargeByteArray() throws IOException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
writeXX
| ||
byte[] arrayRead = new byte[arraySize]; | ||
try (DataInputStream dis = new DataInputStream( | ||
new FileInputStream(file))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prefer to align with new DataInputStream
output.writeInt(i); | ||
} | ||
output.writeInt(200, 1); | ||
// Previous buffer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test 5 kind of position: buffer_start ~ buffer_end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The five kind of position include start point of current buffer, middle point of current buffer, end point of current buffer, before the current buffer, and current buffer, and the last two kind of position throws exception.
for (int i = 0; i < size; i++) { | ||
output.seek(i * 4); | ||
output.writeInt(i); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
empty line
} | ||
| ||
@Test | ||
public void testSeekMoreThanBuffer() throws IOException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
overflow and underflow
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test case is deleted, and overflow and underflow test is in testSeekOutRange
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please addressed all the comments
throw new IOException("The position is beyond the buffer"); | ||
throw new IOException(String.format( | ||
"The seek position %s is before the start position of " + | ||
"buffer %s", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The seek position %s underflows the start position %s of the buffer
/* | ||
* The reason to seek to the position beyond the current buffer is | ||
* the user may need to skip the data unread and known the position of | ||
* the data needed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason for seeking beyond the current buffer location is that the user may need to skip unread data and know the offset of the required data.
output.seek((size - 2) * 4); | ||
output.writeInt(Integer.MAX_VALUE); | ||
output.writeInt(Integer.MIN_VALUE); | ||
// The position is before the buffer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update all the "before" to "underflow"
public static final int UINT16_MAX = 0xffff; | ||
public static final long UINT32_MAX = 0xffffffffL; | ||
| ||
public static final int DEFAULT_BUFFER_SIZE = 8192; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not addressed comments: Bytes.KB * 8
"The seek position %s is before the start position of " + | ||
"buffer %s", | ||
position, this.inputOffset - super.limit())); | ||
"The seek position %s is underflow the start position " + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is underflow => underflows
public long skip(long n) throws IOException { | ||
E.checkArgument(n >= 0, "The parameter n must be >=0, but got %s", n); | ||
public long skip(long bytesToSkip) throws IOException { | ||
E.checkArgument(bytesToSkip >= 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0L
"The parameter bytesToSkip must be <= " + | ||
"Integer.MAX_VALUE"); | ||
public long skip(long bytesToSkip) throws IOException { | ||
E.checkArgument(bytesToSkip >= 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
output.writeByte(1); | ||
Assert.assertThrows(IllegalArgumentException.class, () -> { | ||
output.skip(-1); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert message
Assert.assertEquals((byte) 1, input.readByte()); | ||
Assert.assertThrows(IllegalArgumentException.class, () -> { | ||
input.skip(-1); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert message
private void fillBuffer() throws IOException { | ||
long fileLength = this.file.length(); | ||
int readLen = Math.min(this.bufferSize - super.limit(), | ||
int readLen = Math.min(this.bufferSize - this.limit(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use this.remaining() instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
read fill the buffer after the limit, remaining is the buffer before the limit.
public int remaining() {
return this.limit - this.position;
}
if (position < this.fileOffset && | ||
position >= this.fileOffset - this.bufferSize) { | ||
super.seek(this.bufferSize - (this.fileOffset - position)); | ||
super.seek(this.limit() - (this.fileOffset - position)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this.limit() and this.bufferSize are the same value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not the same value. The last buffer may not equals bufferSize.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bufferStart = this.fileOffset - this.limit
put position >= bufferStart before position < this.fileOffset
super.seek(position - bufferStart)
output.skip(-1); | ||
}, e -> { | ||
e.getMessage().contains("The parameter bytesToSkip must " + | ||
"be >=0"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expect space ">=0"
if (position < this.fileOffset && | ||
position >= this.fileOffset - this.bufferSize) { | ||
super.seek(this.bufferSize - (this.fileOffset - position)); | ||
super.seek(this.limit() - (this.fileOffset - position)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
int expectLen = Math.min(skipLen, this.bufferSize); | ||
int readLen = this.input.read(buffer, 0, expectLen); | ||
if (readLen == -1) { | ||
throw new IOException("Reach the end of input stream"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
improve message
} | ||
this.shiftAndFillBuffer(); | ||
if (size > this.limit()) { | ||
throw new IOException("Can't read " + size + " bytes"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
improve message, like "read %size bytes from position overflows buffer %this.limit()"
private void require(int size) { | ||
@Override | ||
public void close() throws IOException { | ||
// Do nothing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pass
| ||
protected void limit(int limit) { | ||
E.checkArgument(limit <= this.buffer.length, | ||
"The limit must be >= buffer.length: {}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
buffer length %s
Assert.assertContains("is out of range", | ||
e.getMessage()); | ||
}); | ||
Assert.assertThrows(IOException.class, () -> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Behind buffer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
overflows the buffer is better.
| ||
byte[] arrayRead = new byte[10]; | ||
try (DataInputStream dis = new DataInputStream( | ||
new FileInputStream(file))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
align
@Override | ||
public void close() throws IOException { | ||
// Do nothing | ||
// Pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lower case pass
@Override | ||
public void close() throws IOException { | ||
// Do nothing | ||
// Pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
if (size > this.limit()) { | ||
throw new IOException("Can't read " + size + " bytes"); | ||
throw new IOException(String.format( | ||
"Read %s bytes from position overflows buffer %s", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
position %s
"The position %s is out of range [%s, %s]", | ||
position, this.outputOffset, | ||
this.position() - 4)); | ||
"Write int from position %s overflows the write " + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Write int to position
} else { | ||
throw new IOException(String.format( | ||
"Write int from position %s overflows the write " + | ||
"Write int to position %s overflows the write " + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this.position() - 4
use INT_SIZE
private long fileOffset; | ||
| ||
public BufferedFileInput(File file) throws IOException { | ||
this(new RandomAccessFile(file, "r"), Constants.DEFAULT_BUFFER_SIZE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const var "r"
if (position < this.fileOffset && | ||
position >= this.fileOffset - this.bufferSize) { | ||
super.seek(this.bufferSize - (this.fileOffset - position)); | ||
super.seek(this.limit() - (this.fileOffset - position)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bufferStart = this.fileOffset - this.limit
put position >= bufferStart before position < this.fileOffset
super.seek(position - bufferStart)
@Override | ||
public void seek(long position) throws IOException { | ||
if (position < this.fileOffset && | ||
position >= this.fileOffset - this.bufferSize) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-this.limit
if (this.bufferSize >= size) { | ||
this.shiftAndFillBuffer(); | ||
} else { | ||
throw new ComputerException("Should not reach here"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment: Should not reach here
throw XxException
this.fileOffset = position; | ||
this.fillBuffer(); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
empty line
return; | ||
} | ||
this.flushBuffer(); | ||
assert size <= this.bufferAvailable(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throw
private long fileOffset; | ||
| ||
public BufferedFileOutput(File file) throws FileNotFoundException { | ||
this(new RandomAccessFile(file, "rw"), Constants.DEFAULT_BUFFER_SIZE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const var
return; | ||
} | ||
this.flushBuffer(); | ||
if (len <= this.bufferSize) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this.bufferCapacity
E.checkArgument(bufferSize >= 8, | ||
"The parameter bufferSize must be >= 8"); | ||
this.file = file; | ||
this.bufferSize = bufferSize; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bufferCapacity
/* | ||
* The buffer capacity must be >= 8, read primitive data like int, | ||
* long, float, double can be read from buffer. Only read bytes may | ||
* exceed the limit, and read bytes using readFully is overrode |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
override
* The buffer capacity must be >= 8, write primitive data like int, | ||
* long, float, double can be write to buffer after flush buffer. | ||
* Only write bytes may exceed the limit, and write bytes using | ||
* write(byte[] b) is overrode in this class. In conclusion, the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
override
this.file.close(); | ||
} | ||
| ||
protected void require(int size) throws IOException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add @OverRide
try (FileOutputStream fos = new FileOutputStream(file); | ||
DataOutputStream dos = new DataOutputStream(fos)) { | ||
try { | ||
BufferedFileOutput dos = new BufferedFileOutput(file); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try (BufferedFileOutput dos = new BufferedFileOutput(file)) {
...
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't read the data in try, the dos in try only auto close after try.
computer-test/src/main/java/com/baidu/hugegraph/computer/core/io/CsvStructGraphOutputTest.java Show resolved Hide resolved
computer-test/src/main/java/com/baidu/hugegraph/computer/core/io/JsonStructGraphOutputTest.java Show resolved Hide resolved
throw new IOException(String.format( | ||
"The position %s is out of range [%s, %s]", | ||
position, this.outputOffset, | ||
this.outputOffset + this.bufferCapacity)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
upper bound is this.position()
return this.in.readInt(); | ||
} | ||
| ||
public int readFullInt() throws IOException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add final
} | ||
endTime = System.currentTimeMillis(); | ||
time = endTime - startTime; | ||
LOG.info("Read {} bytes use DataInputStream.readFully takes{} ms", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expect space after "takes"
| ||
private static BufferedFileOutput createOutput(File file) | ||
throws FileNotFoundException { | ||
return new BufferedFileOutput(new RandomAccessFile(file, "rw"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use const
| ||
private static BufferedFileInput createInput(File file) | ||
throws IOException { | ||
return new BufferedFileInput(new RandomAccessFile(file, "rw"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
// Middle of current buffer | ||
output.writeInt(200, 2); | ||
output.writeInt(252, 3); | ||
// Previous buffer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update comment
Assert.assertContains("underflows the start position", | ||
e.getMessage()); | ||
}); | ||
Assert.assertThrows(IOException.class, () -> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add comment
Assert.assertContains("out of range", e.getMessage()); | ||
}); | ||
| ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
empty lines
GraphOutputFactory.create( | ||
OutputFormat.CSV, dos); | ||
output.writeVertex(vertex); | ||
dos.close(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prefer to call flush()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
close is better, it calls flush and close other resource.
| ||
@Test | ||
public void testConstructor() throws IOException { | ||
File file = this.createTempFile(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 spaces
f4e4d32
to 2104b2c
Compare
No description provided.