mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 02:44:50 +00:00
Merge pull request #85 from 2OOP/84-Byte-array-ipv-InputStream
Changed Input Stream into byte array
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user