FileDocCategorySizeDatePackage
image_gif.javaAPI DocGlassfish v2 API4224Mon May 14 15:28:42 BST 2007com.sun.mail.handlers

image_gif

public class image_gif extends Object implements DataContentHandler
DataContentHandler for image/gif.

Fields Summary
private static ActivationDataFlavor
myDF
Constructors Summary
Methods Summary
public java.lang.ObjectgetContent(javax.activation.DataSource ds)

	InputStream is = ds.getInputStream();
	int pos = 0;
	int count;
	byte buf[] = new byte[1024];

	while ((count = is.read(buf, pos, buf.length - pos)) != -1) {
	    pos += count;
	    if (pos >= buf.length) {
		int size = buf.length;
		if (size < 256*1024)
		    size += size;
		else
		    size += 256*1024;
		byte tbuf[] = new byte[size];
		System.arraycopy(buf, 0, tbuf, 0, pos);
		buf = tbuf;
	    }
	}
	Toolkit tk = Toolkit.getDefaultToolkit();
	return tk.createImage(buf, 0, pos);
    
protected javax.activation.ActivationDataFlavorgetDF()


       
	return myDF;
    
public java.lang.ObjectgetTransferData(java.awt.datatransfer.DataFlavor df, javax.activation.DataSource ds)
Return the Transfer Data of type DataFlavor from InputStream.

param
df The DataFlavor
param
ins The InputStream corresponding to the data
return
String object

	// use myDF.equals to be sure to get ActivationDataFlavor.equals,
	// which properly ignores Content-Type parameters in comparison
	if (getDF().equals(df))
	    return getContent(ds);
	else
	    return null;
    
public java.awt.datatransfer.DataFlavor[]getTransferDataFlavors()
Return the DataFlavors for this DataContentHandler.

return
The DataFlavors

 // throws Exception;
	return new DataFlavor[] { getDF() };
    
public voidwriteTo(java.lang.Object obj, java.lang.String type, java.io.OutputStream os)
Write the object to the output stream, using the specified MIME type.

	if (!(obj instanceof Image))
	    throw new IOException("\"" + getDF().getMimeType() +
		"\" DataContentHandler requires Image object, " +
		"was given object of type " + obj.getClass().toString());

	throw new IOException(getDF().getMimeType() + " encoding not supported");