]>
git.argeo.org Git - gpl/argeo-slc.git/blob - ext/javax.mail.mbox/src/com/sun/mail/mbox/ContentLengthCounter.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
;
22 * Count the number of bytes in the body of the message written to the stream.
24 class ContentLengthCounter
extends OutputStream
{
25 private long size
= 0;
26 private boolean inHeader
= true;
27 private int lastb1
= -1, lastb2
= -1;
29 public void write(int b
) throws IOException
{
31 // if line terminator is CR
32 if (b
== '\r' && lastb1
== '\r')
35 // if line terminator is \n
38 // if line terminator is CRLF
39 else if (lastb1
== '\r' && lastb2
== '\n')
48 public void write(byte[] b
) throws IOException
{
55 public void write(byte[] b
, int off
, int len
) throws IOException
{
57 super.write(b
, off
, len
);
62 public long getSize() {
67 public static void main(String argv[]) throws Exception {
69 ContentLengthCounter os = new ContentLengthCounter();
70 while ((b = System.in.read()) >= 0)
72 System.out.println("size " + os.getSize());