Here you can find the source of writeFileToArchive(final ZipOutputStream zos, final Path baseSrcPath, final Path filePath)
private static void writeFileToArchive(final ZipOutputStream zos, final Path baseSrcPath, final Path filePath) throws IOException
//package com.java2s; //License from project: Apache License import java.io.File; import java.io.IOException; import java.io.InputStream; import java.nio.file.Files; import java.nio.file.Path; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; public class Main { private static final String CONFIG_NAMES_FILE_TOC = "toc.html"; private static void writeFileToArchive(final ZipOutputStream zos, final Path baseSrcPath, final Path filePath) throws IOException { final byte[] buffer = new byte[1024]; final String zipPath = baseSrcPath.resolve(extractLanguageRelativePath(filePath)).toString(); final ZipEntry ze = new ZipEntry(zipPath); zos.putNextEntry(ze);/* www. j a va 2 s . co m*/ try (InputStream in = Files.newInputStream(filePath);) { int len; while ((len = in.read(buffer)) > 0) { zos.write(buffer, 0, len); } } zos.closeEntry(); } private static String extractLanguageRelativePath(final Path absolutePath) { final String fileName; if (absolutePath != null && absolutePath.getFileName() != null) { fileName = absolutePath.getFileName().toString(); } else { fileName = ""; } final String pathRegexSeparator; if ("\\".equals(File.separator)) { pathRegexSeparator = "\\\\"; } else { pathRegexSeparator = File.separator; } final String languagePathPattern = "(it|en|fr)" + pathRegexSeparator + "(faq|imgs|pages|pdf|toc\\.html)"; Pattern pattern = Pattern.compile(languagePathPattern); final String pathString; if (absolutePath != null) { pathString = absolutePath.toString(); } else { pathString = ""; } Matcher matcher = pattern.matcher(pathString); String lang = ""; String folderType = ""; while (matcher.find()) { lang = matcher.group(1); folderType = matcher.group(2); } String result = lang + File.separator + folderType; if (result.endsWith(File.separator)) { result = fileName; } else if (!fileName.equals(CONFIG_NAMES_FILE_TOC)) { result += File.separator + fileName; } return result; } }