use of org.lastaflute.web.response.StreamResponse in project fess by codelibs.
the class ApiAdminDictKuromojiAction method get$download.
// GET /api/admin/dict/kuromoji/download/{dictId}
@Execute
public StreamResponse get$download(final String dictId, final DownloadBody body) {
body.dictId = dictId;
validateApi(body, messages -> {
});
return kuromojiService.getKuromojiFile(body.dictId).map(file -> {
return asStream(new File(file.getPath()).getName()).contentTypeOctetStream().stream(out -> {
try (InputStream inputStream = file.getInputStream()) {
out.write(inputStream);
}
});
}).orElseGet(() -> {
throwValidationErrorApi(messages -> messages.addErrorsFailedToDownloadProtwordsFile(GLOBAL));
return null;
});
}
use of org.lastaflute.web.response.StreamResponse in project fess by codelibs.
the class ApiAdminDictMappingAction method get$download.
// GET /api/admin/dict/mapping/download/{dictId}
@Execute
public StreamResponse get$download(final String dictId, final DownloadBody body) {
body.dictId = dictId;
validateApi(body, messages -> {
});
return charMappingService.getCharMappingFile(body.dictId).map(file -> {
return asStream(new File(file.getPath()).getName()).contentTypeOctetStream().stream(out -> {
try (InputStream inputStream = file.getInputStream()) {
out.write(inputStream);
}
});
}).orElseGet(() -> {
throwValidationErrorApi(messages -> messages.addErrorsFailedToDownloadProtwordsFile(GLOBAL));
return null;
});
}
use of org.lastaflute.web.response.StreamResponse in project fess by codelibs.
the class ApiAdminDictProtwordsAction method get$download.
// GET /api/admin/dict/protwords/download/{dictId}
@Execute
public StreamResponse get$download(final String dictId, final DownloadBody body) {
body.dictId = dictId;
validateApi(body, messages -> {
});
return protwordsService.getProtwordsFile(body.dictId).map(file -> {
return asStream(new File(file.getPath()).getName()).contentTypeOctetStream().stream(out -> {
try (InputStream inputStream = file.getInputStream()) {
out.write(inputStream);
}
});
}).orElseGet(() -> {
throwValidationErrorApi(messages -> messages.addErrorsFailedToDownloadProtwordsFile(GLOBAL));
return null;
});
}
use of org.lastaflute.web.response.StreamResponse in project fess by codelibs.
the class ApiAdminDictSynonymAction method get$download.
// GET /api/admin/dict/synonym/download/{dictId}
@Execute
public StreamResponse get$download(final String dictId, final DownloadBody body) {
body.dictId = dictId;
validateApi(body, messages -> {
});
return synonymService.getSynonymFile(body.dictId).map(file -> {
return asStream(new File(file.getPath()).getName()).contentTypeOctetStream().stream(out -> {
try (InputStream inputStream = file.getInputStream()) {
out.write(inputStream);
}
});
}).orElseGet(() -> {
throwValidationErrorApi(messages -> messages.addErrorsFailedToDownloadProtwordsFile(GLOBAL));
return null;
});
}
use of org.lastaflute.web.response.StreamResponse in project fess by codelibs.
the class AdminStorageAction method download.
@Execute
@Secured({ ROLE, ROLE + VIEW })
public ActionResponse download(final String id) {
final String[] values = decodeId(id);
if (StringUtil.isEmpty(values[1])) {
throwValidationError(messages -> messages.addErrorsStorageFileNotFound(GLOBAL), () -> asListHtml(encodeId(values[0])));
}
final StreamResponse response = new StreamResponse(StringUtil.EMPTY);
final String name = values[1];
final String encodedName = URLEncoder.encode(name, Constants.UTF_8_CHARSET).replace("+", "%20");
response.header("Content-Disposition", "attachment; filename=\"" + name + "\"; filename*=utf-8''" + encodedName);
response.header("Pragma", "no-cache");
response.header("Cache-Control", "no-cache");
response.header("Expires", "Thu, 01 Dec 1994 16:00:00 GMT");
response.contentTypeOctetStream();
return response.stream(out -> {
try {
downloadObject(getObjectName(values[0], values[1]), out);
} catch (final StorageException e) {
if (logger.isDebugEnabled()) {
logger.debug("Failed to download {}", values[1], e);
}
throwValidationError(messages -> messages.addErrorsStorageFileDownloadFailure(GLOBAL, values[1]), () -> asListHtml(encodeId(values[0])));
}
});
}
Aggregations