-
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cd69f05
commit 7b68012
Showing
6 changed files
with
113 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
...oid-libproofmode/src/main/java/org/witness/proofmode/data_processor/DataWriterReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.witness.proofmode.data_processor; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* Interface for writing and reading files. | ||
* | ||
*/ | ||
public interface DataWriterReader { | ||
void writeData(byte[] data) throws IOException; | ||
byte[] readData() throws IOException; | ||
} | ||
|
||
|
31 changes: 31 additions & 0 deletions
31
...libproofmode/src/main/java/org/witness/proofmode/data_processor/FileDescriptorWriter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.witness.proofmode.data_processor; | ||
|
||
import java.io.FileDescriptor; | ||
import java.io.FileInputStream; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
|
||
public class FileDescriptorWriter implements DataWriterReader { | ||
private final FileDescriptor fileDescriptor; | ||
|
||
public FileDescriptorWriter(FileDescriptor fileDescriptor) { | ||
this.fileDescriptor = fileDescriptor; | ||
} | ||
|
||
@Override | ||
public void writeData(byte[] data) throws IOException { | ||
try (FileOutputStream fos = new FileOutputStream(fileDescriptor)) { | ||
fos.write(data); | ||
fos.flush(); | ||
} | ||
} | ||
|
||
@Override | ||
public byte[] readData() throws IOException { | ||
try (FileInputStream fis = new FileInputStream(fileDescriptor)) { | ||
byte[] buffer = new byte[fis.available()]; | ||
fis.read(buffer); | ||
return buffer; | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...oid-libproofmode/src/main/java/org/witness/proofmode/data_processor/FileWriterReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package org.witness.proofmode.data_processor; | ||
|
||
import java.io.DataInputStream; | ||
import java.io.DataOutputStream; | ||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
|
||
/** | ||
* Writing and reading [File]s | ||
*/ | ||
public class FileWriterReader implements DataWriterReader { | ||
private final File fileOut; | ||
|
||
public FileWriterReader(File fileOut) { | ||
this.fileOut = fileOut; | ||
} | ||
|
||
@Override | ||
public void writeData(byte[] data) throws IOException { | ||
try (DataOutputStream os = new DataOutputStream(new FileOutputStream(fileOut, false))) { | ||
os.write(data); | ||
os.flush(); | ||
} | ||
} | ||
|
||
@Override | ||
public byte[] readData() throws IOException { | ||
try (DataInputStream is = new DataInputStream(new FileInputStream(fileOut))) { | ||
byte[] buffer = new byte[(int) fileOut.length()]; | ||
is.readFully(buffer); | ||
return buffer; | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...ibproofmode/src/main/java/org/witness/proofmode/data_processor/MultiDataWriterReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package org.witness.proofmode.data_processor; | ||
|
||
import java.io.File; | ||
import java.io.FileDescriptor; | ||
import java.io.IOException; | ||
|
||
public class MultiDataWriterReader implements DataWriterReader{ | ||
private final DataWriterReader dataWriterReader; | ||
|
||
public MultiDataWriterReader(File file) { | ||
this.dataWriterReader = new FileWriterReader(file); | ||
} | ||
|
||
public MultiDataWriterReader(FileDescriptor fileDescriptor) { | ||
this.dataWriterReader = new FileDescriptorWriter(fileDescriptor); | ||
} | ||
@Override | ||
public void writeData(byte[] data) throws IOException { | ||
|
||
} | ||
|
||
@Override | ||
public byte[] readData() throws IOException { | ||
return new byte[0]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters