public byte[] toByteArray() { int offset = 0; byte[] buf = new byte[getSizeInBytes()]; _base.serialize( buf, offset ); offset += LFOLVLBase.getSize(); if ( _lvl != null ) { byte[] levelBuf = _lvl.toByteArray(); System.arraycopy( levelBuf, 0, buf, offset, levelBuf.length ); } return buf; } }
public byte[] toByteArray() { int offset = 0; byte[] buf = new byte[getSizeInBytes()]; _base.serialize( buf, offset ); offset += LFOLVLBase.getSize(); if ( _lvl != null ) { byte[] levelBuf = _lvl.toByteArray(); System.arraycopy( levelBuf, 0, buf, offset, levelBuf.length ); } return buf; } }
public void writeListDataTo( FileInformationBlock fib, ByteArrayOutputStream tableStream ) throws IOException { final int startOffset = tableStream.size(); fib.setFcPlfLst( startOffset ); int listSize = _listMap.size(); // use this stream as a buffer for the levels since their size varies. ByteArrayOutputStream levelBuf = new ByteArrayOutputStream(); byte[] shortHolder = new byte[2]; LittleEndian.putShort(shortHolder, 0, (short)listSize); tableStream.write(shortHolder); for(ListData lst : _listMap.values()) { tableStream.write(lst.toByteArray()); ListLevel[] lvls = lst.getLevels(); for (int y = 0; y < lvls.length; y++) { levelBuf.write(lvls[y].toByteArray()); } } /* * An array of LVLs is appended to the PlfLst. lcbPlfLst does not * account for the array of LVLs. -- Page 76 of 621 -- [MS-DOC] -- * v20110315 Word (.doc) Binary File Format */ fib.setLcbPlfLst( tableStream.size() - startOffset ); tableStream.write( levelBuf.toByteArray() ); }
public void writeListDataTo( FileInformationBlock fib, HWPFOutputStream tableStream ) throws IOException { final int startOffset = tableStream.getOffset(); fib.setFcPlcfLst( startOffset ); int listSize = _listMap.size(); // use this stream as a buffer for the levels since their size varies. ByteArrayOutputStream levelBuf = new ByteArrayOutputStream(); byte[] shortHolder = new byte[2]; LittleEndian.putShort(shortHolder, (short)listSize); tableStream.write(shortHolder); for(Integer x : _listMap.sortedKeys()) { ListData lst = _listMap.get(x); tableStream.write(lst.toByteArray()); ListLevel[] lvls = lst.getLevels(); for (int y = 0; y < lvls.length; y++) { levelBuf.write(lvls[y].toByteArray()); } } /* * An array of LVLs is appended to the PlfLst. lcbPlfLst does not * account for the array of LVLs. -- Page 76 of 621 -- [MS-DOC] -- * v20110315 Word (.doc) Binary File Format */ fib.setLcbPlcfLst( tableStream.getOffset() - startOffset ); tableStream.write( levelBuf.toByteArray() ); }