use of io.micronaut.starter.io.ZipOutputHandler in project micronaut-starter by micronaut-projects.
the class ZipCreateController method generateAppIntoZipFile.
public HttpResponse<Writable> generateAppIntoZipFile(@NotNull ApplicationType type, @NotNull String name, @Nullable List<String> features, @Nullable BuildTool buildTool, @Nullable TestFramework testFramework, @Nullable Language lang, @Nullable JdkVersion javaVersion, @Nullable String userAgent) {
GeneratorContext generatorContext = createProjectGeneratorContext(type, name, features, buildTool, testFramework, lang, javaVersion, userAgent);
MutableHttpResponse<Writable> response = HttpResponse.created(new Writable() {
@Override
public void writeTo(OutputStream outputStream, @Nullable Charset charset) throws IOException {
try {
projectGenerator.generate(type, generatorContext.getProject(), new ZipOutputHandler(outputStream), generatorContext);
outputStream.flush();
} catch (Exception e) {
LOG.error("Error generating application: " + e.getMessage(), e);
throw new IOException(e.getMessage(), e);
}
}
@Override
public void writeTo(Writer out) {
// no-op, output stream used
}
});
return response.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + getFilename(generatorContext.getProject()));
}
Aggregations