Skip to content

Commit 85f70ef

Browse files
authored
Merge pull request #5 from ashishb/patch-1
Add buffering to file read/write process
2 parents f08b49b + e0366a3 commit 85f70ef

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

cache/src/main/java/com/tomclaw/cache/Journal.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.tomclaw.cache;
22

3+
import java.io.BufferedInputStream;
4+
import java.io.BufferedOutputStream;
35
import java.io.DataInputStream;
46
import java.io.DataOutputStream;
57
import java.io.File;
@@ -105,7 +107,7 @@ private void setTotalSize(long totalSize) {
105107

106108
public void writeJournal() {
107109
try (FileOutputStream fileStream = new FileOutputStream(file)) {
108-
try (DataOutputStream stream = new DataOutputStream(fileStream)) {
110+
try (DataOutputStream stream = new DataOutputStream(new BufferedOutputStream(fileStream))) {
109111
stream.writeShort(JOURNAL_FORMAT_VERSION);
110112
stream.writeInt(map.size());
111113
for (Record record : map.values()) {
@@ -126,7 +128,7 @@ public static Journal readJournal(FileManager fileManager, Logger logger) {
126128
logger.log("[.] Start journal reading", file.getName());
127129
Journal journal = new Journal(file, fileManager, logger);
128130
try (FileInputStream fileStream = new FileInputStream(file)) {
129-
try (DataInputStream stream = new DataInputStream(fileStream)) {
131+
try (DataInputStream stream = new DataInputStream(new BufferedInputStream(fileStream))) {
130132
int version = stream.readShort();
131133
if (version != JOURNAL_FORMAT_VERSION) {
132134
throw new IllegalArgumentException("Invalid journal format version");

0 commit comments

Comments
 (0)