1d127360fSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3d127360fSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4d127360fSAndrew Rist * or more contributor license agreements. See the NOTICE file 5d127360fSAndrew Rist * distributed with this work for additional information 6d127360fSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7d127360fSAndrew Rist * to you under the Apache License, Version 2.0 (the 8d127360fSAndrew Rist * "License"); you may not use this file except in compliance 9d127360fSAndrew Rist * with the License. You may obtain a copy of the License at 10d127360fSAndrew Rist * 11d127360fSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12d127360fSAndrew Rist * 13d127360fSAndrew Rist * Unless required by applicable law or agreed to in writing, 14d127360fSAndrew Rist * software distributed under the License is distributed on an 15d127360fSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16d127360fSAndrew Rist * KIND, either express or implied. See the License for the 17d127360fSAndrew Rist * specific language governing permissions and limitations 18d127360fSAndrew Rist * under the License. 19d127360fSAndrew Rist * 20d127360fSAndrew Rist *************************************************************/ 21d127360fSAndrew Rist 22d127360fSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir package com.sun.star.help; 25cdf0e10cSrcweir 26cdf0e10cSrcweir import java.io.FileInputStream; 27cdf0e10cSrcweir import java.io.FileOutputStream; 28cdf0e10cSrcweir import java.util.Arrays; 29cdf0e10cSrcweir import java.util.HashSet; 30cdf0e10cSrcweir import java.util.List; 31cdf0e10cSrcweir import java.util.zip.ZipEntry; 32cdf0e10cSrcweir import java.util.zip.ZipOutputStream; 33cdf0e10cSrcweir import java.util.zip.CRC32; 34cdf0e10cSrcweir import org.apache.lucene.analysis.standard.StandardAnalyzer; 35cdf0e10cSrcweir import org.apache.lucene.analysis.cjk.CJKAnalyzer; 36cdf0e10cSrcweir import org.apache.lucene.analysis.Analyzer; 37cdf0e10cSrcweir import org.apache.lucene.index.IndexWriter; 387fb4469bSPedro Giffuni import org.apache.lucene.util.Version; 397fb4469bSPedro Giffuni import org.apache.lucene.store.NIOFSDirectory; 40cdf0e10cSrcweir 41cdf0e10cSrcweir import java.io.File; 42cdf0e10cSrcweir import java.io.FileNotFoundException; 43cdf0e10cSrcweir import java.io.IOException; 44cdf0e10cSrcweir import java.util.Date; 45cdf0e10cSrcweir 46*8211aaaaSPedro Giffuni /** 47*8211aaaaSPedro Giffuni When this tool is used with long path names on Windows, that is paths which start 48*8211aaaaSPedro Giffuni with \\?\, then the caller must make sure that the path is unique. This is achieved 49*8211aaaaSPedro Giffuni by removing '.' and '..' from the path. Paths which are created by 50*8211aaaaSPedro Giffuni osl_getSystemPathFromFileURL fulfill this requirement. This is necessary because 51*8211aaaaSPedro Giffuni lucene is patched to not use File.getCanonicalPath. See long_path.patch in the lucene 52*8211aaaaSPedro Giffuni module. 53*8211aaaaSPedro Giffuni */ 54*8211aaaaSPedro Giffuni 55cdf0e10cSrcweir public class HelpIndexerTool 56cdf0e10cSrcweir { HelpIndexerTool()57cdf0e10cSrcweir public HelpIndexerTool() 58cdf0e10cSrcweir { 59cdf0e10cSrcweir } 60cdf0e10cSrcweir 61cdf0e10cSrcweir 62cdf0e10cSrcweir /** 63cdf0e10cSrcweir * @param args the command line arguments 64cdf0e10cSrcweir */ main( String[] args )65cdf0e10cSrcweir public static void main( String[] args ) 66cdf0e10cSrcweir { 67cdf0e10cSrcweir boolean bExtensionMode = false; 68cdf0e10cSrcweir mainImpl( args, bExtensionMode ); 69cdf0e10cSrcweir } 70cdf0e10cSrcweir mainImpl( String[] args, boolean bExtensionMode )71cdf0e10cSrcweir public static void mainImpl( String[] args, boolean bExtensionMode ) 72cdf0e10cSrcweir { 73cdf0e10cSrcweir String aDirToZipStr = ""; 74cdf0e10cSrcweir String aSrcDirStr = ""; 75cdf0e10cSrcweir String aLanguageStr = ""; 76cdf0e10cSrcweir String aModule = ""; 77cdf0e10cSrcweir String aTargetZipFileStr = ""; 78cdf0e10cSrcweir String aCfsName = ""; 79cdf0e10cSrcweir String aSegmentName = ""; 80cdf0e10cSrcweir 81cdf0e10cSrcweir // Scan arguments 82cdf0e10cSrcweir //If this tool is invoked in the build process for extensions help, 83cdf0e10cSrcweir //then -extension must be set. 84cdf0e10cSrcweir boolean bExtension = false; 85cdf0e10cSrcweir boolean bLang = false; 86cdf0e10cSrcweir boolean bMod = false; 87cdf0e10cSrcweir boolean bZipDir = false; 88cdf0e10cSrcweir boolean bSrcDir = false; 89cdf0e10cSrcweir boolean bOutput = false; 90cdf0e10cSrcweir boolean bCfsName = false; 91cdf0e10cSrcweir boolean bSegmentName = false; 92cdf0e10cSrcweir 93cdf0e10cSrcweir int nArgCount = args.length; 94cdf0e10cSrcweir for( int i = 0 ; i < nArgCount ; i++ ) 95cdf0e10cSrcweir { 96cdf0e10cSrcweir if( "-extension".equals(args[i]) ) 97cdf0e10cSrcweir { 98cdf0e10cSrcweir bExtension = true; 99cdf0e10cSrcweir } 100cdf0e10cSrcweir else if( "-lang".equals(args[i]) ) 101cdf0e10cSrcweir { 102cdf0e10cSrcweir if( i + 1 < nArgCount ) 103cdf0e10cSrcweir { 104cdf0e10cSrcweir aLanguageStr = args[i + 1]; 105cdf0e10cSrcweir bLang = true; 106cdf0e10cSrcweir } 107cdf0e10cSrcweir i++; 108cdf0e10cSrcweir } 109cdf0e10cSrcweir else if( "-mod".equals(args[i]) ) 110cdf0e10cSrcweir { 111cdf0e10cSrcweir if( i + 1 < nArgCount ) 112cdf0e10cSrcweir { 113cdf0e10cSrcweir aModule = args[i + 1]; 114cdf0e10cSrcweir bMod = true; 115cdf0e10cSrcweir } 116cdf0e10cSrcweir i++; 117cdf0e10cSrcweir } 118cdf0e10cSrcweir else if( "-zipdir".equals(args[i]) ) 119cdf0e10cSrcweir { 120cdf0e10cSrcweir if( i + 1 < nArgCount ) 121cdf0e10cSrcweir { 122cdf0e10cSrcweir aDirToZipStr = args[i + 1]; 123cdf0e10cSrcweir bZipDir = true; 124cdf0e10cSrcweir } 125cdf0e10cSrcweir i++; 126cdf0e10cSrcweir } 127cdf0e10cSrcweir else if( "-srcdir".equals(args[i]) ) 128cdf0e10cSrcweir { 129cdf0e10cSrcweir if( i + 1 < nArgCount ) 130cdf0e10cSrcweir { 131cdf0e10cSrcweir aSrcDirStr = args[i + 1]; 132cdf0e10cSrcweir bSrcDir = true; 133cdf0e10cSrcweir } 134cdf0e10cSrcweir i++; 135cdf0e10cSrcweir } 136cdf0e10cSrcweir else if( "-o".equals(args[i]) ) 137cdf0e10cSrcweir { 138cdf0e10cSrcweir if( i + 1 < nArgCount ) 139cdf0e10cSrcweir { 140cdf0e10cSrcweir aTargetZipFileStr = args[i + 1]; 141cdf0e10cSrcweir bOutput = true; 142cdf0e10cSrcweir } 143cdf0e10cSrcweir i++; 144cdf0e10cSrcweir } 145cdf0e10cSrcweir else if( "-checkcfsandsegname".equals(args[i]) ) 146cdf0e10cSrcweir { 147cdf0e10cSrcweir if( i + 1 < nArgCount ) 148cdf0e10cSrcweir { 149cdf0e10cSrcweir aCfsName = args[i + 1] + ".cfs"; 150cdf0e10cSrcweir bCfsName = true; 151cdf0e10cSrcweir } 152cdf0e10cSrcweir i++; 153cdf0e10cSrcweir if( i + 1 < nArgCount ) 154cdf0e10cSrcweir { 155cdf0e10cSrcweir aSegmentName = "segments" + args[i + 1]; 156cdf0e10cSrcweir bSegmentName = true; 157cdf0e10cSrcweir } 158cdf0e10cSrcweir i++; 159cdf0e10cSrcweir if (!(bCfsName && bSegmentName)) 160cdf0e10cSrcweir { 161cdf0e10cSrcweir System.out.println("Usage: HelpIndexer -checkcfsandsegname _0 _3 (2 arguments needed)"); 162cdf0e10cSrcweir System.exit( -1 ); 163cdf0e10cSrcweir } 164cdf0e10cSrcweir } 165cdf0e10cSrcweir } 166cdf0e10cSrcweir 167cdf0e10cSrcweir if( !bLang || !bMod || !bZipDir || (!bOutput && !bExtensionMode && !bExtension) ) 168cdf0e10cSrcweir { 169cdf0e10cSrcweir if( bExtensionMode ) 170cdf0e10cSrcweir return; 171cdf0e10cSrcweir 172cdf0e10cSrcweir System.out.println("Usage: HelpIndexer -lang ISOLangCode -mod HelpModule -zipdir TempZipDir -o OutputZipFile"); 173cdf0e10cSrcweir System.out.println("Usage: HelpIndexer -extension -lang ISOLangCode -mod HelpModule -zipdir PathToLangDir"); 174cdf0e10cSrcweir System.exit( -1 ); 175cdf0e10cSrcweir } 176cdf0e10cSrcweir 177cdf0e10cSrcweir String aIndexDirName = aModule + ".idxl"; 178cdf0e10cSrcweir File aIndexDir = new File( aDirToZipStr + File.separator + aIndexDirName ); 179cdf0e10cSrcweir if( !bSrcDir ) 180cdf0e10cSrcweir aSrcDirStr = aDirToZipStr; 181cdf0e10cSrcweir File aCaptionFilesDir = new File( aSrcDirStr + File.separator + "caption" ); 182cdf0e10cSrcweir File aContentFilesDir = new File( aSrcDirStr + File.separator + "content" ); 183cdf0e10cSrcweir 184cdf0e10cSrcweir try 185cdf0e10cSrcweir { 186cdf0e10cSrcweir Date start = new Date(); 1877fb4469bSPedro Giffuni Analyzer analyzer = aLanguageStr.equals("ja") ? (Analyzer)new CJKAnalyzer(Version.LUCENE_29) : (Analyzer)new StandardAnalyzer(Version.LUCENE_29); 188*8211aaaaSPedro Giffuni IndexWriter writer = new IndexWriter( NIOFSDirectory.open(aIndexDir), analyzer, true, IndexWriter.MaxFieldLength.UNLIMITED ); 189cdf0e10cSrcweir if( !bExtensionMode ) 190cdf0e10cSrcweir System.out.println( "Lucene: Indexing to directory '" + aIndexDir + "'..." ); 191cdf0e10cSrcweir int nRet = indexDocs( writer, aModule, bExtensionMode, aCaptionFilesDir, aContentFilesDir ); 192cdf0e10cSrcweir if( nRet != -1 ) 193cdf0e10cSrcweir { 194cdf0e10cSrcweir if( !bExtensionMode ) 195cdf0e10cSrcweir { 196cdf0e10cSrcweir System.out.println(); 197cdf0e10cSrcweir System.out.println( "Optimizing ..." ); 198cdf0e10cSrcweir } 199cdf0e10cSrcweir writer.optimize(); 200cdf0e10cSrcweir } 201cdf0e10cSrcweir writer.close(); 202cdf0e10cSrcweir 203cdf0e10cSrcweir boolean bCfsFileOk = true; 204cdf0e10cSrcweir boolean bSegmentFileOk = true; 205cdf0e10cSrcweir if( bCfsName && bSegmentName && !bExtensionMode && nRet != -1 ) 206cdf0e10cSrcweir { 207cdf0e10cSrcweir String aCompleteCfsFileName = aDirToZipStr + File.separator + aIndexDirName + File.separator + aCfsName; 208cdf0e10cSrcweir String aCompleteSegmentFileName = aDirToZipStr + File.separator + aIndexDirName + File.separator + aSegmentName; 209cdf0e10cSrcweir File aCfsFile = new File( aCompleteCfsFileName ); 210cdf0e10cSrcweir File aSegmentFile = new File( aCompleteSegmentFileName ); 211cdf0e10cSrcweir bCfsFileOk = aCfsFile.exists(); 212cdf0e10cSrcweir bSegmentFileOk = aSegmentFile.exists(); 213cdf0e10cSrcweir System.out.println( "Checking cfs file " + aCfsName+ ": " + (bCfsFileOk ? "Found" : "Not found") ); 214cdf0e10cSrcweir System.out.println( "Checking segment file " + aSegmentName+ ": " + (bSegmentFileOk ? "Found" : "Not found") ); 215cdf0e10cSrcweir } 216cdf0e10cSrcweir 217cdf0e10cSrcweir if( bExtensionMode || bExtension) 218cdf0e10cSrcweir { 219cdf0e10cSrcweir if( !bSrcDir ) 220cdf0e10cSrcweir { 221cdf0e10cSrcweir deleteRecursively( aCaptionFilesDir ); 222cdf0e10cSrcweir deleteRecursively( aContentFilesDir ); 223cdf0e10cSrcweir } 224cdf0e10cSrcweir } 225cdf0e10cSrcweir else 226cdf0e10cSrcweir { 227cdf0e10cSrcweir if( nRet == -1 ) 228cdf0e10cSrcweir deleteRecursively( aIndexDir ); 229cdf0e10cSrcweir 230cdf0e10cSrcweir if( bCfsFileOk && bSegmentFileOk ) 231cdf0e10cSrcweir System.out.println( "Zipping ..." ); 232cdf0e10cSrcweir File aDirToZipFile = new File( aDirToZipStr ); 233cdf0e10cSrcweir createZipFile( aDirToZipFile, aTargetZipFileStr ); 234cdf0e10cSrcweir deleteRecursively( aDirToZipFile ); 235cdf0e10cSrcweir } 236cdf0e10cSrcweir 237cdf0e10cSrcweir if( !bCfsFileOk ) 238cdf0e10cSrcweir { 239cdf0e10cSrcweir System.out.println( "cfs file check failed, terminating..." ); 240cdf0e10cSrcweir System.exit( -1 ); 241cdf0e10cSrcweir } 242cdf0e10cSrcweir 243cdf0e10cSrcweir if( !bSegmentFileOk ) 244cdf0e10cSrcweir { 245cdf0e10cSrcweir System.out.println( "segment file check failed, terminating..." ); 246cdf0e10cSrcweir System.exit( -1 ); 247cdf0e10cSrcweir } 248cdf0e10cSrcweir 249cdf0e10cSrcweir Date end = new Date(); 250cdf0e10cSrcweir if( !bExtensionMode ) 251cdf0e10cSrcweir System.out.println(end.getTime() - start.getTime() + " total milliseconds"); 252cdf0e10cSrcweir } 253cdf0e10cSrcweir catch (IOException e) 254cdf0e10cSrcweir { 255cdf0e10cSrcweir if( bExtensionMode ) 256cdf0e10cSrcweir return; 257cdf0e10cSrcweir 258cdf0e10cSrcweir System.out.println(" caught a " + e.getClass() + 259cdf0e10cSrcweir "\n with message: " + e.getMessage()); 260cdf0e10cSrcweir System.exit( -1 ); 261cdf0e10cSrcweir } 262cdf0e10cSrcweir } 263cdf0e10cSrcweir indexDocs(IndexWriter writer, String aModule, boolean bExtensionMode, File aCaptionFilesDir, File aContentFilesDir)264cdf0e10cSrcweir private static int indexDocs(IndexWriter writer, String aModule, boolean bExtensionMode, 265cdf0e10cSrcweir File aCaptionFilesDir, File aContentFilesDir) throws IOException 266cdf0e10cSrcweir { 267cdf0e10cSrcweir if( !aCaptionFilesDir.canRead() || !aCaptionFilesDir.isDirectory() ) 268cdf0e10cSrcweir { 269cdf0e10cSrcweir if( !bExtensionMode ) 270cdf0e10cSrcweir System.out.println( "Not found: " + aCaptionFilesDir ); 271cdf0e10cSrcweir return -1; 272cdf0e10cSrcweir } 273cdf0e10cSrcweir if( !aContentFilesDir.canRead() || !aContentFilesDir.isDirectory() ) 274cdf0e10cSrcweir { 275cdf0e10cSrcweir if( !bExtensionMode ) 276cdf0e10cSrcweir System.out.println( "Not found: " + aContentFilesDir ); 277cdf0e10cSrcweir return -1; 278cdf0e10cSrcweir } 279cdf0e10cSrcweir 280cdf0e10cSrcweir String[] aCaptionFiles = aCaptionFilesDir.list(); 281cdf0e10cSrcweir List aCaptionFilesList = Arrays.asList( aCaptionFiles ); 282cdf0e10cSrcweir HashSet aCaptionFilesHashSet = new HashSet( aCaptionFilesList ); 283cdf0e10cSrcweir 284cdf0e10cSrcweir String[] aContentFiles = aContentFilesDir.list(); 285cdf0e10cSrcweir List aContentFilesList = Arrays.asList( aContentFiles ); 286cdf0e10cSrcweir HashSet aContentFilesHashSet = new HashSet( aContentFilesList ); 287cdf0e10cSrcweir 288cdf0e10cSrcweir // Loop over caption files and find corresponding content file 289cdf0e10cSrcweir if( !bExtensionMode ) 290cdf0e10cSrcweir System.out.println( "Indexing, adding files" ); 291cdf0e10cSrcweir int nCaptionFilesLen = aCaptionFiles.length; 292cdf0e10cSrcweir for( int i = 0 ; i < nCaptionFilesLen ; i++ ) 293cdf0e10cSrcweir { 294cdf0e10cSrcweir String aCaptionFileStr = aCaptionFiles[i]; 295cdf0e10cSrcweir File aCaptionFile = new File( aCaptionFilesDir, aCaptionFileStr ); 296cdf0e10cSrcweir File aContentFile = null; 297cdf0e10cSrcweir if( aContentFilesHashSet.contains( aCaptionFileStr ) ) 298cdf0e10cSrcweir aContentFile = new File( aContentFilesDir, aCaptionFileStr ); 299cdf0e10cSrcweir 300cdf0e10cSrcweir if( !bExtensionMode ) 301cdf0e10cSrcweir System.out.print( "." ); 302cdf0e10cSrcweir writer.addDocument( HelpFileDocument.Document( aModule, aCaptionFile, aContentFile ) ); 303cdf0e10cSrcweir } 304cdf0e10cSrcweir 305cdf0e10cSrcweir // Loop over content files to find remaining files not mapped to caption files 306cdf0e10cSrcweir int nContentFilesLen = aContentFiles.length; 307cdf0e10cSrcweir for( int i = 0 ; i < nContentFilesLen ; i++ ) 308cdf0e10cSrcweir { 309cdf0e10cSrcweir String aContentFileStr = aContentFiles[i]; 310cdf0e10cSrcweir if( !aCaptionFilesHashSet.contains( aContentFileStr ) ) 311cdf0e10cSrcweir { 312cdf0e10cSrcweir // Not already handled in caption files loop 313cdf0e10cSrcweir File aCaptionFile = null; 314cdf0e10cSrcweir File aContentFile = new File( aContentFilesDir, aContentFileStr ); 315cdf0e10cSrcweir if( !bExtensionMode ) 316cdf0e10cSrcweir System.out.print( "." ); 317cdf0e10cSrcweir writer.addDocument( HelpFileDocument.Document( aModule, aCaptionFile, aContentFile ) ); 318cdf0e10cSrcweir } 319cdf0e10cSrcweir } 320cdf0e10cSrcweir return 0; 321cdf0e10cSrcweir } 322cdf0e10cSrcweir createZipFile( File aDirToZip, String aTargetZipFileStr )323cdf0e10cSrcweir public static void createZipFile( File aDirToZip, String aTargetZipFileStr ) 324cdf0e10cSrcweir throws FileNotFoundException, IOException 325cdf0e10cSrcweir { 326cdf0e10cSrcweir FileOutputStream fos = new FileOutputStream( aTargetZipFileStr ); 327cdf0e10cSrcweir ZipOutputStream zos = new ZipOutputStream( fos ); 328cdf0e10cSrcweir 329cdf0e10cSrcweir File[] aChildrenFiles = aDirToZip.listFiles(); 330cdf0e10cSrcweir int nFileCount = aChildrenFiles.length; 331cdf0e10cSrcweir for( int i = 0 ; i < nFileCount ; i++ ) 332cdf0e10cSrcweir addToZipRecursively( zos, aChildrenFiles[i], null ); 333cdf0e10cSrcweir 334cdf0e10cSrcweir zos.close(); 335cdf0e10cSrcweir } 336cdf0e10cSrcweir addToZipRecursively( ZipOutputStream zos, File aFile, String aBasePath )337cdf0e10cSrcweir public static void addToZipRecursively( ZipOutputStream zos, File aFile, String aBasePath ) 338cdf0e10cSrcweir throws FileNotFoundException, IOException 339cdf0e10cSrcweir { 340cdf0e10cSrcweir if( aFile.isDirectory() ) 341cdf0e10cSrcweir { 342cdf0e10cSrcweir String aDirName = aFile.getName(); 343cdf0e10cSrcweir if( aDirName.equalsIgnoreCase( "caption" ) || aDirName.equalsIgnoreCase( "content" ) ) 344cdf0e10cSrcweir return; 345cdf0e10cSrcweir 346cdf0e10cSrcweir File[] aChildrenFiles = aFile.listFiles(); 347cdf0e10cSrcweir String aNewBasePath = ""; 348cdf0e10cSrcweir if( aBasePath != null ) 349cdf0e10cSrcweir aNewBasePath += aBasePath + File.separator; 350cdf0e10cSrcweir aNewBasePath += aDirName; 351cdf0e10cSrcweir 352cdf0e10cSrcweir int nFileCount = aChildrenFiles.length; 353cdf0e10cSrcweir for( int i = 0 ; i < nFileCount ; i++ ) 354cdf0e10cSrcweir addToZipRecursively( zos, aChildrenFiles[i], aNewBasePath ); 355cdf0e10cSrcweir 356cdf0e10cSrcweir return; 357cdf0e10cSrcweir } 358cdf0e10cSrcweir 359cdf0e10cSrcweir // No directory 360cdf0e10cSrcweir // read contents of file we are going to put in the zip 361cdf0e10cSrcweir int fileLength = (int) aFile.length(); 362cdf0e10cSrcweir FileInputStream fis = new FileInputStream( aFile ); 363cdf0e10cSrcweir byte[] wholeFile = new byte[fileLength]; 364cdf0e10cSrcweir int bytesRead = fis.read( wholeFile, 0, fileLength ); 365cdf0e10cSrcweir fis.close(); 366cdf0e10cSrcweir 367cdf0e10cSrcweir String aFileName = aFile.getName(); 368cdf0e10cSrcweir String aEntryName = ""; 369cdf0e10cSrcweir if( aBasePath != null ) 370cdf0e10cSrcweir aEntryName += aBasePath + "/"; 371cdf0e10cSrcweir aEntryName += aFileName; 372cdf0e10cSrcweir ZipEntry aZipEntry = new ZipEntry( aEntryName ); 373cdf0e10cSrcweir aZipEntry.setTime( aFile.lastModified() ); 374cdf0e10cSrcweir aZipEntry.setSize( fileLength ); 375cdf0e10cSrcweir 376cdf0e10cSrcweir int nMethod = ( aFileName.toLowerCase().endsWith( ".jar" ) ) 377cdf0e10cSrcweir ? ZipEntry.STORED : ZipEntry.DEFLATED; 378cdf0e10cSrcweir aZipEntry.setMethod( nMethod ); 379cdf0e10cSrcweir 380cdf0e10cSrcweir CRC32 tempCRC = new CRC32(); 381cdf0e10cSrcweir tempCRC.update( wholeFile, 0, wholeFile.length ); 382cdf0e10cSrcweir aZipEntry.setCrc( tempCRC.getValue() ); 383cdf0e10cSrcweir 384cdf0e10cSrcweir // write the contents into the zip element 385cdf0e10cSrcweir zos.putNextEntry( aZipEntry ); 386cdf0e10cSrcweir zos.write( wholeFile, 0, fileLength ); 387cdf0e10cSrcweir zos.closeEntry(); 388cdf0e10cSrcweir } 389cdf0e10cSrcweir deleteRecursively( File aFile )390cdf0e10cSrcweir static public boolean deleteRecursively( File aFile ) 391cdf0e10cSrcweir { 392cdf0e10cSrcweir if( aFile.isDirectory() ) 393cdf0e10cSrcweir { 394cdf0e10cSrcweir File[] aChildrenFiles = aFile.listFiles(); 395cdf0e10cSrcweir int nFileCount = aChildrenFiles.length; 396cdf0e10cSrcweir for( int i = 0 ; i < nFileCount ; i++ ) 397cdf0e10cSrcweir { 398cdf0e10cSrcweir File aChildrenFile = aChildrenFiles[i]; 399cdf0e10cSrcweir boolean bSuccess = deleteRecursively( aChildrenFile ); 400cdf0e10cSrcweir if( !bSuccess ) 401cdf0e10cSrcweir return false; 402cdf0e10cSrcweir } 403cdf0e10cSrcweir } 404cdf0e10cSrcweir 405cdf0e10cSrcweir return aFile.delete(); 406cdf0e10cSrcweir } 407cdf0e10cSrcweir } 408cdf0e10cSrcweir 409