From: <si...@sv...> - 2006-04-26 19:49:53
|
Author: simboss Date: 2006-04-26 12:48:53 -0700 (Wed, 26 Apr 2006) New Revision: 19298 Modified: geotools/branches/coverages_branch/trunk/spike/ArcGrid_ImageIO/src/MET= A-INF/services/javax.imageio.spi.ImageReaderSpi geotools/branches/coverages_branch/trunk/spike/ArcGrid_ImageIO/src/org= /geotools/gce/imageio/asciigrid/AsciiGridsImageReaderSpi.java geotools/branches/coverages_branch/trunk/spike/ArcGrid_ImageIO/src/org= /geotools/gce/imageio/asciigrid/GZIPFileImageInputStreamExtSpi.java Log: -changed the order of the SPI within the META-INF/services/javax.imageio.= spi.ImageReaderSpi -fixed the GZippedFiles input handling within the canDecodeInput method o= f the AsciiGridsImageReaderSpi -fixed the GZIPFileImageInputStreamExtSpi=20 Modified: geotools/branches/coverages_branch/trunk/spike/ArcGrid_ImageIO/= src/META-INF/services/javax.imageio.spi.ImageReaderSpi =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- geotools/branches/coverages_branch/trunk/spike/ArcGrid_ImageIO/src/ME= TA-INF/services/javax.imageio.spi.ImageReaderSpi 2006-04-26 19:12:27 UTC = (rev 19297) +++ geotools/branches/coverages_branch/trunk/spike/ArcGrid_ImageIO/src/ME= TA-INF/services/javax.imageio.spi.ImageReaderSpi 2006-04-26 19:48:53 UTC = (rev 19298) @@ -1,3 +1,3 @@ -org.geotools.gce.imageio.asciigrid.AsciiGridsImageReaderSpi org.geotools.gce.imageio.asciigrid.FileImageInputStreamExtSpi -org.geotools.gce.imageio.asciigrid.GZIPFileImageInputStreamExtSpi \ No newline at end of file +org.geotools.gce.imageio.asciigrid.GZIPFileImageInputStreamExtSpi +org.geotools.gce.imageio.asciigrid.AsciiGridsImageReaderSpi \ No newline at end of file Modified: geotools/branches/coverages_branch/trunk/spike/ArcGrid_ImageIO/= src/org/geotools/gce/imageio/asciigrid/AsciiGridsImageReaderSpi.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- geotools/branches/coverages_branch/trunk/spike/ArcGrid_ImageIO/src/or= g/geotools/gce/imageio/asciigrid/AsciiGridsImageReaderSpi.java 2006-04-26= 19:12:27 UTC (rev 19297) +++ geotools/branches/coverages_branch/trunk/spike/ArcGrid_ImageIO/src/or= g/geotools/gce/imageio/asciigrid/AsciiGridsImageReaderSpi.java 2006-04-26= 19:48:53 UTC (rev 19298) @@ -17,14 +17,12 @@ package org.geotools.gce.imageio.asciigrid; =20 import java.io.File; -import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.util.Locale; import java.util.logging.Logger; -import java.util.zip.GZIPInputStream; =20 import javax.imageio.ImageIO; import javax.imageio.ImageReader; @@ -160,18 +158,6 @@ return true; } =20 - =20 - - // Operating also with GZipped Source cause some problems. When = after - // some conversion steps (For example String->File->InputStream)= we come - // to an InputStream, is it time to know if is a GZipped Stream = or not. - // Thus, we try to create a GZIPInputStream to check if the stre= am is - // zipped. If is GZipped, no problems will occurs. If not GZippe= d, the - // InputStream has already read 2 bytes and we cant come back. S= o, if - // needed we use a second dummy InputStream which will not be mo= fidied - // boolean needDummy =3D false; - InputStream dummyIs =3D null; - // if input source is a string, // convert input from String to File if (input instanceof String) { @@ -190,11 +176,8 @@ // annotating the inputSource of the canDecodeInput inputSource =3D input; } - - // needDummy =3D true; try{ - dummyIs =3D new FileInputStream((File) input); - input =3D new FileInputStream((File) input);=09 + input =3D ImageIO.createImageInputStream((File)input);=20 } catch(FileNotFoundException e){ //maybe the input is not a file but a folder. @@ -211,8 +194,6 @@ inputSource =3D (URL) input; } =20 - // needDummy =3D true; - dummyIs =3D ((URL) input).openStream(); input =3D ((URL) input).openStream(); } =20 @@ -223,36 +204,32 @@ inputSource =3D input; } =20 - if ( /* needDummy */ - dummyIs !=3D null) { - // the InputStream is GZipped or not? - - /** - * ISSUE on the GZipped test: by trying to do: final - * GZIPInputStream stream =3D new GZIPInputStream( (Inpu= tStream) - * input); if it fail, InputStream input has already re= ad 2 - * bytes - */ - try { - final GZIPInputStream stream =3D new GZIPInputStream= ((InputStream) input); - - if (stream !=3D null) { - // the inputStream is GZipped. - input =3D stream; - } - } catch (IOException e) { - // Problem on the GZipped test: by trying to do: - // GZIPInputStream stream =3D new - // GZIPInputStream((InputStream)input); - // if fail, InputStream input has already read 2 byt= es. - // falling here mean that InputStream is not GZipped - if ( /* needDummy */ - dummyIs !=3D null) { - input =3D dummyIs; - } - } - } - + /** + * ISSUE on the GZipped test. + *=20 + * Example A) + * final File f =3D new File("file.asc.gz"); + * final InputStream is =3D new FileInputStream(f); + * Iterator it =3D ImageIO.getImageReaders(stream); + *=20 + * Example B) + * final File f =3D new File("file.asc.gz"); + * final GZIPInputStream stream =3D new GZIPInputStream( + * new FileInputStream(f)); + * Iterator it =3D ImageIO.getImageReaders(stream); + * + * if we use the code of the Example A instead of that=20 + * of Example B, the parseHeader method (which works=20 + * with ImageInputStreams) is unable to try to read=20 + * the header because the stream is GZipped.=20 + *=20 + * Thus, if we want to provide explicitly an InputStream=20 + * (instead of a File) for a GZipped File, we need to + * use the code of the Example B which make use of the + * GZIPInputStream Subclass.=20 + *=20 + */ + =20 // creating an ImageInputStream from the InputStream input =3D ImageIO.createImageInputStream((InputStream) input= ); } Modified: geotools/branches/coverages_branch/trunk/spike/ArcGrid_ImageIO/= src/org/geotools/gce/imageio/asciigrid/GZIPFileImageInputStreamExtSpi.jav= a =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- geotools/branches/coverages_branch/trunk/spike/ArcGrid_ImageIO/src/or= g/geotools/gce/imageio/asciigrid/GZIPFileImageInputStreamExtSpi.java 2006= -04-26 19:12:27 UTC (rev 19297) +++ geotools/branches/coverages_branch/trunk/spike/ArcGrid_ImageIO/src/or= g/geotools/gce/imageio/asciigrid/GZIPFileImageInputStreamExtSpi.java 2006= -04-26 19:48:53 UTC (rev 19298) @@ -18,7 +18,6 @@ =20 import java.io.File; import java.io.FileInputStream; -import java.io.InputStream; import java.util.Iterator; import java.util.Locale; import java.util.zip.GZIPInputStream; @@ -83,19 +82,23 @@ public ImageInputStream createInputStreamInstance(Object input, boolean useCache, File cacheDir) { if (input instanceof File) { - InputStream provIs; try { - provIs =3D new FileInputStream((File) input); - final GZIPInputStream stream =3D new GZIPInputStream(pro= vIs); + final GZIPInputStream stream =3D new GZIPInputStream= (new FileInputStream((File) input)); if (stream !=3D null) { // the inputStream is GZipped. stream.close(); - return new GZIPFileImageInputStreamExt((File) in= put); } } catch (Exception e) { - =09 - return null; + //Maybe the file is not GZipped. + //Thus, I try to create a FileImageInputStreamExtImpl =20 + try { + return new FileImageInputStreamExtImpl((File)input); + } + catch (Exception e2){ + return null; + } + =20 } } =20 |