📄 persistenceelement.java
字号:
public static void int2byteArrayBE(byte[] arr, int start, int num) { if ( bigEndianArchitecture ) { int2byteArrayDirect(arr, start, num); } int2byteArrayInvert(arr, start, num); } public static void int2byteArrayLE(byte[] arr, int start, int num) { if ( bigEndianArchitecture ) { int2byteArrayInvert(arr, start, num); } int2byteArrayDirect(arr, start, num); } /** This method is responsible of taking into account the endianess of the original data */ public static int byteArray2intLE(byte[] arr, int start) { if ( bigEndianArchitecture ) { return byteArray2intInvert(arr, start); } return byteArray2intDirect(arr, start); } /** This method is responsible of taking into account the endianess of the original data */ public static long byteArray2longBE(byte[] arr, int start) { if ( bigEndianArchitecture ) { return byteArray2longDirect(arr, start); } return byteArray2longInvert(arr, start); } /** This method is responsible of taking into account the endianess of the original data */ public static long byteArray2longLE(byte[] arr, int start) { if ( bigEndianArchitecture ) { return byteArray2longInvert(arr, start); } return byteArray2longDirect(arr, start); } /** This method is responsible of taking into account the endianess of the original data */ public static float byteArray2floatBE(byte[] arr, int start) { if ( bigEndianArchitecture ) { return byteArray2longDirect(arr, start); } return byteArray2longInvert(arr, start); } public static void float2byteArrayBE(byte[] arr, int start, float num) { long a = Float.floatToIntBits(num); if ( bigEndianArchitecture ) { long2byteArrayDirect(arr, start, a); } long2byteArrayInvert(arr, start, a); } /** This method is responsible of taking into account the endianess of the original data */ public static float byteArray2floatLE(byte[] arr, int start) { if ( bigEndianArchitecture ) { return byteArray2floatInvert(arr, start); } return byteArray2floatDirect(arr, start); } public static int readIntLE(InputStream is) throws Exception { readBytes(is, bytesForInt); return byteArray2intLE(bytesForInt, 0); } public static int readIntBE(InputStream is) throws Exception { readBytes(is, bytesForInt); return byteArray2intBE(bytesForInt, 0); } public static void writeIntBE(OutputStream os, int num) throws Exception { int2byteArrayBE(bytesForInt, 0, num); writeBytes(os, bytesForInt); } public static void writeIntLE(OutputStream os, int num) throws Exception { int2byteArrayLE(bytesForInt, 0, num); writeBytes(os, bytesForInt); } public static long readLongLE(InputStream is) throws Exception { readBytes(is, bytesForLong); return byteArray2longLE(bytesForLong, 0); } public static long readLongBE(InputStream is) throws Exception { readBytes(is, bytesForLong); return byteArray2longBE(bytesForLong, 0); } public static float readFloatLE(InputStream is) throws Exception { readBytes(is, bytesForFloat); return byteArray2floatLE(bytesForFloat, 0); } public static float readFloatBE(InputStream is) throws Exception { readBytes(is, bytesForFloat); long i = byteArray2longBE(bytesForFloat, 0); int j = (int)i; return Float.intBitsToFloat(j); } public static void writeFloatBE(OutputStream os, float num) throws Exception { float2byteArrayBE(bytesForFloat, 0, num); writeBytes(os, bytesForFloat); } public static void writeLongBE(OutputStream os, long num) throws Exception { if ( bigEndianArchitecture ) { long2byteArrayDirect(bytesForLong, 0, num); } long2byteArrayInvert(bytesForLong, 0, num); writeBytes(os, bytesForLong); } public static void writeLongLE(OutputStream os, long num) throws Exception { if ( bigEndianArchitecture ) { long2byteArrayInvert(bytesForLong, 0, num); } long2byteArrayDirect(bytesForLong, 0, num); writeBytes(os, bytesForLong); } public static String readAsciiString(InputStream is) throws Exception { byte character[] = new byte[1]; char letter; String msg = ""; do { readBytes(is, character); letter = (char)character[0]; if ( character[0] != 0x00 ) { msg = msg + letter; } } while ( character[0] != 0x00 ); return msg; } public static String readAsciiLine(InputStream is) throws Exception { byte character[] = new byte[1]; char letter; String msg = ""; do { readBytes(is, character); letter = (char)character[0]; if ( character[0] != '\n' && character[0] != '\r' ) { msg = msg + letter; } } while ( character[0] != '\n' ); return msg; } public static void writeAsciiString(OutputStream writer, String cad) throws Exception { byte arr[]; arr = cad.getBytes(); writer.write(arr, 0, arr.length); byte end[] = new byte[1]; end[0] = '\0'; writer.write(end, 0, end.length); } public static void writeAsciiLine(OutputStream writer, String cad) throws Exception { byte arr[]; arr = cad.getBytes(); writer.write(arr, 0, arr.length); byte end[] = new byte[1]; end[0] = '\n'; writer.write(end, 0, end.length); } /** Given the name of a native library, this method tries to determine wheter it is available or not. Takes into account the cross-platform differences, and it is supposed to check if a System.loadLibrary call for givel library will succeed or not. Use this method to anticipate any problem before it fails, so a better user feedback instruction can be given instead of waiting for an exception to be thrown. Some libraries, as JOGL fails to return to the application the exception of a failed System.loadLibrary, so this method is useful in bettering the user feedback for this kind of circumstance. */ public static boolean verifyLibrary(String libname) { String nativeLibname = System.mapLibraryName(libname); String paths = System.getProperty("java.library.path"); String os = System.getProperty("os.name").toLowerCase(); if ( os.startsWith("linux") || os.startsWith("solaris") || os.startsWith("unix") ) { paths = paths.concat(":/lib"); paths = paths.concat(":/usr/lib"); paths = paths.concat(":/usr/local/lib"); paths = paths.concat(":/usr/X11R6/lib"); paths = paths.concat(":/usr/X11R6/lib64"); paths = paths.concat(":/usr/openwin/lib"); paths = paths.concat(":/usr/dt/lib"); paths = paths.concat(":/lib64"); paths = paths.concat(":/usr/lib64"); paths = paths.concat(":/usr/local/lib64"); paths = paths.concat(":" + System.getenv("LD_LIBRARY_PATH")); } String separator = File.pathSeparator; StringTokenizer st = new StringTokenizer(paths, separator); String token; String concat = File.separator; while ( st.hasMoreTokens() ) { token = st.nextToken(); File directory = new File(token); if ( !directory.isDirectory() ) { continue; } File file = new File(token + concat + nativeLibname); if ( file.exists() ) { return true; } } return false; }}//===========================================================================//= EOF =//===========================================================================
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -