org.apache.stanbol.enhancer.servicesapi.Blob类的使用及代码示例

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

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

Blob介绍

[英]represents a finite sequence of bytes associated to a mime-type
[中]表示与mime类型关联的有限字节序列

代码示例

代码示例来源: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: apache/stanbol

@Override
public final InputStream getStream() {
  return getBlob().getStream();
}
@Override

代码示例来源: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: apache/stanbol

/**
 * Getter for the Text of an {@link Blob}. This method respects the
 * "charset" if present in the {@link Blob#getParameter() parameter} of the
 * Blob.
 * @param blob the {@link Blob}. MUST NOT be <code>null</code>.
 * @return the text
 * @throws IOException on any exception while reading from the
 * {@link InputStream} provided by the Blob.
 * @throws IllegalArgumentException if the parsed Blob is <code>null</code>
 */
public static String getText(Blob blob) throws IOException {
  if(blob == null){
    throw new IllegalArgumentException("The parsed Blob MUST NOT be NULL!");
  }
  String charset = blob.getParameter().get("charset");
  return IOUtils.toString(blob.getStream(), charset != null ? charset : UTF8);
}
/**

代码示例来源: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: apache/stanbol

blob.getStream(), blob.getContentLength(),
ContentType.create(blob.getMimeType(), 
  blob.getParameter().get("charset"))));

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

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

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

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

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

@Override
public long getContentLength() {
  if(_blob == null){ //do not dereference for calls on getContentLength
    return -1;
  } else {
    return _blob.getContentLength();
  }
}
public Blob getLazy() {

代码示例来源: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: apache/stanbol

request.addHeader(HttpHeaders.CONTENT_LANGUAGE, language);
request.setEntity(new InputStreamEntity(
  blob.getStream(), blob.getContentLength(),
  ContentType.create(blob.getMimeType(), 
    blob.getParameter().get("charset"))));

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

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

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

/**
 * Getter for the Text of an {@link Blob}. This method respects the
 * "charset" if present in the {@link Blob#getParameter() parameter} of the
 * Blob.
 * @param blob the {@link Blob}. MUST NOT be <code>null</code>.
 * @return the text
 * @throws IOException on any exception while reading from the
 * {@link InputStream} provided by the Blob.
 * @throws IllegalArgumentException if the parsed Blob is <code>null</code>
 */
public static String getText(Blob blob) throws IOException {
  if(blob == null){
    throw new IllegalArgumentException("The parsed Blob MUST NOT be NULL!");
  }
  String charset = blob.getParameter().get("charset");
  return IOUtils.toString(blob.getStream(), charset != null ? charset : UTF8);
}
/**

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

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

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

@Override
public long getContentLength() {
  if(_blob == null){ //do not dereference for calls on getContentLength
    return -1;
  } else {
    return _blob.getContentLength();
  }
}
public Blob getLazy() {

代码示例来源: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

result = java.util.Collections.emptySet();
} else {
  String charset = blob.getParameter().get("charset");
  try {
    if(charset != null){
      result = java.util.Collections.singleton(
        backend.createLiteral(IOUtils.toString(blob.getStream(), charset)));
    } else { //binary content
      byte[] data = IOUtils.toByteArray(blob.getStream());
      result = java.util.Collections.singleton(
        (RDFTerm)lf.createTypedLiteral(data));
      + blob.getMimeType()+"' of ContentItem "+ci.getUri(),e);

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

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

代码示例来源: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.servicesapi

@Override
public final InputStream getStream() {
  return getBlob().getStream();
}
@Override

相关文章