aboutsummaryrefslogtreecommitdiffstats
path: root/gl4java/utils/textures/IOTextureLoader.java
blob: 4b06b933e7a9a85c70ce35a9cf4f5c7c87d8bd7b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package gl4java.utils.textures;

import gl4java.*;
import gl4java.utils.glut.*;

import java.awt.*;
import java.awt.Color.*;
import java.awt.event.*;
import java.applet.*;
import java.io.*;
import java.net.*;

/**
 * This abstract Class implements the
 * file and url based methods "readTexture",
 * to call the specialised implementation
 * of the stream based "readTexture" method !
 *
 * @see TextureLoader
 */   
public abstract class IOTextureLoader
extends TextureLoader
{
	protected IOTextureLoader(GLFunc gl, GLUFunc glu)
	{ super(gl, glu); }

	public boolean readTexture(String fname)
	{
	    boolean result = false;
	    InputStream is= null;
	    try {
		    is= new java.io.FileInputStream(fname);
		    result = readTexture(is);
	    } catch (Exception ex) {
		System.out.println("IOTextureLoader.readTexture <"+
			fname+"> failed !\n"+ex);
	    }
	    try {
		    if(is!=null) is.close();
	    } catch (Exception ex) {}
	    return result;
	}

	public boolean readTexture(URL base, String uri)
	{
	    boolean result = false;
	    InputStream is= null;
	    try {
		    URL url = new URL (base, uri);
		    URLConnection urlcon = url.openConnection();
		    urlcon.setDoOutput(false);
		    urlcon.setDoInput(true);
		    is = urlcon.getInputStream();
		    result = readTexture(is);
	    } catch (Exception ex) {
		System.out.println("IOTextureLoader.readTexture <"+
			base+" / "+uri+"> failed !\n"+ex);
	    }
	    try {
		    if(is!=null) is.close();
	    } catch (Exception ex) {}
	    return result;
	}

        protected abstract boolean readTexture(InputStream is);
}