當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。