1 /*
   2  * Copyright (c) 2000, 2003, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.corba.se.impl.encoding;
  27 
  28 import java.nio.ByteBuffer;
  29 import com.sun.corba.se.spi.orb.ORB;
  30 import com.sun.corba.se.spi.logging.CORBALogDomains;
  31 import com.sun.corba.se.impl.protocol.giopmsgheaders.FragmentMessage;
  32 import com.sun.corba.se.impl.protocol.giopmsgheaders.Message;
  33 import com.sun.corba.se.impl.logging.ORBUtilSystemException;
  34 
  35 public class BufferManagerReadGrow
  36     implements BufferManagerRead, MarkAndResetHandler
  37 {
  38     // REVISIT - This should go in an abstract class called
  39     //           BufferManagerReadBase which should implement
  40     //           BufferManagerRead. Then, this class should extend
  41     //           BufferManagerReadBase.
  42     private ORB orb ;
  43 
  44     private ORBUtilSystemException wrapper ;
  45 
  46     BufferManagerReadGrow( ORB orb )
  47     {
  48         this.orb = orb ;
  49         this.wrapper = ORBUtilSystemException.get( orb,
  50             CORBALogDomains.RPC_ENCODING ) ;
  51     }
  52 
  53     public void processFragment (ByteBuffer byteBuffer, FragmentMessage header)
  54     {
  55         // REVISIT - should we consider throwing an exception similar to what's
  56         //           done for underflow()???
  57     }
  58 
  59     public void init(Message msg) {}
  60 
  61     public ByteBufferWithInfo underflow (ByteBufferWithInfo bbwi)
  62     {
  63         throw wrapper.unexpectedEof() ;
  64     }
  65 
  66     public void cancelProcessing(int requestId) {}
  67 
  68     // Mark and reset handler -------------------------
  69 
  70     private Object streamMemento;
  71     private RestorableInputStream inputStream;
  72     private boolean markEngaged = false;
  73 
  74     public MarkAndResetHandler getMarkAndResetHandler() {
  75         return this;
  76     }
  77 
  78     public void mark(RestorableInputStream is) {
  79         markEngaged = true;
  80         inputStream = is;
  81         streamMemento = inputStream.createStreamMemento();
  82     }
  83 
  84     // This will never happen
  85     public void fragmentationOccured(ByteBufferWithInfo newFragment) {}
  86 
  87     public void reset() {
  88 
  89         if (!markEngaged)
  90             return;
  91 
  92         markEngaged = false;
  93         inputStream.restoreInternalState(streamMemento);
  94         streamMemento = null;
  95     }
  96 
  97     // Nothing to close and cleanup.
  98     public void close(ByteBufferWithInfo bbwi) {}
  99 }