Here you can find the source of copyStreamsToFile(String path, Map
public static void copyStreamsToFile(String path, Map<String, InputStream> streamMap) throws IOException
//package com.java2s; /******************************************************************************* * Copyright (c) 2014 OpenLegacy Inc./*www. j av a 2s . co m*/ * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * OpenLegacy Inc. - initial API and implementation *******************************************************************************/ import java.io.BufferedReader; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.util.Map; public class Main { private static String LINE_START = " "; private static int LINE_MIN_LENGTH = 6; private static String newLine = System.getProperty("line.separator"); public static void copyStreamsToFile(String path, Map<String, InputStream> streamMap) throws IOException { for (String copyBookName : streamMap.keySet()) { File copyBookFile = new File(path + copyBookName); OutputStream copyBookStream = new FileOutputStream(copyBookFile); OutputStreamWriter copyBookStreamWriter = new OutputStreamWriter(copyBookStream); copyBookFile.deleteOnExit(); BufferedReader input = new BufferedReader(new InputStreamReader(streamMap.get(copyBookName))); String line; while ((line = input.readLine()) != null) { if ((line = preProcessLine(line)) != null) { copyBookStreamWriter.write(line); } } // IOUtils.copy(streamMap.get(copyBookName), copyBookStream); copyBookStreamWriter.close(); copyBookStream.close(); } } public static String preProcessLine(String line) { if (line.length() > LINE_MIN_LENGTH) { line = LINE_START + line.substring(6); if (isComment(line) == false) { return line + newLine; } } return null; } private static boolean isComment(String line) { for (int i = 6; i < line.length(); i++) { if (line.charAt(i) != ' ') { if (line.charAt(i) == '*') { return true; } else { return false; } } } return false; } }