org.apache.stanbol.enhancer.servicesapi.Blob.getParameter()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(11.9k)|赞(0)|评价(0)|浏览(149)

本文整理了Java中org.apache.stanbol.enhancer.servicesapi.Blob.getParameter()方法的一些代码示例,展示了Blob.getParameter()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Blob.getParameter()方法的具体详情如下:
包路径:org.apache.stanbol.enhancer.servicesapi.Blob
类名称:Blob
方法名:getParameter

Blob.getParameter介绍

[英]Additional parameters parsed with the mime-type. Typically the 'charset' used to encode text is parsed as a parameter.
[中]使用mime类型解析的其他参数。通常,用于编码文本的“字符集”被解析为参数。

代码示例

代码示例来源:origin: org.apache.stanbol/org.apache.stanbol.enhancer.servicesapi

  1. @Override
  2. public Map<String,String> getParameter() {
  3. return getLazy().getParameter();
  4. }

代码示例来源:origin: apache/stanbol

  1. @Override
  2. public Map<String,String> getParameter() {
  3. return getLazy().getParameter();
  4. }

代码示例来源:origin: org.apache.stanbol/org.apache.stanbol.enhancer.servicesapi

  1. /**
  2. * Creates the "{type}/{subtime}; [{param}={value}]+" mime type representation
  3. * for the {@link Blob#getMimeType()} and {@link Blob#getParameter()} values
  4. * @param blob the Blob
  5. * @return the mime type with parameters (e.g. <code>
  6. * text/plain;charset=UTF-8</code>)
  7. */
  8. public static String getMimeTypeWithParameters(Blob blob) {
  9. StringBuilder mimeType = new StringBuilder(blob.getMimeType());
  10. //ensure parameters are preserved
  11. for(Entry<String,String> param : blob.getParameter().entrySet()){
  12. mimeType.append("; ").append(param.getKey()).append('=').append(param.getValue());
  13. }
  14. return mimeType.toString();
  15. }

代码示例来源:origin: apache/stanbol

  1. /**
  2. * Creates the "{type}/{subtime}; [{param}={value}]+" mime type representation
  3. * for the {@link Blob#getMimeType()} and {@link Blob#getParameter()} values
  4. * @param blob the Blob
  5. * @return the mime type with parameters (e.g. <code>
  6. * text/plain;charset=UTF-8</code>)
  7. */
  8. public static String getMimeTypeWithParameters(Blob blob) {
  9. StringBuilder mimeType = new StringBuilder(blob.getMimeType());
  10. //ensure parameters are preserved
  11. for(Entry<String,String> param : blob.getParameter().entrySet()){
  12. mimeType.append("; ").append(param.getKey()).append('=').append(param.getValue());
  13. }
  14. return mimeType.toString();
  15. }

