@Override public String toString() { StringBuffer sb = new StringBuffer(); sb.append("partCode="); sb.append(typeCodeToString(this.typeCode)); sb.append(" partLength=" + getLength()); return sb.toString(); }
public byte getByte() { if (!isBytes()) { Assert.assertTrue(false, "expected int part to be of type BYTE, part = " + this.toString()); } if (getLength() != 1) { Assert.assertTrue(false, "expected int length to be 1 but it was " + getLength() + "; part = " + this.toString()); } final byte[] bytes = getSerializedForm(); return bytes[0]; }
if (getLength() > 0) { final int BUF_MAX = buf.capacity(); if (this.part instanceof byte[]) {
public int getInt() { if (!isBytes()) { Assert.assertTrue(false, "expected int part to be of type BYTE, part = " + this.toString()); } if (getLength() != 4) { Assert.assertTrue(false, "expected int length to be 4 but it was " + getLength() + "; part = " + this.toString()); } byte[] bytes = getSerializedForm(); return decodeInt(bytes, 0); }
public long getLong() { if (!isBytes()) { Assert.assertTrue(false, "expected long part to be of type BYTE, part = " + this.toString()); } if (getLength() != 8) { Assert.assertTrue(false, "expected long length to be 8 but it was " + getLength() + "; part = " + this.toString()); } byte[] bytes = getSerializedForm(); return ((((long) bytes[0]) << 56) & 0xFF00000000000000l) | ((((long) bytes[1]) << 48) & 0x00FF000000000000l) | ((((long) bytes[2]) << 40) & 0x0000FF0000000000l) | ((((long) bytes[3]) << 32) & 0x000000FF00000000l) | ((((long) bytes[4]) << 24) & 0x00000000FF000000l) | ((((long) bytes[5]) << 16) & 0x0000000000FF0000l) | ((((long) bytes[6]) << 8) & 0x000000000000FF00l) | (bytes[7] & 0x00000000000000FFl); }
/** * Write the contents of this part to the specified byte buffer. Precondition: caller has already * checked the length of this part and it will fit into "buf". */ public void writeTo(ByteBuffer buf) { if (getLength() > 0) { if (this.part instanceof byte[]) { buf.put((byte[]) this.part); } else if (this.part instanceof StoredObject) { StoredObject c = (StoredObject) this.part; ByteBuffer bb = c.createDirectByteBuffer(); if (bb != null) { buf.put(bb); } else { int bytesToSend = c.getDataSize(); long addr = c.getAddressForReadingData(0, bytesToSend); while (bytesToSend > 0) { buf.put(AddressableMemoryManager.readByte(addr)); addr++; bytesToSend--; } } } else { HeapDataOutputStream hdos = (HeapDataOutputStream) this.part; hdos.sendTo(buf); hdos.rewind(); } } }
/** * geode-1468: Message should clear the chunks in its Parts when performing cleanup. */ @Test public void streamBuffersAreClearedDuringCleanup() throws Exception { Part mockPart1 = mock(Part.class); when(mockPart1.getLength()).thenReturn(100); Part[] parts = new Part[2]; parts[0] = mockPart1; parts[1] = mockPart1; this.message.setParts(parts); this.message.clearParts(); verify(mockPart1, times(2)).clear(); }
if (getLength() > 0) { if (this.part instanceof byte[]) { byte[] bytes = (byte[]) this.part;
@Test public void messageLongerThanMaxIntIsRejected() throws Exception { Part mockPart1 = mock(Part.class); when(mockPart1.getLength()).thenReturn(Integer.MAX_VALUE / 2); Part[] parts = new Part[2]; parts[0] = mockPart1; parts[1] = mockPart1; this.message.setParts(parts); try { this.message.send(); fail("expected an exception but none was thrown"); } catch (MessageTooLargeException e) { assertTrue(e.getMessage().contains("exceeds maximum integer value")); } }
@Test public void maxMessageSizeIsRespected() throws Exception { Part mockPart1 = mock(Part.class); when(mockPart1.getLength()).thenReturn(Message.DEFAULT_MAX_MESSAGE_SIZE / 2); Part[] parts = new Part[2]; parts[0] = mockPart1; parts[1] = mockPart1; this.message.setParts(parts); try { this.message.send(); fail("expected an exception but none was thrown"); } catch (MessageTooLargeException e) { assertFalse(e.getMessage().contains("exceeds maximum integer value")); } }
if (part0.isBytes() && part0.getLength() == 1 && part0.getSerializedForm()[0] == 0) {