1 17 package com.sslexplorer.vfs.webdav.methods; 18 19 import java.io.IOException ; 20 import java.io.InputStream ; 21 22 import com.sslexplorer.security.LogonControllerFactory; 23 import com.sslexplorer.vfs.VFSLockManager; 24 import com.sslexplorer.vfs.VFSOutputStream; 25 import com.sslexplorer.vfs.VFSResource; 26 import com.sslexplorer.vfs.webdav.DAVMethod; 27 import com.sslexplorer.vfs.webdav.DAVTransaction; 28 import com.sslexplorer.vfs.webdav.LockedException; 29 30 38 public class PUT implements DAVMethod { 39 40 45 public PUT() { 46 super(); 47 } 48 49 54 public void process(DAVTransaction transaction, VFSResource resource) throws LockedException, IOException { 55 56 String handle = VFSLockManager.getNewHandle(); 57 VFSLockManager.getInstance().lock(resource, transaction.getSessionInfo(), true, true, handle); 58 try { 59 64 transaction.setStatus(resource.isNull() ? 201 : 204); 65 66 67 InputStream in = transaction.getInputStream(); 68 VFSOutputStream out = resource.getOutputStream(); 69 70 int sessionTimeoutBlockId = LogonControllerFactory.getInstance().addSessionTimeoutBlock( 71 transaction.getRequest().getSession(), "DAV Upload"); 72 73 74 try { 75 byte buffer[] = new byte[32768]; 76 int k = -1; 77 while (in!=null && (k = in.read(buffer)) != -1) 78 out.write(buffer, 0, k); 79 out.close(); 80 } finally { 81 out.abort(); 82 LogonControllerFactory.getInstance().removeSessionTimeoutBlock(transaction.getRequest().getSession(), sessionTimeoutBlockId); 83 } 84 resource.getMount().resourceUpload(resource, transaction, null); 85 } catch (Exception e) { 86 resource.getMount().resourceUpload(resource, transaction, e); 87 IOException ioe = new IOException (e.getMessage()); 88 ioe.initCause(e); 89 throw ioe; 90 } finally { 91 VFSLockManager.getInstance().unlock(transaction.getSessionInfo(), handle); 92 } 93 } 94 } 95 | Popular Tags |