List of usage examples for com.google.common.net MediaType ANY_TYPE
MediaType ANY_TYPE
To view the source code for com.google.common.net MediaType ANY_TYPE.
Click Source Link
From source file:michal.szymanski.util.URLs.java
public static MediaType getMimeTypeOf(URL url) { HttpURLConnection connection; String result = null;//from w w w. j a va2 s . co m try { connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod(HttpMethod.HEAD); connection.connect(); result = connection.getContentType(); } catch (Exception e) { result = MediaType.ANY_TYPE.toString(); } return MediaType.parse(result); }
From source file:io.rebolt.http.utils.HeaderParser.java
public MediaType getFirst() { return isEmpty() ? MediaType.ANY_TYPE : mediaTypes.get(0); }
From source file:rapture.kernel.plugin.BlobInstaller.java
@Override public void install(CallingContext context, RaptureURI uri, PluginTransportItem item) { BlobApi api = Kernel.getBlob(); try {//from w ww . j a v a 2 s. c o m BlobContainer blob = JacksonUtil.objectFromJson(item.getContent(), BlobContainer.class); } catch (RaptureException e) { // It's a raw blob without a container String mimeType = (uri.getDocPath().endsWith(".jar")) ? JarApiImpl.CONTENT_TYPE : MediaType.ANY_TYPE.toString(); api.putBlob(context, uri.toString(), item.getContent(), mimeType); } }
From source file:com.bennavetta.appsite.serve.HttpServletResp.java
@Override public MediaType getContentType() { return (response.getContentType() == null ? MediaType.ANY_TYPE : MediaType.parse(response.getContentType())); }
From source file:com.bennavetta.appsite.serve.HttpServletReq.java
@Override public MediaType getContentType() { return (request.getContentType() == null ? MediaType.ANY_TYPE : MediaType.parse(request.getContentType())); }
From source file:com.github.avarabyeu.restendpoint.serializer.ByteArraySerializer.java
@Override public final boolean canRead(MediaType mimeType, Class<?> resultType) { return mimeType.is(MediaType.ANY_TYPE) && byte[].class.equals(resultType); }
From source file:com.mastfrog.acteur.ContentConverter.java
@SuppressWarnings("unchecked") public <T> T toObject(ByteBuf content, MediaType mimeType, Class<T> type) throws IOException { if (mimeType == null) { mimeType = MediaType.ANY_TYPE; }/*w w w . jav a 2s . c om*/ // Special handling for strings if (type == String.class || type == CharSequence.class) { return type.cast(toString(content, findCharset(mimeType))); } if (type.isInterface()) { Map<String, Object> m; try (InputStream in = new ByteBufInputStream(content)) { m = codec.readValue(in, Map.class); } return toObject(m, type); } return readObject(content, mimeType, type); }
From source file:com.mastfrog.acteur.server.EventImpl.java
@Override public <T> T getContentAsJSON(Class<T> type) throws IOException { MediaType mimeType = getHeader(Headers.CONTENT_TYPE); if (mimeType == null) { mimeType = MediaType.ANY_TYPE; }/*from ww w . j a v a 2s. c o m*/ return converter.toObject(getContent(), mimeType, type); }
From source file:com.andrewreitz.encryptedcamera.externalstoreage.ExternalStorageManagerImpl.java
protected File getMediaFile(MediaType type, File mediaStorageDir) { String timeStamp = dateFormat.format(new Date()); File mediaFile;/*w ww. j av a 2s . c o m*/ if (type.is(MediaType.ANY_IMAGE_TYPE)) { mediaFile = new File(getFileName(type, mediaStorageDir, IMAGE_FILENAME_PREFIX, timeStamp)); } else if (type.is(MediaType.ANY_VIDEO_TYPE)) { mediaFile = new File(getFileName(type, mediaStorageDir, VIDEO_FILENAME_PREFIX, timeStamp)); } else if (type.is(MediaType.ANY_TYPE)) { mediaFile = new File(mediaStorageDir.getPath()); } else { throw new IllegalArgumentException(String.format("Unknown File Type %s", type)); } return mediaFile; }
From source file:org.wisdom.engine.wrapper.RequestFromNetty.java
/** * Get the preferred content media type that is acceptable for the client. For instance, in Accept: text/*;q=0.3, * text/html;q=0.7, text/html;level=1,text/html;level=2;q=0.4, text/html is returned. * <p/>/*from www. j a v a 2 s.c om*/ * The Accept request-header field can be used to specify certain media * types which are acceptable for the response. Accept headers can be used * to indicate that the request is specifically limited to a small set of * desired types, as in the case of a request for an in-line image. * * @return a MediaType that is acceptable for the * client or {@see MediaType#HTML_UTF_8} if not set * @see <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html" * >http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html</a> */ @Override public MediaType mediaType() { Collection<MediaType> types = mediaTypes(); if (types == null || types.isEmpty()) { return MediaType.ANY_TEXT_TYPE; } else if (types.size() == 1 && types.iterator().next().equals(MediaType.ANY_TYPE)) { return MediaType.ANY_TEXT_TYPE; } else { return types.iterator().next(); } }