Skip to content

Commit

Permalink
Added Properties.load(java.io.Reader) - preferred to avoid encoding i…
Browse files Browse the repository at this point in the history
…ssues
  • Loading branch information
salmonb committed Oct 7, 2023
1 parent dcaaaa5 commit 0df0620
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.io.Reader;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.BiConsumer;
Expand Down Expand Up @@ -372,12 +373,12 @@ public synchronized Object setProperty(String key, String value) {
* @throws NullPointerException if {@code reader} is null.
* @since 1.6
*/
/*

public synchronized void load(Reader reader) throws IOException {
Objects.requireNonNull(reader, "reader parameter is null");
load0(new LineReader(reader));
}
*/


/**
* Reads a property list (key and element pairs) from the input
Expand Down Expand Up @@ -467,20 +468,18 @@ private static class LineReader {
inByteBuf = new byte[8192];
}

/*
LineReader(Reader reader) {
this.reader = reader;
inCharBuf = new char[8192];
}
*/

char[] lineBuf = new char[1024];
private byte[] inByteBuf;
private char[] inCharBuf;
private int inLimit = 0;
private int inOff = 0;
private InputStream inStream;
// private Reader reader;
private Reader reader;

int readLine() throws IOException {
// use locals to optimize for interpreted performance
Expand All @@ -500,7 +499,7 @@ int readLine() throws IOException {
while (true) {
if (off >= limit) {
inLimit = limit = fromStream ? inStream.read(byteBuf, 0, byteBuf.length)
: 0; //reader.read(charBuf, 0, charBuf.length);
: reader.read(charBuf, 0, charBuf.length);
if (limit <= 0) {
if (len == 0) {
return -1;
Expand Down Expand Up @@ -546,7 +545,7 @@ int readLine() throws IOException {
}
off = 0;
}
} /*else {
} else {
while (off < limit) {
c = charBuf[off++];
if (c <= '\r' && (c == '\r' || c == '\n'))
Expand All @@ -559,7 +558,7 @@ int readLine() throws IOException {
}
off = 0;
}
}*/
}
}
skipWhiteSpace = true;
continue;
Expand All @@ -583,7 +582,7 @@ int readLine() throws IOException {
}
if (off >= limit) {
inLimit = limit = fromStream ? inStream.read(byteBuf, 0, byteBuf.length)
: 0; //reader.read(charBuf, 0, charBuf.length);
: reader.read(charBuf, 0, charBuf.length);
off = 0;
if (limit <= 0) { // EOF
return precedingBackslash ? len - 1 : len;
Expand Down Expand Up @@ -623,7 +622,7 @@ public static int newLength(int oldLength, int minGrowth, int prefGrowth) {

int newLength = Math.max(minGrowth, prefGrowth) + oldLength;
//if (newLength - MAX_ARRAY_LENGTH <= 0) {
return newLength;
return newLength;
//}
//return hugeLength(oldLength, minGrowth);
}
Expand Down Expand Up @@ -950,9 +949,9 @@ private void store0(BufferedWriter bw, String comments, boolean escUnicode)
String val = (String)e.getValue();
key = saveConvert(key, true, escUnicode);
*/
/* No need to escape embedded and trailing spaces for value, hence
* pass false to flag.
*//*
/* No need to escape embedded and trailing spaces for value, hence
* pass false to flag.
*//*
val = saveConvert(val, false, escUnicode);
bw.write(key + "=" + val);
Expand Down Expand Up @@ -1531,7 +1530,7 @@ public synchronized Object merge(Object key, Object value,
/*
@Override
protected void rehash() { */
/* no-op *//*
/* no-op *//*
}
*/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import dev.webfx.platform.console.Console;
import dev.webfx.platform.resource.Resource;

import java.io.ByteArrayInputStream;
import java.io.StringReader;
import java.util.Properties;

/**
Expand All @@ -26,7 +26,7 @@ private static Properties getMetaProperties() {
META_PROPERTIES = new Properties();
try {
String content = Resource.getText(META_EXE_RESOURCE_FILE_PATH);
META_PROPERTIES.load(new ByteArrayInputStream(content.getBytes()));
META_PROPERTIES.load(new StringReader(content));
} catch (Exception e) {
Console.log("Failed to read meta resource file " + META_EXE_RESOURCE_FILE_PATH, e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package dev.webfx.platform.util.keyobject.parser.spi.impl.properties;

import dev.webfx.platform.util.keyobject.AST;
import dev.webfx.platform.util.keyobject.ReadOnlyAstNode;
import dev.webfx.platform.util.keyobject.ReadOnlyIndexedArray;
import dev.webfx.platform.util.keyobject.ReadOnlyKeyObject;
import dev.webfx.platform.util.keyobject.ReadOnlyAstNode;
import dev.webfx.platform.util.keyobject.AST;
import dev.webfx.platform.util.keyobject.parser.spi.AstParserProvider;

import java.io.ByteArrayInputStream;
import java.io.StringReader;
import java.util.Properties;

/**
Expand All @@ -22,7 +22,7 @@ public String format() {
private Properties parseProperties(String text) {
Properties properties = new Properties();
try {
properties.load(new ByteArrayInputStream(text.getBytes()));
properties.load(new StringReader(text));
} catch (Exception e) {
//Console.log("WARNING: Ignoring wrong format configuration file " + filePath, e);
}
Expand Down

0 comments on commit 0df0620

Please sign in to comment.