/*
 * $Id: DetachmentContentHandler.java 489 2006-05-22 16:39:47Z skot $
 * $URL: http://subetha.tigris.org/svn/subetha/branches/resin/core/src/org/subethamail/core/util/DetachmentContentHandler.java $
 */

package org.subethamail.core.util;

import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;

import javax.activation.DataContentHandler;
import javax.activation.DataSource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * This content handler stores an attachment id as ascii text.
 * In the future this could get a lot more sophisticated, returning
 * the java.sql.Blob of the attachment, but for now this works.
 * In particular, it allows us to use application/subetha-detachment
 * as a legit mime-type.
 * 
 * The data in and out is java.lang.Long
 * 
 * @author Jeff Schnitzer
 */
public class DetachmentContentHandler implements DataContentHandler
{
	/** */
	@SuppressWarnings("unused")
	private final static Logger log = LoggerFactory.getLogger(DetachmentContentHandler.class);

	/*
	 * (non-Javadoc)
	 * @see javax.activation.DataContentHandler#getContent(javax.activation.DataSource)
	 */
	public Object getContent(DataSource ds) throws IOException
	{
		// Extract the String id
		InputStreamReader reader = new InputStreamReader(ds.getInputStream(), "ASCII");
		StringBuilder builder = new StringBuilder();
		
		int ch;
		while ((ch = reader.read()) >= 0)
			builder.append((char)ch);
		
		// Return it as a Long
		return Long.valueOf(builder.toString());
	}

	/*
	 * (non-Javadoc)
	 * @see javax.activation.DataContentHandler#getTransferData(java.awt.datatransfer.DataFlavor, javax.activation.DataSource)
	 */
	public Object getTransferData(DataFlavor df, DataSource ds) throws UnsupportedFlavorException, IOException
	{
		throw new UnsupportedOperationException();
	}

	/*
	 * (non-Javadoc)
	 * @see javax.activation.DataContentHandler#getTransferDataFlavors()
	 */
	public DataFlavor[] getTransferDataFlavors()
	{
		throw new UnsupportedOperationException();
	}

	/*
	 * (non-Javadoc)
	 * @see javax.activation.DataContentHandler#writeTo(java.lang.Object, java.lang.String, java.io.OutputStream)
	 */
	public void writeTo(Object obj, String mimeType, OutputStream os) throws IOException
	{
		byte[] data = obj.toString().getBytes("ASCII");
		os.write(data);
	}
	
}
	
@@ -534,57 +534,30 @@
 ort 
-org.slf4j.Logger;%0D%0Aimport org.slf4j.LoggerFactory
+lombok.extern.java.Log
 ;%0D%0A%0D
@@ -940,16 +940,22 @@
 r%0D%0A */%0D%0A
+@Log%0D%0A
 public c
@@ -1022,142 +1022,8 @@
 %0A%7B%0D%0A
-%09/** */%0D%0A%09@SuppressWarnings(%22unused%22)%0D%0A%09private final static Logger log = LoggerFactory.getLogger(DetachmentContentHandler.class);%0D%0A%0D%0A
 %09/*%0D

switch logging framework