代码示例来源:origin: org.apache.stanbol/org.apache.stanbol.enhancer.servicesapi

  1. /**
  2. * Getter for the Text of an {@link Blob}. This method respects the
  3. * "charset" if present in the {@link Blob#getParameter() parameter} of the
  4. * Blob.
  5. * @param blob the {@link Blob}. MUST NOT be <code>null</code>.
  6. * @return the text
  7. * @throws IOException on any exception while reading from the
  8. * {@link InputStream} provided by the Blob.
  9. * @throws IllegalArgumentException if the parsed Blob is <code>null</code>
  10. */
  11. public static String getText(Blob blob) throws IOException {
  12. if(blob == null){
  13. throw new IllegalArgumentException("The parsed Blob MUST NOT be NULL!");
  14. }
  15. String charset = blob.getParameter().get("charset");
  16. return IOUtils.toString(blob.getStream(), charset != null ? charset : UTF8);
  17. }
  18. /**

代码示例来源:origin: org.apache.stanbol/org.apache.stanbol.enhancer.test

  1. @Test
  2. public void testMultipleSeparators() throws IOException {
  3. Blob blob = createBlob(createContentSource("text/plain;;charset=UTF-8"));
  4. Assert.assertEquals("text/plain", blob.getMimeType());
  5. Assert.assertTrue(blob.getParameter().containsKey("charset"));
  6. Assert.assertEquals("UTF-8", blob.getParameter().get("charset"));
  7. blob = createBlob(createContentSource("text/plain;charset=UTF-8;;other=test"));
  8. Assert.assertEquals("text/plain", blob.getMimeType());
  9. Assert.assertTrue(blob.getParameter().containsKey("charset"));
  10. Assert.assertEquals("UTF-8", blob.getParameter().get("charset"));
  11. Assert.assertTrue(blob.getParameter().containsKey("other"));
  12. Assert.assertEquals("test", blob.getParameter().get("other"));
  13. }
  14. @Test

代码示例来源:origin: apache/stanbol

  1. @Test
  2. public void testMimeType() throws IOException {
  3. Blob blob = createBlob(createContentSource("text/plain;charset=UTF-8"));
  4. Assert.assertEquals("text/plain", blob.getMimeType());
  5. Assert.assertTrue(blob.getParameter().containsKey("charset"));
  6. Assert.assertEquals("UTF-8", blob.getParameter().get("charset"));
  7. blob = createBlob(createContentSource("text/plain;charset=UTF-8;other=test"));
  8. Assert.assertEquals("text/plain", blob.getMimeType());
  9. Assert.assertTrue(blob.getParameter().containsKey("charset"));
  10. Assert.assertEquals("UTF-8", blob.getParameter().get("charset"));
  11. Assert.assertTrue(blob.getParameter().containsKey("other"));
  12. Assert.assertEquals("test", blob.getParameter().get("other"));
  13. }
  14. @Test

代码示例来源:origin: org.apache.stanbol/org.apache.stanbol.enhancer.test

  1. @Test
  2. public void testMimeType() throws IOException {
  3. Blob blob = createBlob(createContentSource("text/plain;charset=UTF-8"));
  4. Assert.assertEquals("text/plain", blob.getMimeType());
  5. Assert.assertTrue(blob.getParameter().containsKey("charset"));
  6. Assert.assertEquals("UTF-8", blob.getParameter().get("charset"));
  7. blob = createBlob(createContentSource("text/plain;charset=UTF-8;other=test"));
  8. Assert.assertEquals("text/plain", blob.getMimeType());
  9. Assert.assertTrue(blob.getParameter().containsKey("charset"));
  10. Assert.assertEquals("UTF-8", blob.getParameter().get("charset"));
  11. Assert.assertTrue(blob.getParameter().containsKey("other"));
  12. Assert.assertEquals("test", blob.getParameter().get("other"));
  13. }
  14. @Test

代码示例来源:origin: apache/stanbol

  1. @Test
  2. public void testMultipleSeparators() throws IOException {
  3. Blob blob = createBlob(createContentSource("text/plain;;charset=UTF-8"));
  4. Assert.assertEquals("text/plain", blob.getMimeType());
  5. Assert.assertTrue(blob.getParameter().containsKey("charset"));
  6. Assert.assertEquals("UTF-8", blob.getParameter().get("charset"));
  7. blob = createBlob(createContentSource("text/plain;charset=UTF-8;;other=test"));
  8. Assert.assertEquals("text/plain", blob.getMimeType());
  9. Assert.assertTrue(blob.getParameter().containsKey("charset"));
  10. Assert.assertEquals("UTF-8", blob.getParameter().get("charset"));
  11. Assert.assertTrue(blob.getParameter().containsKey("other"));
  12. Assert.assertEquals("test", blob.getParameter().get("other"));
  13. }
  14. @Test

代码示例来源:origin: org.apache.stanbol/org.apache.stanbol.enhancer.test

  1. @Test(expected=UnsupportedOperationException.class)
  2. public void testReadOnlyParameter() throws IOException {
  3. Blob blob = createBlob(createContentSource("text/plain;test;charset=UTF-8"));
  4. blob.getParameter().put("test", "dummy");
  5. }
  6. /**

代码示例来源:origin: apache/stanbol

  1. @Test(expected=UnsupportedOperationException.class)
  2. public void testReadOnlyParameter() throws IOException {
  3. Blob blob = createBlob(createContentSource("text/plain;test;charset=UTF-8"));
  4. blob.getParameter().put("test", "dummy");
  5. }
  6. /**

代码示例来源:origin: apache/stanbol

  1. /**
  2. * @param ci
  3. * @return
  4. */
  5. private MediaType getMediaType(Blob blob) {
  6. String[] mediaTypeArray = blob.getMimeType().split("/");
  7. if(mediaTypeArray.length != 2){
  8. log.warn("Encounterd illegal formatted mediaType '{}' -> will try " +
  9. "to detect the mediaType based on the parsed content!",
  10. blob.getMimeType());
  11. return null;
  12. } else {
  13. return new MediaType(mediaTypeArray[0], mediaTypeArray[1],
  14. blob.getParameter());
  15. }
  16. }

代码示例来源:origin: apache/stanbol

  1. /**
  2. * Tests the default mimeType "application/octet-stream" for binary data.
  3. * @throws IOException
  4. */
  5. @Test
  6. public void testDefaultBinaryMimeType() throws IOException {
  7. Blob blob = createBlob(new ByteArraySource("dummy".getBytes(UTF8)));
  8. Assert.assertEquals("application/octet-stream", blob.getMimeType());
  9. Assert.assertTrue(blob.getParameter().isEmpty());
  10. blob = createBlob(new StreamSource(new ByteArrayInputStream("dummy".getBytes(UTF8))));
  11. Assert.assertEquals("application/octet-stream", blob.getMimeType());
  12. Assert.assertTrue(blob.getParameter().isEmpty());
  13. }
  14. }

