@Override public void build(@NotNull Project project, @NotNull Collection<FileObject> fileObjects) { Collection<InputStream> memoryCache = new ArrayList<>(); for (FileObject fileObject : fileObjects) { InputStream inputStream; try { // copy stream inputStream = new ResetOnCloseInputStream(new ByteArrayInputStream( IOUtils.getInputStreamBytes(fileObject.getContent().getInputStream())) ); } catch (FileSystemException ignored) { continue; } catch (IOException ignored) { continue; } memoryCache.add(inputStream); } storage = new ServiceParameterStorage(memoryCache); }
public static void copyStreamToStream(InputStream src, OutputStream dst) throws IOException { copyStreamToStream(src, dst, true); }
public static void writeToFile(byte[] src, File file) throws IOException { ByteArrayInputStream stream = null; try { stream = new ByteArrayInputStream(src); putInputStreamToFile(stream, file); } finally { try { if (stream != null) stream.close(); } catch (Exception e) { Debug.debug(e); } } }
@NotNull private Map<MonkeyType, MonkeyType> readSettingsFile(File settingsFile) throws IOException { byte[] fileBytes = IOUtils.getFileBytes(settingsFile); Deserializer deserializer = new Deserializer(fileBytes); Optional<MonkeyTypeHash> settings = deserializer.getTypes() .stream() .filter(monkeyType -> monkeyType instanceof MonkeyTypeHash) .map(monkeyType -> (MonkeyTypeHash) monkeyType) .findFirst(); return settings.map(MonkeyTypeHash::getItems).orElse(new HashMap<>()); }
public static void writeToFile(byte[] src, File file) throws IOException { ByteArrayInputStream stream = null; try { stream = new ByteArrayInputStream(src); putInputStreamToFile(stream, file); } finally { try { if (stream != null) stream.close(); } catch (Exception e) { Debug.debug(e); } } }
/** * Reads a File into memory. * <p> * * @param file * The File to read. * @return A byte array containing the contents of the File * @see InputStream */ public static byte[] getFileBytes(File file) throws IOException { InputStream is = null; try { is = new FileInputStream(file); return getInputStreamBytes(is); } finally { try { if (is != null) is.close(); } catch (IOException e) { Debug.debug(e); } } }
public static void copyStreamToStream(InputStream src, OutputStream dst) throws IOException { copyStreamToStream(src, dst, true); }
/** * Reads a File into memory. * <p> * * @param file * The File to read. * @return A byte array containing the contents of the File * @see InputStream */ public static byte[] getFileBytes(File file) throws IOException { InputStream is = null; try { is = new FileInputStream(file); return getInputStreamBytes(is); } finally { try { if (is != null) is.close(); } catch (IOException e) { Debug.debug(e); } } }
public static void putInputStreamToFile(InputStream src, File file) throws IOException { FileOutputStream stream = null; try { if (file.getParentFile() != null) file.getParentFile().mkdirs(); stream = new FileOutputStream(file); copyStreamToStream(src, stream); } finally { try { if (stream != null) stream.close(); } catch (Exception e) { Debug.debug(e); } } }
public static void putInputStreamToFile(InputStream src, File file) throws IOException { FileOutputStream stream = null; try { if (file.getParentFile() != null) file.getParentFile().mkdirs(); stream = new FileOutputStream(file); copyStreamToStream(src, stream); } finally { try { if (stream != null) stream.close(); } catch (Exception e) { Debug.debug(e); } } }