当前位置: 首页>>代码示例>>Java>>正文


Java MultipartFormDataInput.getFormDataMap方法代码示例

本文整理汇总了Java中org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput.getFormDataMap方法的典型用法代码示例。如果您正苦于以下问题:Java MultipartFormDataInput.getFormDataMap方法的具体用法?Java MultipartFormDataInput.getFormDataMap怎么用?Java MultipartFormDataInput.getFormDataMap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput的用法示例。


在下文中一共展示了MultipartFormDataInput.getFormDataMap方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createClass

import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput; //导入方法依赖的package包/类
@Override
public String createClass(@HeaderParam("sessionid") String sessionId, MultipartFormDataInput input)
        throws NotConnectedRestException, IOException {

    String userName = getUserName(sessionId);
    File classesDir = new File(getFileStorageSupport().getWorkflowsDir(userName), "classes");

    if (!classesDir.exists()) {
        logger.info("Creating dir " + classesDir.getAbsolutePath());
        classesDir.mkdirs();
    }

    String fileName = "";

    Map<String, List<InputPart>> uploadForm = input.getFormDataMap();
    String name = uploadForm.keySet().iterator().next();
    List<InputPart> inputParts = uploadForm.get(name);

    for (InputPart inputPart : inputParts) {

        try {
            //convert the uploaded file to inputstream
            InputStream inputStream = inputPart.getBody(InputStream.class, null);
            byte[] bytes = IOUtils.toByteArray(inputStream);

            //constructs upload file path
            fileName = classesDir.getAbsolutePath() + "/" + name;

            FileUtils.writeByteArrayToFile(new File(fileName), bytes);
        } catch (IOException e) {
            logger.warn("Could not read input part", e);
            throw e;
        }

    }

    return fileName;
}
 
开发者ID:ow2-proactive,项目名称:scheduling,代码行数:39,代码来源:StudioRest.java

示例2: upload

import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput; //导入方法依赖的package包/类
@ApiOperation(value = "upload a file")
@POST
@Path("/upload")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA)
public void upload(
    final MultipartFormDataInput input,
    @Suspended final AsyncResponse asyncResponse) throws IOException {

    final JsonObject json = new JsonObject();
    final Map<String, List<InputPart>> uploadForm = input.getFormDataMap();
    final List<InputPart> inputParts = uploadForm.get("uploadedFile");

    for (final InputPart inputPart : inputParts) {

        final MultivaluedMap<String, String> header = inputPart.getHeaders();
        final String fileName = getFileName(header);

        //fromJson the uploaded file to inputstream
        final InputStream inputStream = inputPart.getBody(InputStream.class, null);
        int c = 0;
        while (inputStream.read() != -1) {
            ++c;
        }

        json.add(fileName, new JsonPrimitive(c));
    }
    asyncResponse.resume(json);
}
 
开发者ID:trajano,项目名称:app-ms,代码行数:30,代码来源:HelloResource.java

示例3: validate

import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput; //导入方法依赖的package包/类
@Override
public JobValidationData validate(PathSegment pathSegment, MultipartFormDataInput multipart) {
    File tmpFile = null;
    try {
        Map<String, List<InputPart>> formDataMap = multipart.getFormDataMap();
        String name = formDataMap.keySet().iterator().next();
        InputPart part1 = formDataMap.get(name).get(0);
        InputStream is = part1.getBody(new GenericType<InputStream>() {

        });

        tmpFile = File.createTempFile("valid-job", "d");
        IOUtils.copy(is, new FileOutputStream(tmpFile));

        Map<String, String> jobVariables = workflowVariablesTransformer.getWorkflowVariablesFromPathSegment(pathSegment);

        return jobValidator.validateJobDescriptor(tmpFile, jobVariables);
    } catch (IOException e) {
        JobValidationData validation = new JobValidationData();
        validation.setErrorMessage("Cannot read from the job validation request.");
        validation.setStackTrace(getStackTrace(e));
        return validation;
    } finally {
        if (tmpFile != null) {
            tmpFile.delete();
        }
    }
}
 
开发者ID:ow2-proactive,项目名称:scheduling,代码行数:29,代码来源:SchedulerStateRest.java

示例4: storeRawNetwork

