Switched from Input Stream to Byte array. getStream can now be used to get a buffered stream

This commit is contained in:
2025-09-30 19:53:39 +02:00
parent 44b4613c27
commit 324811d026
3 changed files with 10 additions and 9 deletions

View File

@@ -21,7 +21,7 @@ public class AudioResource extends Resource {
@Override
public Resource load() {
try {
this.audioInputStream = AudioSystem.getAudioInputStream(this.stream);
this.audioInputStream = AudioSystem.getAudioInputStream(this.getStream());
Clip clip = AudioSystem.getClip();
clip.open(this.audioInputStream);
this.clip = clip;

View File

@@ -20,7 +20,7 @@ public class ImageResource extends Resource {
@Override
public Resource load() {
this.image = new Image(this.stream);
this.image = new Image(this.getStream());
return this;
}
}

View File

@@ -1,16 +1,17 @@
package org.toop.framework.assets.resources;
import java.io.*;
import java.nio.file.Files;
public abstract class Resource {
final InputStream stream;
final File file;
final private byte[] rawData;
final private File file;
Resource(final File file) {
Resource(final File file) throws RuntimeException {
this.file = file;
try {
this.stream = new BufferedInputStream(new FileInputStream(file));
} catch (FileNotFoundException e) {
this.rawData = Files.readAllBytes(file.toPath());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@@ -19,8 +20,8 @@ public abstract class Resource {
return this;
}
public InputStream getInputStream() {
return this.stream;
public InputStream getStream() {
return new BufferedInputStream(new ByteArrayInputStream(this.rawData));
}
public File getFile() {