[Schmitzm-commits] r2119 - trunk/schmitzm-core/src/main/java/de/schmitzm/lang
scm-commit at wald.intevation.org
scm-commit at wald.intevation.org
Fri Nov 2 17:31:00 CET 2012
Author: alfonx
Date: 2012-11-02 17:31:00 +0100 (Fri, 02 Nov 2012)
New Revision: 2119
Modified:
trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java
Log:
Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java 2012-10-31 16:13:41 UTC (rev 2118)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java 2012-11-02 16:31:00 UTC (rev 2119)
@@ -112,8 +112,8 @@
public static final long KB_BYTES = 1024;
/** Ein Megabyte (MB) in Bytes */
public static final long MB_BYTES = 1024 * KB_BYTES;
- /** Ein Gigabyte (GB) in Bytes */
- public static final long GB_BYTES = 1024 * MB_BYTES;
+ /** Ein Gigabyte (GB) in Bytes */
+ public static final long GB_BYTES = 1024 * MB_BYTES;
final static Pattern onlyZerosRegEx = Pattern.compile("^([\\s0.,]*)$");
@@ -2563,20 +2563,34 @@
}
}
- /**
- * Returns the given file size in an adequate format.
- */
- public static String formatFileSize(long bytes) {
- if ( bytes < LangUtil.KB_BYTES )
- return bytes + " Byte";
-
- int kBytes = (int)Math.round( bytes*1.0/LangUtil.KB_BYTES );
- if ( bytes < LangUtil.MB_BYTES )
- return kBytes + " KB";
- int mBytes = (int)Math.round( bytes*1.0/LangUtil.MB_BYTES );
- if ( bytes < LangUtil.GB_BYTES )
- return kBytes + " MB";
- int gBytes = (int)Math.round( bytes*1.0/LangUtil.GB_BYTES );
- return kBytes + " GB";
- }
+ /**
+ * Liefert einen String zurück, der nur \\n enthält, und keine \\r
+ */
+ public static String homogenizeNewlines(String mixedNewlines) {
+ if (mixedNewlines == null)
+ return null;
+
+ mixedNewlines = mixedNewlines.replaceAll("\r\n", "\n");
+ mixedNewlines = mixedNewlines.replaceAll("\n\r", "\n");
+ mixedNewlines = mixedNewlines.replaceAll("\r", "\n");
+
+ return mixedNewlines;
+ }
+
+ /**
+ * Returns the given file size in an adequate format.
+ */
+ public static String formatFileSize(long bytes) {
+ if (bytes < LangUtil.KB_BYTES)
+ return bytes + " Byte";
+
+ int kBytes = (int) Math.round(bytes * 1.0 / LangUtil.KB_BYTES);
+ if (bytes < LangUtil.MB_BYTES)
+ return kBytes + " KB";
+ int mBytes = (int) Math.round(bytes * 1.0 / LangUtil.MB_BYTES);
+ if (bytes < LangUtil.GB_BYTES)
+ return kBytes + " MB";
+ int gBytes = (int) Math.round(bytes * 1.0 / LangUtil.GB_BYTES);
+ return kBytes + " GB";
+ }
}
More information about the Schmitzm-commits
mailing list