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

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

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

Blob.getMimeType介绍

[英]Getter for the mime-type of the content. The returned string MUST only contain the "{type}/{sub-type}". No wildcards MUST BE used.
[中]内容的mime类型的Getter。返回的字符串必须仅包含“{type}/{sub type}”。不得使用通配符。

代码示例

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

@Override
public String getMimeType() {
  return getLazy().getMimeType();
}

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

@Override
public final String getMimeType() {
  return getBlob().getMimeType();
}

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

@Override
public String getMimeType() {
  return getLazy().getMimeType();
}

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

@Override
public final String getMimeType() {
  return getBlob().getMimeType();
}

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

/**
 * @param ci
 * @return
 */
private MediaType getMediaType(Blob blob) {
  String[] mediaTypeArray = blob.getMimeType().split("/");
  if(mediaTypeArray.length != 2){
    log.warn("Encounterd illegal formatted mediaType '{}'  -> will try " +
        "to detect the mediaType based on the parsed content!",
      blob.getMimeType());
    return null;
  } else {
    return new MediaType(mediaTypeArray[0], mediaTypeArray[1],
      blob.getParameter());
  }
}

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

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

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

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

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

/**
   * Tests the default mimeType "application/octet-stream" for binary data.
   * @throws IOException
   */
  @Test
  public void testDefaultBinaryMimeType() throws IOException {
    Blob blob = createBlob(new ByteArraySource("dummy".getBytes(UTF8)));
    Assert.assertEquals("application/octet-stream", blob.getMimeType());
    Assert.assertTrue(blob.getParameter().isEmpty());

    blob = createBlob(new StreamSource(new ByteArrayInputStream("dummy".getBytes(UTF8))));
    Assert.assertEquals("application/octet-stream", blob.getMimeType());
    Assert.assertTrue(blob.getParameter().isEmpty());
  }
}

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

/**
   * Tests the default mimeType "application/octet-stream" for binary data.
   * @throws IOException
   */
  @Test
  public void testDefaultBinaryMimeType() throws IOException {
    Blob blob = createBlob(new ByteArraySource("dummy".getBytes(UTF8)));
    Assert.assertEquals("application/octet-stream", blob.getMimeType());
    Assert.assertTrue(blob.getParameter().isEmpty());

    blob = createBlob(new StreamSource(new ByteArrayInputStream("dummy".getBytes(UTF8))));
    Assert.assertEquals("application/octet-stream", blob.getMimeType());
    Assert.assertTrue(blob.getParameter().isEmpty());
  }
}

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

/**
 * Tests correct handling of  UTF-8 as default charset
 * @throws IOException
 */
@Test
public void testString() throws IOException{
  String test = "Exámplê";
  //first via a StringSource
  ContentSource cs = new StringSource(test);
  Blob blob = createBlob(cs);
  Assert.assertEquals("text/plain", blob.getMimeType());
  Assert.assertTrue(blob.getParameter().containsKey("charset"));
  Assert.assertEquals(UTF8.name(), blob.getParameter().get("charset"));
  String value = new String(IOUtils.toByteArray(blob.getStream()),UTF8);
  Assert.assertEquals(test, value);
}
/**

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

/**
 * Tests correct handling of  UTF-8 as default charset
 * @throws IOException
 */
