Java Code Examples for javax.activation.datahandler#getInputStream()
The following examples show how to use
javax.activation.datahandler#getInputStream() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MTOMSwASampleService.java From micro-integrator with Apache License 2.0 | 6 votes |
public void oneWayUploadUsingMTOM(OMElement element) throws Exception { OMText binaryNode = (OMText) element.getFirstOMChild(); DataHandler dataHandler = (DataHandler) binaryNode.getDataHandler(); InputStream is = dataHandler.getInputStream(); File tempFile = File.createTempFile("mtom-", ".gif"); FileOutputStream fos = new FileOutputStream(tempFile); BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER); byte data[] = new byte[BUFFER]; int count; while ((count = is.read(data, 0, BUFFER)) != -1) { dest.write(data, 0, count); } dest.flush(); dest.close(); System.out.println("Wrote to file : " + tempFile.getAbsolutePath()); }
Example 2
Source File: MTOMSwASampleService.java From product-ei with Apache License 2.0 | 6 votes |
public void oneWayUploadUsingMTOM(OMElement element) throws Exception { OMText binaryNode = (OMText) element.getFirstOMChild(); DataHandler dataHandler = (DataHandler) binaryNode.getDataHandler(); InputStream is = dataHandler.getInputStream(); File tempFile = File.createTempFile("mtom-", ".gif"); FileOutputStream fos = new FileOutputStream(tempFile); BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER); byte data[] = new byte[BUFFER]; int count; while ((count = is.read(data, 0, BUFFER)) != -1) { dest.write(data, 0, count); } dest.flush(); dest.close(); System.out.println("Wrote to file : " + tempFile.getAbsolutePath()); }
Example 3
Source File: DocumentService.java From document-management-system with GNU General Public License v2.0 | 6 votes |
@WebMethod public Document createSimple(@WebParam(name = "token") String token, @WebParam(name = "docPath") String docPath, @WebParam(name = "content") @XmlMimeType("application/octet-stream") DataHandler content) throws IOException, UnsupportedMimeTypeException, FileSizeExceededException, UserQuotaExceededException, VirusDetectedException, ItemExistsException, PathNotFoundException, AccessDeniedException, RepositoryException, DatabaseException, ExtensionException, AutomationException { log.debug("createSimple({})", docPath); DocumentModule dm = ModuleManager.getDocumentModule(); InputStream bais = content.getInputStream(); Document doc = new Document(); doc.setPath(docPath); Document newDocument = dm.create(token, doc, bais); bais.close(); log.debug("createSimple: {}", newDocument); return newDocument; }
Example 4
Source File: UserAdmin.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
/** * @param userStoreDomain * @param fileName * @param handler * @param defaultPassword * @throws UserAdminException */ public void bulkImportUsers(String userStoreDomain, String fileName, DataHandler handler, String defaultPassword) throws UserAdminException { //password will no longer be used, instead the password will be taken from the file if (fileName == null || handler == null) { throw new UserAdminException("Required data not provided"); } if (StringUtils.isEmpty(userStoreDomain)) { userStoreDomain = IdentityUtil.getPrimaryDomainName(); } try { InputStream inStream = handler.getInputStream(); getUserAdminProxy().bulkImportUsers(userStoreDomain, fileName, inStream, defaultPassword); } catch (IOException e) { log.error(e.getMessage(), e); throw new UserAdminException(e.getMessage(), e); } }
Example 5
Source File: UserAdmin.java From carbon-identity with Apache License 2.0 | 6 votes |
/** * @param userStoreDomain * @param fileName * @param handler * @param defaultPassword * @throws UserAdminException */ public void bulkImportUsers(String userStoreDomain, String fileName, DataHandler handler, String defaultPassword) throws UserAdminException { //password will no longer be used, instead the password will be taken from the file if (fileName == null || handler == null) { throw new UserAdminException("Required data not provided"); } if (StringUtils.isEmpty(userStoreDomain)) { userStoreDomain = IdentityUtil.getPrimaryDomainName(); } try { InputStream inStream = handler.getInputStream(); getUserAdminProxy().bulkImportUsers(userStoreDomain, fileName, inStream, defaultPassword); } catch (IOException e) { log.error(e.getMessage(), e); throw new UserAdminException(e.getMessage(), e); } }
Example 6
Source File: ContentRepositoryImpl.java From spring-boot-cxf-integration-example with MIT License | 6 votes |
@Override public void storeContent(String name, DataHandler content) throws IOException { File outFile = new File(this.fileStorePath, name + ".tmp"); logger.info("Storing content in file: {}", outFile.getAbsolutePath()); InputStream dhis = content.getInputStream(); logger.info("******************************************** dhis: {}", dhis.getClass().getName()); int i = 0; byte[] buffer = new byte[1024]; try (InputStream is = content.getInputStream()) { try (OutputStream outStream = new FileOutputStream(outFile)) { while ((i = is.read(buffer, 0, buffer.length)) > 0) { outStream.write(buffer, 0, i); } } } logger.info("Content stored."); }
Example 7
Source File: ConsultationFullMessageBuilder.java From freehealth-connector with GNU Affero General Public License v3.0 | 6 votes |
private <T> byte[] base64decoding(DataHandler dataHandler, boolean encrypted, AbstractConsultationBuilder.ExceptionContainer<GetFullMessageResponse> container) throws TechnicalConnectorException, EhboxBusinessConnectorException { InputStream is = null; Object var6; try { is = dataHandler.getInputStream(); byte[] byteVal = ConnectorIOUtils.getBytes(is); if (!ArrayUtils.isEmpty(byteVal)) { byte[] var12 = this.handleAndDecryptIfNeeded(byteVal, encrypted, container); return var12; } var6 = null; } catch (IOException var10) { throw new TechnicalConnectorException(TechnicalConnectorExceptionValues.ERROR_GENERAL, var10, new Object[]{"Unable to decode datahandler"}); } finally { ConnectorIOUtils.closeQuietly((Object)is); } return (byte[])var6; }
Example 8
Source File: ConsultationFullMessageBuilder.java From freehealth-connector with GNU Affero General Public License v3.0 | 6 votes |
private <T> byte[] base64decoding(DataHandler dataHandler, boolean encrypted, AbstractConsultationBuilder.ExceptionContainer<GetFullMessageResponse> container) throws TechnicalConnectorException, EhboxBusinessConnectorException { InputStream is = null; byte[] var6; try { is = dataHandler.getInputStream(); byte[] byteVal = ConnectorIOUtils.getBytes(is); if (ArrayUtils.isEmpty(byteVal)) { Object var12 = null; return (byte[])var12; } var6 = this.handleAndDecryptIfNeeded(byteVal, encrypted, container); } catch (IOException var10) { throw new TechnicalConnectorException(TechnicalConnectorExceptionValues.ERROR_GENERAL, var10, new Object[]{"Unable to decode datahandler"}); } finally { ConnectorIOUtils.closeQuietly((Object)is); } return var6; }
Example 9
Source File: BinaryExtractMediator.java From micro-integrator with Apache License 2.0 | 6 votes |
public boolean mediate(MessageContext msgCtx) { try { log.debug("BinaryExtractMediator Process, with offset: "+offset+" ,length "+length); SOAPBody soapBody = msgCtx.getEnvelope().getBody(); OMElement firstElement = soapBody.getFirstElement(); log.debug("First Element : "+firstElement.getLocalName()); log.debug("First Element Text : "+firstElement.getText()); OMText binaryNode =(OMText) firstElement.getFirstOMChild(); log.debug("First Element Node Text : "+binaryNode.getText()); DataHandler dataHandler =(DataHandler) binaryNode.getDataHandler(); InputStream inputStream = dataHandler.getInputStream(); byte[] searchByte = new byte[length]; inputStream.skip(offset - 1); int readBytes = inputStream.read(searchByte,0,length); String outString = new String(searchByte,binaryEncoding); msgCtx.setProperty(variableName,outString); log.debug("Set property to MsgCtx, "+variableName+" = "+outString); inputStream.close(); } catch (IOException e) { log.error("Excepton on mediation : "+e.getMessage()); } return true; }
Example 10
Source File: BinaryExtractMediator.java From product-ei with Apache License 2.0 | 6 votes |
public boolean mediate(MessageContext msgCtx) { try { log.debug("BinaryExtractMediator Process, with offset: "+offset+" ,length "+length); SOAPBody soapBody = msgCtx.getEnvelope().getBody(); OMElement firstElement = soapBody.getFirstElement(); log.debug("First Element : "+firstElement.getLocalName()); log.debug("First Element Text : "+firstElement.getText()); OMText binaryNode =(OMText) firstElement.getFirstOMChild(); log.debug("First Element Node Text : "+binaryNode.getText()); DataHandler dataHandler =(DataHandler) binaryNode.getDataHandler(); InputStream inputStream = dataHandler.getInputStream(); byte[] searchByte = new byte[length]; inputStream.skip(offset - 1); int readBytes = inputStream.read(searchByte,0,length); String outString = new String(searchByte,binaryEncoding); msgCtx.setProperty(variableName,outString); log.debug("Set property to MsgCtx, "+variableName+" = "+outString); inputStream.close(); } catch (IOException e) { log.error("Excepton on mediation : "+e.getMessage()); } return true; }
Example 11
Source File: DataHandlerJsonSerializer.java From jackson-modules-base with Apache License 2.0 | 6 votes |
@Override public void serialize(DataHandler value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { final ByteArrayOutputStream out = new ByteArrayOutputStream(); /* for copy-through, a small buffer should suffice: ideally * we might want to reuse a generic byte buffer, but for now * there's no serializer context to hold them. * * Also: it'd be nice not to have buffer all data, but use a * streaming output. But currently JsonGenerator won't allow * that. */ byte[] buffer = new byte[1024 * 4]; InputStream in = value.getInputStream(); int len = in.read(buffer); while (len > 0) { out.write(buffer, 0, len); len = in.read(buffer); } in.close(); jgen.writeBinary(out.toByteArray()); }
Example 12
Source File: MTOMSwASampleService.java From micro-integrator with Apache License 2.0 | 6 votes |
public void oneWayUploadUsingMTOM(OMElement element) throws Exception { OMText binaryNode = (OMText) element.getFirstOMChild(); DataHandler dataHandler = (DataHandler) binaryNode.getDataHandler(); InputStream is = dataHandler.getInputStream(); File tempFile = File.createTempFile("mtom-", ".gif"); FileOutputStream fos = new FileOutputStream(tempFile); BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER); byte data[] = new byte[BUFFER]; int count; while ((count = is.read(data, 0, BUFFER)) != -1) { dest.write(data, 0, count); } dest.flush(); dest.close(); System.out.println("Wrote to file : " + tempFile.getAbsolutePath()); }
Example 13
Source File: ByteArrayType.java From cxf with Apache License 2.0 | 5 votes |
@Override protected Object readAttachment(Attachment att, Context context) throws IOException { DataHandler handler = att.getDataHandler(); try (ByteArrayOutputStream out = new ByteArrayOutputStream(); InputStream is = handler.getInputStream()) { IOUtils.copy(is, out); return out.toByteArray(); } }
Example 14
Source File: RestWorkbench.java From document-management-software with GNU Lesser General Public License v3.0 | 5 votes |
private static void updateDocument(long docId) throws Exception { System.out.println("docId: " + docId); DataHandler handler = docClient.getContent(docId); InputStream is = handler.getInputStream(); OutputStream os = new FileOutputStream(new File("C:/tmp/myFile.raw")); IOUtils.copy(is, os); IOUtils.closeQuietly(os); IOUtils.closeQuietly(is); }
Example 15
Source File: SampleIntegrationApplicationTest.java From spring-boot-cxf-integration-example with MIT License | 5 votes |
/** * Saves the specified content to the specified file * * @param content The content * @param outFile The output file * @throws IOException If an error occurs during saving */ static public long saveContentToFile(DataHandler content, File outFile) throws IOException { long size = 0; byte[] buffer = new byte[1024]; try (InputStream is = content.getInputStream()) { try (OutputStream outStream = new FileOutputStream(outFile)) { for (int readBytes; (readBytes = is.read(buffer, 0, buffer.length)) > 0;) { size += readBytes; outStream.write(buffer, 0, readBytes); } } } return size; }
Example 16
Source File: FileAttachManagementImpl.java From opencps-v2 with GNU Affero General Public License v3.0 | 5 votes |
@Override public Response update(HttpServletRequest request, HttpHeaders header, Company company, Locale locale, User user, ServiceContext serviceContext, long id, Attachment attachment, String fileName, String fileType, long fileSize) { FileAttachInterface actions = new FileAttachActions(); FileAttachModel fileAttachModel = new FileAttachModel(); InputStream inputStream = null; try { long groupId = GetterUtil.getLong(header.getHeaderString("groupId")); DataHandler dataHandler = attachment.getDataHandler(); inputStream = dataHandler.getInputStream(); FileAttach fileAttach = actions.update(user.getUserId(), company.getCompanyId(), groupId, id, inputStream, fileName, fileType, fileSize, "FileAttach/", "FileAttach file upload", serviceContext); fileAttachModel = FileAttachUtils.mapperFileAttachModel(fileAttach); return Response.status(200).entity(fileAttachModel).build(); } catch (Exception e) { return BusinessExceptionImpl.processException(e); } finally { if (inputStream != null) { try { inputStream.close(); } catch (Exception io) { _log.error(io); } } } }
Example 17
Source File: DocumentService.java From document-management-system with GNU General Public License v2.0 | 5 votes |
@WebMethod public Version checkin(@WebParam(name = "token") String token, @WebParam(name = "docPath") String docPath, @WebParam(name = "content") @XmlMimeType("application/octet-stream") DataHandler content, @WebParam(name = "comment") String comment) throws FileSizeExceededException, UserQuotaExceededException, VirusDetectedException, LockException, VersionException, PathNotFoundException, AccessDeniedException, RepositoryException, IOException, DatabaseException, ExtensionException, AutomationException { log.debug("checkin({}, {} ,{})", new Object[]{token, docPath, comment}); DocumentModule dm = ModuleManager.getDocumentModule(); InputStream bais = content.getInputStream(); Version version = dm.checkin(token, docPath, bais, comment); log.debug("checkin: {}", version); return version; }
Example 18
Source File: JsonConverter.java From BIMserver with GNU Affero General Public License v3.0 | 4 votes |
public JsonNode toJson(Object object) throws IOException { if (object instanceof SBase) { SBase base = (SBase) object; ObjectNode jsonObject = OBJECT_MAPPER.createObjectNode(); jsonObject.put("__type", base.getSClass().getSimpleName()); for (SField field : base.getSClass().getAllFields()) { jsonObject.set(field.getName(), toJson(base.sGet(field))); } return jsonObject; } else if (object instanceof Collection) { Collection<?> collection = (Collection<?>) object; ArrayNode jsonArray = OBJECT_MAPPER.createArrayNode(); for (Object value : collection) { jsonArray.add(toJson(value)); } return jsonArray; } else if (object instanceof Date) { return new LongNode(((Date) object).getTime()); } else if (object instanceof DataHandler) { DataHandler dataHandler = (DataHandler) object; InputStream inputStream = dataHandler.getInputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream(); IOUtils.copy(inputStream, out); return new TextNode(new String(Base64.encodeBase64(out.toByteArray()), Charsets.UTF_8)); } else if (object instanceof Boolean) { return BooleanNode.valueOf((Boolean) object); } else if (object instanceof String) { return new TextNode((String) object); } else if (object instanceof Long) { return new LongNode((Long) object); } else if (object instanceof UUID) { return new TextNode(((UUID) object).toString()); } else if (object instanceof Integer) { return new IntNode((Integer) object); } else if (object instanceof Double) { return new DoubleNode((Double) object); } else if (object instanceof Float) { return new FloatNode((Float) object); } else if (object instanceof Enum) { return new TextNode(object.toString()); } else if (object == null) { return NullNode.getInstance(); } else if (object instanceof byte[]) { byte[] data = (byte[]) object; return new TextNode(new String(Base64.encodeBase64(data), Charsets.UTF_8)); } throw new UnsupportedOperationException(object.getClass().getName()); }
Example 19
Source File: AttachmentServiceImpl.java From cxf with Apache License 2.0 | 4 votes |
@WebMethod public int test(@WebParam(name = "request") @XmlElement(required = true) Request request) throws Exception { DataHandler dataHandler = request.getContent(); InputStream inputStream = dataHandler.getInputStream(); return IOUtils.readBytesFromStream(inputStream).length; }
Example 20
Source File: ServiceInfoManagementImpl.java From opencps-v2 with GNU Affero General Public License v3.0 | 2 votes |
@Override public Response addFileTemplateToServiceInfo(HttpServletRequest request, HttpHeaders header, Company company, Locale locale, User user, ServiceContext serviceContext, Attachment file, String id, String fileTemplateNo, String templateName, String fileType, int fileSize, String fileName) { long groupId = GetterUtil.getLong(header.getHeaderString("groupId")); long userId = serviceContext.getUserId(); ServiceFileTemplate serviceFileTemplate = null; BackendAuth auth = new BackendAuthImpl(); ServiceInfoActions actions = new ServiceInfoActionsImpl(); DataHandler dataHandler = file.getDataHandler(); InputStream inputStream = null; try { if (!auth.isAuth(serviceContext)) { throw new UnauthenticationException(); } if (!auth.hasResource(serviceContext, ServiceInfo.class.getName(), ActionKeys.ADD_ENTRY)) { throw new UnauthorizationException(); } inputStream = dataHandler.getInputStream(); serviceFileTemplate = actions.addServiceFileTemplate(userId, groupId, GetterUtil.getLong(id), fileTemplateNo, templateName, fileName, inputStream, fileType, fileSize, serviceContext); FileTemplateModel result = ServiceInfoUtils.mappingToFileTemplateModel(serviceFileTemplate); return Response.status(200).entity(result).build(); } catch (Exception e) { return BusinessExceptionImpl.processException(e); } }