Search in sources :

Example 16 with BufferOverflowException

use of java.nio.BufferOverflowException in project voltdb by VoltDB.

the class VoltTable method add.

/**
     * Append a {@link VoltTableRow row} from another <tt>VoltTable</tt>
     * to this VoltTable instance. Technically, it could be from the same
     * table, but this isn't the common usage.
     * @param row {@link VoltTableRow Row} to add.
     */
public final void add(VoltTableRow row) {
    assert (verifyTableInvariants());
    if (m_readOnly) {
        throw new IllegalStateException("Table is read-only. Make a copy before changing.");
    }
    if (m_colCount == 0) {
        throw new IllegalStateException("Table has no columns defined");
    }
    if (row.getColumnCount() != m_colCount) {
        throw new IllegalArgumentException(row.getColumnCount() + " arguments but table has " + m_colCount + " columns");
    }
    // memoize the start of this row in case we roll back
    final int pos = m_buffer.position();
    try {
        // Allow the buffer to grow to max capacity
        m_buffer.limit(m_buffer.capacity());
        byte[] inboundSchemaString = row.getSchemaString();
        byte[] mySchemaString = getSchemaString();
        // The way this works is that when two schema strings are found to have
        // the same value, the target table's reference is pointed at the source
        // table's reference. This allows the copying of multiple rows from one
        // table to another to only do a deep comparison once, and to do reference
        // equivalence checks for subsequent rows.
        boolean canDoRawCopy = (inboundSchemaString == mySchemaString) || Arrays.equals(inboundSchemaString, mySchemaString);
        if (canDoRawCopy) {
            // make them the same object if equal for faster comparison next time
            m_schemaString = inboundSchemaString;
            // raw blit the row (assume the row is valid with proper length)
            ByteBuffer rawRow = row.getRawRow();
            m_buffer.put(rawRow);
        } else {
            // advance the row size value
            m_buffer.position(pos + 4);
            for (int i = 0; i < m_colCount; i++) {
                VoltType inboundType = row.getColumnType(i);
                VoltType outboundType = getColumnType(i);
                if (inboundType == outboundType) {
                    byte[] raw = row.getRaw(i);
                    m_buffer.put(raw);
                } else {
                    Object inboundValue = row.get(i, inboundType);
                    addColumnValue(inboundValue, outboundType, i);
                }
            }
            final int rowsize = m_buffer.position() - pos - 4;
            assert (rowsize >= 0);
            // check for too big rows
            if (rowsize > VoltTableRow.MAX_TUPLE_LENGTH) {
                throw new VoltOverflowException("Table row total length larger than allowed max " + VoltTableRow.MAX_TUPLE_LENGTH_STR);
            }
            // buffer overflow is caught and handled below.
            m_buffer.putInt(pos, rowsize);
        }
        // constrain buffer limit back to the new position
        m_buffer.limit(m_buffer.position());
        // increment the rowcount in the member var and in the buffer
        m_rowCount++;
        m_buffer.putInt(m_rowStart, m_rowCount);
    } catch (VoltTypeException vte) {
        // revert the row size advance and any other
        // buffer additions
        m_buffer.position(pos);
        throw vte;
    } catch (BufferOverflowException e) {
        m_buffer.position(pos);
        expandBuffer();
        add(row);
    }// row was too big, reset and rethrow
     catch (VoltOverflowException e) {
        m_buffer.position(pos);
        throw e;
    } catch (IllegalArgumentException e) {
        // the number 32 was picked out of a hat ( maybe a bug if str > 32 )
        if (m_buffer.limit() - m_buffer.position() < 32) {
            m_buffer.position(pos);
            expandBuffer();
            add(row);
        } else
            throw e;
    }
    assert (verifyTableInvariants());
}
Also used : JSONObject(org.json_voltpatches.JSONObject) BufferOverflowException(java.nio.BufferOverflowException) ByteBuffer(java.nio.ByteBuffer)

Example 17 with BufferOverflowException

use of java.nio.BufferOverflowException in project voltdb by VoltDB.

the class VoltTable method addRow.

/**
     * Append a new row to the table using the supplied column values.
     * @param values Values of each column in the row.
     * @throws VoltTypeException  when there are casting/type failures
     *         between an input value and the corresponding column
     */
