use of org.glassfish.jersey.media.multipart.ContentDisposition in project jersey by eclipse-ee4j.
the class StreamDataBodyPartTest method testBuildContentDispositionWithoutFilename.
@Test
public void testBuildContentDispositionWithoutFilename() {
String name = "foo";
String expectedType = "form-data";
String expectedFilename = "foo";
cut.setName(name);
ContentDisposition actual = cut.buildContentDisposition();
assertEquals(expectedType, actual.getType());
assertEquals(expectedFilename, actual.getFileName());
}
use of org.glassfish.jersey.media.multipart.ContentDisposition in project jersey by eclipse-ee4j.
the class ContentDispositionTest method testToString.
@Test
public void testToString() {
final Date date = new Date();
final ContentDisposition contentDisposition = ContentDisposition.type(contentDispositionType).fileName("test.file").creationDate(date).modificationDate(date).readDate(date).size(1222).build();
final String dateString = HttpDateFormat.getPreferredDateFormat().format(date);
final String header = contentDispositionType + "; filename=\"test.file\"; creation-date=\"" + dateString + "\"; modification-date=\"" + dateString + "\"; read-date=\"" + dateString + "\"; size=1222";
assertEquals(header, contentDisposition.toString());
}
use of org.glassfish.jersey.media.multipart.ContentDisposition in project jersey by eclipse-ee4j.
the class ContentDispositionTest method assertFileNameExt.
private void assertFileNameExt(final String expectedFileName, final String actualFileName, final String actualFileNameExt) throws ParseException {
final Date date = new Date();
final String dateString = HttpDateFormat.getPreferredDateFormat().format(date);
final String prefixHeader = contentDispositionType + ";filename=\"" + actualFileName + "\";" + "creation-date=\"" + dateString + "\";modification-date=\"" + dateString + "\";read-date=\"" + dateString + "\";size=1222" + ";name=\"testData\";" + "filename*=\"";
final String header = prefixHeader + actualFileNameExt + "\"";
final ContentDisposition contentDisposition = new ContentDisposition(HttpHeaderReader.newInstance(header), true);
assertEquals(expectedFileName, contentDisposition.getFileName());
}
use of org.glassfish.jersey.media.multipart.ContentDisposition in project joa by sebastianfrey.
the class GeoPackageService method addService.
@Override
public void addService(FormDataBodyPart body) throws InterruptedException {
for (BodyPart part : body.getParent().getBodyParts()) {
InputStream fileInputStream = part.getEntityAs(InputStream.class);
ContentDisposition fileMetaData = part.getContentDisposition();
try {
int read = 0;
byte[] bytes = new byte[1024];
String fullFileName = fileMetaData.getFileName();
String fileName = MoreFiles.getNameWithoutExtension(Paths.get(fullFileName));
File target = Paths.get(workspace.toString(), fullFileName).toFile();
OutputStream out = new FileOutputStream(target);
while ((read = fileInputStream.read(bytes)) != -1) {
out.write(bytes, 0, read);
}
out.flush();
out.close();
String[] cmd = { "ogr2ogr", "-f", "GPKG", fileName + ".gpkg", fullFileName, "-update", "-append" };
ProcessBuilder b = new ProcessBuilder(cmd);
b.directory(workspace);
Process p = b.start();
p.waitFor();
} catch (IOException e) {
throw new WebApplicationException("Error while uploading file. Please try again !!", e);
}
}
}
use of org.glassfish.jersey.media.multipart.ContentDisposition in project winery by eclipse.
the class RestUtils method getYamlCSARofSelectedResource.
public static Response getYamlCSARofSelectedResource(final AbstractComponentInstanceResource resource) {
LocalDateTime start = LocalDateTime.now();
final YamlExporter exporter = new YamlExporter(RepositoryFactory.getRepository());
Map<String, Object> exportConfiguration = new HashMap<>();
StreamingOutput so = output -> {
try {
exporter.writeCsar(resource.getId(), output, exportConfiguration);
LOGGER.debug("CSAR export lasted {}", Duration.between(LocalDateTime.now(), start).toString());
} catch (Exception e) {
LOGGER.error("Error while exporting CSAR", e);
throw new WebApplicationException(e);
}
};
String contentDisposition = String.format("attachment;filename=\"%s%s\"", resource.getXmlId().getEncoded(), Constants.SUFFIX_CSAR);
return Response.ok().header("Content-Disposition", contentDisposition).type(MimeTypes.MIMETYPE_ZIP).entity(so).build();
}
Aggregations