private String reEncodeWriteAccessIfNecessary( String writeAccess ) { if ( writeAccess == null || writeAccess.length() == 0 ) { return writeAccess; } byte[] data = new byte[112]; try { // jxl reads writeAccess with "UnicodeLittle" encoding, but will try to write later with "file.encoding" // this throws an ArrayIndexOutOfBoundsException in *nix systems StringHelper.getBytes( writeAccess, data, 0 ); } catch ( ArrayIndexOutOfBoundsException e ) { try { // properly re-encoding string from UnicodeLittle, removing BOM characters return new String( writeAccess.getBytes( "UnicodeLittle" ), System.getProperty( "file.encoding" ) ).substring( 2 ); } catch ( UnsupportedEncodingException e1 ) { logError( Const.getStackTracker( e ) ); } } return writeAccess; } }
/** * Reads the ptg data from the array starting at the specified position * * @param data the RPN array * @param pos the current position in the array, excluding the ptg identifier * @return the number of bytes read */ public int read(byte[] data, int pos) { int length = data[pos] & 0xff; int consumed = 2; if ((data[pos+1] & 0x01) == 0) { value = StringHelper.getString(data, length, pos+2, settings); consumed += length; } else { value = StringHelper.getUnicodeString(data, length, pos+2); consumed += length * 2; } return consumed; }
/** * Inserts the unicode byte representation of the specified string into the * array passed in * * @param pos the position at which to insert the converted data * @param s the string to convert * @param d the byte array which will hold the string data */ public static void getUnicodeBytes(String s, byte[] d, int pos) { byte[] b = getUnicodeBytes(s); System.arraycopy(b, 0, d, pos, b.length); }
StringHelper.getUnicodeBytes(contents, d, filePos + 4); filePos += (contents.length() + 1) * 2 + 4; StringHelper.getBytes(shortFilePath, d, curPos+4); StringHelper.getUnicodeBytes(filePath, d, curPos); curPos += (filePath.length() + 1) * 2;
/** * Constructs this object from the raw data * * @param t the record data * @param ws the workbook settings * @param dummy dummy record to indicate a biff7 document */ FooterRecord(Record t, WorkbookSettings ws, Biff7 dummy) { super(t); byte[] data = getRecord().getData(); if (data.length == 0) { return; } int chars = data[0]; footer = StringHelper.getString(data, chars, 1, ws); }
/** * Gets the fully qualified cell reference given the column, row * external sheet reference etc * * @param sheet * @param column * @param row * @param workbook * @param buf */ public static void getCellReference (int sheet, int column, int row, ExternalSheet workbook, StringBuffer buf) { // Quotes are added by the WorkbookParser String name = workbook.getExternalSheetName(sheet); buf.append(StringHelper.replace(name, "\'", "\'\'")); buf.append(sheetInd); getCellReference(column, row, buf); }
col1Name = StringHelper.getUnicodeString(data, col1Size, curPos); curPos += col1Size * 2; col2Name = StringHelper.getUnicodeString(data, col2Size, curPos); curPos += col2Size * 2; col3Name = StringHelper.getUnicodeString(data, col3Size, curPos); curPos += col3Size * 2;
StringHelper.getUnicodeBytes(contents, d, filePos + 4); filePos += (contents.length() + 1) * 2 + 4; StringHelper.getBytes(shortFilePath, d, curPos+4); StringHelper.getUnicodeBytes(filePath, d, curPos); curPos += (filePath.length() + 1) * 2;
/** * Constructs this object from the raw data * * @param t the record data * @param ws the workbook settings * @param dummy dummy record to indicate a biff7 document */ HeaderRecord(Record t, WorkbookSettings ws, Biff7 dummy) { super(t); byte[] data = getRecord().getData(); if (data.length == 0) { return; } int chars = data[0]; header = StringHelper.getString(data, chars, 1, ws); }
/** * Gets the fully qualified cell reference given the column, row * external sheet reference etc * * @param sheet * @param column * @param row * @param workbook * @param buf */ public static void getCellReference (int sheet, int column, int row, ExternalSheet workbook, StringBuffer buf) { // Quotes are added by the WorkbookParser String name = workbook.getExternalSheetName(sheet); buf.append(StringHelper.replace(name, "\'", "\'\'")); buf.append(sheetInd); getCellReference(column, row, buf); }
col1Name = StringHelper.getUnicodeString(data, col1Size, curPos); curPos += col1Size * 2; col2Name = StringHelper.getUnicodeString(data, col2Size, curPos); curPos += col2Size * 2; col3Name = StringHelper.getUnicodeString(data, col3Size, curPos); curPos += col3Size * 2;
/** * Reads the ptg data from the array starting at the specified position * * @param data the RPN array * @param pos the current position in the array, excluding the ptg identifier * @return the number of bytes read */ public int read(byte[] data, int pos) { int length = data[pos] & 0xff; int consumed = 2; if ((data[pos+1] & 0x01) == 0) { value = StringHelper.getString(data, length, pos+2, settings); consumed += length; } else { value = StringHelper.getUnicodeString(data, length, pos+2); consumed += length * 2; } return consumed; }
/** * Inserts the unicode byte representation of the specified string into the * array passed in * * @param pos the position at which to insert the converted data * @param s the string to convert * @param d the byte array which will hold the string data */ public static void getUnicodeBytes(String s, byte[] d, int pos) { byte[] b = getUnicodeBytes(s); System.arraycopy(b, 0, d, pos, b.length); }
/** * Gets the ASCII bytes from the specified string and places them in the * array at the specified position * * @param pos the position at which to place the converted data * @param s the string to convert * @param d the byte array which will contain the converted string data */ public static void getBytes(String s, byte[] d, int pos) { byte[] b = getBytes(s); System.arraycopy(b, 0, d, pos, b.length); }
/** * Constructs this object from the raw data * * @param t the record data * @param ws the workbook settings * @param dummy dummy record to indicate a biff7 document */ HeaderRecord(Record t, WorkbookSettings ws, Biff7 dummy) { super(t); byte[] data = getRecord().getData(); if (data.length == 0) { return; } int chars = data[0]; header = StringHelper.getString(data, chars, 1, ws); }
StringHelper.replace(sheetName, "\'", "\'\'");
if (p.complex) p.stringValue = StringHelper.getUnicodeString(bytes, p.value / 2, pos); pos += p.value;
/** * Constructor * * @param t the raw bytes * @param isBiff8 Is record BIFF8 (else BIFF7) */ public WriteAccessRecord(Record t, boolean isBiff8, WorkbookSettings ws) { super(Type.WRITEACCESS); byte[] data = t.getData(); if (isBiff8) { wauser= StringHelper.getUnicodeString(data, 112/2, 0); } else { // BIFF7 does not use unicode encoding in string int length= data[1]; wauser= StringHelper.getString(data, length, 1, ws); } }
/** * Gets the binary data for output to file * * @return the binary data */ public byte[] getData() { byte[] data = new byte[name.length() * 2 + 12]; data[6] = (byte) name.length(); data[7] = 0x1; StringHelper.getUnicodeBytes(name, data, 8); int pos = 8 + name.length() * 2; data[pos] = 0x2; data[pos+1] = 0x0; data[pos+2] = 0x1c; data[pos+3] = 0x17; return data; } }
/** * Gets the ASCII bytes from the specified string and places them in the * array at the specified position * * @param pos the position at which to place the converted data * @param s the string to convert * @param d the byte array which will contain the converted string data */ public static void getBytes(String s, byte[] d, int pos) { byte[] b = getBytes(s); System.arraycopy(b, 0, d, pos, b.length); }