com.arch.util.ByteUtils Maven / Gradle / Ivy
package com.arch.util;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
/**
* Created by wagner.araujo on 6/17/16.
*/
public final class ByteUtils {
public static final int BLOCK_SIZE = 1024;
private ByteUtils() {
}
public static byte[] getByte(File arquivo) throws IOException {
Path path = Paths.get(arquivo.getAbsolutePath());
return Files.readAllBytes(path);
}
public static byte[] getByte(InputStream is) throws IOException {
int size = BLOCK_SIZE;
byte[] buf;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
buf = new byte[size];
int len;
while ((len = is.read(buf, 0, size)) != -1) {
bos.write(buf, 0, len);
}
buf = bos.toByteArray();
return buf;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy