package org.apache.poi.hpsf;
import org.apache.poi.util.HexDump;
+import org.apache.poi.util.StringUtil;
/**
* <p>Represents a class ID (16 bytes). Unlike other little-endian
* type the {@link ClassID} is not just 16 bytes stored in the wrong
* order. Instead, it is a double word (4 bytes) followed by two
* words (2 bytes each) followed by 8 bytes.</p>
- *
- * @author Rainer Klute <a
- * href="mailto:klute@rainer-klute.de"><klute@rainer-klute.de></a>
*/
public class ClassID
{
*/
public int hashCode()
{
- return new String(bytes).hashCode();
+ return new String(bytes, StringUtil.UTF8).hashCode();
}
-
-
/**
* <p>Returns a human-readable representation of the Class ID in standard
* format <code>"{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}"</code>.</p>
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
+import org.apache.poi.util.StringUtil;
@Internal
class CodePageString
{
String result;
if ( codepage == -1 )
- result = new String( _value );
+ result = new String( _value, StringUtil.UTF8 );
else
result = CodePageUtil.getStringFromCodePage(_value, codepage);
final int terminator = result.indexOf( '\0' );
{
String stringNT = string + "\0";
if ( codepage == -1 )
- _value = stringNT.getBytes();
+ _value = stringNT.getBytes(StringUtil.UTF8);
else
_value = CodePageUtil.getBytesInCodePage(stringNT, codepage);
}
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.nio.charset.Charset;
import java.util.List;
import org.apache.poi.hpsf.wellknown.PropertyIDMap;
return Long.toString( LittleEndian.getUInt(b) );
}
// Maybe it's a string? who knows!
- return new String(b);
+ return new String(b, Charset.forName("ASCII"));
}
return propertyValue.toString();
}
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.io.OutputStreamWriter;
import java.io.PrintWriter;
+import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
DrawingGroupRecord r = (DrawingGroupRecord) workbook.findFirstRecordBySid( DrawingGroupRecord.sid );
r.decode();
List<EscherRecord> escherRecords = r.getEscherRecords();
- PrintWriter w = new PrintWriter(System.out);
+ PrintWriter w = new PrintWriter(new OutputStreamWriter(System.out, Charset.defaultCharset()));
for ( Iterator<EscherRecord> iterator = escherRecords.iterator(); iterator.hasNext(); )
{
EscherRecord escherRecord = iterator.next();
* <li>If this argument is negative, this function returns the #NUM! error value.</li>\r
* <li>If this argument contains a decimal value, this function ignores the numbers to the right side of the decimal point.</li>\r
* </ul>\r
- *\r
- * @author cedric dot walter @ gmail dot com\r
*/\r
public final class Dec2Hex extends Var1or2ArgFunction implements FreeRefFunction {\r
\r
\r
String hex;\r
if (placesNumber != 0) {\r
- hex = String.format("%0"+placesNumber+"X", number1.intValue());\r
+ hex = String.format("%0"+placesNumber+"X", number1.intValue(), Locale.ROOT);\r
}\r
else {\r
hex = Integer.toHexString(number1.intValue());\r
import java.util.Calendar;
import java.util.Date;
+import java.util.Locale;
+import java.util.TimeZone;
import org.apache.poi.ss.formula.OperationEvaluationContext;
import org.apache.poi.ss.formula.eval.BlankEval;
* Implementation for Excel EDATE () function.
*/
public class EDate implements FreeRefFunction {
+ /**
+ * Excel doesn't store TimeZone information in the file, so if in doubt,
+ * use UTC to perform calculations
+ */
+ private static final TimeZone DEFAULT_TIMEZONE = TimeZone.getTimeZone("UTC");
+
public static final FreeRefFunction instance = new EDate();
public ValueEval evaluate(ValueEval[] args, OperationEvaluationContext ec) {
int offsetInMonthAsNumber = (int) getValue(args[1]);
Date startDate = DateUtil.getJavaDate(startDateAsNumber);
- Calendar calendar = Calendar.getInstance();
+ Calendar calendar = Calendar.getInstance(DEFAULT_TIMEZONE, Locale.ROOT);
calendar.setTime(startDate);
calendar.add(Calendar.MONTH, offsetInMonthAsNumber);
return new NumberEval(DateUtil.getExcelDate(calendar.getTime()));
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
-import java.io.PrintStream;
+import java.io.PrintWriter;
-import org.apache.poi.POIDataSamples;
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
-import org.junit.Ignore;
-import org.junit.Test;
public class TestBiffViewer extends BaseXLSIteratingTest {
static {
InputStream is = BiffViewer.getPOIFSInputStream(fs);
try {
// use a NullOutputStream to not write the bytes anywhere for best runtime
- BiffViewer.runBiffViewer(new PrintStream(NULL_OUTPUT_STREAM), is, true, true, true, false);
+ BiffViewer.runBiffViewer(new PrintWriter(NULL_OUTPUT_STREAM), is, true, true, true, false);
} finally {
is.close();
fs.close();