001 /** 002 * Copyright (c) 2003 Daffodil Software Ltd all rights reserved, 003 * Modifications Copyright (c) 2008 Regiscope Digital Imaging Co, LLC, All rights reserved. 004 * This program is free software; you can redistribute it and/or modify 005 * it under the terms of version 2 of the GNU General Public License as 006 * published by the Free Software Foundation. 007 * There are special exceptions to the terms and conditions of the GPL 008 * as it is applied to this software. See the GNU General Public License for more details. 009 * 010 * This program is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 013 * GNU General Public License for more details. 014 * 015 * You should have received a copy of the GNU General Public License 016 * along with this program; if not, write to the Free Software 017 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 018 */ 019 020 package org.dbreplicator.replication.xml; 021 022 import java.io.*; 023 import org.dbreplicator.replication.*; 024 025 public class WriteOnSocket extends Thread { 026 private String xmlFilePath,zipFilePath,fileName; 027 private _FileUpload fileUpload; 028 boolean deleteXML =false, isFileForSynchronization =false; 029 030 public WriteOnSocket( String zipFilePath0,String xmlFilePath0,boolean deleteXML0, String fileName0,_FileUpload fileUpload0,boolean isFileForSynchronization0 ) { 031 zipFilePath = zipFilePath0; 032 xmlFilePath =xmlFilePath0; 033 deleteXML =deleteXML0; 034 fileUpload =fileUpload0; 035 fileName=fileName0; 036 isFileForSynchronization =isFileForSynchronization0; 037 } 038 039 // To write the zip file on client side. 040 public void run() { 041 try { 042 FileInputStream fis = new FileInputStream(zipFilePath); 043 //byte[] buf = new byte[1024]; 044 // bjt - test to see if changing speeds this up --- it DOES! 045 byte[] buf = new byte[8192]; 046 int len = 0; 047 fileUpload.fileStart(fileName,isFileForSynchronization); 048 while ( (len = fis.read(buf)) > 0) { 049 fileUpload.writeFileContent(buf,0,len); 050 } 051 fis.close(); 052 fileUpload.closeFile(); 053 } 054 catch (IOException ex) { 055 RepConstants.writeERROR_FILE(ex); 056 new RuntimeException(ex); 057 } 058 catch (RepException ex) { 059 RepConstants.writeERROR_FILE(ex); 060 new RuntimeException(ex); 061 } 062 063 if (deleteXML) { 064 // deleting zip file 065 deleteFile(zipFilePath); 066 // deleting xml file 067 deleteFile(xmlFilePath); 068 } 069 070 } 071 072 private void deleteFile(String fileName) 073 { 074 File f = new File(fileName); 075 boolean deleted = f.delete(); 076 } 077 078 }

