本文整理汇总了Java中org.restlet.representation.FileRepresentation类的典型用法代码示例。如果您正苦于以下问题:Java FileRepresentation类的具体用法?Java FileRepresentation怎么用?Java FileRepresentation使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FileRepresentation类属于org.restlet.representation包,在下文中一共展示了FileRepresentation类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTestForm
import org.restlet.representation.FileRepresentation; //导入依赖的package包/类
@Get
public FileRepresentation getTestForm() {
ExtensionTokenManager tokenManager = this.getTokenManager();
if (tokenManager.authenticationRequired()) {
getResponse().setStatus(Status.CLIENT_ERROR_UNAUTHORIZED);
return null;
} else {
try {
File webDir = getWebDirectory();
File file = new File(webDir, TEST_FORM_HTML);
FileRepresentation htmlForm = new FileRepresentation(file, MediaType.TEXT_HTML);
return htmlForm;
} catch (Exception ex) {
getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
return null;
}
}
}
示例2: cacheResponse
import org.restlet.representation.FileRepresentation; //导入依赖的package包/类
protected void cacheResponse(File cacheFile, File metadataFile, Response response)
throws IOException
{
try {
Representation entity = response.getEntity();
InputStream is = entity.getStream();
OutputStream os = new FileOutputStream(cacheFile);
byte [] buffer = new byte[8192];
int len = 0;
while ((len=is.read(buffer))>0) {
os.write(buffer,0,len);
}
os.close();
is.close();
MediaType type = entity.getMediaType();
Writer w = new OutputStreamWriter(new FileOutputStream(metadataFile),"UTF-8");
w.write(type.toString());
w.close();
response.setEntity(new FileRepresentation(cacheFile,entity.getMediaType()));
} catch (IOException ex) {
cacheFile.delete();
metadataFile.delete();
throw ex;
}
}
示例3: get
import org.restlet.representation.FileRepresentation; //导入依赖的package包/类
@Override
protected Representation get() throws ResourceException {
if ( !CodebaseDatabase.getInstance().containsResource(this.id))
throw new RuntimeException(MSG_ID_NOT_FOUND);
String path = CodebaseProperties.getInstance().getApkPath(this.id);
File apkFile = new File(path);
if (!apkFile.exists()) {
log.error("Could not load apk file from " + apkFile);
throw new RuntimeException("Could not load file " + apkFile.getName());
}
Representation representation = new FileRepresentation(apkFile, APPLICATION_APK);
Disposition disposition = representation.getDisposition();
disposition.setFilename(CodebaseProperties.getApkFilename(this.id));
disposition.setType(Disposition.TYPE_ATTACHMENT);
return representation;
}
示例4: get
import org.restlet.representation.FileRepresentation; //导入依赖的package包/类
@Override
protected Representation get() throws ResourceException {
if (!CodebaseDatabase.getInstance().containsResource(this.id))
throw new RuntimeException(MSG_ID_NOT_FOUND);
File imageFile = new File(CodebaseProperties.getInstance()
.getImagePath(this.id));
if (!imageFile.exists()) {
log.error("Could not load image file from " + imageFile.getPath());
throw new RuntimeException(this.id + " has no image");
}
Representation representation = new FileRepresentation(imageFile,
MediaType.IMAGE_PNG);
Disposition disposition = representation.getDisposition();
disposition.setFilename(imageFile.getName());
disposition.setType(Disposition.TYPE_ATTACHMENT);
return representation;
}
示例5: listResources
import org.restlet.representation.FileRepresentation; //导入依赖的package包/类
/**
* This resource returns the swagger.json
*/
@Get("json")
public String listResources() {
final ServletContext servlet = (ServletContext) getContext().getAttributes().get(
"org.restlet.ext.servlet.ServletContext");
final String realPath = servlet.getRealPath("/");
final JacksonRepresentation<ApiDeclaration> result = new JacksonRepresentation<ApiDeclaration>(
new FileRepresentation(
realPath + "swagger.json",
MediaType.APPLICATION_JSON),
ApiDeclaration.class);
try {
return result.getText();
}
catch (final IOException e) {
LOGGER.warn(
"Error building swagger json",
e);
}
return "Not Found: swagger.json";
}
示例6: retrieveFile
import org.restlet.representation.FileRepresentation; //导入依赖的package包/类
@Get
public Representation retrieveFile() {
GeoPackager gpkger = packagerPool.find(getAttribute("id"));
if (gpkger == null) {
return error(ExceptionCode.InvalidParameterValue, "No GeoPackage with that ID");
} else if (! gpkger.getCurrentStatus().isFinal()) {
return error(ExceptionCode.InvalidParameterValue, "GeoPackaging for that ID is still in progress");
} else if (gpkger.getCurrentStatus() != ProcessingStatus.SUCCEEDED) {
return error(ExceptionCode.InvalidParameterValue, "GeoPackaging previously failed for that ID");
}
Representation result = new FileRepresentation(gpkger.getFile(), gpkger.getMediaType());
result.getDisposition().setType(Disposition.TYPE_ATTACHMENT);
return result;
}
示例7: getVariants
import org.restlet.representation.FileRepresentation; //导入依赖的package包/类
@Override
public List<VariantInfo> getVariants(Class<?> source) {
List<VariantInfo> result = null;
if (source != null) {
if (String.class.isAssignableFrom(source)
|| StringRepresentation.class.isAssignableFrom(source)) {
result = addVariant(result, VARIANT_ALL);
} else if (File.class.isAssignableFrom(source)
|| FileRepresentation.class.isAssignableFrom(source)) {
result = addVariant(result, VARIANT_ALL);
} else if (InputStream.class.isAssignableFrom(source)
|| InputRepresentation.class.isAssignableFrom(source)) {
result = addVariant(result, VARIANT_ALL);
} else if (Reader.class.isAssignableFrom(source)
|| ReaderRepresentation.class.isAssignableFrom(source)) {
result = addVariant(result, VARIANT_ALL);
} else if (Representation.class.isAssignableFrom(source)) {
result = addVariant(result, VARIANT_ALL);
} else if (Form.class.isAssignableFrom(source)) {
result = addVariant(result, VARIANT_FORM);
} else if (Serializable.class.isAssignableFrom(source)) {
if (ObjectRepresentation.VARIANT_OBJECT_BINARY_SUPPORTED) {
result = addVariant(result, VARIANT_OBJECT);
}
if (ObjectRepresentation.VARIANT_OBJECT_XML_SUPPORTED) {
result = addVariant(result, VARIANT_OBJECT_XML);
}
}
}
return result;
}
示例8: createRepresentationFromBody
import org.restlet.representation.FileRepresentation; //导入依赖的package包/类
protected Representation createRepresentationFromBody(Exchange exchange, MediaType mediaType) {
Object body = exchange.getIn().getBody();
if (body == null) {
return new EmptyRepresentation();
}
// unwrap file
if (body instanceof WrappedFile) {
body = ((WrappedFile) body).getFile();
}
if (body instanceof InputStream) {
return new InputRepresentation((InputStream) body, mediaType);
} else if (body instanceof File) {
return new FileRepresentation((File) body, mediaType);
} else if (body instanceof byte[]) {
return new ByteArrayRepresentation((byte[]) body, mediaType);
} else if (body instanceof String) {
return new StringRepresentation((CharSequence) body, mediaType);
}
// fallback as string
body = exchange.getIn().getBody(String.class);
if (body != null) {
return new StringRepresentation((CharSequence) body, mediaType);
} else {
return new EmptyRepresentation();
}
}
示例9: makeResponse
import org.restlet.representation.FileRepresentation; //导入依赖的package包/类
protected void makeResponse(File cacheFile,File metadataFile,Response response)
throws IOException
{
Reader metadataReader = new InputStreamReader(new FileInputStream(metadataFile),"UTF-8");
LineNumberReader lineReader = new LineNumberReader(metadataReader);
String type = lineReader.readLine();
response.setEntity(new FileRepresentation(cacheFile,MediaType.valueOf(type)));
metadataReader.close();
}
示例10: score
import org.restlet.representation.FileRepresentation; //导入依赖的package包/类
@Override
public <T> float score(Representation source, Class<T> target,
Resource resource) {
float result = -1.0F;
if (target != null) {
if (target.isAssignableFrom(source.getClass())) {
result = 1.0F;
} else if (String.class.isAssignableFrom(target)) {
result = 1.0F;
} else if (StringRepresentation.class.isAssignableFrom(target)) {
result = 1.0F;
} else if (EmptyRepresentation.class.isAssignableFrom(target)) {
result = 1.0F;
} else if (File.class.isAssignableFrom(target)) {
if (source instanceof FileRepresentation) {
result = 1.0F;
}
} else if (Form.class.isAssignableFrom(target)) {
if (MediaType.APPLICATION_WWW_FORM.isCompatible(source
.getMediaType())) {
result = 1.0F;
} else {
result = 0.5F;
}
} else if (InputStream.class.isAssignableFrom(target)) {
result = 1.0F;
} else if (InputRepresentation.class.isAssignableFrom(target)) {
result = 1.0F;
} else if (Reader.class.isAssignableFrom(target)) {
result = 1.0F;
} else if (ReaderRepresentation.class.isAssignableFrom(target)) {
result = 1.0F;
} else if (Serializable.class.isAssignableFrom(target)
|| target.isPrimitive()) {
if (ObjectRepresentation.VARIANT_OBJECT_BINARY_SUPPORTED
&& MediaType.APPLICATION_JAVA_OBJECT.equals(source
.getMediaType())) {
result = 1.0F;
} else if (ObjectRepresentation.VARIANT_OBJECT_BINARY_SUPPORTED
&& MediaType.APPLICATION_JAVA_OBJECT
.isCompatible(source.getMediaType())) {
result = 0.6F;
} else if (ObjectRepresentation.VARIANT_OBJECT_XML_SUPPORTED
&& MediaType.APPLICATION_JAVA_OBJECT_XML.equals(source
.getMediaType())) {
result = 1.0F;
} else if (ObjectRepresentation.VARIANT_OBJECT_XML_SUPPORTED
&& MediaType.APPLICATION_JAVA_OBJECT_XML
.isCompatible(source.getMediaType())) {
result = 0.6F;
} else {
result = 0.5F;
}
}
} else if (source instanceof ObjectRepresentation<?>) {
result = 1.0F;
}
return result;
}
示例11: getRepresentation
import org.restlet.representation.FileRepresentation; //导入依赖的package包/类
@Override
public Representation getRepresentation(MediaType defaultMediaType,
int timeToLive) {
return new FileRepresentation(getFile(), defaultMediaType, timeToLive);
}
示例12: getRepresentation
import org.restlet.representation.FileRepresentation; //导入依赖的package包/类
public Representation getRepresentation() {
FileRepresentation fileRep = new FileRepresentation(mediaFile,contentType);
fileRep.setModificationDate(getLastModified());
fileRep.setSize(getSize());
return fileRep;
}
示例13: convert
import org.restlet.representation.FileRepresentation; //导入依赖的package包/类
/**
* @param file the input document
* @param conversionPath path to convert from input format to output format.
* @param properties the conversion properties
* @return the conversion result as a Stream
* @throws IOException in case of any failure
*/
private InputStream convert(
File file, ConversionPath conversionPath, Properties properties) throws IOException {
FileRepresentation fr = new FileRepresentation(file, MediaType.APPLICATION_ALL);
return convert(fr, conversionPath, properties);
}