import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput; //导入方法依赖的package包/类
private static UUID storeRawNetwork (MultipartFormDataInput input) throws IOException {
 Map<String, List<InputPart>> uploadForm = input.getFormDataMap();
    
//      ProvenanceEntity entity = this.getProvenanceEntityFromMultiPart(uploadForm);
      
//Get file data to save
List<InputPart> inputParts = uploadForm.get("CXNetworkStream");
	
   byte[] bytes = new byte[8192];
   UUID uuid = NdexUUIDFactory.INSTANCE.createNewNDExUUID();
   String pathPrefix = Configuration.getInstance().getNdexRoot() + "/data/" + uuid.toString();
   
   //Create dir
   java.nio.file.Path dir = Paths.get(pathPrefix);
   Set<PosixFilePermission> perms =
		    PosixFilePermissions.fromString("rwxrwxr-x");
		FileAttribute<Set<PosixFilePermission>> attr =
		    PosixFilePermissions.asFileAttribute(perms);
   Files.createDirectory(dir,attr);
   
   //write content to file
   String cxFilePath = pathPrefix + "/network.cx";
   try (FileOutputStream out = new FileOutputStream (cxFilePath ) ){     
	   for (InputPart inputPart : inputParts) {
               // convert the uploaded file to inputstream and write it to disk
        	org.jboss.resteasy.plugins.providers.multipart.MultipartInputImpl.PartImpl p =
        			   (org.jboss.resteasy.plugins.providers.multipart.MultipartInputImpl.PartImpl) inputPart;
            try (InputStream inputStream = p.getBody()) {
              
            	int read = 0;
            	while ((read = inputStream.read(bytes)) != -1) {
                  out.write(bytes, 0, read);
            	}
            }
               
	   }
   }
return uuid; 
}
 
开发者ID:ndexbio,项目名称:ndex-rest,代码行数:40,代码来源:NetworkServiceV2.java

示例5: storeRawNetwork

import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput; //导入方法依赖的package包/类
private static UUID storeRawNetwork (MultipartFormDataInput input) throws IOException {
 Map<String, List<InputPart>> uploadForm = input.getFormDataMap();
    
//      ProvenanceEntity entity = this.getProvenanceEntityFromMultiPart(uploadForm);
      
//Get file data to save
List<InputPart> inputParts = uploadForm.get("CXNetworkStream");
	
   byte[] bytes = new byte[8192];
   UUID uuid = NdexUUIDFactory.INSTANCE.createNewNDExUUID();
   String uuidStr = uuid.toString();
   String pathPrefix = Configuration.getInstance().getNdexRoot() + "/data/" + uuidStr;
   
   //Create dir
   java.nio.file.Path dir = Paths.get(pathPrefix);
   Files.createDirectory(dir);
   
   //write content to file
   String cxFilePath = pathPrefix + "/network.cx";
   try (FileOutputStream out = new FileOutputStream (cxFilePath ) ){     
	   for (InputPart inputPart : inputParts) {
               // convert the uploaded file to inputstream and write it to disk
        	org.jboss.resteasy.plugins.providers.multipart.MultipartInputImpl.PartImpl p =
        			   (org.jboss.resteasy.plugins.providers.multipart.MultipartInputImpl.PartImpl) inputPart;
            try (InputStream inputStream = p.getBody()) {
              
            	int read = 0;
            	while ((read = inputStream.read(bytes)) != -1) {
                  out.write(bytes, 0, read);
            	}
            }
               
	   }
   }
return uuid; 
}
 
开发者ID:ndexbio,项目名称:ndex-rest,代码行数:37,代码来源:NetworkService.java

示例6: submit

import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput; //导入方法依赖的package包/类
/**
 * Submits a job to the scheduler
 *
 * @param sessionId
 *            a valid session id
 * @return the <code>jobid</code> of the newly created job
 * @throws IOException
 *             if the job was not correctly uploaded/stored
 */
