1 /*
2 * #%L
3 * Nuiton Utils
4 * %%
5 * Copyright (C) 2004 - 2011 CodeLutin, Chatellier Eric
6 * %%
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Lesser Public License for more details.
16 *
17 * You should have received a copy of the GNU General Lesser Public
18 * License along with this program. If not, see
19 * <http://www.gnu.org/licenses/lgpl-3.0.html>.
20 * #L%
21 */
22
23 package org.nuiton.util;
24
25 import java.io.FilterOutputStream;
26 import java.io.IOException;
27 import java.io.OutputStream;
28 import java.util.Properties;
29
30 /**
31 * Class used to not print first line into delegated {@link OutputStream}.
32 *
33 * Used to remove first comment line writed by {@link Properties#store(OutputStream, String)}.
34 *
35 * @author chatellier
36 */
37 public class PropertiesDateRemoveFilterStream extends FilterOutputStream {
38
39 protected boolean firstLineOver;
40
41 protected char endChar;
42
43 public PropertiesDateRemoveFilterStream(OutputStream out) {
44 super(out);
45 firstLineOver = false;
46 String lineSeparator = System.getProperty("line.separator");
47 endChar = lineSeparator.charAt(lineSeparator.length() - 1);
48 }
49
50 @Override
51 public void write(int b) throws IOException {
52 if (!firstLineOver) {
53 char c = (char) b;
54 if (c == endChar) {
55 firstLineOver = true;
56 }
57 } else {
58 out.write(b);
59 }
60 }
61
62 }