本文整理汇总了Java中javax.activation.MimeTypeParseException类的典型用法代码示例。如果您正苦于以下问题:Java MimeTypeParseException类的具体用法?Java MimeTypeParseException怎么用?Java MimeTypeParseException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MimeTypeParseException类属于javax.activation包,在下文中一共展示了MimeTypeParseException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: calcExpectedMediaType
import javax.activation.MimeTypeParseException; //导入依赖的package包/类
static MimeType calcExpectedMediaType(AnnotationSource primarySource,
ModelBuilder builder ) {
XmlMimeType xmt = primarySource.readAnnotation(XmlMimeType.class);
if(xmt==null)
return null;
try {
return new MimeType(xmt.value());
} catch (MimeTypeParseException e) {
builder.reportError(new IllegalAnnotationException(
Messages.ILLEGAL_MIME_TYPE.format(xmt.value(),e.getMessage()),
xmt
));
return null;
}
}
示例2: getReader
import javax.activation.MimeTypeParseException; //导入依赖的package包/类
@Override
public BufferedReader getReader() throws IOException {
if (null == servletReader) {
if (null != servletInputStream) {
throw new IllegalStateException("Cannot call getReader() after getInputStream()");
}
try {
servletReader = new BufferedReader(new InputStreamReader(
inputStream, null == getOrParseCharacterEncodingImpl() ? UTF8 : characterEncoding
));
} catch (MimeTypeParseException e) {
throw new UnsupportedEncodingException(format("Couldn't parse encoding from mime type: %s", e.getMessage()));
}
}
return servletReader;
}
示例3: testUnmarshalJsonContent
import javax.activation.MimeTypeParseException; //导入依赖的package包/类
@Test
public void testUnmarshalJsonContent() throws MimeTypeParseException {
// PREPARE
final Data data = new Data("BookAddedEvent",
new EnhancedMimeType("application/json; encoding=utf-8"),
"{\"name\":\"Shining\",\"author\":\"Stephen King\"}");
// TEST
final JsonObject event = data.unmarshalContent(null);
// VERIFY
assertThat(event.getString("name")).isEqualTo("Shining");
assertThat(event.getString("author")).isEqualTo("Stephen King");
}
示例4: testValueOfXml
import javax.activation.MimeTypeParseException; //导入依赖的package包/类
@Test
public void testValueOfXml() throws MimeTypeParseException {
// PREPARE
final BookAddedEvent event = new BookAddedEvent("Shining",
"Stephen King");
// TEST
final Data data = Data.valueOf("BookAddedEvent", event);
// VERIFY
assertThat(data.getType()).isEqualTo("BookAddedEvent");
assertThat(data.getMimeType()).isEqualTo(
new EnhancedMimeType("application/xml; encoding=utf-8"));
assertThat(data.getContent()).isEqualTo(Units4JUtils.XML_PREFIX
+ "<book-added-event><name>Shining</name><author>Stephen King</author></book-added-event>");
assertThat(data.isXml()).isTrue();
assertThat(data.isJson()).isFalse();
}
示例5: testValueOfJson
import javax.activation.MimeTypeParseException; //导入依赖的package包/类
@Test
public void testValueOfJson() throws MimeTypeParseException {
// PREPARE
final JsonObject event = Json.createObjectBuilder()
.add("name", "Shining").add("author", "Stephen King").build();
// TEST
final Data data = Data.valueOf("BookAddedEvent", event);
System.out.println(event.toString());
// VERIFY
assertThat(data.getType()).isEqualTo("BookAddedEvent");
assertThat(data.getMimeType()).isEqualTo(
new EnhancedMimeType("application/json; encoding=utf-8"));
assertThat(data.getContent()).isEqualTo(
"{\"name\":\"Shining\",\"author\":\"Stephen King\"}");
assertThat(data.isXml()).isFalse();
assertThat(data.isJson()).isTrue();
}
示例6: testConstrcutionAllArgs
import javax.activation.MimeTypeParseException; //导入依赖的package包/类
@Test
public void testConstrcutionAllArgs() throws MimeTypeParseException {
// PREPARE & TEST
final Map<String, String> params = new HashMap<String, String>();
params.put("a", "1");
final EnhancedMimeType testee = new EnhancedMimeType("application",
"json", Charset.forName("utf-8"), "1.0.2", params);
// VERIFY
assertThat(testee.getPrimaryType()).isEqualTo("application");
assertThat(testee.getSubType()).isEqualTo("json");
assertThat(testee.getEncoding()).isEqualTo(Charset.forName("utf-8"));
assertThat(testee.getParameter(EnhancedMimeType.ENCODING)).isEqualTo(
"UTF-8");
assertThat(testee.getVersion()).isEqualTo("1.0.2");
assertThat(testee.getParameter(EnhancedMimeType.VERSION)).isEqualTo(
"1.0.2");
assertThat(testee.getParameter("a")).isEqualTo("1");
assertThat(testee.getParameters().size()).isEqualTo(3);
}
示例7: testXmlXml
import javax.activation.MimeTypeParseException; //导入依赖的package包/类
@Test
public void testXmlXml() throws IOException, MimeTypeParseException {
// PREPARE
final SerializedDataType dataType = new SerializedDataType(MyEvent.TYPE.asBaseType());
final EnhancedMimeType mimeType = new EnhancedMimeType("application/xml");
final DeserializerRegistry registry = createRegistry();
final Node node = parse("/event-xml-xml-xml.xml", "/Event/Data");
// TEST
final Object obj = new ESHttpXmlUnmarshaller().unmarshal(registry, dataType, mimeType, node);
// VERIFY
assertThat(obj).isInstanceOf(MyEvent.class);
final MyEvent event = (MyEvent) obj;
assertThat(event.getId()).isEqualTo("68616d90-cf72-4c2a-b913-32bf6e6506ed");
assertThat(event.getDescription()).isEqualTo("Hello, XML!");
}
示例8: testXmlOther
import javax.activation.MimeTypeParseException; //导入依赖的package包/类
@Test
public void testXmlOther() throws IOException, MimeTypeParseException {
// PREPARE
final SerializedDataType dataType = new SerializedDataType(MyEvent.TYPE.asBaseType());
final EnhancedMimeType mimeType = new EnhancedMimeType(
"application/json; version=1; encoding=utf-8; transfer-encoding=base64");
final DeserializerRegistry registry = createRegistry();
final Node node = parse("/event-xml-xml-other.xml", "/Event/Data");
// TEST
final Object obj = new ESHttpXmlUnmarshaller().unmarshal(registry, dataType, mimeType, node);
// VERIFY
assertThat(obj).isInstanceOf(JsonObject.class);
final JsonObject event = (JsonObject) obj;
assertThat(event.getString("id")).isEqualTo("68616d90-cf72-4c2a-b913-32bf6e6506e");
assertThat(event.getString("description")).isEqualTo("Hello, JSON!");
}
示例9: testJsonJson
import javax.activation.MimeTypeParseException; //导入依赖的package包/类
@Test
public void testJsonJson() throws IOException, MimeTypeParseException {
// PREPARE
final SerializedDataType dataType = new SerializedDataType(MyEvent.TYPE.asBaseType());
final EnhancedMimeType mimeType = new EnhancedMimeType("application/json");
final DeserializerRegistry registry = createRegistry();
final JsonObject jsonObj = parse("/event-json-json-json.json", "$.Data");
// TEST
final Object obj = new ESHttpJsonUnmarshaller().unmarshal(registry, dataType, mimeType, jsonObj);
// VERIFY
assertThat(obj).isInstanceOf(JsonObject.class);
final JsonObject event = (JsonObject) obj;
assertThat(event.getString("id")).isEqualTo("b2a936ce-d479-414f-b67f-3df4da383d47");
assertThat(event.getString("description")).isEqualTo("Hello, JSON!");
}
示例10: testJsonOther
import javax.activation.MimeTypeParseException; //导入依赖的package包/类
@Test
public void testJsonOther() throws IOException, MimeTypeParseException {
// PREPARE
final SerializedDataType dataType = new SerializedDataType(MyEvent.TYPE.asBaseType());
final EnhancedMimeType mimeType = new EnhancedMimeType(
"application/xml; version=1; encoding=utf-8; transfer-encoding=base64");
final DeserializerRegistry registry = createRegistry();
final JsonObject jsonObj = parse("/event-json-json-other.json", "$.Data");
// TEST
final Object obj = new ESHttpJsonUnmarshaller().unmarshal(registry, dataType, mimeType, jsonObj);
// VERIFY
assertThat(obj).isInstanceOf(MyEvent.class);
final MyEvent event = (MyEvent) obj;
assertThat(event.getId()).isEqualTo("bd58da40-9249-4b42-a077-10455b483c80");
assertThat(event.getDescription()).isEqualTo("Hello, XML!");
}
示例11: calcExpectedMediaType
import javax.activation.MimeTypeParseException; //导入依赖的package包/类
static MimeType calcExpectedMediaType(AnnotationSource primarySource,
ModelBuilder builder ) {
XmlMimeType xmt = primarySource.readAnnotation(XmlMimeType.class);
if(xmt==null)
return null;
try {
return new MimeType(xmt.value());
} catch (MimeTypeParseException e) {
builder.reportError(new IllegalAnnotationException(
Messages.ILLEGAL_MIME_TYPE.format(xmt.value(),e.getMessage()),
xmt
));
return null;
}
}
示例12: getImageType
import javax.activation.MimeTypeParseException; //导入依赖的package包/类
@Override
public String getImageType() throws TileStoreException
{
try
{
final MimeType mimeType = new MimeType(Files.probeContentType(this.rawImage.toPath()));
if(mimeType.getPrimaryType().toLowerCase().equals("image"))
{
return mimeType.getSubType();
}
return null;
}
catch(final MimeTypeParseException | IOException ex)
{
throw new TileStoreException(ex);
}
}
示例13: createMimeTypeSet
import javax.activation.MimeTypeParseException; //导入依赖的package包/类
/**
* Create a set of {@link MimeType} objects from their corresponding string
* designations
*
* @param types
* Mime type strings
* @return A set of MimeType objects
*/
public static Set<MimeType> createMimeTypeSet(final String... types)
{
if(types == null)
{
throw new IllegalArgumentException("The mime type strings cannot be null.");
}
final Set<MimeType> imageFormats = new HashSet<>();
for(final String type : types)
{
try
{
imageFormats.add(new MimeType(type));
}
catch(final MimeTypeParseException | NullPointerException ex)
{
// This method was specifically created to avoid checked exceptions
}
}
return imageFormats;
}
示例14: createMimeTypeSetVerify
import javax.activation.MimeTypeParseException; //导入依赖的package包/类
@Test
public void createMimeTypeSetVerify() throws MimeTypeParseException
{
final String[] mimeTypeStrings = {"image/png",
"image/jpeg",
null,
"video/avi",
"image/bmp",
"text/plain"};
final Set<MimeType> expectedMimeTypes = new HashSet<>(Arrays.asList(new MimeType("image/png"),
new MimeType("image/jpeg"),
new MimeType("video/avi"),
new MimeType("image/bmp"),
new MimeType("text/plain")));
final Set<MimeType> returnedMimeTypes = MimeTypeUtility.createMimeTypeSet(mimeTypeStrings);
MimeTypeUtilityTest.assertCreateMimeTypes(expectedMimeTypes, returnedMimeTypes);
}
示例15: addTileIllegalArgumentException2
import javax.activation.MimeTypeParseException; //导入依赖的package包/类
/**
* Tests if GeoPackageWriter will throw an Illegal argumentException when
* adding a tile with a null value for buffered image
*/
@Test(expected = IllegalArgumentException.class)
public void addTileIllegalArgumentException2() throws SQLException, MimeTypeParseException, TileStoreException
{
final File testFile = this.getRandomFile(6);
try(final GeoPackageWriter gpkgWriter = new GeoPackageWriter(testFile,
new CoordinateReferenceSystem("EPSG", 4326),
"foo",
"identifier",
"description",
new BoundingBox(0.0,0.0,90.0,90.0),
new ZoomTimesTwo(0, 0, 4, 2),
new MimeType("image/jpeg"),
null))
{
gpkgWriter.addTile(new CrsCoordinate(30.0,20.0, "epsg", 4326), 0, null);
fail("Expected GeoPackageWriter to throw an IllegalArgumentException if a user puts in a null value for the parameter image.");
}
finally
{
deleteFile(testFile);
}
}