@Override
@POST
@Path("{path:submit}")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces("application/json")
public JobIdData submit(@HeaderParam("sessionid") String sessionId, @PathParam("path") PathSegment pathSegment,
        MultipartFormDataInput multipart) throws JobCreationRestException, NotConnectedRestException,
        PermissionRestException, SubmissionClosedRestException, IOException {
    try {
        Scheduler scheduler = checkAccess(sessionId, "submit");

        Map<String, List<InputPart>> formDataMap = multipart.getFormDataMap();

        String name = formDataMap.keySet().iterator().next();
        File tmpJobFile = null;
        try {

            InputPart part1 = multipart.getFormDataMap().get(name).get(0); // "file"

            String fileType = part1.getMediaType().toString().toLowerCase();
            if (!fileType.contains(MediaType.APPLICATION_XML.toLowerCase())) {
                throw new JobCreationRestException("Unknown job descriptor type: " + fileType);
            }

            // is the name of the browser's input field
            InputStream is = part1.getBody(new GenericType<InputStream>() {

            });
            tmpJobFile = File.createTempFile("job", "d");

            IOUtils.copy(is, new FileOutputStream(tmpJobFile));

            Map<String, String> jobVariables = workflowVariablesTransformer.getWorkflowVariablesFromPathSegment(pathSegment);

            WorkflowSubmitter workflowSubmitter = new WorkflowSubmitter(scheduler);

            JobId jobId = workflowSubmitter.submit(tmpJobFile, jobVariables);

            return mapper.map(jobId, JobIdData.class);

        } finally {
            if (tmpJobFile != null) {
                // clean the temporary file
                tmpJobFile.delete();
            }
        }
    } catch (IOException e) {
        throw new IOException("I/O Error: " + e.getMessage(), e);
    }
}
 
开发者ID:ow2-proactive,项目名称:scheduling,代码行数:60,代码来源:SchedulerStateRest.java

示例7: pushFile

import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput; //导入方法依赖的package包/类
/**
 * Pushes a file from the local file system into the given DataSpace
 * 
 * @param sessionId
 *            a valid session id
 * @param spaceName
 *            the name of the DataSpace
 * @param filePath
 *            the path inside the DataSpace where to put the file e.g.
 *            "/myfolder"
 * @param multipart
 *            the form data containing : - fileName the name of the file
 *            that will be created on the DataSpace - fileContent the
 *            content of the file
 * @return true if the transfer succeeded
 * @see org.ow2.proactive.scheduler.common.SchedulerConstants for spaces
 *      names
 **/
@Override
public boolean pushFile(@HeaderParam("sessionid") String sessionId, @PathParam("spaceName") String spaceName,
        @PathParam("filePath") String filePath, MultipartFormDataInput multipart)
        throws IOException, NotConnectedRestException, PermissionRestException {
    checkAccess(sessionId, "pushFile");

    Session session = dataspaceRestApi.checkSessionValidity(sessionId);

    Map<String, List<InputPart>> formDataMap = multipart.getFormDataMap();

    List<InputPart> fNL = formDataMap.get("fileName");
    if ((fNL == null) || (fNL.size() == 0)) {
        throw new IllegalArgumentException("Illegal multipart argument definition (fileName), received " + fNL);
    }
    String fileName = fNL.get(0).getBody(String.class, null);

    List<InputPart> fCL = formDataMap.get("fileContent");
    if ((fCL == null) || (fCL.size() == 0)) {
        throw new IllegalArgumentException("Illegal multipart argument definition (fileContent), received " + fCL);
    }
    InputStream fileContent = fCL.get(0).getBody(InputStream.class, null);

    if (fileName == null) {
        throw new IllegalArgumentException("Wrong file name : " + fileName);
    }

    filePath = normalizeFilePath(filePath, fileName);

    FileObject destfo = dataspaceRestApi.resolveFile(session, spaceName, filePath);

    URL targetUrl = destfo.getURL();
    logger.info("[pushFile] pushing file to " + targetUrl);

    if (!destfo.isWriteable()) {
        RuntimeException ex = new IllegalArgumentException("File " + filePath + " is not writable in space " +
                                                           spaceName);
        logger.error(ex);
        throw ex;
    }
    if (destfo.exists()) {
        destfo.delete();
    }
    // used to create the necessary directories if needed
    destfo.createFile();

    dataspaceRestApi.writeFile(fileContent, destfo, null);

    return true;
}
 
开发者ID:ow2-proactive,项目名称:scheduling,代码行数:68,代码来源:SchedulerStateRest.java


注:本文中的org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput.getFormDataMap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。