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


Java Part类代码示例

本文整理汇总了Java中javax.servlet.http.Part的典型用法代码示例。如果您正苦于以下问题:Java Part类的具体用法?Java Part怎么用?Java Part使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: parseRequest

import javax.servlet.http.Part; //导入依赖的package包/类
private void parseRequest(HttpServletRequest request) {
	try {
		Collection<Part> parts = request.getParts();
		this.multipartParameterNames = new LinkedHashSet<String>(parts.size());
		MultiValueMap<String, MultipartFile> files = new LinkedMultiValueMap<String, MultipartFile>(parts.size());
		for (Part part : parts) {
			String filename = extractFilename(part.getHeader(CONTENT_DISPOSITION));
			if (filename != null) {
				files.add(part.getName(), new StandardMultipartFile(part, filename));
			}
			else {
				this.multipartParameterNames.add(part.getName());
			}
		}
		setMultipartFiles(files);
	}
	catch (Exception ex) {
		throw new MultipartException("Could not parse multipart servlet request", ex);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:21,代码来源:StandardMultipartHttpServletRequest.java

示例2: getParts

import javax.servlet.http.Part; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public Collection<Part> getParts() throws IOException, IllegalStateException, ServletException {

	parseParts();

	if (partsParseException != null) {
		if (partsParseException instanceof IOException) {
			throw (IOException) partsParseException;
		} else if (partsParseException instanceof IllegalStateException) {
			throw (IllegalStateException) partsParseException;
		} else if (partsParseException instanceof ServletException) {
			throw (ServletException) partsParseException;
		}
	}

	return parts;
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:21,代码来源:Request.java

示例3: initPropertyMap

import javax.servlet.http.Part; //导入依赖的package包/类
private static void initPropertyMap() {
  PROPERTY_MAP.put(BooleanProperty.class, SimpleType.constructUnsafe(Boolean.class));

  PROPERTY_MAP.put(FloatProperty.class, SimpleType.constructUnsafe(Float.class));
  PROPERTY_MAP.put(DoubleProperty.class, SimpleType.constructUnsafe(Double.class));
  PROPERTY_MAP.put(DecimalProperty.class, SimpleType.constructUnsafe(BigDecimal.class));

  PROPERTY_MAP.put(ByteProperty.class, SimpleType.constructUnsafe(Byte.class));
  PROPERTY_MAP.put(ShortProperty.class, SimpleType.constructUnsafe(Short.class));
  PROPERTY_MAP.put(IntegerProperty.class, SimpleType.constructUnsafe(Integer.class));
  PROPERTY_MAP.put(BaseIntegerProperty.class, SimpleType.constructUnsafe(Integer.class));
  PROPERTY_MAP.put(LongProperty.class, SimpleType.constructUnsafe(Long.class));

  // stringProperty包含了enum的场景,并不一定是转化为string
  // 但是,如果统一走StringPropertyConverter则可以处理enum的场景
  PROPERTY_MAP.put(StringProperty.class, SimpleType.constructUnsafe(String.class));

  PROPERTY_MAP.put(DateProperty.class, SimpleType.constructUnsafe(LocalDate.class));
  PROPERTY_MAP.put(DateTimeProperty.class, SimpleType.constructUnsafe(Date.class));

  PROPERTY_MAP.put(ByteArrayProperty.class, SimpleType.constructUnsafe(byte[].class));

  PROPERTY_MAP.put(FileProperty.class, SimpleType.constructUnsafe(Part.class));
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:25,代码来源:ConverterMgr.java

示例4: get

import javax.servlet.http.Part; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public T get() {
    final MinijaxRequestContext context = MinijaxRequestContext.getThreadLocal();
    final Class<?> c = key.getType();
    final MinijaxForm form = context.getForm();
    final String name = key.getName();

    if (c == InputStream.class) {
        return form == null ? null : (T) form.getInputStream(name);
    }

    if (c == Part.class) {
        return form == null ? null : (T) form.getPart(name);
    }

    String value = form == null ? null : form.getString(name);

    final DefaultValue defaultValue = key.getDefaultValue();
    if (value == null && defaultValue != null) {
        value = defaultValue.value();
    }

    return (T) context.getApplication().convertParamToType(value, c, key.getAnnotations());
}
 
开发者ID:minijax,项目名称:minijax,代码行数:26,代码来源:FormParamProvider.java

示例5: fileBoundaryInfo_nullSubmittedFileName

import javax.servlet.http.Part; //导入依赖的package包/类
@Test
public void fileBoundaryInfo_nullSubmittedFileName(@Mocked Part part) {
  new Expectations() {
    {
      part.getSubmittedFileName();
      result = null;
      part.getContentType();
      result = "abc";
    }
  };
  RestClientRequestImpl restClientRequest = new RestClientRequestImpl(request, null, null);
  Buffer buffer = restClientRequest.fileBoundaryInfo("boundary", "name", part);
  Assert.assertEquals("\r\n" +
      "--boundary\r\n" +
      "Content-Disposition: form-data; name=\"name\"; filename=\"null\"\r\n" +
      "Content-Type: abc\r\n" +
      "Content-Transfer-Encoding: binary\r\n" +
      "\r\n", buffer.toString());
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:20,代码来源:TestRestClientRequestImpl.java

示例6: fileBoundaryInfo_validSubmittedFileName

import javax.servlet.http.Part; //导入依赖的package包/类
@Test
public void fileBoundaryInfo_validSubmittedFileName(@Mocked Part part) {
  new Expectations() {
    {
      part.getSubmittedFileName();
      result = "a.txt";
      part.getContentType();
      result = MediaType.TEXT_PLAIN;
    }
  };
  RestClientRequestImpl restClientRequest = new RestClientRequestImpl(request, null, null);
  Buffer buffer = restClientRequest.fileBoundaryInfo("boundary", "name", part);
  Assert.assertEquals("\r\n" +
      "--boundary\r\n" +
      "Content-Disposition: form-data; name=\"name\"; filename=\"a.txt\"\r\n" +
      "Content-Type: text/plain\r\n" +
      "Content-Transfer-Encoding: binary\r\n" +
      "\r\n", buffer.toString());
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:20,代码来源:TestRestClientRequestImpl.java

示例7: parseAll

import javax.servlet.http.Part; //导入依赖的package包/类
public static List<Part> parseAll(final String str) {
    final int index = str.indexOf('\n');
    final String boundary = str.substring(0, index) + "\n";
    if (str.length() <= 2 * boundary.length()) {
        return Collections.emptyList();
    }

    final String content = str.substring(index + 1, str.length() - boundary.length());
    final String[] strParts = content.split(boundary, 0);
    final List<Part> parts = new ArrayList<>(strParts.length);

    for (final String strPart : strParts) {
        parts.add(MockPart.parse(strPart));
    }

    return parts;
}
 
开发者ID:minijax,项目名称:minijax,代码行数:18,代码来源:MockPart.java

示例8: testKeyValue

import javax.servlet.http.Part; //导入依赖的package包/类
@Test
public void testKeyValue() throws IOException {
    final String mockContent =
            "------WebKitFormBoundarycTqA2AimXQHBAJbZ\n" +
            "Content-Disposition: form-data; name=\"key\"\n" +
            "\n" +
            "myvalue1\n" +
            "------WebKitFormBoundarycTqA2AimXQHBAJbZ";

    final List<Part> parts = MockPart.parseAll(mockContent);
    assertNotNull(parts);
    assertEquals(1, parts.size());

    final Part part = parts.get(0);
    assertEquals("key", part.getName());
    assertEquals("myvalue1", IOUtils.toString(part.getInputStream(), StandardCharsets.UTF_8));
}
 
开发者ID:minijax,项目名称:minijax,代码行数:18,代码来源:MockPartTest.java

示例9: getParts

import javax.servlet.http.Part; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public Collection<Part> getParts() throws IOException, IllegalStateException,
        ServletException {

    parseParts();

    if (partsParseException != null) {
        if (partsParseException instanceof IOException) {
            throw (IOException) partsParseException;
        } else if (partsParseException instanceof IllegalStateException) {
            throw (IllegalStateException) partsParseException;
        } else if (partsParseException instanceof ServletException) {
            throw (ServletException) partsParseException;
        }
    }

    return parts;
}
 
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:22,代码来源:Request.java

示例10: testDoPutSyncLost

import javax.servlet.http.Part; //导入依赖的package包/类
@Test
public void testDoPutSyncLost() throws IOException, ServletException {
    cut.cleanUpWS(Paths.get(new File(wd).getPath()));

    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    Mockito.when(request.getServletPath()).thenReturn(SERVLET_PATH);
    Mockito.when(request.getRequestURI()).thenReturn(SERVLET_PATH + NEW_ARTIFACT_PATH);
    Part part1 = Mockito.mock(Part.class);

    Mockito.when(part1.getInputStream()).thenReturn(TestUtils.getZipStream("newProject.zip"));
    Collection<Part> parts = Collections.singleton(part1);
    Mockito.when(request.getParts()).thenReturn(parts);

    cut.doPut(request, response);

    Mockito.verify(response, times(NO_CONTENT_STATS)).setStatus(HttpServletResponse.SC_NO_CONTENT);
    NO_CONTENT_STATS++;
}
 
开发者ID:SAP,项目名称:cloud-language-servers-container,代码行数:19,代码来源:WSSynchronizationTest.java

示例11: testDoPostSyncLost

import javax.servlet.http.Part; //导入依赖的package包/类
@Test
public void testDoPostSyncLost() throws IOException, ServletException {
    cut.cleanUpWS(Paths.get(new File(wd).getPath()));

    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    Mockito.when(request.getRequestURI()).thenReturn(SERVLET_PATH + ARTIFACT_PATH);
    Mockito.when(request.getServletPath()).thenReturn(SERVLET_PATH);
    Part part1 = Mockito.mock(Part.class);
    Mockito.when(part1.getInputStream()).thenReturn(TestUtils.getZipStream("postTest.zip"));
    Collection<Part> parts = Collections.singleton(part1);
    Mockito.when(request.getParts()).thenReturn(parts);

    cut.doPost(request, response);

    Mockito.verify(response, times(NO_CONTENT_STATS)).setStatus(HttpServletResponse.SC_NO_CONTENT);
    NO_CONTENT_STATS++;
}
 
开发者ID:SAP,项目名称:cloud-language-servers-container,代码行数:18,代码来源:WSSynchronizationTest.java

示例12: asForm

import javax.servlet.http.Part; //导入依赖的package包/类
@Override
public Form asForm() {
    final MultivaluedMap<String, String> map = new MultivaluedHashMap<>();

    for (final Part part : values.values()) {
        if (part.getSubmittedFileName() != null) {
            continue;
        }
        try {
            map.add(part.getName(), IOUtils.toString(part.getInputStream(), StandardCharsets.UTF_8));
        } catch (final IOException ex) {
            LOG.error(ex.getMessage(), ex);
        }
    }

    return new Form(map);
}
 
开发者ID:minijax,项目名称:minijax,代码行数:18,代码来源:MinijaxMultipartForm.java

示例13: doPost

import javax.servlet.http.Part; //导入依赖的package包/类
public void doPost(MCRServletJob job) throws Exception {
    HttpServletRequest req = job.getRequest();
    Collection<Part> parts = req.getParts();
    File uploadDir = new File(inputDir + "/upload"); 
    if (!uploadDir.exists()) uploadDir.mkdirs();
    byte[] buffer = new byte[8 * 1024];
    for (Part part : parts) {
    File uploadedFile = new File(uploadDir,getFileName(part));
    
    InputStream input = part.getInputStream();
    try {
      OutputStream output = new FileOutputStream(uploadedFile);
      try {
        int bytesRead;
        while ((bytesRead = input.read(buffer)) != -1) {
          output.write(buffer, 0, bytesRead);
        }
      } finally {
        output.close();
      }
    } finally {
      input.close();
    }
    LOGGER.info("saved csv-file " + uploadedFile);
    job.getResponse().sendRedirect("getScopusAuthorData?listName="+ uploadedFile);
    }
    
}
 
开发者ID:ETspielberg,项目名称:bibliometrics,代码行数:29,代码来源:CSVUploadServlet.java

示例14: getInputStream

import javax.servlet.http.Part; //导入依赖的package包/类
public InputStream getInputStream(SectionInfo info)
{
    Part file = getMultipartFile(info);
    if( file != null )
    {
        try
        {
            return file.getInputStream();
        }
        catch( IOException e )
        {
            SectionUtils.throwRuntime(e);
        }
    }
    return null;
}
 
开发者ID:equella,项目名称:Equella,代码行数:17,代码来源:AbstractFileUpload.java

示例15: testMultipleLines

import javax.servlet.http.Part; //导入依赖的package包/类
@Test
public void testMultipleLines() throws IOException {
    final String mockContent =
            "------WebKitFormBoundarycTqA2AimXQHBAJbZ\n" +
            "Content-Disposition: form-data; name=\"key\"\n" +
            "\n" +
            "myvalue1\n" +
            "myvalue1\n" +
            "------WebKitFormBoundarycTqA2AimXQHBAJbZ";

    final List<Part> parts = MockPart.parseAll(mockContent);
    assertNotNull(parts);
    assertEquals(1, parts.size());

    final Part part = parts.get(0);
    assertEquals("key", part.getName());
    assertEquals("myvalue1" + "\n" + "myvalue1", IOUtils.toString(part.getInputStream(), StandardCharsets.UTF_8));
}
 
开发者ID:minijax,项目名称:minijax,代码行数:19,代码来源:MockPartTest.java


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