- if(writeBufferIndex < (BUFFER_SIZE-4)) {
- writeBytes[writeBufferIndex++] = (byte)(i&0xff);
- writeBytes[writeBufferIndex++] = (byte)((i>>>8)&0xff);
- writeBytes[writeBufferIndex++] = (byte)((i>>>16)&0xff);
+ int wi = writeBufferIndex;
+ int room = BUFFER_SIZE - wi;
+ switch (room) {
+ case 0:
+ flushWriteBuffer(BUFFER_SIZE);
+ // Intentional fall-through
+ default:
+ writeBytes[wi] = (byte)(i&0xff);
+ writeBytes[wi+1] = (byte)((i>>>8)&0xff);
+ writeBytes[wi+2] = (byte)((i>>>16)&0xff);
+ writeBytes[wi+3] = (byte)((i>>>24)&0xff);
+ writeBufferIndex += 4;
+ break;
+
+ case 4:
+ writeBytes[wi] = (byte)(i&0xff);
+ writeBytes[wi+1] = (byte)((i>>>8)&0xff);
+ writeBytes[wi+2] = (byte)((i>>>16)&0xff);
+ writeBytes[wi+3] = (byte)((i>>>24)&0xff);
+ flushWriteBuffer(BUFFER_SIZE);
+ break;
+
+ case 3:
+ writeBytes[wi] = (byte)(i&0xff);
+ writeBytes[wi+1] = (byte)((i>>>8)&0xff);
+ writeBytes[wi+2] = (byte)((i>>>16)&0xff);
+ flushWriteBuffer(BUFFER_SIZE);