use of org.apache.poi.util.LittleEndianInputStream in project poi by apache.
the class PropertySetFactory method create.
/**
* Creates the most specific {@link PropertySet} from an {@link
* InputStream}. This is preferrably a {@link
* DocumentSummaryInformation} or a {@link SummaryInformation}. If
* the specified {@link InputStream} does not contain a property
* set stream, an exception is thrown and the {@link InputStream}
* is repositioned at its beginning.
*
* @param stream Contains the property set stream's data.
* @return The created {@link PropertySet}.
* @throws NoPropertySetStreamException if the stream does not
* contain a property set.
* @throws MarkUnsupportedException if the stream does not support
* the {@code mark} operation.
* @throws IOException if some I/O problem occurs.
* @exception UnsupportedEncodingException if the specified codepage is not
* supported.
*/
public static PropertySet create(final InputStream stream) throws NoPropertySetStreamException, MarkUnsupportedException, UnsupportedEncodingException, IOException {
stream.mark(PropertySet.OFFSET_HEADER + ClassID.LENGTH + 1);
LittleEndianInputStream leis = new LittleEndianInputStream(stream);
int byteOrder = leis.readUShort();
int format = leis.readUShort();
int osVersion = (int) leis.readUInt();
byte[] clsIdBuf = new byte[ClassID.LENGTH];
leis.readFully(clsIdBuf);
int sectionCount = (int) leis.readUInt();
if (byteOrder != PropertySet.BYTE_ORDER_ASSERTION || format != PropertySet.FORMAT_ASSERTION || sectionCount < 0) {
throw new NoPropertySetStreamException();
}
if (sectionCount > 0) {
leis.readFully(clsIdBuf);
}
stream.reset();
ClassID clsId = new ClassID(clsIdBuf, 0);
if (sectionCount > 0 && PropertySet.matchesSummary(clsId, SectionIDMap.SUMMARY_INFORMATION_ID)) {
return new SummaryInformation(stream);
} else if (sectionCount > 0 && PropertySet.matchesSummary(clsId, SectionIDMap.DOCUMENT_SUMMARY_INFORMATION_ID)) {
return new DocumentSummaryInformation(stream);
} else {
return new PropertySet(stream);
}
}
use of org.apache.poi.util.LittleEndianInputStream in project poi by apache.
the class EmbeddedObjectRefSubRecord method readRefPtg.
private static Ptg readRefPtg(byte[] formulaRawBytes) {
LittleEndianInput in = new LittleEndianInputStream(new ByteArrayInputStream(formulaRawBytes));
byte ptgSid = in.readByte();
switch(ptgSid) {
case AreaPtg.sid:
return new AreaPtg(in);
case Area3DPtg.sid:
return new Area3DPtg(in);
case RefPtg.sid:
return new RefPtg(in);
case Ref3DPtg.sid:
return new Ref3DPtg(in);
}
return null;
}
use of org.apache.poi.util.LittleEndianInputStream in project poi by apache.
the class TestUnicodeString method formatRun.
@Test
public void formatRun() throws Exception {
FormatRun fr = new FormatRun((short) 4, (short) 0x15c);
assertEquals(4, fr.getCharacterPos());
assertEquals(0x15c, fr.getFontIndex());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
LittleEndianOutputStream out = new LittleEndianOutputStream(baos);
fr.serialize(out);
byte[] b = baos.toByteArray();
assertEquals(4, b.length);
assertEquals(4, b[0]);
assertEquals(0, b[1]);
assertEquals(0x5c, b[2]);
assertEquals(0x01, b[3]);
LittleEndianInputStream inp = new LittleEndianInputStream(new ByteArrayInputStream(b));
fr = new FormatRun(inp);
assertEquals(4, fr.getCharacterPos());
assertEquals(0x15c, fr.getFontIndex());
}
use of org.apache.poi.util.LittleEndianInputStream in project poi by apache.
the class TestUnicodeString method extRstFromData.
@Test
public void extRstFromData() throws Exception {
byte[] data = new byte[] { 01, 00, 0x0C, 00, 00, 00, 0x37, 00, 00, 00, 00, 00, 00, 00, // Cruft at the end, as found from real files
00, // Cruft at the end, as found from real files
00 };
assertEquals(16, data.length);
LittleEndianInputStream inp = new LittleEndianInputStream(new ByteArrayInputStream(data));
ExtRst ext = new ExtRst(inp, data.length);
// Excludes 4 byte header
assertEquals(0x0c, ext.getDataSize());
assertEquals(0, ext.getNumberOfRuns());
assertEquals(0x37, ext.getFormattingOptions());
assertEquals(0, ext.getFormattingFontIndex());
assertEquals("", ext.getPhoneticText());
assertEquals(0, ext.getPhRuns().length);
}
use of org.apache.poi.util.LittleEndianInputStream in project poi by apache.
the class TestUnicodeString method extRstFromEmpty.
@Test
public void extRstFromEmpty() throws Exception {
ExtRst ext = new ExtRst();
assertEquals(0, ext.getNumberOfRuns());
assertEquals(0, ext.getFormattingFontIndex());
assertEquals(0, ext.getFormattingOptions());
assertEquals("", ext.getPhoneticText());
assertEquals(0, ext.getPhRuns().length);
// Excludes 4 byte header
assertEquals(10, ext.getDataSize());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
LittleEndianOutputStream out = new LittleEndianOutputStream(baos);
ContinuableRecordOutput cout = new ContinuableRecordOutput(out, 0xffff);
ext.serialize(cout);
cout.writeContinue();
byte[] b = baos.toByteArray();
assertEquals(20, b.length);
// First 4 bytes from the outputstream
assertEquals(-1, b[0]);
assertEquals(-1, b[1]);
assertEquals(14, b[2]);
assertEquals(00, b[3]);
// Reserved
assertEquals(1, b[4]);
assertEquals(0, b[5]);
// Data size
assertEquals(10, b[6]);
assertEquals(00, b[7]);
// Font*2
assertEquals(0, b[8]);
assertEquals(0, b[9]);
assertEquals(0, b[10]);
assertEquals(0, b[11]);
// 0 Runs
assertEquals(0, b[12]);
assertEquals(0, b[13]);
// Size=0, *2
assertEquals(0, b[14]);
assertEquals(0, b[15]);
assertEquals(0, b[16]);
assertEquals(0, b[17]);
// Last 2 bytes from the outputstream
assertEquals(ContinueRecord.sid, b[18]);
assertEquals(0, b[19]);
// Load in again and re-test
byte[] data = new byte[14];
System.arraycopy(b, 4, data, 0, data.length);
LittleEndianInputStream inp = new LittleEndianInputStream(new ByteArrayInputStream(data));
ext = new ExtRst(inp, data.length);
assertEquals(0, ext.getNumberOfRuns());
assertEquals(0, ext.getFormattingFontIndex());
assertEquals(0, ext.getFormattingOptions());
assertEquals("", ext.getPhoneticText());
assertEquals(0, ext.getPhRuns().length);
}
Aggregations