From 56a6e74de1cd61998826e1fb943231661927c219 Mon Sep 17 00:00:00 2001 From: Tomas Zeman Date: Fri, 8 Mar 2019 11:20:31 +0100 Subject: [PATCH] Optional charset for SpssInputStream --- .../com/bedatadriven/spss/SpssDataFileReader.java | 4 ++-- .../java/com/bedatadriven/spss/SpssInputStream.java | 13 +++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/bedatadriven/spss/SpssDataFileReader.java b/src/main/java/com/bedatadriven/spss/SpssDataFileReader.java index df72964..349f5ec 100644 --- a/src/main/java/com/bedatadriven/spss/SpssDataFileReader.java +++ b/src/main/java/com/bedatadriven/spss/SpssDataFileReader.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 BeDataDriven Groep BV + * Copyright 2017-2019 BeDataDriven Groep BV * * Licensed 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 @@ -86,7 +86,7 @@ public SpssDataFileReader(InputStream input) throws IOException { this(new SpssInputStream(input)); } - private SpssDataFileReader(SpssInputStream inStream) throws IOException { + public SpssDataFileReader(SpssInputStream inStream) throws IOException { inputStream = inStream; String fileType = new String(inputStream.readBytes(4)); diff --git a/src/main/java/com/bedatadriven/spss/SpssInputStream.java b/src/main/java/com/bedatadriven/spss/SpssInputStream.java index 6128271..609e3af 100644 --- a/src/main/java/com/bedatadriven/spss/SpssInputStream.java +++ b/src/main/java/com/bedatadriven/spss/SpssInputStream.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 BeDataDriven Groep BV + * Copyright 2017-2019 BeDataDriven Groep BV * * Licensed 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 @@ -19,13 +19,18 @@ import java.io.InputStream; import java.nio.charset.Charset; -class SpssInputStream { +public class SpssInputStream { private DataInputStream file; private boolean needToFlipBytes; - private Charset charset = Charset.forName("Cp1252"); + private final Charset charset; + + public SpssInputStream(InputStream is, Charset charset) { + this.file = new DataInputStream(is); + this.charset = charset; + } public SpssInputStream(InputStream is) { - file = new DataInputStream(is); + this(is, Charset.forName("Cp1252")); } public DataInputStream getFile() {