1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 package org.openoffice.xmerge.converter.xml.sxc.pexcel.records; 25 26 import java.io.OutputStream; 27 import java.io.InputStream; 28 import java.io.IOException; 29 30 import org.openoffice.xmerge.util.Debug; 31 import org.openoffice.xmerge.util.EndianConverter; 32 import org.openoffice.xmerge.converter.xml.sxc.pexcel.PocketExcelConstants; 33 34 /** 35 * Represents the codepage for the document. There is a number of unknown 36 * fields which are hardcoded at construction 37 */ 38 public class CodePage implements BIFFRecord { 39 40 private byte[] codepage = new byte[2]; 41 private byte[] unknown1 = new byte[2]; 42 private byte[] unknown2 = new byte[2]; 43 private byte unknown3; 44 45 /** 46 * Constructs a pocket Excel Codepage 47 */ CodePage()48 public CodePage() { 49 codepage = new byte[] {(byte)0xE4, (byte)0x04}; 50 unknown1 = new byte[] {(byte)0x8C, (byte)0x01}; 51 unknown2 = new byte[] {(byte)0x00, (byte)0x01}; 52 unknown3 = 0x00; 53 } 54 55 /** 56 * Constructs a pocket Excel Codepage from the<code>InputStream</code> 57 * 58 * @param is InputStream containing a Pocket Excel Data file. 59 */ CodePage(InputStream is)60 public CodePage(InputStream is) throws IOException { 61 read(is); 62 } 63 64 /** 65 * Get the hex code for this particular <code>BIFFRecord</code> 66 * 67 * @return the hex code for <code>BoundSheet</code> 68 */ getBiffType()69 public short getBiffType() { 70 return PocketExcelConstants.CODEPAGE; 71 } 72 read(InputStream input)73 public int read(InputStream input) throws IOException { 74 75 int numOfBytesRead = input.read(codepage); 76 numOfBytesRead += input.read(unknown1); 77 numOfBytesRead += input.read(unknown2); 78 // numOfBytesRead += input.read(unknown3); 79 unknown3 = (byte) input.read(); 80 numOfBytesRead++; 81 82 Debug.log(Debug.TRACE,"\tcodepage : "+ EndianConverter.readShort(codepage) + 83 " unknown1 : " + EndianConverter.readShort(unknown1) + 84 " unknown2 : " + EndianConverter.readShort(unknown2) + 85 " unknown3 : " + unknown3); 86 87 return numOfBytesRead; 88 } 89 write(OutputStream output)90 public void write(OutputStream output) throws IOException { 91 92 output.write(getBiffType()); 93 output.write(codepage); 94 output.write(unknown1); 95 output.write(unknown2); 96 output.write(unknown3); 97 98 Debug.log(Debug.TRACE,"Writing CodePage record"); 99 100 101 } 102 103 } 104