Fix line-ending differences between windows and unix in UtilIO parsing.
git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@1605837 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -382,6 +382,9 @@ public final class UtilIO {
|
||||
if (buffer[length - 1] == '\n') {
|
||||
length--;
|
||||
}
|
||||
if (buffer[length - 1] == '\r') {
|
||||
length--;
|
||||
}
|
||||
return convertObject(String.class, new String(buffer, i + 1, length - i - 1), type);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -138,6 +138,8 @@ public class UtilIOTests extends GenericTestCaseBase {
|
||||
}
|
||||
|
||||
protected void checkBasicReadWriteObject(Object value, String text) throws Exception {
|
||||
String lineEnding = System.getProperty("line.separator");
|
||||
text = text.replaceAll("\n", lineEnding);
|
||||
byte[] bytes = text.getBytes("UTF-8");
|
||||
assertEquals("read bytes " + value.getClass().getName(), value, UtilIO.readObject(new ByteArrayInputStream(bytes)));
|
||||
assertEquals("read chars " + value.getClass().getName(), value, UtilIO.readObject(text.toCharArray()));
|
||||
@@ -147,7 +149,7 @@ public class UtilIOTests extends GenericTestCaseBase {
|
||||
assertEquals("write stream " + value.getClass().getName(), text, new String(baos.toByteArray(), "UTF-8"));
|
||||
StringBuilder sb = new StringBuilder();
|
||||
UtilIO.writeObject(sb, value);
|
||||
sb.append('\n');
|
||||
sb.append(lineEnding);
|
||||
assertEquals("write builder " + value.getClass().getName(), text, sb.toString());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user