本文整理了Java中org.apache.stanbol.enhancer.servicesapi.Blob.getParameter()
方法的一些代码示例,展示了Blob.getParameter()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Blob.getParameter()
方法的具体详情如下:
包路径:org.apache.stanbol.enhancer.servicesapi.Blob
类名称: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
@Override
public Map<String,String> getParameter() {
return getLazy().getParameter();
}
代码示例来源:origin: apache/stanbol
@Override
public Map<String,String> getParameter() {
return getLazy().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: 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.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: 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: 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: org.apache.stanbol/org.apache.stanbol.enhancer.test
@Test(expected=UnsupportedOperationException.class)
public void testReadOnlyParameter() throws IOException {
Blob blob = createBlob(createContentSource("text/plain;test;charset=UTF-8"));
blob.getParameter().put("test", "dummy");
}
/**
代码示例来源:origin: apache/stanbol
@Test(expected=UnsupportedOperationException.class)
public void testReadOnlyParameter() throws IOException {
Blob blob = createBlob(createContentSource("text/plain;test;charset=UTF-8"));
blob.getParameter().put("test", "dummy");
}
/**
代码示例来源: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
/**
* 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.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: 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.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 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"));
}
内容来源于网络,如有侵权,请联系作者删除!