diff options
Diffstat (limited to 'src/classes/com/sun/opengl/util')
-rwxr-xr-x | src/classes/com/sun/opengl/util/FileUtil.java | 89 | ||||
-rwxr-xr-x | src/classes/com/sun/opengl/util/StreamUtil.java | 100 | ||||
-rwxr-xr-x | src/classes/com/sun/opengl/util/TGAWriter.java (renamed from src/classes/com/sun/opengl/util/io/TGAWriter.java) | 6 | ||||
-rwxr-xr-x | src/classes/com/sun/opengl/util/awt/Screenshot.java | 3 | ||||
-rwxr-xr-x | src/classes/com/sun/opengl/util/awt/TextRenderer.java | 1 | ||||
-rwxr-xr-x | src/classes/com/sun/opengl/util/texture/TextureIO.java.javame_cdc_fp | 2 | ||||
-rwxr-xr-x | src/classes/com/sun/opengl/util/texture/TextureIO.java.javase | 2 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/util/texture/spi/awt/IIOTextureWriter.java | 2 |
8 files changed, 196 insertions, 9 deletions
diff --git a/src/classes/com/sun/opengl/util/FileUtil.java b/src/classes/com/sun/opengl/util/FileUtil.java new file mode 100755 index 000000000..84b846853 --- /dev/null +++ b/src/classes/com/sun/opengl/util/FileUtil.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2005 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.sun.opengl.util; + +import java.io.*; + +/** Utilities for dealing with files. */ + +public class FileUtil { + private FileUtil() {} + + /** + * Returns the lowercase suffix of the given file name (the text + * after the last '.' in the file name). Returns null if the file + * name has no suffix. Only operates on the given file name; + * performs no I/O operations. + * + * @param file name of the file + * @return lowercase suffix of the file name + * @throws NullPointerException if file is null + */ + + public static String getFileSuffix(File file) { + return getFileSuffix(file.getName()); + } + + /** + * Returns the lowercase suffix of the given file name (the text + * after the last '.' in the file name). Returns null if the file + * name has no suffix. Only operates on the given file name; + * performs no I/O operations. + * + * @param filename name of the file + * @return lowercase suffix of the file name + * @throws NullPointerException if filename is null + */ + public static String getFileSuffix(String filename) { + int lastDot = filename.lastIndexOf('.'); + if (lastDot < 0) { + return null; + } + return toLowerCase(filename.substring(lastDot + 1)); + } + + private static String toLowerCase(String arg) { + if (arg == null) { + return null; + } + + return arg.toLowerCase(); + } +} diff --git a/src/classes/com/sun/opengl/util/StreamUtil.java b/src/classes/com/sun/opengl/util/StreamUtil.java new file mode 100755 index 000000000..eeb08175e --- /dev/null +++ b/src/classes/com/sun/opengl/util/StreamUtil.java @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.sun.opengl.util; + +import javax.media.opengl.util.*; + +import java.io.*; +import java.nio.*; + +/** Utilities for dealing with streams. */ + +public class StreamUtil { + private StreamUtil() {} + + public static byte[] readAll2Array(InputStream stream) throws IOException { + BytesRead bytesRead = readAllImpl(stream); + byte[] data = bytesRead.data; + if (bytesRead.payloadLen != data.length) { + data = new byte[bytesRead.payloadLen]; + System.arraycopy(bytesRead.data, 0, data, 0, bytesRead.payloadLen); + } + return data; + } + + public static ByteBuffer readAll2Buffer(InputStream stream) throws IOException { + BytesRead bytesRead = readAllImpl(stream); + return BufferUtil.newByteBuffer(bytesRead.data, 0, bytesRead.payloadLen); + } + + private static BytesRead readAllImpl(InputStream stream) throws IOException { + // FIXME: Shall we do this here ? + if( !(stream instanceof BufferedInputStream) ) { + stream = new BufferedInputStream(stream); + } + int avail = stream.available(); + byte[] data = new byte[avail]; + int numRead = 0; + int pos = 0; + do { + if (pos + avail > data.length) { + byte[] newData = new byte[pos + avail]; + System.arraycopy(data, 0, newData, 0, pos); + data = newData; + } + numRead = stream.read(data, pos, avail); + if (numRead >= 0) { + pos += numRead; + } + avail = stream.available(); + } while (avail > 0 && numRead >= 0); + + return new BytesRead(pos, data); + } + + private static class BytesRead { + BytesRead(int payloadLen, byte[] data) { + this.payloadLen=payloadLen; + this.data=data; + } + int payloadLen; + byte[] data; + } +} diff --git a/src/classes/com/sun/opengl/util/io/TGAWriter.java b/src/classes/com/sun/opengl/util/TGAWriter.java index f6ae79049..c5b1041a0 100755 --- a/src/classes/com/sun/opengl/util/io/TGAWriter.java +++ b/src/classes/com/sun/opengl/util/TGAWriter.java @@ -34,7 +34,7 @@ * facility. */ -package com.sun.opengl.util.io; +package com.sun.opengl.util; import java.io.*; import java.nio.*; @@ -43,8 +43,8 @@ import java.nio.channels.*; /** * Utility class which helps take fast screenshots of OpenGL rendering * results into Targa-format files. Used by the {@link - * com.sun.opengl.util.Screenshot Screenshot} class; can also be used - * in conjunction with the {@link com.sun.opengl.util.TileRenderer + * com.sun.opengl.util.gl2.Screenshot Screenshot} class; can also be used + * in conjunction with the {@link com.sun.opengl.util.gl2.TileRenderer * TileRenderer} class. <P> */ diff --git a/src/classes/com/sun/opengl/util/awt/Screenshot.java b/src/classes/com/sun/opengl/util/awt/Screenshot.java index 6c6bc7a26..55099445a 100755 --- a/src/classes/com/sun/opengl/util/awt/Screenshot.java +++ b/src/classes/com/sun/opengl/util/awt/Screenshot.java @@ -46,8 +46,7 @@ import javax.media.opengl.*; import javax.media.opengl.glu.*; import javax.media.opengl.glu.gl2.*; -import com.sun.opengl.impl.io.*; -import com.sun.opengl.util.io.*; +import com.sun.opengl.util.*; /** Utilities for taking screenshots of OpenGL applications. */ diff --git a/src/classes/com/sun/opengl/util/awt/TextRenderer.java b/src/classes/com/sun/opengl/util/awt/TextRenderer.java index 525e0824f..6c9aa578b 100755 --- a/src/classes/com/sun/opengl/util/awt/TextRenderer.java +++ b/src/classes/com/sun/opengl/util/awt/TextRenderer.java @@ -41,7 +41,6 @@ package com.sun.opengl.util.awt; import com.sun.opengl.impl.*; import com.sun.opengl.impl.packrect.*; import com.sun.opengl.util.*; -import com.sun.opengl.util.io.*; import com.sun.opengl.util.texture.*; import com.sun.opengl.util.texture.awt.*; diff --git a/src/classes/com/sun/opengl/util/texture/TextureIO.java.javame_cdc_fp b/src/classes/com/sun/opengl/util/texture/TextureIO.java.javame_cdc_fp index 3f72fdbff..7ea88a9ca 100755 --- a/src/classes/com/sun/opengl/util/texture/TextureIO.java.javame_cdc_fp +++ b/src/classes/com/sun/opengl/util/texture/TextureIO.java.javame_cdc_fp @@ -47,7 +47,7 @@ import java.util.*; import javax.media.opengl.*; import javax.media.opengl.glu.*; import com.sun.opengl.impl.Debug; -import com.sun.opengl.impl.io.*; +import com.sun.opengl.util.*; import com.sun.opengl.util.texture.spi.*; /** <P> Provides input and output facilities for both loading OpenGL diff --git a/src/classes/com/sun/opengl/util/texture/TextureIO.java.javase b/src/classes/com/sun/opengl/util/texture/TextureIO.java.javase index 2cb2d2c9f..aa2cb1799 100755 --- a/src/classes/com/sun/opengl/util/texture/TextureIO.java.javase +++ b/src/classes/com/sun/opengl/util/texture/TextureIO.java.javase @@ -47,7 +47,7 @@ import java.util.*; import javax.media.opengl.*; import javax.media.opengl.glu.*; import com.sun.opengl.impl.Debug; -import com.sun.opengl.impl.io.*; +import com.sun.opengl.util.*; import com.sun.opengl.util.texture.spi.*; /** <P> Provides input and output facilities for both loading OpenGL diff --git a/src/classes/com/sun/opengl/util/texture/spi/awt/IIOTextureWriter.java b/src/classes/com/sun/opengl/util/texture/spi/awt/IIOTextureWriter.java index 5700b57bb..db77572bf 100644 --- a/src/classes/com/sun/opengl/util/texture/spi/awt/IIOTextureWriter.java +++ b/src/classes/com/sun/opengl/util/texture/spi/awt/IIOTextureWriter.java @@ -47,7 +47,7 @@ import java.nio.*; import javax.imageio.*; import javax.media.opengl.*; -import com.sun.opengl.impl.io.*; +import com.sun.opengl.util.*; import com.sun.opengl.util.awt.*; import com.sun.opengl.util.texture.*; import com.sun.opengl.util.texture.spi.*; |