(File dir, String sofar,
ZipOutputStream zos)
| 148 | |
| 149 | |
| 150 | public void buildZip(File dir, String sofar, |
| 151 | ZipOutputStream zos) throws IOException { |
| 152 | String files[] = dir.list(); |
| 153 | if (files == null) { |
| 154 | throw new IOException("Unable to list files from " + dir); |
| 155 | } |
| 156 | for (int i = 0; i < files.length; i++) { |
| 157 | if (files[i].equals(".") || |
| 158 | files[i].equals("..")) continue; |
| 159 | |
| 160 | File sub = new File(dir, files[i]); |
| 161 | String nowfar = (sofar == null) ? |
| 162 | files[i] : (sofar + "/" + files[i]); |
| 163 | |
| 164 | if (sub.isDirectory()) { |
| 165 | // directories are empty entries and have / at the end |
| 166 | ZipEntry entry = new ZipEntry(nowfar + "/"); |
| 167 | //System.out.println(entry); |
| 168 | zos.putNextEntry(entry); |
| 169 | zos.closeEntry(); |
| 170 | buildZip(sub, nowfar, zos); |
| 171 | |
| 172 | } else { |
| 173 | ZipEntry entry = new ZipEntry(nowfar); |
| 174 | entry.setTime(sub.lastModified()); |
| 175 | zos.putNextEntry(entry); |
| 176 | zos.write(Base.loadBytesRaw(sub)); |
| 177 | zos.closeEntry(); |
| 178 | } |
| 179 | } |
| 180 | } |
| 181 | } |
| 182 | |
| 183 |
no test coverage detected