@Test
public void testString() throws IOException{
  String test = "Exámplê";
  //first via a StringSource
  ContentSource cs = new StringSource(test);
  Blob blob = createBlob(cs);
  Assert.assertEquals("text/plain", blob.getMimeType());
  Assert.assertTrue(blob.getParameter().containsKey("charset"));
  Assert.assertEquals(UTF8.name(), blob.getParameter().get("charset"));
  String value = new String(IOUtils.toByteArray(blob.getStream()),UTF8);
  Assert.assertEquals(test, value);
}
/**

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

@Test
public void testMultipleSeparators() throws IOException {
  Blob blob = createBlob(createContentSource("text/plain;;charset=UTF-8"));
  Assert.assertEquals("text/plain", blob.getMimeType());
  Assert.assertTrue(blob.getParameter().containsKey("charset"));
  Assert.assertEquals("UTF-8", blob.getParameter().get("charset"));
  
  blob = createBlob(createContentSource("text/plain;charset=UTF-8;;other=test"));
  Assert.assertEquals("text/plain", blob.getMimeType());
  Assert.assertTrue(blob.getParameter().containsKey("charset"));
  Assert.assertEquals("UTF-8", blob.getParameter().get("charset"));
  Assert.assertTrue(blob.getParameter().containsKey("other"));
  Assert.assertEquals("test", blob.getParameter().get("other"));
}
@Test

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

@Test
public void testContentSinkDefaultMimeType() throws IOException {
  String DEFAULT = "application/octet-stream";
  ContentSink cs = contentItemFactory.createContentSink(null);
  assertNotNull(cs);
  assertNotNull(cs.getBlob());
  assertNotNull(cs.getBlob().getMimeType());
  //get MimeType MUST return the simple mime type
  assertEquals(DEFAULT, cs.getBlob().getMimeType());
  assertNull(cs.getBlob().getParameter().get("charset"));
}

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

@Test
public void testMimeType() throws IOException {
  Blob blob = createBlob(createContentSource("text/plain;charset=UTF-8"));
  Assert.assertEquals("text/plain", blob.getMimeType());
  Assert.assertTrue(blob.getParameter().containsKey("charset"));
  Assert.assertEquals("UTF-8", blob.getParameter().get("charset"));
  
  blob = createBlob(createContentSource("text/plain;charset=UTF-8;other=test"));
  Assert.assertEquals("text/plain", blob.getMimeType());
  Assert.assertTrue(blob.getParameter().containsKey("charset"));
  Assert.assertEquals("UTF-8", blob.getParameter().get("charset"));
  Assert.assertTrue(blob.getParameter().containsKey("other"));
  Assert.assertEquals("test", blob.getParameter().get("other"));
}
@Test

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

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

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

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

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

@Test
public void testMimeType() throws IOException {
  Blob blob = createBlob(createContentSource("text/plain;charset=UTF-8"));
  Assert.assertEquals("text/plain", blob.getMimeType());
  Assert.assertTrue(blob.getParameter().containsKey("charset"));
  Assert.assertEquals("UTF-8", blob.getParameter().get("charset"));
  
  blob = createBlob(createContentSource("text/plain;charset=UTF-8;other=test"));
  Assert.assertEquals("text/plain", blob.getMimeType());
  Assert.assertTrue(blob.getParameter().containsKey("charset"));
  Assert.assertEquals("UTF-8", blob.getParameter().get("charset"));
  Assert.assertTrue(blob.getParameter().containsKey("other"));
  Assert.assertEquals("test", blob.getParameter().get("other"));
}
@Test

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

@Test
public void testMultipleSeparators() throws IOException {
  Blob blob = createBlob(createContentSource("text/plain;;charset=UTF-8"));
  Assert.assertEquals("text/plain", blob.getMimeType());
  Assert.assertTrue(blob.getParameter().containsKey("charset"));
  Assert.assertEquals("UTF-8", blob.getParameter().get("charset"));
  
  blob = createBlob(createContentSource("text/plain;charset=UTF-8;;other=test"));
  Assert.assertEquals("text/plain", blob.getMimeType());
  Assert.assertTrue(blob.getParameter().containsKey("charset"));
  Assert.assertEquals("UTF-8", blob.getParameter().get("charset"));
  Assert.assertTrue(blob.getParameter().containsKey("other"));
  Assert.assertEquals("test", blob.getParameter().get("other"));
}
@Test

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

@Test
public void testContentSinkDefaultMimeType() throws IOException {
  String DEFAULT = "application/octet-stream";
  ContentSink cs = contentItemFactory.createContentSink(null);
  assertNotNull(cs);
  assertNotNull(cs.getBlob());
  assertNotNull(cs.getBlob().getMimeType());
  //get MimeType MUST return the simple mime type
  assertEquals(DEFAULT, cs.getBlob().getMimeType());
  assertNull(cs.getBlob().getParameter().get("charset"));
}

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

assertNotNull(cs.getBlob().getMimeType());
assertEquals(mt, cs.getBlob().getMimeType());
String charsetParam = cs.getBlob().getParameter().get("charset");
assertNotNull("expected charset parameter is missing!",charsetParam);

相关文章