git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1797838 13f79535-47bb-0310-9956-ffa450edef68tags/REL_3_17_BETA1
==================================================================== */ | ==================================================================== */ | ||||
package org.apache.poi.hwpf.model; | package org.apache.poi.hwpf.model; | ||||
import java.io.ByteArrayOutputStream; | |||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import java.util.Arrays; | import java.util.Arrays; | ||||
import java.util.List; | import java.util.List; | ||||
import org.apache.poi.hwpf.model.io.HWPFOutputStream; | |||||
import org.apache.poi.util.Internal; | import org.apache.poi.util.Internal; | ||||
import org.apache.poi.util.POILogFactory; | import org.apache.poi.util.POILogFactory; | ||||
import org.apache.poi.util.POILogger; | import org.apache.poi.util.POILogger; | ||||
} | } | ||||
public void writePlcfBkmkf( FileInformationBlock fib, | public void writePlcfBkmkf( FileInformationBlock fib, | ||||
HWPFOutputStream tableStream ) throws IOException | |||||
ByteArrayOutputStream tableStream ) throws IOException | |||||
{ | { | ||||
if ( descriptorsFirst == null || descriptorsFirst.length() == 0 ) | if ( descriptorsFirst == null || descriptorsFirst.length() == 0 ) | ||||
{ | { | ||||
return; | return; | ||||
} | } | ||||
int start = tableStream.getOffset(); | |||||
int start = tableStream.size(); | |||||
tableStream.write( descriptorsFirst.toByteArray() ); | tableStream.write( descriptorsFirst.toByteArray() ); | ||||
int end = tableStream.getOffset(); | |||||
int end = tableStream.size(); | |||||
fib.setFcPlcfbkf( start ); | fib.setFcPlcfbkf( start ); | ||||
fib.setLcbPlcfbkf( end - start ); | fib.setLcbPlcfbkf( end - start ); | ||||
} | } | ||||
public void writePlcfBkmkl( FileInformationBlock fib, | public void writePlcfBkmkl( FileInformationBlock fib, | ||||
HWPFOutputStream tableStream ) throws IOException | |||||
ByteArrayOutputStream tableStream ) throws IOException | |||||
{ | { | ||||
if ( descriptorsLim == null || descriptorsLim.length() == 0 ) | if ( descriptorsLim == null || descriptorsLim.length() == 0 ) | ||||
{ | { | ||||
return; | return; | ||||
} | } | ||||
int start = tableStream.getOffset(); | |||||
int start = tableStream.size(); | |||||
tableStream.write( descriptorsLim.toByteArray() ); | tableStream.write( descriptorsLim.toByteArray() ); | ||||
int end = tableStream.getOffset(); | |||||
int end = tableStream.size(); | |||||
fib.setFcPlcfbkl( start ); | fib.setFcPlcfbkl( start ); | ||||
fib.setLcbPlcfbkl( end - start ); | fib.setLcbPlcfbkl( end - start ); | ||||
} | } | ||||
public void writeSttbfBkmk( FileInformationBlock fib, | public void writeSttbfBkmk( FileInformationBlock fib, | ||||
HWPFOutputStream tableStream ) throws IOException | |||||
ByteArrayOutputStream tableStream ) throws IOException | |||||
{ | { | ||||
if ( names == null || names.isEmpty() ) | if ( names == null || names.isEmpty() ) | ||||
{ | { | ||||
return; | return; | ||||
} | } | ||||
int start = tableStream.getOffset(); | |||||
int start = tableStream.size(); | |||||
SttbUtils.writeSttbfBkmk( names.toArray( new String[names.size()] ), | SttbUtils.writeSttbfBkmk( names.toArray( new String[names.size()] ), | ||||
tableStream ); | tableStream ); | ||||
int end = tableStream.getOffset(); | |||||
int end = tableStream.size(); | |||||
fib.setFcSttbfbkmk( start ); | fib.setFcSttbfbkmk( start ); | ||||
fib.setLcbSttbfbkmk( end - start ); | fib.setLcbSttbfbkmk( end - start ); |
package org.apache.poi.hwpf.model; | package org.apache.poi.hwpf.model; | ||||
import java.io.ByteArrayOutputStream; | |||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import java.util.Arrays; | import java.util.Arrays; | ||||
import java.util.Set; | import java.util.Set; | ||||
import org.apache.poi.hwpf.model.io.HWPFFileSystem; | import org.apache.poi.hwpf.model.io.HWPFFileSystem; | ||||
import org.apache.poi.hwpf.model.io.HWPFOutputStream; | |||||
import org.apache.poi.hwpf.sprm.SprmBuffer; | import org.apache.poi.hwpf.sprm.SprmBuffer; | ||||
import org.apache.poi.hwpf.sprm.SprmIterator; | import org.apache.poi.hwpf.sprm.SprmIterator; | ||||
import org.apache.poi.hwpf.sprm.SprmOperation; | import org.apache.poi.hwpf.sprm.SprmOperation; | ||||
public void writeTo( HWPFFileSystem sys, int fcMin, | public void writeTo( HWPFFileSystem sys, int fcMin, | ||||
CharIndexTranslator translator ) throws IOException | CharIndexTranslator translator ) throws IOException | ||||
{ | { | ||||
HWPFOutputStream docStream = sys.getStream( "WordDocument" ); | |||||
HWPFOutputStream tableStream = sys.getStream( "1Table" ); | |||||
ByteArrayOutputStream docStream = sys.getStream( "WordDocument" ); | |||||
ByteArrayOutputStream tableStream = sys.getStream( "1Table" ); | |||||
writeTo( docStream, tableStream, fcMin, translator ); | writeTo( docStream, tableStream, fcMin, translator ); | ||||
} | } | ||||
public void writeTo( HWPFOutputStream wordDocumentStream, | |||||
HWPFOutputStream tableStream, int fcMin, | |||||
public void writeTo( ByteArrayOutputStream wordDocumentStream, | |||||
ByteArrayOutputStream tableStream, int fcMin, | |||||
CharIndexTranslator translator ) throws IOException | CharIndexTranslator translator ) throws IOException | ||||
{ | { | ||||
PlexOfCps bte = new PlexOfCps( 4 ); | PlexOfCps bte = new PlexOfCps( 4 ); | ||||
// each FKP must start on a 512 byte page. | // each FKP must start on a 512 byte page. | ||||
int docOffset = wordDocumentStream.getOffset(); | |||||
int docOffset = wordDocumentStream.size(); | |||||
int mod = docOffset % POIFSConstants.SMALLER_BIG_BLOCK_SIZE; | int mod = docOffset % POIFSConstants.SMALLER_BIG_BLOCK_SIZE; | ||||
if (mod != 0) | if (mod != 0) | ||||
{ | { | ||||
} | } | ||||
// get the page number for the first fkp | // get the page number for the first fkp | ||||
docOffset = wordDocumentStream.getOffset(); | |||||
docOffset = wordDocumentStream.size(); | |||||
int pageNum = docOffset/POIFSConstants.SMALLER_BIG_BLOCK_SIZE; | int pageNum = docOffset/POIFSConstants.SMALLER_BIG_BLOCK_SIZE; | ||||
// get the ending fc | // get the ending fc |
package org.apache.poi.hwpf.model; | package org.apache.poi.hwpf.model; | ||||
import java.io.ByteArrayOutputStream; | |||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.nio.charset.Charset; | import java.nio.charset.Charset; | ||||
import java.util.LinkedList; | import java.util.LinkedList; | ||||
import java.util.List; | import java.util.List; | ||||
import org.apache.poi.hwpf.model.io.HWPFFileSystem; | import org.apache.poi.hwpf.model.io.HWPFFileSystem; | ||||
import org.apache.poi.hwpf.model.io.HWPFOutputStream; | |||||
import org.apache.poi.hwpf.sprm.SprmBuffer; | import org.apache.poi.hwpf.sprm.SprmBuffer; | ||||
import org.apache.poi.util.Internal; | import org.apache.poi.util.Internal; | ||||
import org.apache.poi.util.LittleEndian; | import org.apache.poi.util.LittleEndian; | ||||
@Deprecated | @Deprecated | ||||
public void writeTo(HWPFFileSystem sys) throws IOException { | public void writeTo(HWPFFileSystem sys) throws IOException { | ||||
HWPFOutputStream docStream = sys.getStream("WordDocument"); | |||||
HWPFOutputStream tableStream = sys.getStream("1Table"); | |||||
ByteArrayOutputStream docStream = sys.getStream("WordDocument"); | |||||
ByteArrayOutputStream tableStream = sys.getStream("1Table"); | |||||
writeTo(docStream, tableStream); | writeTo(docStream, tableStream); | ||||
} | } | ||||
public void writeTo(HWPFOutputStream wordDocumentStream, | |||||
HWPFOutputStream tableStream) throws IOException { | |||||
public void writeTo(ByteArrayOutputStream wordDocumentStream, | |||||
ByteArrayOutputStream tableStream) throws IOException { | |||||
tableStream.write(TEXT_PIECE_TABLE_TYPE); | tableStream.write(TEXT_PIECE_TABLE_TYPE); | ||||
byte[] table = _tpt.writeTo(wordDocumentStream); | byte[] table = _tpt.writeTo(wordDocumentStream); |
package org.apache.poi.hwpf.model; | package org.apache.poi.hwpf.model; | ||||
import java.io.ByteArrayOutputStream; | |||||
import java.io.IOException; | import java.io.IOException; | ||||
import org.apache.poi.hwpf.model.io.HWPFOutputStream; | |||||
import org.apache.poi.hwpf.model.types.DOPAbstractType; | import org.apache.poi.hwpf.model.types.DOPAbstractType; | ||||
import org.apache.poi.util.Internal; | import org.apache.poi.util.Internal; | ||||
import org.apache.poi.util.LittleEndian; | import org.apache.poi.util.LittleEndian; | ||||
super.serialize( data, offset ); | super.serialize( data, offset ); | ||||
} | } | ||||
public void writeTo( HWPFOutputStream tableStream ) throws IOException | |||||
public void writeTo( ByteArrayOutputStream tableStream ) throws IOException | |||||
{ | { | ||||
byte[] supported = new byte[getSize()]; | byte[] supported = new byte[getSize()]; | ||||
serialize( supported, 0 ); | serialize( supported, 0 ); |
package org.apache.poi.hwpf.model; | package org.apache.poi.hwpf.model; | ||||
import java.io.ByteArrayOutputStream; | |||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.util.Arrays; | import java.util.Arrays; | ||||
import java.util.HashMap; | import java.util.HashMap; | ||||
import java.util.HashSet; | import java.util.HashSet; | ||||
import java.util.Map; | import java.util.Map; | ||||
import org.apache.poi.hwpf.model.io.HWPFOutputStream; | |||||
import org.apache.poi.util.Internal; | import org.apache.poi.util.Internal; | ||||
import org.apache.poi.util.LittleEndian; | import org.apache.poi.util.LittleEndian; | ||||
import org.apache.poi.util.POILogFactory; | import org.apache.poi.util.POILogFactory; | ||||
return _fields.length / 2; | return _fields.length / 2; | ||||
} | } | ||||
void writeTo(byte[] mainStream, int offset, HWPFOutputStream tableStream) | |||||
void writeTo(byte[] mainStream, int offset, ByteArrayOutputStream tableStream) | |||||
throws IOException | throws IOException | ||||
{ | { | ||||
for (int x = 0; x < _fields.length/2; x++) | for (int x = 0; x < _fields.length/2; x++) | ||||
UnhandledDataStructure ds = _unknownMap.get(Integer.valueOf(x)); | UnhandledDataStructure ds = _unknownMap.get(Integer.valueOf(x)); | ||||
if (ds != null) | if (ds != null) | ||||
{ | { | ||||
_fields[x * 2] = tableStream.getOffset(); | |||||
LittleEndian.putInt(mainStream, offset, tableStream.getOffset()); | |||||
_fields[x * 2] = tableStream.size(); | |||||
LittleEndian.putInt(mainStream, offset, tableStream.size()); | |||||
offset += LittleEndian.INT_SIZE; | offset += LittleEndian.INT_SIZE; | ||||
byte[] buf = ds.getBuf(); | byte[] buf = ds.getBuf(); |
package org.apache.poi.hwpf.model; | package org.apache.poi.hwpf.model; | ||||
import java.io.ByteArrayOutputStream; | |||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import java.util.HashMap; | import java.util.HashMap; | ||||
import java.util.Map; | import java.util.Map; | ||||
import org.apache.poi.hwpf.model.io.HWPFOutputStream; | |||||
import org.apache.poi.util.Internal; | import org.apache.poi.util.Internal; | ||||
/** | /** | ||||
} | } | ||||
private int savePlex( FileInformationBlock fib, FieldsDocumentPart part, | private int savePlex( FileInformationBlock fib, FieldsDocumentPart part, | ||||
PlexOfCps plexOfCps, HWPFOutputStream outputStream ) | |||||
PlexOfCps plexOfCps, ByteArrayOutputStream outputStream ) | |||||
throws IOException | throws IOException | ||||
{ | { | ||||
if ( plexOfCps == null || plexOfCps.length() == 0 ) | if ( plexOfCps == null || plexOfCps.length() == 0 ) | ||||
{ | { | ||||
fib.setFieldsPlcfOffset( part, outputStream.getOffset() ); | |||||
fib.setFieldsPlcfOffset( part, outputStream.size() ); | |||||
fib.setFieldsPlcfLength( part, 0 ); | fib.setFieldsPlcfLength( part, 0 ); | ||||
return 0; | return 0; | ||||
} | } | ||||
byte[] data = plexOfCps.toByteArray(); | byte[] data = plexOfCps.toByteArray(); | ||||
int start = outputStream.getOffset(); | |||||
int start = outputStream.size(); | |||||
int length = data.length; | int length = data.length; | ||||
outputStream.write( data ); | outputStream.write( data ); | ||||
return length; | return length; | ||||
} | } | ||||
public void write( FileInformationBlock fib, HWPFOutputStream tableStream ) | |||||
public void write( FileInformationBlock fib, ByteArrayOutputStream tableStream ) | |||||
throws IOException | throws IOException | ||||
{ | { | ||||
for ( FieldsDocumentPart part : FieldsDocumentPart.values() ) | for ( FieldsDocumentPart part : FieldsDocumentPart.values() ) |
package org.apache.poi.hwpf.model; | package org.apache.poi.hwpf.model; | ||||
import java.io.ByteArrayOutputStream; | |||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.lang.reflect.Method; | import java.lang.reflect.Method; | ||||
import java.lang.reflect.Modifier; | import java.lang.reflect.Modifier; | ||||
import java.util.HashSet; | import java.util.HashSet; | ||||
import java.util.Locale; | import java.util.Locale; | ||||
import org.apache.poi.EncryptedDocumentException; | |||||
import org.apache.poi.hwpf.model.io.HWPFOutputStream; | |||||
import org.apache.poi.util.Internal; | import org.apache.poi.util.Internal; | ||||
import org.apache.poi.util.LittleEndian; | import org.apache.poi.util.LittleEndian; | ||||
import org.apache.poi.util.POILogFactory; | import org.apache.poi.util.POILogFactory; | ||||
offset = FibBase.getSize(); | offset = FibBase.getSize(); | ||||
assert offset == 32; | assert offset == 32; | ||||
if ( _fibBase.isFEncrypted() ) | |||||
{ | |||||
throw new EncryptedDocumentException( | |||||
"Cannot process encrypted word file" ); | |||||
} | |||||
_csw = LittleEndian.getUShort( mainDocument, offset ); | _csw = LittleEndian.getUShort( mainDocument, offset ); | ||||
offset += LittleEndian.SHORT_SIZE; | offset += LittleEndian.SHORT_SIZE; | ||||
assert offset == 34; | assert offset == 34; | ||||
offset ); | offset ); | ||||
} | } | ||||
public void writeTo( byte[] mainStream, HWPFOutputStream tableStream ) | |||||
public void writeTo( byte[] mainStream, ByteArrayOutputStream tableStream ) | |||||
throws IOException | throws IOException | ||||
{ | { | ||||
_cbRgFcLcb = _fieldHandler.getFieldsCount(); | _cbRgFcLcb = _fieldHandler.getFieldsCount(); |
package org.apache.poi.hwpf.model; | package org.apache.poi.hwpf.model; | ||||
import java.io.ByteArrayOutputStream; | |||||
import java.io.IOException; | import java.io.IOException; | ||||
import org.apache.poi.hwpf.model.io.HWPFFileSystem; | import org.apache.poi.hwpf.model.io.HWPFFileSystem; | ||||
import org.apache.poi.hwpf.model.io.HWPFOutputStream; | |||||
import org.apache.poi.util.Internal; | import org.apache.poi.util.Internal; | ||||
import org.apache.poi.util.LittleEndian; | import org.apache.poi.util.LittleEndian; | ||||
import org.apache.poi.util.POILogFactory; | import org.apache.poi.util.POILogFactory; | ||||
@Deprecated | @Deprecated | ||||
public void writeTo( HWPFFileSystem sys ) throws IOException | public void writeTo( HWPFFileSystem sys ) throws IOException | ||||
{ | { | ||||
HWPFOutputStream tableStream = sys.getStream( "1Table" ); | |||||
ByteArrayOutputStream tableStream = sys.getStream( "1Table" ); | |||||
writeTo( tableStream ); | writeTo( tableStream ); | ||||
} | } | ||||
public void writeTo( HWPFOutputStream tableStream ) throws IOException | |||||
public void writeTo( ByteArrayOutputStream tableStream ) throws IOException | |||||
{ | { | ||||
byte[] buf = new byte[LittleEndian.SHORT_SIZE]; | byte[] buf = new byte[LittleEndian.SHORT_SIZE]; | ||||
LittleEndian.putShort(buf, 0, _stringCount); | LittleEndian.putShort(buf, 0, _stringCount); |
*/ | */ | ||||
package org.apache.poi.hwpf.model; | package org.apache.poi.hwpf.model; | ||||
import java.io.ByteArrayOutputStream; | |||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.util.Arrays; | import java.util.Arrays; | ||||
import org.apache.poi.hwpf.model.io.HWPFOutputStream; | |||||
import org.apache.poi.util.Internal; | import org.apache.poi.util.Internal; | ||||
import org.apache.poi.util.LittleEndian; | import org.apache.poi.util.LittleEndian; | ||||
return result; | return result; | ||||
} | } | ||||
void writeTo( HWPFOutputStream tableStream ) throws IOException | |||||
void writeTo( ByteArrayOutputStream tableStream ) throws IOException | |||||
{ | { | ||||
LittleEndian.putInt( _cp, tableStream ); | LittleEndian.putInt( _cp, tableStream ); | ||||
for ( ListFormatOverrideLevel lfolvl : _rgLfoLvl ) | for ( ListFormatOverrideLevel lfolvl : _rgLfoLvl ) |
import java.util.LinkedHashMap; | import java.util.LinkedHashMap; | ||||
import java.util.NoSuchElementException; | import java.util.NoSuchElementException; | ||||
import org.apache.poi.hwpf.model.io.HWPFOutputStream; | |||||
import org.apache.poi.util.Internal; | import org.apache.poi.util.Internal; | ||||
import org.apache.poi.util.LittleEndian; | import org.apache.poi.util.LittleEndian; | ||||
import org.apache.poi.util.POILogFactory; | import org.apache.poi.util.POILogFactory; | ||||
} | } | ||||
public void writeListDataTo( FileInformationBlock fib, | public void writeListDataTo( FileInformationBlock fib, | ||||
HWPFOutputStream tableStream ) throws IOException | |||||
ByteArrayOutputStream tableStream ) throws IOException | |||||
{ | { | ||||
final int startOffset = tableStream.getOffset(); | |||||
final int startOffset = tableStream.size(); | |||||
fib.setFcPlfLst( startOffset ); | fib.setFcPlfLst( startOffset ); | ||||
int listSize = _listMap.size(); | int listSize = _listMap.size(); | ||||
* account for the array of LVLs. -- Page 76 of 621 -- [MS-DOC] -- | * account for the array of LVLs. -- Page 76 of 621 -- [MS-DOC] -- | ||||
* v20110315 Word (.doc) Binary File Format | * v20110315 Word (.doc) Binary File Format | ||||
*/ | */ | ||||
fib.setLcbPlfLst( tableStream.getOffset() - startOffset ); | |||||
fib.setLcbPlfLst( tableStream.size() - startOffset ); | |||||
tableStream.write( levelBuf.toByteArray() ); | tableStream.write( levelBuf.toByteArray() ); | ||||
} | } | ||||
public void writeListOverridesTo( FileInformationBlock fib, | public void writeListOverridesTo( FileInformationBlock fib, | ||||
HWPFOutputStream tableStream ) throws IOException | |||||
ByteArrayOutputStream tableStream ) throws IOException | |||||
{ | { | ||||
_plfLfo.writeTo( fib, tableStream ); | _plfLfo.writeTo( fib, tableStream ); | ||||
} | } |
==================================================================== */ | ==================================================================== */ | ||||
package org.apache.poi.hwpf.model; | package org.apache.poi.hwpf.model; | ||||
import java.io.ByteArrayOutputStream; | |||||
import java.io.IOException; | import java.io.IOException; | ||||
import org.apache.poi.hwpf.model.io.HWPFOutputStream; | |||||
import org.apache.poi.util.Internal; | import org.apache.poi.util.Internal; | ||||
/** | /** | ||||
textPositionsStart, textPositionsLength, 0 ); | textPositionsStart, textPositionsLength, 0 ); | ||||
} | } | ||||
public void writeRef( FileInformationBlock fib, HWPFOutputStream tableStream ) | |||||
public void writeRef( FileInformationBlock fib, ByteArrayOutputStream tableStream ) | |||||
throws IOException | throws IOException | ||||
{ | { | ||||
if ( descriptors == null || descriptors.length() == 0 ) | if ( descriptors == null || descriptors.length() == 0 ) | ||||
{ | { | ||||
fib.setNotesDescriptorsOffset( noteType, tableStream.getOffset() ); | |||||
fib.setNotesDescriptorsOffset( noteType, tableStream.size() ); | |||||
fib.setNotesDescriptorsSize( noteType, 0 ); | fib.setNotesDescriptorsSize( noteType, 0 ); | ||||
return; | return; | ||||
} | } | ||||
int start = tableStream.getOffset(); | |||||
int start = tableStream.size(); | |||||
tableStream.write( descriptors.toByteArray() ); | tableStream.write( descriptors.toByteArray() ); | ||||
int end = tableStream.getOffset(); | |||||
int end = tableStream.size(); | |||||
fib.setNotesDescriptorsOffset( noteType, start ); | fib.setNotesDescriptorsOffset( noteType, start ); | ||||
fib.setNotesDescriptorsSize( noteType, end - start ); | fib.setNotesDescriptorsSize( noteType, end - start ); | ||||
} | } | ||||
public void writeTxt( FileInformationBlock fib, HWPFOutputStream tableStream ) | |||||
public void writeTxt( FileInformationBlock fib, ByteArrayOutputStream tableStream ) | |||||
throws IOException | throws IOException | ||||
{ | { | ||||
if ( textPositions == null || textPositions.length() == 0 ) | if ( textPositions == null || textPositions.length() == 0 ) | ||||
{ | { | ||||
fib.setNotesTextPositionsOffset( noteType, tableStream.getOffset() ); | |||||
fib.setNotesTextPositionsOffset( noteType, tableStream.size() ); | |||||
fib.setNotesTextPositionsSize( noteType, 0 ); | fib.setNotesTextPositionsSize( noteType, 0 ); | ||||
return; | return; | ||||
} | } | ||||
int start = tableStream.getOffset(); | |||||
int start = tableStream.size(); | |||||
tableStream.write( textPositions.toByteArray() ); | tableStream.write( textPositions.toByteArray() ); | ||||
int end = tableStream.getOffset(); | |||||
int end = tableStream.size(); | |||||
fib.setNotesTextPositionsOffset( noteType, start ); | fib.setNotesTextPositionsOffset( noteType, start ); | ||||
fib.setNotesTextPositionsSize( noteType, end - start ); | fib.setNotesTextPositionsSize( noteType, end - start ); |
package org.apache.poi.hwpf.model; | package org.apache.poi.hwpf.model; | ||||
import java.io.ByteArrayOutputStream; | |||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import java.util.Collections; | import java.util.Collections; | ||||
import java.util.List; | import java.util.List; | ||||
import java.util.Map; | import java.util.Map; | ||||
import org.apache.poi.hwpf.model.io.HWPFOutputStream; | |||||
import org.apache.poi.hwpf.sprm.SprmBuffer; | import org.apache.poi.hwpf.sprm.SprmBuffer; | ||||
import org.apache.poi.hwpf.sprm.SprmIterator; | import org.apache.poi.hwpf.sprm.SprmIterator; | ||||
import org.apache.poi.hwpf.sprm.SprmOperation; | import org.apache.poi.hwpf.sprm.SprmOperation; | ||||
return _paragraphs; | return _paragraphs; | ||||
} | } | ||||
public void writeTo( HWPFOutputStream wordDocumentStream, | |||||
HWPFOutputStream tableStream, CharIndexTranslator translator ) | |||||
public void writeTo( ByteArrayOutputStream wordDocumentStream, | |||||
ByteArrayOutputStream tableStream, CharIndexTranslator translator ) | |||||
throws IOException | throws IOException | ||||
{ | { | ||||
PlexOfCps binTable = new PlexOfCps(4); | PlexOfCps binTable = new PlexOfCps(4); | ||||
// each FKP must start on a 512 byte page. | // each FKP must start on a 512 byte page. | ||||
int docOffset = wordDocumentStream.getOffset(); | |||||
int docOffset = wordDocumentStream.size(); | |||||
int mod = docOffset % POIFSConstants.SMALLER_BIG_BLOCK_SIZE; | int mod = docOffset % POIFSConstants.SMALLER_BIG_BLOCK_SIZE; | ||||
if (mod != 0) | if (mod != 0) | ||||
{ | { | ||||
} | } | ||||
// get the page number for the first fkp | // get the page number for the first fkp | ||||
docOffset = wordDocumentStream.getOffset(); | |||||
docOffset = wordDocumentStream.size(); | |||||
int pageNum = docOffset/POIFSConstants.SMALLER_BIG_BLOCK_SIZE; | int pageNum = docOffset/POIFSConstants.SMALLER_BIG_BLOCK_SIZE; | ||||
// get the ending fc | // get the ending fc |
package org.apache.poi.hwpf.model; | package org.apache.poi.hwpf.model; | ||||
import java.io.ByteArrayOutputStream; | |||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import java.util.Arrays; | import java.util.Arrays; | ||||
import java.util.Collections; | import java.util.Collections; | ||||
import java.util.List; | import java.util.List; | ||||
import org.apache.poi.hwpf.model.io.HWPFOutputStream; | |||||
import org.apache.poi.util.Internal; | import org.apache.poi.util.Internal; | ||||
import org.apache.poi.util.LittleEndian; | import org.apache.poi.util.LittleEndian; | ||||
* @throws IOException | * @throws IOException | ||||
* if an I/O error occurs. | * if an I/O error occurs. | ||||
*/ | */ | ||||
protected byte[] toByteArray( HWPFOutputStream dataStream, | |||||
protected byte[] toByteArray( ByteArrayOutputStream dataStream, | |||||
CharIndexTranslator translator ) throws IOException | CharIndexTranslator translator ) throws IOException | ||||
{ | { | ||||
byte[] buf = new byte[512]; | byte[] buf = new byte[512]; | ||||
byte[] hugePapx = new byte[grpprl.length - 2]; | byte[] hugePapx = new byte[grpprl.length - 2]; | ||||
System.arraycopy( grpprl, 2, hugePapx, 0, grpprl.length - 2 ); | System.arraycopy( grpprl, 2, hugePapx, 0, grpprl.length - 2 ); | ||||
int dataStreamOffset = dataStream.getOffset(); | |||||
int dataStreamOffset = dataStream.size(); | |||||
dataStream.write( hugePapx ); | dataStream.write( hugePapx ); | ||||
// grpprl = grpprl containing only a sprmPHugePapx2 | // grpprl = grpprl containing only a sprmPHugePapx2 |
*/ | */ | ||||
package org.apache.poi.hwpf.model; | package org.apache.poi.hwpf.model; | ||||
import java.io.ByteArrayOutputStream; | |||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.util.Arrays; | import java.util.Arrays; | ||||
import java.util.NoSuchElementException; | import java.util.NoSuchElementException; | ||||
import org.apache.poi.hwpf.model.io.HWPFOutputStream; | |||||
import org.apache.poi.util.LittleEndian; | import org.apache.poi.util.LittleEndian; | ||||
import org.apache.poi.util.POILogFactory; | import org.apache.poi.util.POILogFactory; | ||||
import org.apache.poi.util.POILogger; | import org.apache.poi.util.POILogger; | ||||
return result; | return result; | ||||
} | } | ||||
void writeTo( FileInformationBlock fib, HWPFOutputStream outputStream ) | |||||
void writeTo( FileInformationBlock fib, ByteArrayOutputStream outputStream ) | |||||
throws IOException | throws IOException | ||||
{ | { | ||||
final int offset = outputStream.getOffset(); | |||||
final int offset = outputStream.size(); | |||||
fib.setFcPlfLfo( offset ); | fib.setFcPlfLfo( offset ); | ||||
LittleEndian.putUInt( _lfoMac, outputStream ); | LittleEndian.putUInt( _lfoMac, outputStream ); | ||||
{ | { | ||||
_rgLfoData[i].writeTo( outputStream ); | _rgLfoData[i].writeTo( outputStream ); | ||||
} | } | ||||
fib.setLcbPlfLfo( outputStream.getOffset() - offset ); | |||||
fib.setLcbPlfLfo( outputStream.size() - offset ); | |||||
} | } | ||||
} | } |
package org.apache.poi.hwpf.model; | package org.apache.poi.hwpf.model; | ||||
import java.io.ByteArrayOutputStream; | |||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.util.Arrays; | import java.util.Arrays; | ||||
import java.util.Collections; | import java.util.Collections; | ||||
import java.util.List; | import java.util.List; | ||||
import org.apache.poi.hwpf.model.io.HWPFOutputStream; | |||||
import org.apache.poi.util.Internal; | import org.apache.poi.util.Internal; | ||||
/** | /** | ||||
* @param tableStream the table stream to write to. | * @param tableStream the table stream to write to. | ||||
* @throws IOException if an error occurs while writing. | * @throws IOException if an error occurs while writing. | ||||
*/ | */ | ||||
public void writeTo( HWPFOutputStream tableStream ) throws IOException | |||||
public void writeTo( ByteArrayOutputStream tableStream ) throws IOException | |||||
{ | { | ||||
SttbUtils.writeSttbfRMark( entries, tableStream ); | SttbUtils.writeSttbfRMark( entries, tableStream ); | ||||
} | } |
==================================================================== */ | ==================================================================== */ | ||||
package org.apache.poi.hwpf.model; | package org.apache.poi.hwpf.model; | ||||
import java.io.ByteArrayOutputStream; | |||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.util.Arrays; | import java.util.Arrays; | ||||
import java.util.Collections; | import java.util.Collections; | ||||
import java.util.List; | import java.util.List; | ||||
import org.apache.poi.hwpf.model.io.HWPFOutputStream; | |||||
import org.apache.poi.util.Internal; | import org.apache.poi.util.Internal; | ||||
/** | /** | ||||
* @throws IOException | * @throws IOException | ||||
* if an error occurs while writing. | * if an error occurs while writing. | ||||
*/ | */ | ||||
public void writeTo( HWPFOutputStream tableStream ) throws IOException | |||||
public void writeTo( ByteArrayOutputStream tableStream ) throws IOException | |||||
{ | { | ||||
String[] toSave = new String[entries.length * 2]; | String[] toSave = new String[entries.length * 2]; | ||||
int counter = 0; | int counter = 0; |
package org.apache.poi.hwpf.model; | package org.apache.poi.hwpf.model; | ||||
import java.io.ByteArrayOutputStream; | |||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import java.util.Collections; | import java.util.Collections; | ||||
import java.util.List; | import java.util.List; | ||||
import org.apache.poi.hwpf.model.io.HWPFFileSystem; | import org.apache.poi.hwpf.model.io.HWPFFileSystem; | ||||
import org.apache.poi.hwpf.model.io.HWPFOutputStream; | |||||
import org.apache.poi.util.Internal; | import org.apache.poi.util.Internal; | ||||
import org.apache.poi.util.LittleEndian; | import org.apache.poi.util.LittleEndian; | ||||
import org.apache.poi.util.POILogFactory; | import org.apache.poi.util.POILogFactory; | ||||
@Deprecated | @Deprecated | ||||
public void writeTo( HWPFFileSystem sys, int fcMin ) throws IOException | public void writeTo( HWPFFileSystem sys, int fcMin ) throws IOException | ||||
{ | { | ||||
HWPFOutputStream docStream = sys.getStream( "WordDocument" ); | |||||
HWPFOutputStream tableStream = sys.getStream( "1Table" ); | |||||
ByteArrayOutputStream docStream = sys.getStream( "WordDocument" ); | |||||
ByteArrayOutputStream tableStream = sys.getStream( "1Table" ); | |||||
writeTo( docStream, tableStream ); | writeTo( docStream, tableStream ); | ||||
} | } | ||||
public void writeTo( | public void writeTo( | ||||
HWPFOutputStream wordDocumentStream, | |||||
HWPFOutputStream tableStream ) throws IOException | |||||
ByteArrayOutputStream wordDocumentStream, | |||||
ByteArrayOutputStream tableStream ) throws IOException | |||||
{ | { | ||||
int offset = wordDocumentStream.getOffset(); | |||||
int offset = wordDocumentStream.size(); | |||||
int len = _sections.size(); | int len = _sections.size(); | ||||
PlexOfCps plex = new PlexOfCps(SED_SIZE); | PlexOfCps plex = new PlexOfCps(SED_SIZE); | ||||
plex.addProperty(property); | plex.addProperty(property); | ||||
offset = wordDocumentStream.getOffset(); | |||||
offset = wordDocumentStream.size(); | |||||
} | } | ||||
tableStream.write(plex.toByteArray()); | tableStream.write(plex.toByteArray()); | ||||
} | } |
package org.apache.poi.hwpf.model; | package org.apache.poi.hwpf.model; | ||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.io.OutputStream; | |||||
import org.apache.poi.hwpf.model.io.HWPFOutputStream; | |||||
import org.apache.poi.util.Internal; | import org.apache.poi.util.Internal; | ||||
/** | /** | ||||
.getData(); | .getData(); | ||||
} | } | ||||
static void writeSttbfBkmk( String[] data, HWPFOutputStream tableStream ) | |||||
static void writeSttbfBkmk( String[] data, OutputStream tableStream ) | |||||
throws IOException | throws IOException | ||||
{ | { | ||||
tableStream.write( new Sttb( CDATA_SIZE_STTBF_BKMK, data ).serialize() ); | tableStream.write( new Sttb( CDATA_SIZE_STTBF_BKMK, data ).serialize() ); | ||||
} | } | ||||
static void writeSttbfRMark( String[] data, HWPFOutputStream tableStream ) | |||||
static void writeSttbfRMark( String[] data, OutputStream tableStream ) | |||||
throws IOException | throws IOException | ||||
{ | { | ||||
tableStream.write( new Sttb( CDATA_SIZE_STTBF_R_MARK, data ) | |||||
.serialize() ); | |||||
tableStream.write( new Sttb( CDATA_SIZE_STTBF_R_MARK, data ).serialize() ); | |||||
} | } | ||||
static void writeSttbSavedBy( String[] data, HWPFOutputStream tableStream ) | |||||
static void writeSttbSavedBy( String[] data, OutputStream tableStream ) | |||||
throws IOException | throws IOException | ||||
{ | { | ||||
tableStream.write( new Sttb( CDATA_SIZE_STTB_SAVED_BY, data ) | |||||
.serialize() ); | |||||
tableStream.write( new Sttb( CDATA_SIZE_STTB_SAVED_BY, data ).serialize() ); | |||||
} | } | ||||
} | } |
package org.apache.poi.hwpf.model; | package org.apache.poi.hwpf.model; | ||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.io.OutputStream; | |||||
import org.apache.poi.hwpf.model.io.HWPFOutputStream; | |||||
import org.apache.poi.hwpf.sprm.CharacterSprmUncompressor; | import org.apache.poi.hwpf.sprm.CharacterSprmUncompressor; | ||||
import org.apache.poi.hwpf.sprm.ParagraphSprmUncompressor; | import org.apache.poi.hwpf.sprm.ParagraphSprmUncompressor; | ||||
import org.apache.poi.hwpf.usermodel.CharacterProperties; | import org.apache.poi.hwpf.usermodel.CharacterProperties; | ||||
} | } | ||||
} | } | ||||
public void writeTo(HWPFOutputStream out) | |||||
public void writeTo(OutputStream out) | |||||
throws IOException | throws IOException | ||||
{ | { | ||||
==================================================================== */ | ==================================================================== */ | ||||
package org.apache.poi.hwpf.model; | package org.apache.poi.hwpf.model; | ||||
import java.io.ByteArrayOutputStream; | |||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.io.Serializable; | import java.io.Serializable; | ||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import java.util.LinkedList; | import java.util.LinkedList; | ||||
import java.util.List; | import java.util.List; | ||||
import org.apache.poi.hwpf.model.io.HWPFOutputStream; | |||||
import org.apache.poi.poifs.common.POIFSConstants; | import org.apache.poi.poifs.common.POIFSConstants; | ||||
import org.apache.poi.util.Internal; | import org.apache.poi.util.Internal; | ||||
import org.apache.poi.util.POILogFactory; | import org.apache.poi.util.POILogFactory; | ||||
return _textPiecesFCOrder.get(low + 1).getPieceDescriptor().getFilePosition(); | return _textPiecesFCOrder.get(low + 1).getPieceDescriptor().getFilePosition(); | ||||
} | } | ||||
public byte[] writeTo(HWPFOutputStream docStream) throws IOException { | |||||
public byte[] writeTo(ByteArrayOutputStream docStream) throws IOException { | |||||
PlexOfCps textPlex = new PlexOfCps(PieceDescriptor.getSizeInBytes()); | PlexOfCps textPlex = new PlexOfCps(PieceDescriptor.getSizeInBytes()); | ||||
// int fcMin = docStream.getOffset(); | // int fcMin = docStream.getOffset(); | ||||
for (TextPiece next : _textPieces) { | for (TextPiece next : _textPieces) { | ||||
PieceDescriptor pd = next.getPieceDescriptor(); | PieceDescriptor pd = next.getPieceDescriptor(); | ||||
int offset = docStream.getOffset(); | |||||
int offset = docStream.size(); | |||||
int mod = (offset % POIFSConstants.SMALLER_BIG_BLOCK_SIZE); | int mod = (offset % POIFSConstants.SMALLER_BIG_BLOCK_SIZE); | ||||
if (mod != 0) { | if (mod != 0) { | ||||
mod = POIFSConstants.SMALLER_BIG_BLOCK_SIZE - mod; | mod = POIFSConstants.SMALLER_BIG_BLOCK_SIZE - mod; | ||||
} | } | ||||
// set the text piece position to the current docStream offset. | // set the text piece position to the current docStream offset. | ||||
pd.setFilePosition(docStream.getOffset()); | |||||
pd.setFilePosition(docStream.size()); | |||||
// write the text to the docstream and save the piece descriptor to | // write the text to the docstream and save the piece descriptor to | ||||
// the | // the |
package org.apache.poi.hwpf.model.io; | package org.apache.poi.hwpf.model.io; | ||||
import java.io.ByteArrayOutputStream; | |||||
import java.util.HashMap; | import java.util.HashMap; | ||||
import java.util.Map; | import java.util.Map; | ||||
@Internal | @Internal | ||||
public final class HWPFFileSystem | public final class HWPFFileSystem | ||||
{ | { | ||||
Map<String, HWPFOutputStream> _streams = new HashMap<String, HWPFOutputStream>(); | |||||
private Map<String, ByteArrayOutputStream> _streams = new HashMap<String, ByteArrayOutputStream>(); | |||||
public HWPFFileSystem() | public HWPFFileSystem() | ||||
{ | { | ||||
_streams.put("WordDocument", new HWPFOutputStream()); | |||||
_streams.put("1Table", new HWPFOutputStream()); | |||||
_streams.put("Data", new HWPFOutputStream()); | |||||
_streams.put("WordDocument", new ByteArrayOutputStream()); | |||||
_streams.put("1Table", new ByteArrayOutputStream()); | |||||
_streams.put("Data", new ByteArrayOutputStream()); | |||||
} | } | ||||
public HWPFOutputStream getStream(String name) | |||||
public ByteArrayOutputStream getStream(String name) | |||||
{ | { | ||||
return _streams.get(name); | return _streams.get(name); | ||||
} | } |
/* ==================================================================== | |||||
Licensed to the Apache Software Foundation (ASF) under one or more | |||||
contributor license agreements. See the NOTICE file distributed with | |||||
this work for additional information regarding copyright ownership. | |||||
The ASF licenses this file to You under the Apache License, Version 2.0 | |||||
(the "License"); you may not use this file except in compliance with | |||||
the License. You may obtain a copy of the License at | |||||
http://www.apache.org/licenses/LICENSE-2.0 | |||||
Unless required by applicable law or agreed to in writing, software | |||||
distributed under the License is distributed on an "AS IS" BASIS, | |||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||||
See the License for the specific language governing permissions and | |||||
limitations under the License. | |||||
==================================================================== */ | |||||
package org.apache.poi.hwpf.model.io; | |||||
import java.io.ByteArrayOutputStream; | |||||
import org.apache.poi.util.Internal; | |||||
@Internal | |||||
public final class HWPFOutputStream extends ByteArrayOutputStream { | |||||
int _offset; | |||||
public HWPFOutputStream() { | |||||
super(); | |||||
} | |||||
public int getOffset() { | |||||
return _offset; | |||||
} | |||||
public synchronized void reset() { | |||||
super.reset(); | |||||
_offset = 0; | |||||
} | |||||
public synchronized void write(byte[] buf, int off, int len) { | |||||
super.write(buf, off, len); | |||||
_offset += len; | |||||
} | |||||
public synchronized void write(int b) { | |||||
super.write(b); | |||||
_offset++; | |||||
} | |||||
} |
package org.apache.poi.hwpf.model; | package org.apache.poi.hwpf.model; | ||||
import junit.framework.*; | |||||
import org.apache.poi.hwpf.*; | |||||
import org.apache.poi.hwpf.model.io.*; | |||||
import static org.junit.Assert.assertTrue; | |||||
public final class TestFontTable | |||||
extends TestCase | |||||
{ | |||||
import java.io.ByteArrayOutputStream; | |||||
import java.io.IOException; | |||||
import org.apache.poi.hwpf.HWPFDocFixture; | |||||
import org.apache.poi.hwpf.model.io.HWPFFileSystem; | |||||
import org.junit.After; | |||||
import org.junit.Before; | |||||
import org.junit.Test; | |||||
public final class TestFontTable { | |||||
private FontTable _fontTable = null; | private FontTable _fontTable = null; | ||||
private HWPFDocFixture _hWPFDocFixture; | private HWPFDocFixture _hWPFDocFixture; | ||||
public void testReadWrite() | |||||
throws Exception | |||||
{ | |||||
@Test | |||||
public void testReadWrite() throws IOException { | |||||
FileInformationBlock fib = _hWPFDocFixture._fib; | FileInformationBlock fib = _hWPFDocFixture._fib; | ||||
byte[] tableStream = _hWPFDocFixture._tableStream; | byte[] tableStream = _hWPFDocFixture._tableStream; | ||||
HWPFFileSystem fileSys = new HWPFFileSystem(); | HWPFFileSystem fileSys = new HWPFFileSystem(); | ||||
_fontTable.writeTo(fileSys); | _fontTable.writeTo(fileSys); | ||||
HWPFOutputStream tableOut = fileSys.getStream("1Table"); | |||||
ByteArrayOutputStream tableOut = fileSys.getStream("1Table"); | |||||
byte[] newTableStream = tableOut.toByteArray(); | byte[] newTableStream = tableOut.toByteArray(); | ||||
} | } | ||||
@Override | |||||
protected void setUp() | |||||
throws Exception | |||||
{ | |||||
super.setUp(); | |||||
/**@todo verify the constructors*/ | |||||
@Before | |||||
public void setUp() throws IOException { | |||||
_hWPFDocFixture = new HWPFDocFixture(this, HWPFDocFixture.DEFAULT_TEST_FILE); | _hWPFDocFixture = new HWPFDocFixture(this, HWPFDocFixture.DEFAULT_TEST_FILE); | ||||
_hWPFDocFixture.setUp(); | _hWPFDocFixture.setUp(); | ||||
} | } | ||||
@Override | |||||
protected void tearDown() | |||||
throws Exception | |||||
{ | |||||
@After | |||||
public void tearDown() throws IOException { | |||||
_hWPFDocFixture.tearDown(); | _hWPFDocFixture.tearDown(); | ||||
_hWPFDocFixture = null; | |||||
super.tearDown(); | |||||
} | } | ||||
} | } |
import static org.junit.Assert.assertEquals; | import static org.junit.Assert.assertEquals; | ||||
import java.io.ByteArrayOutputStream; | |||||
import java.io.IOException; | import java.io.IOException; | ||||
import org.apache.poi.hwpf.HWPFTestCase; | import org.apache.poi.hwpf.HWPFTestCase; | ||||
import org.apache.poi.hwpf.model.io.HWPFFileSystem; | import org.apache.poi.hwpf.model.io.HWPFFileSystem; | ||||
import org.apache.poi.hwpf.model.io.HWPFOutputStream; | |||||
import org.junit.Test; | import org.junit.Test; | ||||
public final class TestListTables extends HWPFTestCase { | public final class TestListTables extends HWPFTestCase { | ||||
ListTables listTables = new ListTables(tableStream, listOffset, lfoOffset, bLfoOffset); | ListTables listTables = new ListTables(tableStream, listOffset, lfoOffset, bLfoOffset); | ||||
HWPFFileSystem fileSys = new HWPFFileSystem(); | HWPFFileSystem fileSys = new HWPFFileSystem(); | ||||
HWPFOutputStream tableOut = fileSys.getStream("1Table"); | |||||
ByteArrayOutputStream tableOut = fileSys.getStream("1Table"); | |||||
listTables.writeListDataTo(fib, tableOut); | listTables.writeListDataTo(fib, tableOut); | ||||
listTables.writeListOverridesTo(fib, tableOut); | listTables.writeListOverridesTo(fib, tableOut); |
package org.apache.poi.hwpf.model; | package org.apache.poi.hwpf.model; | ||||
import java.util.List; | |||||
import static org.junit.Assert.assertEquals; | |||||
import static org.junit.Assert.assertTrue; | |||||
import junit.framework.TestCase; | |||||
import java.io.ByteArrayOutputStream; | |||||
import java.io.IOException; | |||||
import java.util.List; | |||||
import org.apache.poi.hwpf.HWPFDocFixture; | import org.apache.poi.hwpf.HWPFDocFixture; | ||||
import org.apache.poi.hwpf.HWPFTestDataSamples; | import org.apache.poi.hwpf.HWPFTestDataSamples; | ||||
import org.apache.poi.hwpf.model.io.HWPFFileSystem; | import org.apache.poi.hwpf.model.io.HWPFFileSystem; | ||||
import org.apache.poi.hwpf.model.io.HWPFOutputStream; | |||||
import org.junit.Test; | |||||
public final class TestPAPBinTable extends TestCase | |||||
{ | |||||
public final class TestPAPBinTable { | |||||
public void testObIs() | |||||
{ | |||||
@Test | |||||
public void testObIs() throws IOException { | |||||
// shall not fail with assertions on | // shall not fail with assertions on | ||||
HWPFTestDataSamples.openSampleFile( "ob_is.doc" ); | |||||
HWPFTestDataSamples.openSampleFile( "ob_is.doc" ).close();; | |||||
} | } | ||||
public void testReadWrite() throws Exception | |||||
{ | |||||
@Test | |||||
public void testReadWrite() throws IOException { | |||||
/** @todo verify the constructors */ | /** @todo verify the constructors */ | ||||
HWPFDocFixture _hWPFDocFixture = new HWPFDocFixture( this, | |||||
HWPFDocFixture.DEFAULT_TEST_FILE ); | |||||
HWPFDocFixture _hWPFDocFixture = new HWPFDocFixture( this, HWPFDocFixture.DEFAULT_TEST_FILE ); | |||||
_hWPFDocFixture.setUp(); | _hWPFDocFixture.setUp(); | ||||
TextPieceTable fakeTPT = new TextPieceTable(); | TextPieceTable fakeTPT = new TextPieceTable(); | ||||
null, fib.getFcPlcfbtePapx(), fib.getLcbPlcfbtePapx(), fakeTPT ); | null, fib.getFcPlcfbtePapx(), fib.getLcbPlcfbtePapx(), fakeTPT ); | ||||
HWPFFileSystem fileSys = new HWPFFileSystem(); | HWPFFileSystem fileSys = new HWPFFileSystem(); | ||||
HWPFOutputStream tableOut = fileSys.getStream( "1Table" ); | |||||
HWPFOutputStream mainOut = fileSys.getStream( "WordDocument" ); | |||||
ByteArrayOutputStream tableOut = fileSys.getStream( "1Table" ); | |||||
ByteArrayOutputStream mainOut = fileSys.getStream( "WordDocument" ); | |||||
_pAPBinTable.writeTo( mainOut, tableOut, fakeTPT ); | _pAPBinTable.writeTo( mainOut, tableOut, fakeTPT ); | ||||
byte[] newTableStream = tableOut.toByteArray(); | byte[] newTableStream = tableOut.toByteArray(); |
package org.apache.poi.hwpf.model; | package org.apache.poi.hwpf.model; | ||||
import junit.framework.*; | |||||
import static org.junit.Assert.assertEquals; | |||||
import org.apache.poi.hwpf.*; | |||||
import org.apache.poi.hwpf.model.io.*; | |||||
import java.io.ByteArrayOutputStream; | |||||
import java.io.IOException; | |||||
public final class TestStyleSheet | |||||
extends TestCase | |||||
{ | |||||
import org.apache.poi.hwpf.HWPFDocFixture; | |||||
import org.apache.poi.hwpf.model.io.HWPFFileSystem; | |||||
import org.junit.After; | |||||
import org.junit.Before; | |||||
import org.junit.Test; | |||||
public final class TestStyleSheet { | |||||
private StyleSheet _styleSheet = null; | private StyleSheet _styleSheet = null; | ||||
private HWPFDocFixture _hWPFDocFixture; | private HWPFDocFixture _hWPFDocFixture; | ||||
public void testReadWrite() | |||||
throws Exception | |||||
@Test | |||||
public void testReadWrite() throws IOException | |||||
{ | { | ||||
HWPFFileSystem fileSys = new HWPFFileSystem(); | HWPFFileSystem fileSys = new HWPFFileSystem(); | ||||
HWPFOutputStream tableOut = fileSys.getStream("1Table"); | |||||
HWPFOutputStream mainOut = fileSys.getStream("WordDocument"); | |||||
ByteArrayOutputStream tableOut = fileSys.getStream("1Table"); | |||||
ByteArrayOutputStream mainOut = fileSys.getStream("WordDocument"); | |||||
_styleSheet.writeTo(tableOut); | _styleSheet.writeTo(tableOut); | ||||
StyleSheet newStyleSheet = new StyleSheet(newTableStream, 0); | StyleSheet newStyleSheet = new StyleSheet(newTableStream, 0); | ||||
assertEquals(newStyleSheet, _styleSheet); | assertEquals(newStyleSheet, _styleSheet); | ||||
} | } | ||||
public void testReadWriteFromNonZeroOffset() | |||||
throws Exception | |||||
@Test | |||||
public void testReadWriteFromNonZeroOffset() throws IOException | |||||
{ | { | ||||
HWPFFileSystem fileSys = new HWPFFileSystem(); | HWPFFileSystem fileSys = new HWPFFileSystem(); | ||||
HWPFOutputStream tableOut = fileSys.getStream("1Table"); | |||||
ByteArrayOutputStream tableOut = fileSys.getStream("1Table"); | |||||
tableOut.write(new byte[20]); // 20 bytes of whatever at the front. | tableOut.write(new byte[20]); // 20 bytes of whatever at the front. | ||||
_styleSheet.writeTo(tableOut); | _styleSheet.writeTo(tableOut); | ||||
assertEquals(newStyleSheet, _styleSheet); | assertEquals(newStyleSheet, _styleSheet); | ||||
} | } | ||||
@Override | |||||
protected void setUp() | |||||
throws Exception | |||||
{ | |||||
super.setUp(); | |||||
@Before | |||||
public void setUp() throws IOException { | |||||
/**@todo verify the constructors*/ | /**@todo verify the constructors*/ | ||||
_hWPFDocFixture = new HWPFDocFixture(this, HWPFDocFixture.DEFAULT_TEST_FILE); | _hWPFDocFixture = new HWPFDocFixture(this, HWPFDocFixture.DEFAULT_TEST_FILE); | ||||
_hWPFDocFixture.setUp(); | _hWPFDocFixture.setUp(); | ||||
_styleSheet = new StyleSheet(tableStream, fib.getFcStshf()); | _styleSheet = new StyleSheet(tableStream, fib.getFcStshf()); | ||||
} | } | ||||
@Override | |||||
protected void tearDown() | |||||
throws Exception | |||||
{ | |||||
@After | |||||
public void tearDown() throws Exception { | |||||
_styleSheet = null; | _styleSheet = null; | ||||
_hWPFDocFixture.tearDown(); | _hWPFDocFixture.tearDown(); | ||||
_hWPFDocFixture = null; | _hWPFDocFixture = null; | ||||
super.tearDown(); | |||||
} | } | ||||
} | } |
==================================================================== */ | ==================================================================== */ | ||||
package org.apache.poi.hwpf.usermodel; | package org.apache.poi.hwpf.usermodel; | ||||
import static org.junit.Assert.assertEquals; | |||||
import static org.junit.Assert.assertNotNull; | |||||
import static org.apache.poi.POITestCase.assertContains; | import static org.apache.poi.POITestCase.assertContains; | ||||
import static org.apache.poi.POITestCase.assertNotContained; | import static org.apache.poi.POITestCase.assertNotContained; | ||||
import static org.junit.Assert.assertEquals; | |||||
import static org.junit.Assert.assertNotNull; | |||||
import java.io.ByteArrayOutputStream; | import java.io.ByteArrayOutputStream; | ||||
import java.io.File; | import java.io.File; | ||||
import java.util.Collection; | import java.util.Collection; | ||||
import java.util.List; | import java.util.List; | ||||
import junit.framework.TestCase; | |||||
import org.apache.commons.codec.digest.DigestUtils; | import org.apache.commons.codec.digest.DigestUtils; | ||||
import org.apache.poi.POIDataSamples; | import org.apache.poi.POIDataSamples; | ||||
import org.apache.poi.hwpf.HWPFDocument; | import org.apache.poi.hwpf.HWPFDocument; | ||||
import org.apache.poi.hwpf.model.FileInformationBlock; | import org.apache.poi.hwpf.model.FileInformationBlock; | ||||
import org.apache.poi.hwpf.model.PlexOfField; | import org.apache.poi.hwpf.model.PlexOfField; | ||||
import org.apache.poi.hwpf.model.SubdocumentType; | import org.apache.poi.hwpf.model.SubdocumentType; | ||||
import org.apache.poi.hwpf.model.io.HWPFOutputStream; | |||||
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; | import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; | ||||
import org.apache.poi.poifs.filesystem.POIFSFileSystem; | import org.apache.poi.poifs.filesystem.POIFSFileSystem; | ||||
import org.apache.poi.util.IOUtils; | import org.apache.poi.util.IOUtils; | ||||
import org.apache.poi.util.POILogger; | import org.apache.poi.util.POILogger; | ||||
import org.junit.Test; | import org.junit.Test; | ||||
import junit.framework.TestCase; | |||||
/** | /** | ||||
* Test different problems reported in the Apache Bugzilla | * Test different problems reported in the Apache Bugzilla | ||||
* against HWPF | * against HWPF | ||||
System.arraycopy(doc.getTableStream(), doc.getFileInformationBlock() | System.arraycopy(doc.getTableStream(), doc.getFileInformationBlock() | ||||
.getFcDop(), originalData, 0, originalData.length); | .getFcDop(), originalData, 0, originalData.length); | ||||
HWPFOutputStream outputStream = new HWPFOutputStream(); | |||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); | |||||
doc.getDocProperties().writeTo(outputStream); | doc.getDocProperties().writeTo(outputStream); | ||||
final byte[] oldData = outputStream.toByteArray(); | final byte[] oldData = outputStream.toByteArray(); | ||||
doc = HWPFTestDataSamples.writeOutAndReadBack(doc); | doc = HWPFTestDataSamples.writeOutAndReadBack(doc); | ||||
outputStream = new HWPFOutputStream(); | |||||
outputStream = new ByteArrayOutputStream(); | |||||
doc.getDocProperties().writeTo(outputStream); | doc.getDocProperties().writeTo(outputStream); | ||||
final byte[] newData = outputStream.toByteArray(); | final byte[] newData = outputStream.toByteArray(); | ||||