1. /*
  2. * @(#)BufferManagerWriteGrow.java 1.10 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package com.sun.corba.se.internal.iiop;
  8. import java.util.Iterator;
  9. import java.util.NoSuchElementException;
  10. import com.sun.corba.se.internal.orbutil.ORBConstants;
  11. import com.sun.corba.se.internal.iiop.messages.MessageBase;
  12. public class BufferManagerWriteGrow extends BufferManagerWrite
  13. {
  14. private ByteBufferWithInfo _bbwi; // For sending later. REVISIT - iterator
  15. private int initialBufferSize;
  16. public BufferManagerWriteGrow(int initialBufferSize)
  17. {
  18. this.initialBufferSize = initialBufferSize;
  19. }
  20. public ByteBufferWithInfo getInitialBuffer (int size)
  21. {
  22. return new ByteBufferWithInfo(size);
  23. }
  24. public int getInitialBufferSize()
  25. {
  26. return initialBufferSize;
  27. }
  28. public void overflow (ByteBufferWithInfo bbwi)
  29. {
  30. // This code used to live directly in CDROutputStream.grow.
  31. byte[] old = bbwi.buf;
  32. int newLength = old.length * 2;
  33. while (bbwi.index + bbwi.needed >= newLength)
  34. newLength = newLength * 2;
  35. bbwi.buf = new byte[newLength];
  36. System.arraycopy(old, 0, bbwi.buf, 0, old.length);
  37. bbwi.buflen = bbwi.buf.length;
  38. // Must be false for the grow case
  39. bbwi.fragmented = false;
  40. }
  41. public void sendMessage ()
  42. {
  43. IIOPConnection conn = (IIOPConnection)stream.getConnection();
  44. conn.writeLock();
  45. //conn.createOutCallDescriptor(stream.getMessage().getRequestId());
  46. conn.createOutCallDescriptor(MessageBase.getRequestId(stream.getMessage()));
  47. try {
  48. conn.sendWithoutLock(stream);
  49. } finally {
  50. conn.writeUnlock();
  51. }
  52. }
  53. /*
  54. public Iterator iterator ()
  55. {
  56. return new BufferManagerWriteGrowIterator();
  57. }
  58. public class BufferManagerWriteGrowIterator
  59. implements
  60. Iterator
  61. {
  62. private boolean _hasNext = true;
  63. public boolean hasNext ()
  64. {
  65. return _hasNext;
  66. }
  67. public Object next ()
  68. {
  69. if (_hasNext) {
  70. _hasNext = false;
  71. return _bbwi;
  72. }
  73. throw new NoSuchElementException();
  74. }
  75. public void remove ()
  76. {
  77. throw new UnsupportedOperationException();
  78. }
  79. }
  80. */
  81. }