public final void addRow(Object... values) {
    assert (verifyTableInvariants());
    if (m_readOnly) {
        throw new IllegalStateException("Table is read-only. Make a copy before changing.");
    }
    if (m_colCount == 0) {
        throw new IllegalStateException("Table has no columns defined");
    }
    if (values.length != m_colCount) {
        throw new IllegalArgumentException(values.length + " arguments but table has " + m_colCount + " columns");
    }
    // memoize the start of this row in case we roll back
    final int pos = m_buffer.position();
    try {
        // Allow the buffer to grow to max capacity
        m_buffer.limit(m_buffer.capacity());
        // advance the row size value
        m_buffer.position(pos + 4);
        // where does the type bytes start
        // skip rowstart + status code + colcount
        int typePos = 4 + 1 + 2;
        for (int col = 0; col < m_colCount; col++) {
            Object value = values[col];
            VoltType columnType = VoltType.get(m_buffer.get(typePos + col));
            addColumnValue(value, columnType, col);
        }
        //
        // Note, there is some near-identical code in both row add methods.
        // [ add(..) and addRow(..) ]
        // If you change code below here, change it in the other method too.
        // (It would be nice to re-factor, but I couldn't make a clean go at
        //  it quickly - Hugg)
        //
        final int rowsize = m_buffer.position() - pos - 4;
        assert (rowsize >= 0);
        // check for too big rows
        if (rowsize > VoltTableRow.MAX_TUPLE_LENGTH) {
            throw new VoltOverflowException("Table row total length larger than allowed max " + VoltTableRow.MAX_TUPLE_LENGTH_STR);
        }
        // buffer overflow is caught and handled below.
        m_buffer.putInt(pos, rowsize);
        m_rowCount++;
        m_buffer.putInt(m_rowStart, m_rowCount);
    } catch (VoltTypeException vte) {
        // revert the row size advance and any other
        // buffer additions
        m_buffer.position(pos);
        throw vte;
    } catch (BufferOverflowException e) {
        m_buffer.position(pos);
        expandBuffer();
        addRow(values);
    }// row was too big, reset and rethrow
     catch (VoltOverflowException e) {
        m_buffer.position(pos);
        throw e;
    } catch (IllegalArgumentException e) {
        m_buffer.position(pos);
        // the number 32 was picked out of a hat ( maybe a bug if str > 32 )
        if (m_buffer.limit() - m_buffer.position() < 32) {
            expandBuffer();
            addRow(values);
        } else
            throw e;
    } finally {
        // constrain buffer limit back to the new position
        m_buffer.limit(m_buffer.position());
    }
    assert (verifyTableInvariants());
}
Also used : JSONObject(org.json_voltpatches.JSONObject) BufferOverflowException(java.nio.BufferOverflowException)

Example 18 with BufferOverflowException

use of java.nio.BufferOverflowException in project voltdb by VoltDB.

the class StoredProcedureInvocation method serializeParams.

private void serializeParams(ByteBuffer buf) throws IOException {
    if (serializedParams != null) {
        if (serializedParams.hasArray()) {
            // would be wrong?
            assert (serializedParams.position() == 0);
            buf.put(serializedParams.array(), serializedParams.position() + serializedParams.arrayOffset(), serializedParams.remaining());
        } else {
            // duplicate for thread-safety
            assert (serializedParams.position() == 0);
            ByteBuffer dup = serializedParams.duplicate();
            dup.rewind();
            buf.put(dup);
        }
    } else if (params != null) {
        try {
            getParams().flattenToBuffer(buf);
        } catch (BufferOverflowException e) {
            hostLog.info("SP \"" + procName + "\" has thrown BufferOverflowException");
            hostLog.info(toString());
            throw e;
        }
    }
}
Also used : BufferOverflowException(java.nio.BufferOverflowException) ByteBuffer(java.nio.ByteBuffer)

Example 19 with BufferOverflowException

use of java.nio.BufferOverflowException in project android_frameworks_base by ResurrectionRemix.

the class RouterAdvertisementDaemon method assembleRaLocked.

