Safe image exporting
This commit is contained in:
parent
04df65cdfb
commit
232b338fb9
@ -50,15 +50,20 @@ public class ResourceDecalImage implements DecalImage {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void exportImage(File file) throws IOException {
|
public void exportImage(File file) throws IOException {
|
||||||
InputStream is;
|
InputStream is = getBytes();
|
||||||
is = getBytes();
|
|
||||||
OutputStream os = new BufferedOutputStream(new FileOutputStream(file));
|
OutputStream os = new BufferedOutputStream(new FileOutputStream(file));
|
||||||
|
|
||||||
FileUtils.copy(is, os);
|
if (is == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
FileUtils.copy(is, os);
|
||||||
|
} finally {
|
||||||
is.close();
|
is.close();
|
||||||
os.close();
|
os.close();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fireChangeEvent(Object source) {
|
public void fireChangeEvent(Object source) {
|
||||||
|
@ -35,6 +35,8 @@ import net.sf.openrocket.rocketcomponent.RocketComponent;
|
|||||||
import net.sf.openrocket.rocketcomponent.Transition;
|
import net.sf.openrocket.rocketcomponent.Transition;
|
||||||
import net.sf.openrocket.rocketcomponent.TubeFinSet;
|
import net.sf.openrocket.rocketcomponent.TubeFinSet;
|
||||||
import net.sf.openrocket.util.FileUtils;
|
import net.sf.openrocket.util.FileUtils;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
@ -68,6 +70,8 @@ public class OBJExporterFactory {
|
|||||||
private final OBJExportOptions options;
|
private final OBJExportOptions options;
|
||||||
private final File file;
|
private final File file;
|
||||||
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(OBJExporterFactory.class);
|
||||||
|
|
||||||
// The different exporters for each component
|
// The different exporters for each component
|
||||||
private static final Map<Class<? extends RocketComponent>, ExporterFactory<?>> EXPORTER_MAP = Map.of(
|
private static final Map<Class<? extends RocketComponent>, ExporterFactory<?>> EXPORTER_MAP = Map.of(
|
||||||
BodyTube.class, (ExporterFactory<BodyTube>) BodyTubeExporter::new,
|
BodyTube.class, (ExporterFactory<BodyTube>) BodyTubeExporter::new,
|
||||||
@ -188,11 +192,15 @@ public class OBJExporterFactory {
|
|||||||
if (options.isExportAppearance()) {
|
if (options.isExportAppearance()) {
|
||||||
String mtlFilePath = FileUtils.removeExtension(filePath) + ".mtl";
|
String mtlFilePath = FileUtils.removeExtension(filePath) + ".mtl";
|
||||||
List<DefaultMtl> mtls = materials.get(obj);
|
List<DefaultMtl> mtls = materials.get(obj);
|
||||||
|
if (mtls != null) {
|
||||||
try (OutputStream mtlOutputStream = new FileOutputStream(mtlFilePath, false)) {
|
try (OutputStream mtlOutputStream = new FileOutputStream(mtlFilePath, false)) {
|
||||||
DefaultMtlWriter.write(mtls, mtlOutputStream);
|
DefaultMtlWriter.write(mtls, mtlOutputStream);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
log.debug("No materials to export for {}", filePath);
|
||||||
|
}
|
||||||
obj.setMtlFileNames(List.of(mtlFilePath));
|
obj.setMtlFileNames(List.of(mtlFilePath));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user