X-Git-Url: https://git.nmode.ca/signal-cli/blobdiff_plain/4adb11dada29ac6ca2d12270fd7e617007ff9bf3..c72aeed8bba4d5ca873b36b4edb2b8eda9c24ec7:/src/main/java/org/asamk/signal/manager/util/IOUtils.java diff --git a/src/main/java/org/asamk/signal/manager/util/IOUtils.java b/src/main/java/org/asamk/signal/manager/util/IOUtils.java deleted file mode 100644 index 8f47c9f4..00000000 --- a/src/main/java/org/asamk/signal/manager/util/IOUtils.java +++ /dev/null @@ -1,76 +0,0 @@ -package org.asamk.signal.manager.util; - -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.attribute.PosixFilePermission; -import java.nio.file.attribute.PosixFilePermissions; -import java.util.EnumSet; -import java.util.Set; - -import static java.nio.file.attribute.PosixFilePermission.OWNER_EXECUTE; -import static java.nio.file.attribute.PosixFilePermission.OWNER_READ; -import static java.nio.file.attribute.PosixFilePermission.OWNER_WRITE; - -public class IOUtils { - - public static File createTempFile() throws IOException { - final File tempFile = File.createTempFile("signal-cli_tmp_", ".tmp"); - tempFile.deleteOnExit(); - return tempFile; - } - - public static byte[] readFully(InputStream in) throws IOException { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - IOUtils.copyStream(in, baos); - return baos.toByteArray(); - } - - public static void createPrivateDirectories(File file) throws IOException { - if (file.exists()) { - return; - } - - final Path path = file.toPath(); - try { - Set perms = EnumSet.of(OWNER_READ, OWNER_WRITE, OWNER_EXECUTE); - Files.createDirectories(path, PosixFilePermissions.asFileAttribute(perms)); - } catch (UnsupportedOperationException e) { - Files.createDirectories(path); - } - } - - public static void createPrivateFile(File path) throws IOException { - final Path file = path.toPath(); - try { - Set perms = EnumSet.of(OWNER_READ, OWNER_WRITE); - Files.createFile(file, PosixFilePermissions.asFileAttribute(perms)); - } catch (UnsupportedOperationException e) { - Files.createFile(file); - } - } - - public static void copyFileToStream(File inputFile, OutputStream output) throws IOException { - try (InputStream inputStream = new FileInputStream(inputFile)) { - copyStream(inputStream, output); - } - } - - public static void copyStream(InputStream input, OutputStream output) throws IOException { - copyStream(input, output, 4096); - } - - public static void copyStream(InputStream input, OutputStream output, int bufferSize) throws IOException { - byte[] buffer = new byte[bufferSize]; - int read; - - while ((read = input.read(buffer)) != -1) { - output.write(buffer, 0, read); - } - } -}