]>
git.argeo.org Git - gpl/argeo-slc.git/blob - ext/javax.mail.mbox/src/com/sun/mail/mbox/NewlineOutputStream.java
2 * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v. 2.0, which is available at
6 * http://www.eclipse.org/legal/epl-2.0.
8 * This Source Code may also be made available under the following Secondary
9 * Licenses when the conditions for such availability set forth in the
10 * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
11 * version 2 with the GNU Classpath Exception, which is available at
12 * https://www.gnu.org/software/classpath/license.html.
14 * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
17 package com
.sun
.mail
.mbox
;
20 import java
.nio
.charset
.StandardCharsets
;
23 * Convert the various newline conventions to the local platform's
24 * newline convention. Optionally, make sure the output ends with
27 public class NewlineOutputStream
extends FilterOutputStream
{
28 private int lastb
= -1;
29 private int bol
= 1; // number of times in a row we're at beginning of line
30 private final boolean endWithBlankLine
;
31 private static final byte[] newline
;
36 s
= System
.lineSeparator();
37 } catch (SecurityException sex
) {
38 // ignore, should never happen
40 if (s
== null || s
.length() <= 0)
42 newline
= s
.getBytes(StandardCharsets
.ISO_8859_1
);
45 public NewlineOutputStream(OutputStream os
) {
49 public NewlineOutputStream(OutputStream os
, boolean endWithBlankLine
) {
51 this.endWithBlankLine
= endWithBlankLine
;
54 public void write(int b
) throws IOException
{
58 } else if (b
== '\n') {
65 bol
= 0; // no longer at beginning of line
70 public void write(byte b
[]) throws IOException
{
71 write(b
, 0, b
.length
);
74 public void write(byte b
[], int off
, int len
) throws IOException
{
75 for (int i
= 0 ; i
< len
; i
++) {
80 public void flush() throws IOException
{
81 if (endWithBlankLine
) {
83 // not at bol, return to bol and add a blank line
86 } else if (bol
== 1) {
87 // at bol, add a blank line