/* * $Id: FileObjectMessageAdapter.java 10935 2008-02-22 03:48:54Z dfeist $ * -------------------------------------------------------------------------------------- * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com * * The software in this package is published under the terms of the CPAL v1.0 * license, a copy of which has been included with this distribution in the * LICENSE.txt file. */ package org.mule.transport.file; import org.mule.api.MessagingException; import org.mule.api.ThreadSafeAccess; import org.mule.api.transport.MessageTypeNotSupportedException; import org.mule.transport.AbstractMessageAdapter; import org.mule.transport.file.i18n.FileMessages; import org.mule.util.ObjectUtils; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; /** * FileObjectMessageAdapter provides a wrapper for a file reference. Users * can obtain the file object through the payload property and can get * the filename and directory in the properties using FileConnector.PROPERTY_FILENAME and * FileConnector.PROPERTY_DIRECTORY. */ public class FileObjectMessageAdapter extends AbstractMessageAdapter { /** Serial version */ private static final long serialVersionUID = 4127485947547548996L; protected File payload; public FileObjectMessageAdapter(Object message) throws MessagingException { super(); if (message instanceof File) { this.setFileMessage((File) message); } else { throw new MessageTypeNotSupportedException(message, this.getClass()); } } protected FileObjectMessageAdapter(FileObjectMessageAdapter template) { super(template); payload = template.payload; } public Object getPayload() { return payload; } protected void setFileMessage(File message) throws MessagingException { this.payload = message; setProperty(FileConnector.PROPERTY_ORIGINAL_FILENAME, this.payload.getName()); setProperty(FileConnector.PROPERTY_DIRECTORY, this.payload.getParent()); } public String getUniqueId() { return payload.getAbsolutePath(); } public ThreadSafeAccess newThreadCopy() { return new FileObjectMessageAdapter(this); } }