Changeset 24969 for main


Ignore:
Timestamp:
2012-01-24T15:35:00+13:00 (12 years ago)
Author:
sjm84
Message:

This will now copy the uploaded file rather than moving it

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/LibraryServlet.java

    r24967 r24969  
    2222import java.io.File;
    2323import java.lang.reflect.Type;
     24import java.nio.channels.FileChannel;
    2425import java.util.Hashtable;
    2526import org.apache.log4j.*;
     
    437438                        }
    438439
    439                         logger.info("Moving uploaded file (" + uploadedFile.getAbsolutePath() + ") to " + toFile.getAbsolutePath());
    440                         uploadedFile.renameTo(toFile);
     440                       
     441                        FileChannel source = null;
     442                        FileChannel destination = null;
     443                        try
     444                        {
     445                            logger.info("Moving uploaded file (" + uploadedFile.getAbsolutePath() + ") to " + toFile.getAbsolutePath());
     446                            source = new FileInputStream(uploadedFile).getChannel();
     447                            destination = new FileOutputStream(toFile).getChannel();
     448                            destination.transferFrom(source, 0, source.size());
     449                        }
     450                        finally
     451                        {
     452                            if (source != null)
     453                            {
     454                                source.close();
     455                            }
     456                            if (destination != null)
     457                            {
     458                                destination.close();
     459                            }
     460                        }
     461
    441462                    }
    442463                }
Note: See TracChangeset for help on using the changeset viewer.