本文整理汇总了Java中org.restlet.data.Disposition类的典型用法代码示例。如果您正苦于以下问题:Java Disposition类的具体用法?Java Disposition怎么用?Java Disposition使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Disposition类属于org.restlet.data包,在下文中一共展示了Disposition类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: finalizeZip
import org.restlet.data.Disposition; //导入依赖的package包/类
protected Representation finalizeZip(List<String> config, ZipOutputStream zip, ByteArrayOutputStream baos) throws Exception {
String file = "";
for (String s : config) {
file += s + '\n';
}
if (caCert == null) {
caCert = IOUtils.toByteArray(new FileInputStream(VPN.cfg.getProperty("ca.crt")));
}
ZipEntry configFile = new ZipEntry("neutrinet.ovpn");
configFile.setCreationTime(FileTime.from(Instant.now()));
zip.putNextEntry(configFile);
zip.write(file.getBytes());
zip.putNextEntry(new ZipEntry("ca.crt"));
zip.write(caCert);
zip.close();
ByteArrayRepresentation rep = new ByteArrayRepresentation(baos.toByteArray());
rep.setMediaType(MediaType.APPLICATION_ZIP);
rep.setSize(baos.size());
rep.setCharacterSet(CharacterSet.UTF_8);
rep.setDisposition(new Disposition(Disposition.TYPE_ATTACHMENT));
return rep;
}
示例2: get
import org.restlet.data.Disposition; //导入依赖的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;
}
示例3: get
import org.restlet.data.Disposition; //导入依赖的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;
}
示例4: testDoGetNormal
import org.restlet.data.Disposition; //导入依赖的package包/类
@Test
public void testDoGetNormal() throws Exception {
Request request = createGetRequest("{\"gadgets\":[]}", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz._");;
Response response = createResponse(request, MediaType.APPLICATION_JSON,
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz._({\"GADGETS\":[]})", Status.SUCCESS_OK);
Form params = new Form();
params.add(Disposition.NAME_FILENAME, "rpc.txt");
Disposition disposition = new Disposition(Disposition.TYPE_ATTACHMENT, params);
response.getEntity().setDisposition(disposition);
resource.init(Context.getCurrent(), request, response);
JSONObject handlerResponse = new JSONObject("{\"GADGETS\":[]}");
expect(handler.process(isA(JSONObject.class))).andReturn(handlerResponse);
replay(handler);
resource.doGet();
// verify(response);
}
示例5: getLotDownload
import org.restlet.data.Disposition; //导入依赖的package包/类
/**
* Downloads a lot/file
* @param id ID of the lot/file
* @param directory Directory where the file should be downloaded
* @custom.require Authentication
* @return Download succeeded
*/
public boolean getLotDownload(int id, File directory) {
ClientResource resource = new ClientResource(Route.DOWNLOAD_LOT.url(id));
resource.setChallengeResponse(this.auth.toChallenge());
try {
Representation repr = resource.get(MediaType.APPLICATION_ZIP);
Disposition disposition = repr.getDisposition();
File file = new File(directory, disposition.getFilename());
FileOutputStream fos = new FileOutputStream(file);
repr.write(fos);
// Flush remaining buffer to output and close the stream
fos.flush();
fos.close();
return true;
} catch (IOException ex) {
LEX4JLogger.log(Level.WARNING, "Could not write download to the FileOutputStream!");
return false;
}
}
示例6: retrieveFile
import org.restlet.data.Disposition; //导入依赖的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: retrieve
import org.restlet.data.Disposition; //导入依赖的package包/类
@Override
public StringRepresentation retrieve() {
InterpolatedValueList mList = doRetrieve();
//RFC4180 CSV http://tools.ietf.org/html/rfc4180
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
StringBuilder sb = new StringBuilder();
sb.append("Start,Value\r\n");
for (InterpolatedValue interpolatedValue : mList.getInterpolatedValues()) {
sb.append(sdf.format(interpolatedValue.getStart()));
sb.append(",");
sb.append(interpolatedValue.getValue());
sb.append("\r\n");
}
StringRepresentation response = new StringRepresentation(sb.toString(), MediaType.TEXT_CSV);
response.setDisposition(new Disposition(Disposition.TYPE_ATTACHMENT));
response.getDisposition().setFilename(String.format("%s_%s_%s.csv", depositoryId, sensorId, dataType));
return response;
}
示例8: saveAs
import org.restlet.data.Disposition; //导入依赖的package包/类
/**
* Handle POST requests for file save
* @param entity entity body information (form encoded)
*/
@Post
public Representation saveAs(Representation entity) throws ResourceException
{
try
{
// build the response xml
Form form = new Form(entity);
String filename = form.getFirstValue("filename");
if (filename == null || filename.isEmpty()) filename = "out.xml";
String format = form.getFirstValue("format");
String data = form.getFirstValue("data");
if (data == null)
{
throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "No data specified");
}
// TODO: format to pdf, word, ppt?
Disposition disposition = new Disposition();
disposition.setType(Disposition.TYPE_ATTACHMENT);
disposition.setFilename(filename);
StringRepresentation dataRepresentation = new StringRepresentation(data);
dataRepresentation.setDisposition(disposition);
return dataRepresentation;
}
catch (IllegalArgumentException iae)
{
FileLogger.getInstance().error(iae.getMessage());
try { getResponse().setEntity(new ErrorXMLRepresentation(iae.getMessage())); }
catch (IOException e) {}
getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, iae.getMessage());
}
//return entity;
}
示例9: getDisposition
import org.restlet.data.Disposition; //导入依赖的package包/类
public Disposition getDisposition() {
return getResponseEntity().getDisposition();
}
示例10: setDisposition
import org.restlet.data.Disposition; //导入依赖的package包/类
public void setDisposition(Disposition disposition) {
getResponseEntity().setDisposition(disposition);
}
示例11: getDisposition
import org.restlet.data.Disposition; //导入依赖的package包/类
/**
* Returns the disposition characteristics of the representation.
*
* @return The disposition characteristics of the representation.
*/
public Disposition getDisposition() {
return disposition;
}
示例12: setDisposition
import org.restlet.data.Disposition; //导入依赖的package包/类
/**
* Sets the disposition characteristics of the representation.
*
* @param disposition
* The disposition characteristics of the representation.
*/
public void setDisposition(Disposition disposition) {
this.disposition = disposition;
}
示例13: getDisposition
import org.restlet.data.Disposition; //导入依赖的package包/类
/**
* The representation's disposition.
*
* @return A disposition
*/
public Disposition getDisposition()
{
return disposition;
}