All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hfg.util.mime.MimeEntity Maven / Gradle / Ivy

There is a newer version: 20240423
Show newest version
package com.hfg.util.mime;

import com.hfg.util.FileUtil;

import java.io.File;
import java.io.IOException;

//------------------------------------------------------------------------------
/**
 MIME Entity.
 @author J. Alex Taylor, hairyfatguy.com
 */
//------------------------------------------------------------------------------
// com.hfg XML/HTML Coding Library
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com
// [email protected]
//------------------------------------------------------------------------------

public class MimeEntity
{
   //##########################################################################
   // PRIVATE FIELDS
   //##########################################################################

   private MimeContentDisposition mContentDisposition;
   private String mContentType;
   private StringBuilder mContent;
   private File mCachedContentFile;

   //##########################################################################
   // PUBLIC METHODS
   //##########################################################################

   //--------------------------------------------------------------------------
   public MimeContentDisposition getContentDisposition()
   {
      return mContentDisposition;
   }

   //--------------------------------------------------------------------------
   public void setContentDisposition(MimeContentDisposition inValue)
   {
      mContentDisposition = inValue;
   }

   //--------------------------------------------------------------------------
   public String getContentType()
   {
      return mContentType;
   }

   //--------------------------------------------------------------------------
   public void setContentType(String inValue)
   {
      mContentType = inValue;
   }

   //--------------------------------------------------------------------------
   public void setContent(String inValue)
         throws IOException
   {
      if (mCachedContentFile != null)
      {
         FileUtil.write(mCachedContentFile, inValue);
         mContent = null;
      }
      else
      {
         mContent = new StringBuilder(inValue);
      }
   }

   //--------------------------------------------------------------------------
   public String getContent()
   {
      return (mContent != null ? mContent.toString() : null);
   }

   //--------------------------------------------------------------------------
   public File getCachedContentFile()
   {
      return mCachedContentFile;
   }

   //--------------------------------------------------------------------------
   /**
    Sets the file in which the entity's content will be cached.
    */
   public void setCachedContentFile(File inValue)
         throws IOException
   {
      mCachedContentFile = inValue;
      if (mCachedContentFile != null)
      {
/*
         if (mCachedContentFile.exists())
         {
            if (!mCachedContentFile.delete())
            {
               throw new IOException("The preexisting cache file '" + mCachedContentFile + "' couldn't be deleted!");
            }
         }
*/
         if (!mCachedContentFile.exists()
             && !mCachedContentFile.createNewFile())
         {
            throw new IOException("The cache file '" + mCachedContentFile + "' couldn't be created!");
         }
      }
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy