summaryrefslogtreecommitdiff
path: root/java/src/IceInternal/OutputStreamWrapper.java
diff options
context:
space:
mode:
authorMatthew Newhook <matthew@zeroc.com>2014-10-20 11:40:05 -0230
committerMatthew Newhook <matthew@zeroc.com>2014-10-20 11:40:05 -0230
commitb51469b41167fb86ae2059a15cf0475c53fdda7b (patch)
treefc85d6ca2efd89c67e1e4e7438f437c3e08313f4 /java/src/IceInternal/OutputStreamWrapper.java
parentFixed (ICE-5695) - IceSSL: misleading exception (diff)
downloadice-b51469b41167fb86ae2059a15cf0475c53fdda7b.tar.bz2
ice-b51469b41167fb86ae2059a15cf0475c53fdda7b.tar.xz
ice-b51469b41167fb86ae2059a15cf0475c53fdda7b.zip
Down with ant. From the gradle to the grave.
Diffstat (limited to 'java/src/IceInternal/OutputStreamWrapper.java')
-rw-r--r--java/src/IceInternal/OutputStreamWrapper.java178
1 files changed, 0 insertions, 178 deletions
diff --git a/java/src/IceInternal/OutputStreamWrapper.java b/java/src/IceInternal/OutputStreamWrapper.java
deleted file mode 100644
index 722f420603a..00000000000
--- a/java/src/IceInternal/OutputStreamWrapper.java
+++ /dev/null
@@ -1,178 +0,0 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2014 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-
-package IceInternal;
-
-import java.io.*;
-
-//
-// Class to provide a java.io.OutputStream on top of a BasicStream.
-// We use this to serialize arbitrary Java serializable classes into
-//
-// Slice sequences are encoded on the wire as a count of elements, followed
-// by the sequence contents. For arbitrary Java classes, we do not know how
-// big the sequence that is eventually written will be. To avoid excessive
-// data copying, this class mantains a private _bytes array of 254 bytes and,
-// initially, writes data into that array. If more than 254 bytes end up being
-// written, we write a dummy sequence size of 255 (which occupies five bytes
-// on the wire) into the BasicStream and, once this stream is closed, patch
-// that size to match the actual size. Otherwise, if the _bytes buffer contains
-// fewer than 255 bytes when this stream is closed, we write the sequence size
-// as a single byte, followed by the contents of the _bytes buffer.
-//
-
-public class OutputStreamWrapper extends java.io.OutputStream
-{
- public
- OutputStreamWrapper(BasicStream s)
- {
- _s = s;
- _spos = s.pos();
- _bytes = new byte[254];
- _pos = 0;
- }
-
- @Override
- public void
- write(int b) throws IOException
- {
- try
- {
- if(_bytes != null)
- {
- //
- // If we can fit the data into the first 254 bytes, write it to _bytes.
- //
- if(_pos < _bytes.length)
- {
- _bytes[_pos++] = (byte)b;
- return;
- }
-
- _s.writeSize(255); // Dummy size, until we know how big the stream
- // really is and can patch the size.
-
- if(_pos > 0)
- {
- //
- // Write the current contents of _bytes.
- //
- _s.expand(_pos);
- _s.getBuffer().b.put(_bytes, 0, _pos);
- }
- _bytes = null;
- }
-
- //
- // Write data passed by caller.
- //
- _s.expand(1);
- _s.getBuffer().b.put((byte)b);
- _pos += 1;
- }
- catch(java.lang.Exception ex)
- {
- throw new IOException(ex.toString());
- }
- }
-
- @Override
- public void
- write(byte[] b) throws IOException
- {
- write(b, 0, b.length);
- }
-
- @Override
- public void
- write(byte[] bytes, int offset, int count) throws IOException
- {
- try
- {
- if(_bytes != null)
- {
- //
- // If we can fit the data into the first 254 bytes, write it to _bytes.
- //
- if(count <= _bytes.length - _pos)
- {
- System.arraycopy(bytes, offset, _bytes, _pos, count);
- _pos += count;
- return;
- }
-
- _s.writeSize(255); // Dummy size, until we know how big the stream
- // really is and can patch the size.
-
- if(_pos > 0)
- {
- //
- // Write the current contents of _bytes.
- //
- _s.expand(_pos);
- _s.getBuffer().b.put(_bytes, 0, _pos);
- }
- _bytes = null;
- }
-
- //
- // Write data passed by caller.
- //
- _s.expand(count);
- _s.getBuffer().b.put(bytes, offset, count);
- _pos += count;
- }
- catch(java.lang.Exception ex)
- {
- throw new IOException(ex.toString());
- }
- }
-
- @Override
- public void
- flush() throws IOException
- {
- // This does nothing because we do not know the final size of a writable stream until it is closed,
- // and we cannot write to the BasicStream until we know whether the final size is < 255 or not.
- }
-
- @Override
- public void
- close() throws IOException
- {
- try
- {
- if(_bytes != null)
- {
- assert(_pos <= _bytes.length);
- _s.pos(_spos);
- _s.writeSize(_pos);
- _s.expand(_pos);
- _s.getBuffer().b.put(_bytes, 0, _pos);
- _bytes = null;
- }
- else
- {
- int currentPos = _s.pos();
- _s.pos(_spos);
- _s.writeSize(_pos); // Patch previously-written dummy value.
- _s.pos(currentPos);
- }
- }
- catch(java.lang.Exception ex)
- {
- throw new IOException(ex.toString());
- }
- }
-
- private BasicStream _s;
- private int _spos;
- private byte[] _bytes;
- private int _pos;
-}