package org.newdawn.slick.opengl; import java.io.BufferedInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; import java.util.ArrayList; import org.newdawn.slick.util.Log; /** * A composite data source that checks multiple loaders in order of * preference * * @author kevin */ public class CompositeImageData implements LoadableImageData { /** The list of images sources in order of preference to try loading the data with */ private ArrayList sources = new ArrayList(); /** The data source that worked and was used - or null if no luck */ private LoadableImageData picked; /** * Add a potentional source of image data * * @param data The data source to try */ public void add(LoadableImageData data) { sources.add(data); } /** * @see org.newdawn.slick.opengl.LoadableImageData#loadImage(java.io.InputStream) */ public ByteBuffer loadImage(InputStream fis) throws IOException { return loadImage(fis, false, null); } /** * @see org.newdawn.slick.opengl.LoadableImageData#loadImage(java.io.InputStream, boolean, int[]) */ public ByteBuffer loadImage(InputStream fis, boolean flipped, int[] transparent) throws IOException { return loadImage(fis, flipped, false, transparent); } /** * @see org.newdawn.slick.opengl.LoadableImageData#loadImage(java.io.InputStream, boolean, boolean, int[]) */ public ByteBuffer loadImage(InputStream is, boolean flipped, boolean forceAlpha, int[] transparent) throws IOException { CompositeIOException exception = new CompositeIOException(); ByteBuffer buffer = null; BufferedInputStream in = new BufferedInputStream(is, is.available()); in.mark(is.available()); // cycle through our source until one of them works for (int i=0;i