private void assembleRaLocked() {
    final ByteBuffer ra = ByteBuffer.wrap(mRA);
    ra.order(ByteOrder.BIG_ENDIAN);
    boolean shouldSendRA = false;
    try {
        putHeader(ra, mRaParams != null && mRaParams.hasDefaultRoute);
        putSlla(ra, mHwAddr);
        mRaLength = ra.position();
        if (mRaParams != null) {
            putMtu(ra, mRaParams.mtu);
            mRaLength = ra.position();
            for (IpPrefix ipp : mRaParams.prefixes) {
                putPio(ra, ipp, DEFAULT_LIFETIME, DEFAULT_LIFETIME);
                mRaLength = ra.position();
                shouldSendRA = true;
            }
            if (mRaParams.dnses.size() > 0) {
                putRdnss(ra, mRaParams.dnses, DEFAULT_LIFETIME);
                mRaLength = ra.position();
                shouldSendRA = true;
            }
        }
        for (IpPrefix ipp : mDeprecatedInfoTracker.getPrefixes()) {
            putPio(ra, ipp, 0, 0);
            mRaLength = ra.position();
            shouldSendRA = true;
        }
        final Set<Inet6Address> deprecatedDnses = mDeprecatedInfoTracker.getDnses();
        if (!deprecatedDnses.isEmpty()) {
            putRdnss(ra, deprecatedDnses, 0);
            mRaLength = ra.position();
            shouldSendRA = true;
        }
    } catch (BufferOverflowException e) {
        // The packet up to mRaLength  is valid, since it has been updated
        // progressively as the RA was built. Log an error, and continue
        // on as best as possible.
        Log.e(TAG, "Could not construct new RA: " + e);
    }
    // We have nothing worth announcing; indicate as much to maybeSendRA().
    if (!shouldSendRA) {
        mRaLength = 0;
    }
}
Also used : IpPrefix(android.net.IpPrefix) Inet6Address(java.net.Inet6Address) BufferOverflowException(java.nio.BufferOverflowException) ByteBuffer(java.nio.ByteBuffer)

Example 20 with BufferOverflowException

use of java.nio.BufferOverflowException in project azure-iot-sdk-java by Azure.

the class AmqpSendHandlerTest method createProtonObjects.

