* New getASCII() for use in findbugs cleanups for 7-bit strings

This code was supplied by zab
This commit is contained in:
zzz
2013-01-02 13:31:41 +00:00
parent 8c2ddec400
commit f2331b0603

View File

@@ -1724,6 +1724,19 @@ public class DataHelper {
throw new RuntimeException("no utf8!?");
}
}
/**
* Roughly the same as orig.getBytes("ISO-8859-1") but much faster and
* will not throw an exception.
*
* @param orig non-null, must be 7-bit chars
* @since 0.9.5
*/
public static byte[] getASCII(String orig) {
byte[] rv = new byte[orig.length()];
for (int i = 0; i < rv.length; i++) {
rv[i] = (byte)orig.charAt(i);
}
return rv;
}
}