jdk/src/share/classes/sun/net/www/http/ChunkedOutputStream.java
author xdono
Wed, 02 Jul 2008 12:55:45 -0700
changeset 715 f16baef3a20e
parent 88 b2fea49cad6b
child 1635 8ca7ecc0226d
permissions -rw-r--r--
6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
715
f16baef3a20e 6719955: Update copyright year
xdono
parents: 88
diff changeset
     2
 * Copyright 2004-2008 Sun Microsystems, Inc.  All Rights Reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package sun.net.www.http;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * OutputStream that sends the output to the underlying stream using chunked
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * encoding as specified in RFC 2068.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * @author  Alan Bateman
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
public class ChunkedOutputStream extends PrintStream {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
    /* Default chunk size (including chunk header) if not specified */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    static final int DEFAULT_CHUNK_SIZE = 4096;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    /* internal buffer */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    private byte buf[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    private int count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    /* underlying stream */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    private PrintStream out;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    /* the chunk size we use */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private int preferredChunkSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    /* if the users write buffer is bigger than this size, we
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     * write direct from the users buffer instead of copying
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    static final int MAX_BUF_SIZE = 10 * 1024;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    /* return the size of the header for a particular chunk size */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private int headerSize(int size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        return 2 + (Integer.toHexString(size)).length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    public ChunkedOutputStream(PrintStream o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        this(o, DEFAULT_CHUNK_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    public ChunkedOutputStream(PrintStream o, int size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        super(o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        out = o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        if (size <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            size = DEFAULT_CHUNK_SIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        /* Adjust the size to cater for the chunk header - eg: if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
         * preferred chunk size is 1k this means the chunk size should
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
         * be 1019 bytes (differs by 5 from preferred size because of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
         * 3 bytes for chunk size in hex and CRLF).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        if (size > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            int adjusted_size = size - headerSize(size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            if (adjusted_size + headerSize(adjusted_size) < size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                adjusted_size++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            size = adjusted_size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        if (size > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            preferredChunkSize = size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            preferredChunkSize = DEFAULT_CHUNK_SIZE - headerSize(DEFAULT_CHUNK_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        /* start with an initial buffer */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        buf = new byte[preferredChunkSize + 32];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * If flushAll is true, then all data is flushed in one chunk.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * If false and the size of the buffer data exceeds the preferred
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * chunk size then chunks are flushed to the output stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * If there isn't enough data to make up a complete chunk,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * then the method returns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    private void flush(byte[] buf, boolean flushAll) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        flush (buf, flushAll, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    private void flush(byte[] buf, boolean flushAll, int offset) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        int chunkSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            if (count < preferredChunkSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                if (!flushAll) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                chunkSize = count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                chunkSize = preferredChunkSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            byte[] bytes = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                bytes = (Integer.toHexString(chunkSize)).getBytes("US-ASCII");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            } catch (java.io.UnsupportedEncodingException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                //This should never happen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                throw new InternalError(e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            out.write(bytes, 0, bytes.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            out.write((byte)'\r');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            out.write((byte)'\n');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            if (chunkSize > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                out.write(buf, offset, chunkSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                out.write((byte)'\r');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                out.write((byte)'\n');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            out.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            if (checkError()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            if (chunkSize > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                count -= chunkSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                offset += chunkSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        } while (count > 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        if (!checkError() && count > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            System.arraycopy(buf, offset, this.buf, 0, count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    public boolean checkError() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        return out.checkError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * Check if we have enough data for a chunk and if so flush to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * underlying output stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    private void checkFlush() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        if (count >= preferredChunkSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            flush(buf, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    /* Check that the output stream is still open */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    private void ensureOpen() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        if (out == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            setError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    public synchronized void write(byte b[], int off, int len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        ensureOpen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        if ((off < 0) || (off > b.length) || (len < 0) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            ((off + len) > b.length) || ((off + len) < 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            throw new IndexOutOfBoundsException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        } else if (len == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
88
b2fea49cad6b 6631048: Problem when writing on output stream of HttpURLConnection
chegar
parents: 2
diff changeset
   180
        int l = preferredChunkSize - count;
b2fea49cad6b 6631048: Problem when writing on output stream of HttpURLConnection
chegar
parents: 2
diff changeset
   181
b2fea49cad6b 6631048: Problem when writing on output stream of HttpURLConnection
chegar
parents: 2
diff changeset
   182
        if ((len > MAX_BUF_SIZE) && (len > l)) {
b2fea49cad6b 6631048: Problem when writing on output stream of HttpURLConnection
chegar
parents: 2
diff changeset
   183
            /* current chunk is empty just write the data */
b2fea49cad6b 6631048: Problem when writing on output stream of HttpURLConnection
chegar
parents: 2
diff changeset
   184
            if (count == 0) {
b2fea49cad6b 6631048: Problem when writing on output stream of HttpURLConnection
chegar
parents: 2
diff changeset
   185
                count = len;
b2fea49cad6b 6631048: Problem when writing on output stream of HttpURLConnection
chegar
parents: 2
diff changeset
   186
                flush (b, false, off);
b2fea49cad6b 6631048: Problem when writing on output stream of HttpURLConnection
chegar
parents: 2
diff changeset
   187
                return;
b2fea49cad6b 6631048: Problem when writing on output stream of HttpURLConnection
chegar
parents: 2
diff changeset
   188
            }
b2fea49cad6b 6631048: Problem when writing on output stream of HttpURLConnection
chegar
parents: 2
diff changeset
   189
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            /* first finish the current chunk */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            if (l > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                System.arraycopy(b, off, buf, count, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                count = preferredChunkSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                flush(buf, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            }
88
b2fea49cad6b 6631048: Problem when writing on output stream of HttpURLConnection
chegar
parents: 2
diff changeset
   196
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            count = len - l;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            /* Now write the rest of the data */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            flush (b, false, l+off);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            int newcount = count + len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            if (newcount > buf.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                byte newbuf[] = new byte[Math.max(buf.length << 1, newcount)];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                System.arraycopy(buf, 0, newbuf, 0, count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                buf = newbuf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            System.arraycopy(b, off, buf, count, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            count = newcount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            checkFlush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    public synchronized void write(int b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        ensureOpen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        int newcount = count + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        if (newcount > buf.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            byte newbuf[] = new byte[Math.max(buf.length << 1, newcount)];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            System.arraycopy(buf, 0, newbuf, 0, count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            buf = newbuf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        buf[count] = (byte)b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        count = newcount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        checkFlush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    public synchronized void reset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    public int size() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        return count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    public synchronized void close() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        ensureOpen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        /* if we have buffer a chunked send it */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        if (count > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            flush(buf, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        /* send a zero length chunk */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        flush(buf, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        /* don't close the underlying stream */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        out = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    public synchronized void flush() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        ensureOpen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        if (count > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            flush(buf, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
}