public URLInputStreamRepresentation( String type, InputStream input, HttpURLConnection urlConn ) { super( MediaType.valueOf( type ) ); if ( input == null ) { throw new NullPointerException( "input" ); } if ( urlConn == null ) { throw new NullPointerException( "urlConn" ); } this.input = input; this.urlConn = urlConn; }
/** * Converts the given mimes to a List of MediaTypes. Will never returns * null. * * @param mimes * @return Returns an unmodifiable List of MediaTypes */ public static List<MediaType> convertToMediaTypes(String[] mimes) { final List<MediaType> mediaTypes; mediaTypes = new ArrayList<MediaType>(mimes.length); for (String mime : mimes) { if (mime == null) { mediaTypes.add(MediaType.ALL); } else { mediaTypes.add(MediaType.valueOf(mime)); } } return Collections.unmodifiableList(mediaTypes); }
public StaticResourceResource( Context ctx, Request req, Response rsp, StaticResource resource ) { super( ctx, req, rsp ); setVariants( Collections.singletonList( new Variant( MediaType.valueOf( resource.getContentType() ) ) ) ); this.resource = resource; }
mediaTypes.add(MediaType.valueOf(acceptToken));
public static String convertSampleAccordingToMediaType( Object content, String mediaTypeAsString, String representationName) { MetadataService ms = new MetadataService(); MediaType mediaType = MediaType.valueOf(mediaTypeAsString); if (!supportedExtensions.contains(ms.getExtension(mediaType))) { return null; } String text; try { text = new JacksonRepresentation<>(mediaType, content).getText(); } catch (IOException e) { throw new RuntimeException(e); } if (ms.getAllMediaTypes("xml").contains(mediaType)) { text = text.replaceAll("HashMap", representationName); } return text; }
public static String convertSampleAccordingToMediaType( Object content, String mediaTypeAsString, String representationName) { MetadataService ms = new MetadataService(); MediaType mediaType = MediaType.valueOf(mediaTypeAsString); if (!supportedExtensions.contains(ms.getExtension(mediaType))) { return null; } String text; try { text = new JacksonRepresentation<>(mediaType, content).getText(); } catch (IOException e) { throw new RuntimeException(e); } if (ms.getAllMediaTypes("xml").contains(mediaType)) { text = text.replaceAll("HashMap", representationName); } return text; }
public static String convertSampleAccordingToMediaType( Object content, String mediaTypeAsString, String representationName) { MetadataService ms = new MetadataService(); MediaType mediaType = MediaType.valueOf(mediaTypeAsString); if (!supportedExtensions.contains(ms.getExtension(mediaType))) { return null; } String text; try { text = new JacksonRepresentation<>(mediaType, content).getText(); } catch (IOException e) { throw new RuntimeException(e); } if (ms.getAllMediaTypes("xml").contains(mediaType)) { text = text.replaceAll("HashMap", representationName); } return text; }
public static String convertSampleAccordingToMediaType( Object content, String mediaTypeAsString, String representationName) { MetadataService ms = new MetadataService(); MediaType mediaType = MediaType.valueOf(mediaTypeAsString); if (!supportedExtensions.contains(ms.getExtension(mediaType))) { return null; } String text; try { text = new JacksonRepresentation<>(mediaType, content).getText(); } catch (IOException e) { throw new RuntimeException(e); } if (ms.getAllMediaTypes("xml").contains(mediaType)) { text = text.replaceAll("HashMap", representationName); } return text; }
public static String convertSampleAccordingToMediaType( Object content, String mediaTypeAsString, String representationName) { MetadataService ms = new MetadataService(); MediaType mediaType = MediaType.valueOf(mediaTypeAsString); if (!supportedExtensions.contains(ms.getExtension(mediaType))) { return null; } String text; try { text = new JacksonRepresentation<>(mediaType, content).getText(); } catch (IOException e) { throw new RuntimeException(e); } if (ms.getAllMediaTypes("xml").contains(mediaType)) { text = text.replaceAll("HashMap", representationName); } return text; }
new AppendableRepresentation(writer.toString(), MediaType.valueOf(outputFormat.getDefaultMIMEType()), Language.DEFAULT, CharacterSet.UTF_8);
/** * {@inheritDoc}<br> * In case the media type has parameters, this method returns the * concatenation of the main type and the subtype. If the subtype is not * equal to "*", it returns the concatenation of the main type and "*". * Otherwise, it returns either the {@link #ALL} media type if it is already * the {@link #ALL} media type, or null. */ @Override public MediaType getParent() { MediaType result = null; if (getParameters().size() > 0) { result = MediaType.valueOf(getMainType() + "/" + getSubType()); } else { if (getSubType().equals("*")) { result = equals(ALL) ? null : ALL; } else { result = MediaType.valueOf(getMainType() + "/*"); } } return result; }
/** * {@inheritDoc}<br> * In case the media type has parameters, this method returns the * concatenation of the main type and the subtype. If the subtype is not * equal to "*", it returns the concatenation of the main type and "*". * Otherwise, it returns either the {@link #ALL} media type if it is already * the {@link #ALL} media type, or null. */ @Override public MediaType getParent() { MediaType result = null; if (getParameters().size() > 0) { result = MediaType.valueOf(getMainType() + "/" + getSubType()); } else { if (getSubType().equals("*")) { result = equals(ALL) ? null : ALL; } else { result = MediaType.valueOf(getMainType() + "/*"); } } return result; }
public StaticResourceRepresentation( StaticResource resource ) { super( MediaType.valueOf( resource.getContentType() ) ); setSize( resource.getSize() ); setModificationDate( new Date( resource.getLastModified() ) ); setAvailable( true ); this.resource = resource; }
new AppendableRepresentation(writer.toString(), MediaType.valueOf(outputFormat.getDefaultMIMEType()), Language.DEFAULT, CharacterSet.UTF_8);
public void setTargetEntity() { final Entity entity; if ((entity = getEntity()) != null) { MediaType contentType = MediaType.valueOf(getContentTypeHeader()); getTarget().setEntity(new OutputRepresentation(contentType) { @Override public void write(OutputStream outputStream) throws IOException { try { entity.write(ResponseAdapter.this, outputStream); } catch (IOException ex) { throw ex; } catch (Exception ex) { throw new RuntimeException(ex); } } }); } }
/** * Returns the requested Nexus configuration. The keys for various configurations should be discovered by querying * * the "/configs" resource first. This resource emits the raw configuration file used by Nexus as response body. * * @param configKey The configuration key for which we want to get the configuration. */ @Override @GET @ResourceMethodSignature(pathParams = {@PathParam("configKey")}, output = String.class) public Object get(Context context, Request request, Response response, Variant variant) throws ResourceException { String key = request.getAttributes().get(GlobalConfigurationPlexusResource.CONFIG_NAME_KEY).toString(); try { NexusStreamResponse result; if (!getNexusConfiguration().getConfigurationFiles().containsKey(key)) { throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND, "No configuration with key '" + key + "' found!"); } else { result = getNexusConfiguration().getConfigurationAsStreamByKey(key); } // TODO: make this real resource being able to be polled (ETag and last modified support) return new InputStreamRepresentation(MediaType.valueOf(result.getMimeType()), result.getInputStream()); } catch (IOException e) { throw new ResourceException(Status.SERVER_ERROR_INTERNAL, "IOException during configuration retrieval!", e); } }
return new InputStreamRepresentation( MediaType.valueOf( result.getMimeType() ), result.getInputStream() );
result.setMetadata((T) MediaType.valueOf(metadata.toString())); break;
public StorageFileItemRepresentation(StorageFileItem file) { super(MediaType.valueOf(file.getMimeType()), file); setSize(file.getLength()); if (file.getRepositoryItemAttributes().containsKey(DigestCalculatingInspector.DIGEST_SHA1_KEY)) { // Shield SHA1 // {SHA1{xxxx}} final String tag = String.format("{SHA1{%s}}", file.getRepositoryItemAttributes().get(DigestCalculatingInspector.DIGEST_SHA1_KEY)); setTag(new Tag(tag, false)); } if (file.getItemContext().containsKey(AbstractResourceStoreContentPlexusResource.OVERRIDE_FILENAME_KEY)) { String filename = file.getItemContext().get(AbstractResourceStoreContentPlexusResource.OVERRIDE_FILENAME_KEY).toString(); setDownloadable(true); setDownloadName(filename); } }
public StorageFileItemRepresentation( StorageFileItem file ) { super( MediaType.valueOf( file.getMimeType() ), file ); setSize( file.getLength() ); if ( file.getRepositoryItemAttributes().containsKey( DigestCalculatingInspector.DIGEST_SHA1_KEY ) ) { // Shield SHA1 // {SHA1{xxxx}} final String tag = String.format( "{SHA1{%s}}", file.getRepositoryItemAttributes().get( DigestCalculatingInspector.DIGEST_SHA1_KEY ) ); setTag( new Tag( tag, false ) ); } if ( file.getItemContext().containsKey( AbstractResourceStoreContentPlexusResource.OVERRIDE_FILENAME_KEY ) ) { String filename = file.getItemContext().get( AbstractResourceStoreContentPlexusResource.OVERRIDE_FILENAME_KEY ).toString(); setDownloadable( true ); setDownloadName( filename ); } }