Skip to content

Commit

Permalink
Merge pull request #5 from ashishb/patch-1
Browse files Browse the repository at this point in the history
Add buffering to file read/write process
  • Loading branch information
solkin committed Feb 14, 2023
2 parents f08b49b + e0366a3 commit 85f70ef
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions cache/src/main/java/com/tomclaw/cache/Journal.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.tomclaw.cache;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
Expand Down Expand Up @@ -105,7 +107,7 @@ private void setTotalSize(long totalSize) {

public void writeJournal() {
try (FileOutputStream fileStream = new FileOutputStream(file)) {
try (DataOutputStream stream = new DataOutputStream(fileStream)) {
try (DataOutputStream stream = new DataOutputStream(new BufferedOutputStream(fileStream))) {
stream.writeShort(JOURNAL_FORMAT_VERSION);
stream.writeInt(map.size());
for (Record record : map.values()) {
Expand All @@ -126,7 +128,7 @@ public static Journal readJournal(FileManager fileManager, Logger logger) {
logger.log("[.] Start journal reading", file.getName());
Journal journal = new Journal(file, fileManager, logger);
try (FileInputStream fileStream = new FileInputStream(file)) {
try (DataInputStream stream = new DataInputStream(fileStream)) {
try (DataInputStream stream = new DataInputStream(new BufferedInputStream(fileStream))) {
int version = stream.readShort();
if (version != JOURNAL_FORMAT_VERSION) {
throw new IllegalArgumentException("Invalid journal format version");
Expand Down

0 comments on commit 85f70ef

Please sign in to comment.