reduced flag arguments

This commit is contained in:
Lars Gohlke 2013-02-18 00:12:56 +01:00
parent eabe5b5902
commit a5cde51f04
5 changed files with 24 additions and 21 deletions
src
main/java
test/java/org/mrpdaemon/sec/encfs/tests

View file

@ -667,7 +667,7 @@ public class EncFSShell {
continue;
}
EncFSUtil.copyWholeStream(new EncFSFileInputStream(lastPathElement), System.out, true, false);
EncFSUtil.copyWholeStreamAndCloseInput(new EncFSFileInputStream(lastPathElement), System.out);
System.out.println();
}

View file

@ -310,7 +310,7 @@ public class EncFSFile {
* used.
*/
try {
EncFSUtil.copyWholeStream(openInputStream(), dstPath.openOutputStream(getLength()), true, true);
EncFSUtil.copyWholeStreamAndClose(openInputStream(), dstPath.openOutputStream(getLength()));
} catch (EncFSException e) {
throw new IOException(e);
}

View file

@ -22,8 +22,11 @@ import java.nio.ByteBuffer;
public class EncFSUtil {
private static final int EIGHT = 8;
private static final int EIGHT_KILO = 8192;
public static int convertBigEndianByteArrayToInt(byte[] b) {
int capacity = Integer.SIZE / 8;
int capacity = Integer.SIZE / EIGHT;
if (b.length > capacity) {
return -1;
}
@ -31,11 +34,11 @@ public class EncFSUtil {
}
public static byte[] convertIntToByteArrayBigEndian(int i) {
return ByteBuffer.allocate(Integer.SIZE / 8).putInt(i).array();
return ByteBuffer.allocate(Integer.SIZE / EIGHT).putInt(i).array();
}
public static long convertByteArrayToLong(byte[] b) {
int capacity = Long.SIZE / 8;
int capacity = Long.SIZE / EIGHT;
if (b.length > capacity) {
return -1;
}
@ -43,27 +46,27 @@ public class EncFSUtil {
}
public static byte[] convertLongToByteArrayBigEndian(long l) {
return ByteBuffer.allocate(Long.SIZE / 8).putLong(l).array();
return ByteBuffer.allocate(Long.SIZE / EIGHT).putLong(l).array();
}
public static void copyWholeStream(InputStream in, OutputStream out, boolean closeInput, boolean closeOutput) throws IOException {
public static void copyWholeStreamAndCloseInput(InputStream in, OutputStream out) throws IOException {
try {
try {
readFromAndWriteTo(in, out);
} finally {
if (closeInput) {
in.close();
}
}
readFromAndWriteTo(in, out);
} finally {
if (closeOutput) {
out.close();
}
in.close();
}
}
public static void copyWholeStreamAndClose(InputStream in, OutputStream out) throws IOException {
try {
copyWholeStreamAndCloseInput(in, out);
} finally {
out.close();
}
}
private static void readFromAndWriteTo(InputStream in, OutputStream out) throws IOException {
byte[] buf = new byte[8192];
byte[] buf = new byte[EIGHT_KILO];
int bytesRead = in.read(buf);
while (bytesRead >= 0) {
out.write(buf, 0, bytesRead);

View file

@ -158,7 +158,7 @@ public class EncFSComparer {
// the file is the same
File t = File.createTempFile(this.getClass().getName(), ".tmp");
try {
EncFSUtil.copyWholeStream(new EncFSFileInputStream(encFsFile), new EncFSOutputStream(encFsDir.getVolume(), new BufferedOutputStream(new FileOutputStream(t)), encFsFile.getPath()), true, true);
EncFSUtil.copyWholeStreamAndClose(new EncFSFileInputStream(encFsFile), new EncFSOutputStream(encFsDir.getVolume(), new BufferedOutputStream(new FileOutputStream(t)), encFsFile.getPath()));
FileInputStream reEncFSIs = new FileInputStream(t);
try {

View file

@ -330,7 +330,7 @@ public class EncFSVolumeIntegrationTest {
if (!encFsFile.isDirectory()) { /* Copy the file via input/output streams & then check that the file is the same */
File t = File.createTempFile(this.getClass().getName(), ".tmp");
try {
EncFSUtil.copyWholeStream(new EncFSFileInputStream(encFsFile), new EncFSOutputStream(encFsFile.getVolume(), new BufferedOutputStream(new FileOutputStream(t)), encFsFile.getPath()), true, true);
EncFSUtil.copyWholeStreamAndClose(new EncFSFileInputStream(encFsFile), new EncFSOutputStream(encFsFile.getVolume(), new BufferedOutputStream(new FileOutputStream(t)), encFsFile.getPath()));
if (!encFsFile.getVolume().getVolumeConfiguration().isUseUniqueIV()) {
FileInputStream reEncFSIs = new FileInputStream(t);
try {
@ -429,7 +429,7 @@ public class EncFSVolumeIntegrationTest {
private static byte[] readInputStreamAsByteArray(EncFSFile encFSFile) throws Exception {
ByteArrayOutputStream buf = new ByteArrayOutputStream();
EncFSUtil.copyWholeStream(new EncFSFileInputStream(encFSFile), buf, true, false);
EncFSUtil.copyWholeStreamAndCloseInput(new EncFSFileInputStream(encFSFile), buf);
return buf.toByteArray();
}