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 @Override
public Resource load() { public Resource load() {
try { try {
this.audioInputStream = AudioSystem.getAudioInputStream(this.stream); this.audioInputStream = AudioSystem.getAudioInputStream(this.getStream());
Clip clip = AudioSystem.getClip(); Clip clip = AudioSystem.getClip();
clip.open(this.audioInputStream); clip.open(this.audioInputStream);
this.clip = clip; this.clip = clip;

View File

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

View File

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