mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 10:54:51 +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
|
@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;
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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() {
|
||||||
|
|||||||
Reference in New Issue
Block a user