Using RasterMaster for the JavaTM Platform to Process an Image from a Specified URL
The
Snow.Snowbnd class does not contain a method to decompress an image directly
from a java.net.URL, but certain methods, such as IMGLOW_get_pages and IMG_decompress_bitmap, do allow the passing of a java.io.Data.InputStream. This tech tip explains how to
create an instance of DataInputStream from a specified URL.
Snowbnd
srcSnow = new Snowbnd();
DataInputStream urlStream =
getURLInputStream("http://myserver:20000/snowserv1.tif");
int pages = srcSnow.IMGLOW_get_pages(urlStream);
System.out.println ("pages:" + pages);
/**
* This method returns a DataInputStream
of the contents of the
* specified URL
* @param url
* @return
*/
public static DataInputStream getURLInputStream (String url)
{
byte[] urlBytes = getURLBytes (url);
return new DataInputStream(new ByteArrayInputStream
(urlBytes));
}
[if !supportLineBreakNewLine]
[endif]
/**
* This method returns a byte array
containing the contents the
* specified URL
*
* @param sURL
* @return
*/
public static byte[] getURLBytes(String sURL)
{
try
{
URL u = new URL(sURL);
URLConnection conn = u.openConnection();
InputStream in = conn.getInputStream();
BufferedInputStream buff_in = new
BufferedInputStream(in);
byte[] file = new byte[15000000];
int size = buff_in.read(file);
return trimBytes(file, size);
}
catch (Exception e)
{
e.printStackTrace();
return null;
}
}
/**
* This method trims a byte array to the
specified size
*
* @param inByte the byte array
* @param realSize the size
* @return the trimmed byte array
*/
public static byte[] trimBytes(byte[] inByte, int realSize)
{
byte[]
retBytes = new byte[realSize];
System.arraycopy(inByte, 0, retBytes, 0, realSize);
return retBytes;
}