private void createProtonObjects() {
    String exceptionMessage = "Not expected function called";
    message = Proton.message();
    messageWithException = new Message() {

        @Override
        public boolean isDurable() {
            return false;
        }

        @Override
        public long getDeliveryCount() {
            return 0;
        }

        @Override
        public short getPriority() {
            return 0;
        }

        @Override
        public boolean isFirstAcquirer() {
            return false;
        }

        @Override
        public long getTtl() {
            return 0;
        }

        @Override
        public void setDurable(boolean b) {
        }

        @Override
        public void setTtl(long l) {
        }

        @Override
        public void setDeliveryCount(long l) {
        }

        @Override
        public void setFirstAcquirer(boolean b) {
        }

        @Override
        public void setPriority(short i) {
        }

        @Override
        public Object getMessageId() {
            return null;
        }

        @Override
        public long getGroupSequence() {
            return 0;
        }

        @Override
        public String getReplyToGroupId() {
            return null;
        }

        @Override
        public long getCreationTime() {
            return 0;
        }

        @Override
        public String getAddress() {
            return null;
        }

        @Override
        public byte[] getUserId() {
            return new byte[0];
        }

        @Override
        public String getReplyTo() {
            return null;
        }

        @Override
        public String getGroupId() {
            return null;
        }

        @Override
        public String getContentType() {
            return null;
        }

        @Override
        public long getExpiryTime() {
            return 0;
        }

        @Override
        public Object getCorrelationId() {
            return null;
        }

        @Override
        public String getContentEncoding() {
            return null;
        }

        @Override
        public String getSubject() {
            return null;
        }

        @Override
        public void setGroupSequence(long l) {
        }

        @Override
        public void setUserId(byte[] bytes) {
        }

        @Override
        public void setCreationTime(long l) {
        }

        @Override
        public void setSubject(String s) {
        }

        @Override
        public void setGroupId(String s) {
        }

        @Override
        public void setAddress(String s) {
        }

        @Override
        public void setExpiryTime(long l) {
        }

        @Override
        public void setReplyToGroupId(String s) {
        }

        @Override
        public void setContentEncoding(String s) {
        }

        @Override
        public void setContentType(String s) {
        }

        @Override
        public void setReplyTo(String s) {
        }

        @Override
        public void setCorrelationId(Object o) {
        }

        @Override
        public void setMessageId(Object o) {
        }

        @Override
        public Header getHeader() {
            return null;
        }

        @Override
        public DeliveryAnnotations getDeliveryAnnotations() {
            return null;
        }

        @Override
        public MessageAnnotations getMessageAnnotations() {
            return null;
        }

        @Override
        public Properties getProperties() {
            return null;
        }

        @Override
        public ApplicationProperties getApplicationProperties() {
            return null;
        }

        @Override
        public Section getBody() {
            return null;
        }

        @Override
        public Footer getFooter() {
            return null;
        }

        @Override
        public void setHeader(Header header) {
        }

        @Override
        public void setDeliveryAnnotations(DeliveryAnnotations deliveryAnnotations) {
        }

        @Override
        public void setMessageAnnotations(MessageAnnotations messageAnnotations) {
        }

        @Override
        public void setProperties(Properties properties) {
        }

        @Override
        public void setApplicationProperties(ApplicationProperties applicationProperties) {
        }

        @Override
        public void setBody(Section section) {
        }

        @Override
        public void setFooter(Footer footer) {
        }

        @Override
        public int decode(byte[] bytes, int i, int i1) {
            return 0;
        }

        @Override
        public int encode(byte[] bytes, int i, int i1) {
            if (exceptionCount == 0) {
                exceptionCount++;
                throw new BufferOverflowException();
            } else {
                return 0;
            }
        }

        @Override
        public void clear() {
        }

        @Override
        public MessageError getError() {
            return null;
        }
    };
    sender = new Sender() {

        @Override
        public Record attachments() {
            return null;
        }

        @Override
        public EndpointState getLocalState() {
            return null;
        }

        @Override
        public EndpointState getRemoteState() {
            return null;
        }

        @Override
        public ErrorCondition getCondition() {
            return null;
        }

        @Override
        public void setCondition(ErrorCondition errorCondition) {
        }

        @Override
        public ErrorCondition getRemoteCondition() {
            return null;
        }

        @Override
        public void free() {
        }

        @Override
        public void open() {
        }

        @Override
        public void close() {
        }

        @Override
        public void setContext(Object o) {
        }

        @Override
        public Object getContext() {
            return null;
        }

        @Override
        public void offer(int i) {
        }

        @Override
        public int send(byte[] bytes, int i, int i1) {
            return 0;
        }

        @Override
        public int send(ReadableBuffer readableBuffer) {
            return 0;
        }

        @Override
        public void abort() {
        }

        @Override
        public String getName() {
            return null;
        }

        @Override
        public Delivery delivery(byte[] bytes) {
            return delivery;
        }

        @Override
        public Delivery delivery(byte[] bytes, int i, int i1) {
            return null;
        }

        @Override
        public Delivery head() {
            return null;
        }

        @Override
        public Delivery current() {
            return null;
        }

        @Override
        public boolean advance() {
            return false;
        }

        @Override
        public Source getSource() {
            return null;
        }

        @Override
        public org.apache.qpid.proton.amqp.transport.Target getTarget() {
            return null;
        }

        @Override
        public void setSource(Source source) {
        }

        @Override
        public void setTarget(org.apache.qpid.proton.amqp.transport.Target target) {
        }

        @Override
        public Source getRemoteSource() {
            return null;
        }

        @Override
        public org.apache.qpid.proton.amqp.transport.Target getRemoteTarget() {
            return null;
        }

        @Override
        public Link next(EnumSet<EndpointState> enumSet, EnumSet<EndpointState> enumSet1) {
            return null;
        }

        @Override
        public int getCredit() {
            return 1;
        }

        @Override
        public int getQueued() {
            return 0;
        }

        @Override
        public int getUnsettled() {
            return 0;
        }

        @Override
        public Session getSession() {
            return session;
        }

        @Override
        public SenderSettleMode getSenderSettleMode() {
            return null;
        }

        @Override
        public void setSenderSettleMode(SenderSettleMode senderSettleMode) {
        }

        @Override
        public SenderSettleMode getRemoteSenderSettleMode() {
            return null;
        }

        @Override
        public ReceiverSettleMode getReceiverSettleMode() {
            return null;
        }

        @Override
        public void setReceiverSettleMode(ReceiverSettleMode receiverSettleMode) {
        }

        @Override
        public ReceiverSettleMode getRemoteReceiverSettleMode() {
            return null;
        }

        @Override
        public void setRemoteSenderSettleMode(SenderSettleMode senderSettleMode) {
        }

        @Override
        public Map<Symbol, Object> getProperties() {
            return null;
        }

        @Override
        public void setProperties(Map<Symbol, Object> map) {
        }

        @Override
        public Map<Symbol, Object> getRemoteProperties() {
            return null;
        }

        @Override
        public int drained() {
            return 0;
        }

        @Override
        public int getRemoteCredit() {
            return 0;
        }

        @Override
        public boolean getDrain() {
            return false;
        }

        @Override
        public void detach() {
        }

        @Override
        public boolean detached() {
            return false;
        }

        @Override
        public void setOfferedCapabilities(Symbol[] symbols) {
        }

        @Override
        public Symbol[] getOfferedCapabilities() {
            return new Symbol[0];
        }

        @Override
        public Symbol[] getRemoteOfferedCapabilities() {
            return new Symbol[0];
        }

        @Override
        public void setDesiredCapabilities(Symbol[] symbols) {
        }

        @Override
        public Symbol[] getDesiredCapabilities() {
            return new Symbol[0];
        }

        @Override
        public Symbol[] getRemoteDesiredCapabilities() {
            return new Symbol[0];
        }
    };
    event = new Event() {

        @Override
        public EventType getEventType() {
            return null;
        }

        @Override
        public Event.Type getType() {
            throw new UnsupportedOperationException(exceptionMessage);
        }

        @Override
        public Object getContext() {
            throw new UnsupportedOperationException(exceptionMessage);
        }

        @Override
        public Handler getRootHandler() {
            return null;
        }

        @Override
        public void dispatch(Handler hndlr) throws HandlerException {
            throw new UnsupportedOperationException(exceptionMessage);
        }

        @Override
        public void redispatch(EventType eventType, Handler handler) throws HandlerException {
        }

        @Override
        public void delegate() throws HandlerException {
        }

        @Override
        public Connection getConnection() {
            return connection;
        }

        @Override
        public Session getSession() {
            throw new UnsupportedOperationException(exceptionMessage);
        }

        @Override
        public Link getLink() {
            return sender;
        }

        @Override
        public Sender getSender() {
            return null;
        }

        @Override
        public Receiver getReceiver() {
            return null;
        }

        @Override
        public Delivery getDelivery() {
            throw new UnsupportedOperationException(exceptionMessage);
        }

        @Override
        public Transport getTransport() {
            throw new UnsupportedOperationException(exceptionMessage);
        }

        @Override
        public Reactor getReactor() {
            throw new UnsupportedOperationException(exceptionMessage);
        }

        @Override
        public Selectable getSelectable() {
            throw new UnsupportedOperationException(exceptionMessage);
        }

        @Override
        public Task getTask() {
            throw new UnsupportedOperationException(exceptionMessage);
        }

        @Override
        public Event copy() {
            throw new UnsupportedOperationException(exceptionMessage);
        }

        @Override
        public Record attachments() {
            throw new UnsupportedOperationException(exceptionMessage);
        }
    };
}
Also used : Task(org.apache.qpid.proton.reactor.Task) ReadableBuffer(org.apache.qpid.proton.codec.ReadableBuffer) Reactor(org.apache.qpid.proton.reactor.Reactor) AmqpSendHandler(com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpSendHandler) Message(org.apache.qpid.proton.message.Message) Symbol(org.apache.qpid.proton.amqp.Symbol) Properties(org.apache.qpid.proton.amqp.messaging.Properties) Source(org.apache.qpid.proton.amqp.transport.Source) Target(org.apache.qpid.proton.amqp.messaging.Target) MessageError(org.apache.qpid.proton.message.MessageError) Selectable(org.apache.qpid.proton.reactor.Selectable) BufferOverflowException(java.nio.BufferOverflowException) org.apache.qpid.proton.amqp.transport(org.apache.qpid.proton.amqp.transport)

Aggregations

BufferOverflowException (java.nio.BufferOverflowException)78 ByteBuffer (java.nio.ByteBuffer)27 ShortBufferException (javax.crypto.ShortBufferException)10 CharBuffer (java.nio.CharBuffer)9 ShortBuffer (java.nio.ShortBuffer)7 Test (org.junit.Test)7 FloatBuffer (java.nio.FloatBuffer)6 IntBuffer (java.nio.IntBuffer)6 IOException (java.io.IOException)5 BufferUnderflowException (java.nio.BufferUnderflowException)5 ReadOnlyBufferException (java.nio.ReadOnlyBufferException)5 IpPrefix (android.net.IpPrefix)4 Inet6Address (java.net.Inet6Address)4 DoubleBuffer (java.nio.DoubleBuffer)4 LongBuffer (java.nio.LongBuffer)4 MappedByteBuffer (java.nio.MappedByteBuffer)4 Pointer (com.cetsoft.imcache.offheap.bytebuffer.Pointer)2 EOFException (java.io.EOFException)2 CoderResult (java.nio.charset.CoderResult)2 JSONObject (org.json_voltpatches.JSONObject)2