Changeset 13307


Ignore:
Timestamp:
05/30/11 15:12:02 (10 years ago)
Author:
Mark Evenson
Message:

SYSTEM:ZIP now preserves last modified times.

Refactored common logic between two variants into auxillary methods.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/abcl/src/org/armedbear/lisp/zip.java

    r13016 r13307  
    3737
    3838import java.io.File;
     39import java.io.FileNotFoundException;
    3940import java.io.FileInputStream;
    4041import java.io.FileOutputStream;
     
    8485                }
    8586                File file = new File(namestring);
    86                 FileInputStream in = new FileInputStream(file);
    87                 ZipEntry entry = new ZipEntry(file.getName());
    88                 out.putNextEntry(entry);
    89                 int n;
    90                 while ((n = in.read(buffer)) > 0)
    91                     out.write(buffer, 0, n);
    92                 out.closeEntry();
    93                 in.close();
     87    makeEntry(out, file);
    9488                list = list.cdr();
    9589            }
     
    106100    {
    107101        Pathname zipfilePathname = coerceToPathname(first);
    108         byte[] buffer = new byte[4096];
    109102        try {
    110103            String zipfileNamestring = zipfilePathname.getNamestring();
     
    152145                    continue;
    153146                }
    154                 FileInputStream in = new FileInputStream(file);
    155                 ZipEntry entry = new ZipEntry(directory + file.getName());
    156                 out.putNextEntry(entry);
    157                 int n;
    158                 while ((n = in.read(buffer)) > 0)
    159                     out.write(buffer, 0, n);
    160                 out.closeEntry();
    161                 in.close();
     147    makeEntry(out, file, directory + file.getName());
    162148                list = list.cdr();
    163149            }
     
    170156    }
    171157
     158    private static final Primitive zip = new zip();
    172159
    173     private static final Primitive zip = new zip();
     160    private void makeEntry(ZipOutputStream zip, File file)
     161  throws FileNotFoundException, IOException
     162    {
     163  makeEntry(zip, file, file.getName());
     164    }
     165
     166    private void makeEntry(ZipOutputStream zip, File file, String name)
     167  throws FileNotFoundException, IOException
     168    {
     169        byte[] buffer = new byte[4096];
     170  long lastModified = file.lastModified();
     171  FileInputStream in = new FileInputStream(file);
     172  ZipEntry entry = new ZipEntry(name);
     173  if (lastModified > 0) {
     174      entry.setTime(lastModified);
     175  }
     176  zip.putNextEntry(entry);
     177  int n;
     178  while ((n = in.read(buffer)) > 0)
     179      zip.write(buffer, 0, n);
     180  zip.closeEntry();
     181  in.close();
     182    }
     183 
    174184}
Note: See TracChangeset for help on using the changeset viewer.