代码示例来源:origin: org.apache.stanbol/org.apache.stanbol.enhancer.test

  1. /**
  2. * Tests the default mimeType "application/octet-stream" for binary data.
  3. * @throws IOException
  4. */
  5. @Test
  6. public void testDefaultBinaryMimeType() throws IOException {
  7. Blob blob = createBlob(new ByteArraySource("dummy".getBytes(UTF8)));
  8. Assert.assertEquals("application/octet-stream", blob.getMimeType());
  9. Assert.assertTrue(blob.getParameter().isEmpty());
  10. blob = createBlob(new StreamSource(new ByteArrayInputStream("dummy".getBytes(UTF8))));
  11. Assert.assertEquals("application/octet-stream", blob.getMimeType());
  12. Assert.assertTrue(blob.getParameter().isEmpty());
  13. }
  14. }

代码示例来源:origin: apache/stanbol

  1. /**
  2. * Tests correct handling of UTF-8 as default charset
  3. * @throws IOException
  4. */
  5. @Test
  6. public void testString() throws IOException{
  7. String test = "Exámplê";
  8. //first via a StringSource
  9. ContentSource cs = new StringSource(test);
  10. Blob blob = createBlob(cs);
  11. Assert.assertEquals("text/plain", blob.getMimeType());
  12. Assert.assertTrue(blob.getParameter().containsKey("charset"));
  13. Assert.assertEquals(UTF8.name(), blob.getParameter().get("charset"));
  14. String value = new String(IOUtils.toByteArray(blob.getStream()),UTF8);
  15. Assert.assertEquals(test, value);
  16. }
  17. /**

代码示例来源:origin: org.apache.stanbol/org.apache.stanbol.enhancer.test

  1. /**
  2. * Tests correct handling of UTF-8 as default charset
  3. * @throws IOException
  4. */
  5. @Test
  6. public void testString() throws IOException{
  7. String test = "Exámplê";
  8. //first via a StringSource
  9. ContentSource cs = new StringSource(test);
  10. Blob blob = createBlob(cs);
  11. Assert.assertEquals("text/plain", blob.getMimeType());
  12. Assert.assertTrue(blob.getParameter().containsKey("charset"));
  13. Assert.assertEquals(UTF8.name(), blob.getParameter().get("charset"));
  14. String value = new String(IOUtils.toByteArray(blob.getStream()),UTF8);
  15. Assert.assertEquals(test, value);
  16. }
  17. /**

代码示例来源:origin: org.apache.stanbol/org.apache.stanbol.enhancer.servicesapi

  1. @Override
  2. public String toString() {
  3. return String.format("%s uri=[%s], content=[%s;mime-type:%s%s], metadata=[%s triples], " +
  4. "parts=%s",
  5. getClass().getSimpleName(), //the implementation
  6. getUri().getUnicodeString(), //the URI
  7. //the size in Bytes (if available)
  8. getBlob().getContentLength()>=0 ?("size:"+getBlob().getContentLength()+" bytes;") : "",
  9. getBlob().getMimeType(), //the mime-type
  10. //and parameter (if available)
  11. getBlob().getParameter().isEmpty() ? "" : (";parameter:"+getBlob().getParameter()),
  12. getMetadata().size(), //the number of triples
  13. parts.keySet()); //and the part URIs
  14. }

代码示例来源:origin: apache/stanbol

  1. @Override
  2. public String toString() {
  3. return String.format("%s uri=[%s], content=[%s;mime-type:%s%s], metadata=[%s triples], " +
  4. "parts=%s",
  5. getClass().getSimpleName(), //the implementation
  6. getUri().getUnicodeString(), //the URI
  7. //the size in Bytes (if available)
  8. getBlob().getContentLength()>=0 ?("size:"+getBlob().getContentLength()+" bytes;") : "",
  9. getBlob().getMimeType(), //the mime-type
  10. //and parameter (if available)
  11. getBlob().getParameter().isEmpty() ? "" : (";parameter:"+getBlob().getParameter()),
  12. getMetadata().size(), //the number of triples
  13. parts.keySet()); //and the part URIs
  14. }

代码示例来源:origin: org.apache.stanbol/org.apache.stanbol.enhancer.test

  1. @Test
  2. public void testContentSinkDefaultMimeType() throws IOException {
  3. String DEFAULT = "application/octet-stream";
  4. ContentSink cs = contentItemFactory.createContentSink(null);
  5. assertNotNull(cs);
  6. assertNotNull(cs.getBlob());
  7. assertNotNull(cs.getBlob().getMimeType());
  8. //get MimeType MUST return the simple mime type
  9. assertEquals(DEFAULT, cs.getBlob().getMimeType());
  10. assertNull(cs.getBlob().getParameter().get("charset"));
  11. }

代码示例来源:origin: apache/stanbol

  1. @Test
  2. public void testContentSinkDefaultMimeType() throws IOException {
  3. String DEFAULT = "application/octet-stream";
  4. ContentSink cs = contentItemFactory.createContentSink(null);
  5. assertNotNull(cs);
  6. assertNotNull(cs.getBlob());
  7. assertNotNull(cs.getBlob().getMimeType());
  8. //get MimeType MUST return the simple mime type
  9. assertEquals(DEFAULT, cs.getBlob().getMimeType());
  10. assertNull(cs.getBlob().getParameter().get("charset"));
  11. }

相关文章