use of org.apache.wicket.util.resource.FileResourceStream in project wicket by apache.
the class CachingResourceStreamLocatorTest method fileResourceDifferentExtensions.
/**
* Tests two FileResourceStreamReferences with different extensions
*/
@Test
void fileResourceDifferentExtensions() {
IResourceStreamLocator resourceStreamLocator = mock(IResourceStreamLocator.class);
FileResourceStream frs = new FileResourceStream(new File("."));
when(resourceStreamLocator.locate(String.class, "path", "style", "variation", null, "extension", true)).thenReturn(frs);
CachingResourceStreamLocator cachingLocator = new CachingResourceStreamLocator(resourceStreamLocator);
cachingLocator.locate(String.class, "path", "style", "variation", null, "extension", true);
cachingLocator.locate(String.class, "path", "style", "variation", null, "extension", true);
cachingLocator.locate(String.class, "path", "style", "variation", null, "extension2", true);
// there is a file resource with that Key so expect just one call to the delegate
verify(resourceStreamLocator, times(1)).locate(String.class, "path", "style", "variation", null, "extension", true);
verify(resourceStreamLocator, times(1)).locate(String.class, "path", "style", "variation", null, "extension2", true);
}
use of org.apache.wicket.util.resource.FileResourceStream in project wicket by apache.
the class CachingResourceStreamLocatorTest method fileResource.
/**
* Tests FileResourceStreamReference
*/
@Test
void fileResource() {
IResourceStreamLocator resourceStreamLocator = mock(IResourceStreamLocator.class);
FileResourceStream frs = new FileResourceStream(new File("."));
when(resourceStreamLocator.locate(String.class, "path", "style", "variation", null, "extension", true)).thenReturn(frs);
CachingResourceStreamLocator cachingLocator = new CachingResourceStreamLocator(resourceStreamLocator);
cachingLocator.locate(String.class, "path", "style", "variation", null, "extension", true);
cachingLocator.locate(String.class, "path", "style", "variation", null, "extension", true);
// there is a file resource with that Key so expect just one call to the delegate
verify(resourceStreamLocator, times(1)).locate(String.class, "path", "style", "variation", null, "extension", true);
}
use of org.apache.wicket.util.resource.FileResourceStream in project wicket by apache.
the class ResourceTest method testFileResourceStream.
/**
* tests a resource that is not cacheable.
*/
@Test
void testFileResourceStream() {
final File testFile;
try {
testFile = File.createTempFile(ResourceTest.class.getName(), null);
OutputStream out = new FileOutputStream(testFile);
out.write(TEST_STRING.getBytes());
out.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
bindToApplicationAsResourceAndRequestIt(new FileResourceStream(new org.apache.wicket.util.file.File(testFile)));
assertEquals(MockHttpServletResponse.formatDate(testFile.lastModified()), tester.getLastModifiedFromResponseHeader());
assertEquals(TEST_STRING.length(), tester.getContentLengthFromResponseHeader());
}
use of org.apache.wicket.util.resource.FileResourceStream in project webanno by webanno.
the class FileSystemResource method respond.
@Override
public void respond(Attributes attributes) {
FileResourceStream fileResourceStream = new FileResourceStream(file);
ResourceStreamResource resource = new ResourceStreamResource(fileResourceStream);
resource.respond(attributes);
}
use of org.apache.wicket.util.resource.FileResourceStream in project webanno by webanno.
the class TagSetEditorPanel method export.
private FileResourceStream export() {
File exportFile = null;
if (exportFormat.getObject().equals(JSON_FORMAT)) {
try {
exportFile = File.createTempFile("exportedtagsets", ".json");
} catch (IOException e1) {
error("Unable to create temporary File!!");
return null;
}
if (isNull(selectedTagSet.getObject().getId())) {
error("Project not yet created. Please save project details first!");
} else {
TagSet tagSet = selectedTagSet.getObject();
ExportedTagSet exTagSet = new ExportedTagSet();
exTagSet.setDescription(tagSet.getDescription());
exTagSet.setLanguage(tagSet.getLanguage());
exTagSet.setName(tagSet.getName());
List<ExportedTag> exportedTags = new ArrayList<>();
for (Tag tag : annotationSchemaService.listTags(tagSet)) {
ExportedTag exportedTag = new ExportedTag();
exportedTag.setDescription(tag.getDescription());
exportedTag.setName(tag.getName());
exportedTags.add(exportedTag);
}
exTagSet.setTags(exportedTags);
try {
JSONUtil.generatePrettyJson(exTagSet, exportFile);
} catch (IOException e) {
error("File Path not found or No permision to save the file!");
}
info("TagSets successfully exported to :" + exportFile.getAbsolutePath());
}
} else if (exportFormat.getObject().equals(TAB_FORMAT)) {
TagSet tagSet = selectedTagSet.getObject();
try {
exportFile = File.createTempFile("exportedtagsets", ".txt");
} catch (IOException e1) {
error("Unable to create temporary File!!");
}
OutputStream os;
OutputStreamWriter osw;
BufferedWriter bw;
try {
String tagSetDescription = tagSet.getDescription() == null ? "" : tagSet.getDescription();
os = new FileOutputStream(exportFile);
osw = new OutputStreamWriter(os, "UTF-8");
bw = new BufferedWriter(osw);
bw.write(tagSet.getName() + "\t" + tagSetDescription.replace("\n", "\\n") + "\n");
bw.write(tagSet.getLanguage() + "\t" + " \n");
for (Tag tag : annotationSchemaService.listTags(tagSet)) {
String tagDescription = tag.getDescription() == null ? "" : tag.getDescription();
bw.write(tag.getName() + "\t" + tagDescription.replace("\n", "\\n") + "\n");
}
bw.flush();
bw.close();
} catch (FileNotFoundException e) {
error("The file for export not found " + ExceptionUtils.getRootCauseMessage(e));
} catch (UnsupportedEncodingException e) {
error("Unsupported encoding " + ExceptionUtils.getRootCauseMessage(e));
} catch (IOException e) {
error(ExceptionUtils.getRootCause(e));
}
}
return new FileResourceStream(exportFile);
}
Aggregations