/** Pop the message before and record current message in the stack. */ void pop() { ByteArrayOutputStream currentMessage = mMessage; int currentPosition = mPosition; mMessage = stack.currentMessage; mPosition = stack.currentPosition; toCopy = stack; // Re using the top element of the stack to avoid memory allocation stack = stack.next; stackSize = stackSize - 1; toCopy.currentMessage = currentMessage; toCopy.currentPosition = currentPosition; }
/** Create a new message buffer and push it into the stack. */ void newbuf() { // You can't create a new buff when toCopy != null // That is after calling pop() and before calling copy() // If you do, it is a bug if (toCopy != null) { throw new RuntimeException("BUG: Invalid newbuf() before copy()"); } LengthRecordNode temp = new LengthRecordNode(); temp.currentMessage = mMessage; temp.currentPosition = mPosition; temp.next = stack; stack = temp; stackSize = stackSize + 1; mMessage = new ByteArrayOutputStream(); mPosition = 0; }