private void addResource(VirtualFile virtualFile, VirtualFile processArchiveRoot, Map<String, byte[]> resources) { String resourceName = virtualFile.getPathNameRelativeTo(processArchiveRoot); try { InputStream inputStream = virtualFile.openStream(); byte[] bytes = IoUtil.readInputStream(inputStream, resourceName); IoUtil.closeSilently(inputStream); resources.put(resourceName, bytes); } catch (IOException e) { LOG.cannotReadInputStreamForFile(resourceName, processArchiveRoot, e); } }
public static String readFileAsString(String filePath) { byte[] buffer = new byte[(int) getFile(filePath).length()]; BufferedInputStream inputStream = null; try { inputStream = new BufferedInputStream(new FileInputStream(getFile(filePath))); inputStream.read(buffer); } catch(Exception e) { throw LOG.exceptionWhileReadingFile(filePath, e); } finally { IoUtil.closeSilently(inputStream); } return new String(buffer, Charset.forName("UTF-8")); }
protected byte[] serializeToByteArray(Object deserializedObject) throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream ois = null; try { ois = new ObjectOutputStream(baos); ois.writeObject(deserializedObject); return baos.toByteArray(); } finally { IoUtil.closeSilently(ois); IoUtil.closeSilently(baos); } }
private String readInputStreamToString(InputStream inputStream) { byte[] bytes = IoUtil.readInputStream(inputStream, "input stream"); return new String(bytes); }
@Override public byte[] writeConfiguration(T configuration) { JSONObject jsonObject = getJsonConverterInstance().toJsonObject(configuration); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); Writer writer = StringUtil.writerForStream(outStream); jsonObject.write(writer); IoUtil.flushSilently(writer); return outStream.toByteArray(); }
protected byte[] serializeToByteArray(Object deserializedObject) throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream ois = null; try { ois = new ObjectOutputStream(baos); ois.writeObject(deserializedObject); return baos.toByteArray(); } finally { IoUtil.closeSilently(ois); IoUtil.closeSilently(baos); } }
public DeploymentBuilder addInputStream(String resourceName, InputStream inputStream) { ensureNotNull("inputStream for resource '" + resourceName + "' is null", "inputStream", inputStream); byte[] bytes = IoUtil.readInputStream(inputStream, resourceName); return addBytes(resourceName, bytes); }
private void addResource(VirtualFile virtualFile, VirtualFile processArchiveRoot, Map<String, byte[]> resources) { String resourceName = virtualFile.getPathNameRelativeTo(processArchiveRoot); try { InputStream inputStream = virtualFile.openStream(); byte[] bytes = IoUtil.readInputStream(inputStream, resourceName); IoUtil.closeSilently(inputStream); resources.put(resourceName, bytes); } catch (IOException e) { LOG.cannotReadInputStreamForFile(resourceName, processArchiveRoot, e); } }
protected Object deserializeFromByteArray(byte[] bytes, String objectTypeName) throws Exception { ByteArrayInputStream bais = new ByteArrayInputStream(bytes); ObjectInputStream ois = null; try { ois = new ClassloaderAwareObjectInputStream(bais); return ois.readObject(); } finally { IoUtil.closeSilently(ois); IoUtil.closeSilently(bais); } }
public DeploymentBuilder addInputStream(String resourceName, InputStream inputStream) { ensureNotNull("inputStream for resource '" + resourceName + "' is null", "inputStream", inputStream); byte[] bytes = IoUtil.readInputStream(inputStream, resourceName); return addBytes(resourceName, bytes); }
public static String readFileAsString(String filePath) { byte[] buffer = new byte[(int) getFile(filePath).length()]; BufferedInputStream inputStream = null; try { inputStream = new BufferedInputStream(new FileInputStream(getFile(filePath))); inputStream.read(buffer); } catch(Exception e) { throw LOG.exceptionWhileReadingFile(filePath, e); } finally { IoUtil.closeSilently(inputStream); } return new String(buffer, Charset.forName("UTF-8")); }
protected void addResource(Object source, Map<String, byte[]> resourceMap, String resourceRootPath, String resourceName) { String resourcePath = (resourceRootPath == null ? "" : resourceRootPath).concat(resourceName); LOG.debugDiscoveredResource(resourcePath); InputStream inputStream = null; try { if(source instanceof File) { try { inputStream = new FileInputStream((File) source); } catch (IOException e) { throw LOG.cannotOpenFileInputStream(((File) source).getAbsolutePath(), e); } } else { inputStream = (InputStream) source; } byte[] bytes = IoUtil.readInputStream(inputStream, resourcePath); resourceMap.put(resourceName, bytes); } finally { if(inputStream != null) { IoUtil.closeSilently(inputStream); } } }
protected Object deserializeFromByteArray(byte[] bytes, String objectTypeName) throws Exception { ByteArrayInputStream bais = new ByteArrayInputStream(bytes); ObjectInputStream ois = null; try { ois = new ClassloaderAwareObjectInputStream(bais); return ois.readObject(); } finally { IoUtil.closeSilently(ois); IoUtil.closeSilently(bais); } }
protected byte[] readBinaryContent(FileItemStream stream) { InputStream inputStream = getInputStream(stream); return IoUtil.readInputStream(inputStream, stream.getFieldName()); }
public static void writeStringToFile(String content, String filePath) { BufferedOutputStream outputStream = null; try { outputStream = new BufferedOutputStream(new FileOutputStream(getFile(filePath))); outputStream.write(content.getBytes()); outputStream.flush(); } catch(Exception e) { throw LOG.exceptionWhileWritingToFile(filePath, e); } finally { IoUtil.closeSilently(outputStream); } }
protected void addResource(Object source, Map<String, byte[]> resourceMap, String resourceRootPath, String resourceName) { String resourcePath = (resourceRootPath == null ? "" : resourceRootPath).concat(resourceName); LOG.debugDiscoveredResource(resourcePath); InputStream inputStream = null; try { if(source instanceof File) { try { inputStream = new FileInputStream((File) source); } catch (IOException e) { throw LOG.cannotOpenFileInputStream(((File) source).getAbsolutePath(), e); } } else { inputStream = (InputStream) source; } byte[] bytes = IoUtil.readInputStream(inputStream, resourcePath); resourceMap.put(resourceName, bytes); } finally { if(inputStream != null) { IoUtil.closeSilently(inputStream); } } }
protected boolean isEmptyFile(URL url) { InputStream inputStream = null; try { inputStream = url.openStream(); return inputStream.available() == 0; } catch (IOException e) { throw new ProcessEngineException("Could not open stream for " + url, e); } finally { IoUtil.closeSilently(inputStream); } }
protected byte[] readBinaryContent(FileItemStream stream) { InputStream inputStream = getInputStream(stream); return IoUtil.readInputStream(inputStream, stream.getFieldName()); }
public static void writeStringToFile(String content, String filePath) { BufferedOutputStream outputStream = null; try { outputStream = new BufferedOutputStream(new FileOutputStream(getFile(filePath))); outputStream.write(content.getBytes()); outputStream.flush(); } catch(Exception e) { throw LOG.exceptionWhileWritingToFile(filePath, e); } finally { IoUtil.closeSilently(outputStream); } }
@Override public ProcessDefinitionDiagramDto getProcessDefinitionBpmn20Xml() { InputStream processModelIn = null; try { processModelIn = engine.getRepositoryService().getProcessModel(processDefinitionId); byte[] processModel = IoUtil.readInputStream(processModelIn, "processModelBpmn20Xml"); return ProcessDefinitionDiagramDto.create(processDefinitionId, new String(processModel, "UTF-8")); } catch (AuthorizationException e) { throw e; } catch (ProcessEngineException e) { throw new InvalidRequestException(Status.BAD_REQUEST, e, "No matching definition with id " + processDefinitionId); } catch (UnsupportedEncodingException e) { throw new RestException(Status.INTERNAL_SERVER_ERROR, e); } finally { IoUtil.closeSilently(processModelIn); } }