avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From craft...@apache.org
Subject cvs commit: avalon-excalibur/sourceresolve/src/java/org/apache/excalibur/source/impl FTPSource.java
Date Tue, 05 Aug 2003 11:44:51 GMT
crafterm    2003/08/05 04:44:51

  Modified:    sourceresolve/src/java/org/apache/excalibur/source/impl
                        FTPSource.java
  Log:
  Applied patch from Unico Hommes <Unico@hippo.nl>/myself to work around java
  bug 4255280 (skipping of input bytes when attempting to determine remote source
  content type).
  
  Also adds ability to set transfer type (binary/ascii) via the METHOD source
  parameter object.
  
  Revision  Changes    Path
  1.5       +67 -6     avalon-excalibur/sourceresolve/src/java/org/apache/excalibur/source/impl/FTPSource.java
  
  Index: FTPSource.java
  ===================================================================
  RCS file: /home/cvs/avalon-excalibur/sourceresolve/src/java/org/apache/excalibur/source/impl/FTPSource.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- FTPSource.java	10 Jul 2003 14:14:00 -0000	1.4
  +++ FTPSource.java	5 Aug 2003 11:44:51 -0000	1.5
  @@ -58,10 +58,15 @@
   import java.io.FileNotFoundException;
   import java.io.IOException;
   import java.io.OutputStream;
  +import java.net.URL;
  +import java.util.Map;
   
   import org.apache.excalibur.source.ModifiableSource;
   import org.apache.excalibur.source.SourceException;
   import org.apache.excalibur.source.SourceNotFoundException;
  +import org.apache.excalibur.source.SourceParameters;
  +import org.apache.excalibur.source.SourceResolver;
  +import org.apache.excalibur.source.SourceUtil;
   
   import sun.net.ftp.FtpClient;
   
  @@ -72,13 +77,39 @@
    */
   public class FTPSource extends URLSource implements ModifiableSource
   {   
  -    
  +    private boolean m_isAscii;
  +	
       public FTPSource()
       {
           super();
       }
   
       /**
  +     * Initialize a new object from a <code>URL</code>.
  +     * @param parameters This is optional
  +     */
  +    public void init(final URL url, final Map parameters) throws IOException
  +    {
  +        final String systemId = url.toExternalForm();
  +        setSystemId(systemId);
  +        setScheme(SourceUtil.getScheme(systemId));
  +
  +        m_url = url;
  +        m_isAscii = false;
  +
  +        if (parameters != null)
  +        {
  +            m_parameters = (SourceParameters) parameters.get(SourceResolver.URI_PARAMETERS);
  +            final String method = (String) parameters.get(SourceResolver.METHOD);
  +
  +            if ("ASCII".equalsIgnoreCase(method))
  +            {
  +                m_isAscii = true;
  +            }
  +        }
  +    }
  +
  +    /**
        * Can the data sent to an <code>OutputStream</code> returned by
        * {@link #getOutputStream()} be cancelled ?
        *
  @@ -165,6 +196,36 @@
       }
   
       /**
  +     * Get the last modification date and content length of the source.
  +     * Any exceptions are ignored.
  +     */
  +    protected void getInfos()
  +    {
  +        // exists will be set below depending on the m_url type
  +        m_exists = false;
  +        try
  +        {
  +            if (null == m_connection)
  +            {
  +                m_connection = m_url.openConnection();
  +                String userInfo = m_url.getUserInfo();
  +            }
  +            setLastModified(m_connection.getLastModified());
  +            setContentLength(m_connection.getContentLength());
  +            // getting the content type here seems to screw up=20
  +            // the InputStream on the URLConnection.
  +//            m_mimeType = m_connection.getContentType();
  +            m_mimeType = null;
  +            m_exists = true;
  +        }
  +        catch (IOException ignore)
  +        {
  +            setContentLength(-1);
  +            setLastModified(0);
  +        }
  +    }
  +
  +    /**
        * Return an {@link OutputStream} to write to.
        */
       public OutputStream getOutputStream() throws IOException
  @@ -310,11 +371,11 @@
                   try
                   {
                       ftpClient = m_source.getFtpClient();
  -                    // NOTE:
  -                    // we don't have a way to determine whether we are
  -                    // dealing with an ascii file or not. Therefore transfer mode
  -                    // will be binary by default as this will cause the least problems.
  -                    // The worse that can happen now is that linebreaks get messed up.
  +                    if (m_source.m_isAscii) {
  +                        ftpClient.ascii();
  +                    } else {
  +                        ftpClient.binary();
  +                    }
                       String parentPath = null;
                       String fileName = null;
                       final String relativePath = m_source.m_url.getPath().substring( 1 );
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org


Mime
View raw message