
com.mntviews.jreport.JROutputFile Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mnt-report Show documentation
Show all versions of mnt-report Show documentation
JasperReport server engine
package com.mntviews.jreport;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
import com.mntviews.jreport.exception.JROutputException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
@JsonDeserialize(builder = JROutputFile.Builder.class)
public class JROutputFile extends JROutput {
@JsonProperty("path")
private final String path;
@JsonProperty("path")
public String getPath() {
return path;
}
private JROutputFile(Builder builder) {
path = builder.path;
}
public static Builder custom() {
return new Builder();
}
private void outputFile(JRFile file) throws IOException {
Files.createDirectories(Paths.get(path));
try (OutputStream outputStream = new FileOutputStream(path + "/" + file.getFileName())) {
file.getData().writeTo(outputStream);
} catch (Exception e) {
throw new JROutputException(e);
} finally {
if (file.getData() != null)
file.getData().close();
}
}
@Override
public void execute(List fileList) {
for (JRFile file : fileList) {
try {
outputFile(file);
} catch (IOException e) {
throw new JROutputException(e);
}
}
}
@JsonPOJOBuilder
public static class Builder {
private String path;
@JsonProperty("path")
public Builder withPath(String path) {
this.path = path;
return this;
}
public JROutputFile build() {
return new JROutputFile(this);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy