8074657: Missing space on a boundary of concatenated strings
Added missing spaces, fixed indentation, replaced StringBuffer with StringBuilder Reviewed-by: martin, rriggs
This commit is contained in:
parent
608c2ef496
commit
ff06dffa94
@ -62,8 +62,8 @@ class WindowsPreferences extends AbstractPreferences {
|
|||||||
/**
|
/**
|
||||||
* Windows registry path to <tt>Preferences</tt>'s root nodes.
|
* Windows registry path to <tt>Preferences</tt>'s root nodes.
|
||||||
*/
|
*/
|
||||||
private static final byte[] WINDOWS_ROOT_PATH
|
private static final byte[] WINDOWS_ROOT_PATH =
|
||||||
= stringToByteArray("Software\\JavaSoft\\Prefs");
|
stringToByteArray("Software\\JavaSoft\\Prefs");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Windows handles to <tt>HKEY_CURRENT_USER</tt> and
|
* Windows handles to <tt>HKEY_CURRENT_USER</tt> and
|
||||||
@ -147,12 +147,12 @@ class WindowsPreferences extends AbstractPreferences {
|
|||||||
* Java wrapper for Windows registry API RegOpenKey()
|
* Java wrapper for Windows registry API RegOpenKey()
|
||||||
*/
|
*/
|
||||||
private static native int[] WindowsRegOpenKey(int hKey, byte[] subKey,
|
private static native int[] WindowsRegOpenKey(int hKey, byte[] subKey,
|
||||||
int securityMask);
|
int securityMask);
|
||||||
/**
|
/**
|
||||||
* Retries RegOpenKey() MAX_ATTEMPTS times before giving up.
|
* Retries RegOpenKey() MAX_ATTEMPTS times before giving up.
|
||||||
*/
|
*/
|
||||||
private static int[] WindowsRegOpenKey1(int hKey, byte[] subKey,
|
private static int[] WindowsRegOpenKey1(int hKey, byte[] subKey,
|
||||||
int securityMask) {
|
int securityMask) {
|
||||||
int[] result = WindowsRegOpenKey(hKey, subKey, securityMask);
|
int[] result = WindowsRegOpenKey(hKey, subKey, securityMask);
|
||||||
if (result[ERROR_CODE] == ERROR_SUCCESS) {
|
if (result[ERROR_CODE] == ERROR_SUCCESS) {
|
||||||
return result;
|
return result;
|
||||||
@ -167,16 +167,16 @@ class WindowsPreferences extends AbstractPreferences {
|
|||||||
} else if (result[ERROR_CODE] != ERROR_ACCESS_DENIED) {
|
} else if (result[ERROR_CODE] != ERROR_ACCESS_DENIED) {
|
||||||
long sleepTime = INIT_SLEEP_TIME;
|
long sleepTime = INIT_SLEEP_TIME;
|
||||||
for (int i = 0; i < MAX_ATTEMPTS; i++) {
|
for (int i = 0; i < MAX_ATTEMPTS; i++) {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(sleepTime);
|
Thread.sleep(sleepTime);
|
||||||
} catch(InterruptedException e) {
|
} catch(InterruptedException e) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
sleepTime *= 2;
|
sleepTime *= 2;
|
||||||
result = WindowsRegOpenKey(hKey, subKey, securityMask);
|
result = WindowsRegOpenKey(hKey, subKey, securityMask);
|
||||||
if (result[ERROR_CODE] == ERROR_SUCCESS) {
|
if (result[ERROR_CODE] == ERROR_SUCCESS) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
@ -198,10 +198,10 @@ class WindowsPreferences extends AbstractPreferences {
|
|||||||
private static int[] WindowsRegCreateKeyEx1(int hKey, byte[] subKey) {
|
private static int[] WindowsRegCreateKeyEx1(int hKey, byte[] subKey) {
|
||||||
int[] result = WindowsRegCreateKeyEx(hKey, subKey);
|
int[] result = WindowsRegCreateKeyEx(hKey, subKey);
|
||||||
if (result[ERROR_CODE] == ERROR_SUCCESS) {
|
if (result[ERROR_CODE] == ERROR_SUCCESS) {
|
||||||
return result;
|
return result;
|
||||||
} else {
|
} else {
|
||||||
long sleepTime = INIT_SLEEP_TIME;
|
long sleepTime = INIT_SLEEP_TIME;
|
||||||
for (int i = 0; i < MAX_ATTEMPTS; i++) {
|
for (int i = 0; i < MAX_ATTEMPTS; i++) {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(sleepTime);
|
Thread.sleep(sleepTime);
|
||||||
} catch(InterruptedException e) {
|
} catch(InterruptedException e) {
|
||||||
@ -210,7 +210,7 @@ class WindowsPreferences extends AbstractPreferences {
|
|||||||
sleepTime *= 2;
|
sleepTime *= 2;
|
||||||
result = WindowsRegCreateKeyEx(hKey, subKey);
|
result = WindowsRegCreateKeyEx(hKey, subKey);
|
||||||
if (result[ERROR_CODE] == ERROR_SUCCESS) {
|
if (result[ERROR_CODE] == ERROR_SUCCESS) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -232,10 +232,10 @@ class WindowsPreferences extends AbstractPreferences {
|
|||||||
private static int WindowsRegFlushKey1(int hKey) {
|
private static int WindowsRegFlushKey1(int hKey) {
|
||||||
int result = WindowsRegFlushKey(hKey);
|
int result = WindowsRegFlushKey(hKey);
|
||||||
if (result == ERROR_SUCCESS) {
|
if (result == ERROR_SUCCESS) {
|
||||||
return result;
|
return result;
|
||||||
} else {
|
} else {
|
||||||
long sleepTime = INIT_SLEEP_TIME;
|
long sleepTime = INIT_SLEEP_TIME;
|
||||||
for (int i = 0; i < MAX_ATTEMPTS; i++) {
|
for (int i = 0; i < MAX_ATTEMPTS; i++) {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(sleepTime);
|
Thread.sleep(sleepTime);
|
||||||
} catch(InterruptedException e) {
|
} catch(InterruptedException e) {
|
||||||
@ -244,7 +244,7 @@ class WindowsPreferences extends AbstractPreferences {
|
|||||||
sleepTime *= 2;
|
sleepTime *= 2;
|
||||||
result = WindowsRegFlushKey(hKey);
|
result = WindowsRegFlushKey(hKey);
|
||||||
if (result == ERROR_SUCCESS) {
|
if (result == ERROR_SUCCESS) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -255,23 +255,23 @@ class WindowsPreferences extends AbstractPreferences {
|
|||||||
* Java wrapper for Windows registry API RegQueryValueEx()
|
* Java wrapper for Windows registry API RegQueryValueEx()
|
||||||
*/
|
*/
|
||||||
private static native byte[] WindowsRegQueryValueEx(int hKey,
|
private static native byte[] WindowsRegQueryValueEx(int hKey,
|
||||||
byte[] valueName);
|
byte[] valueName);
|
||||||
/**
|
/**
|
||||||
* Java wrapper for Windows registry API RegSetValueEx()
|
* Java wrapper for Windows registry API RegSetValueEx()
|
||||||
*/
|
*/
|
||||||
private static native int WindowsRegSetValueEx(int hKey, byte[] valueName,
|
private static native int WindowsRegSetValueEx(int hKey, byte[] valueName,
|
||||||
byte[] value);
|
byte[] value);
|
||||||
/**
|
/**
|
||||||
* Retries RegSetValueEx() MAX_ATTEMPTS times before giving up.
|
* Retries RegSetValueEx() MAX_ATTEMPTS times before giving up.
|
||||||
*/
|
*/
|
||||||
private static int WindowsRegSetValueEx1(int hKey, byte[] valueName,
|
private static int WindowsRegSetValueEx1(int hKey, byte[] valueName,
|
||||||
byte[] value) {
|
byte[] value) {
|
||||||
int result = WindowsRegSetValueEx(hKey, valueName, value);
|
int result = WindowsRegSetValueEx(hKey, valueName, value);
|
||||||
if (result == ERROR_SUCCESS) {
|
if (result == ERROR_SUCCESS) {
|
||||||
return result;
|
return result;
|
||||||
} else {
|
} else {
|
||||||
long sleepTime = INIT_SLEEP_TIME;
|
long sleepTime = INIT_SLEEP_TIME;
|
||||||
for (int i = 0; i < MAX_ATTEMPTS; i++) {
|
for (int i = 0; i < MAX_ATTEMPTS; i++) {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(sleepTime);
|
Thread.sleep(sleepTime);
|
||||||
} catch(InterruptedException e) {
|
} catch(InterruptedException e) {
|
||||||
@ -280,7 +280,7 @@ class WindowsPreferences extends AbstractPreferences {
|
|||||||
sleepTime *= 2;
|
sleepTime *= 2;
|
||||||
result = WindowsRegSetValueEx(hKey, valueName, value);
|
result = WindowsRegSetValueEx(hKey, valueName, value);
|
||||||
if (result == ERROR_SUCCESS) {
|
if (result == ERROR_SUCCESS) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -303,10 +303,10 @@ class WindowsPreferences extends AbstractPreferences {
|
|||||||
private static int[] WindowsRegQueryInfoKey1(int hKey) {
|
private static int[] WindowsRegQueryInfoKey1(int hKey) {
|
||||||
int[] result = WindowsRegQueryInfoKey(hKey);
|
int[] result = WindowsRegQueryInfoKey(hKey);
|
||||||
if (result[ERROR_CODE] == ERROR_SUCCESS) {
|
if (result[ERROR_CODE] == ERROR_SUCCESS) {
|
||||||
return result;
|
return result;
|
||||||
} else {
|
} else {
|
||||||
long sleepTime = INIT_SLEEP_TIME;
|
long sleepTime = INIT_SLEEP_TIME;
|
||||||
for (int i = 0; i < MAX_ATTEMPTS; i++) {
|
for (int i = 0; i < MAX_ATTEMPTS; i++) {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(sleepTime);
|
Thread.sleep(sleepTime);
|
||||||
} catch(InterruptedException e) {
|
} catch(InterruptedException e) {
|
||||||
@ -315,7 +315,7 @@ class WindowsPreferences extends AbstractPreferences {
|
|||||||
sleepTime *= 2;
|
sleepTime *= 2;
|
||||||
result = WindowsRegQueryInfoKey(hKey);
|
result = WindowsRegQueryInfoKey(hKey);
|
||||||
if (result[ERROR_CODE] == ERROR_SUCCESS) {
|
if (result[ERROR_CODE] == ERROR_SUCCESS) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -326,19 +326,19 @@ class WindowsPreferences extends AbstractPreferences {
|
|||||||
* Java wrapper for Windows registry API RegEnumKeyEx()
|
* Java wrapper for Windows registry API RegEnumKeyEx()
|
||||||
*/
|
*/
|
||||||
private static native byte[] WindowsRegEnumKeyEx(int hKey, int subKeyIndex,
|
private static native byte[] WindowsRegEnumKeyEx(int hKey, int subKeyIndex,
|
||||||
int maxKeyLength);
|
int maxKeyLength);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retries RegEnumKeyEx() MAX_ATTEMPTS times before giving up.
|
* Retries RegEnumKeyEx() MAX_ATTEMPTS times before giving up.
|
||||||
*/
|
*/
|
||||||
private static byte[] WindowsRegEnumKeyEx1(int hKey, int subKeyIndex,
|
private static byte[] WindowsRegEnumKeyEx1(int hKey, int subKeyIndex,
|
||||||
int maxKeyLength) {
|
int maxKeyLength) {
|
||||||
byte[] result = WindowsRegEnumKeyEx(hKey, subKeyIndex, maxKeyLength);
|
byte[] result = WindowsRegEnumKeyEx(hKey, subKeyIndex, maxKeyLength);
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
return result;
|
return result;
|
||||||
} else {
|
} else {
|
||||||
long sleepTime = INIT_SLEEP_TIME;
|
long sleepTime = INIT_SLEEP_TIME;
|
||||||
for (int i = 0; i < MAX_ATTEMPTS; i++) {
|
for (int i = 0; i < MAX_ATTEMPTS; i++) {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(sleepTime);
|
Thread.sleep(sleepTime);
|
||||||
} catch(InterruptedException e) {
|
} catch(InterruptedException e) {
|
||||||
@ -347,7 +347,7 @@ class WindowsPreferences extends AbstractPreferences {
|
|||||||
sleepTime *= 2;
|
sleepTime *= 2;
|
||||||
result = WindowsRegEnumKeyEx(hKey, subKeyIndex, maxKeyLength);
|
result = WindowsRegEnumKeyEx(hKey, subKeyIndex, maxKeyLength);
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -358,19 +358,19 @@ class WindowsPreferences extends AbstractPreferences {
|
|||||||
* Java wrapper for Windows registry API RegEnumValue()
|
* Java wrapper for Windows registry API RegEnumValue()
|
||||||
*/
|
*/
|
||||||
private static native byte[] WindowsRegEnumValue(int hKey, int valueIndex,
|
private static native byte[] WindowsRegEnumValue(int hKey, int valueIndex,
|
||||||
int maxValueNameLength);
|
int maxValueNameLength);
|
||||||
/**
|
/**
|
||||||
* Retries RegEnumValueEx() MAX_ATTEMPTS times before giving up.
|
* Retries RegEnumValueEx() MAX_ATTEMPTS times before giving up.
|
||||||
*/
|
*/
|
||||||
private static byte[] WindowsRegEnumValue1(int hKey, int valueIndex,
|
private static byte[] WindowsRegEnumValue1(int hKey, int valueIndex,
|
||||||
int maxValueNameLength) {
|
int maxValueNameLength) {
|
||||||
byte[] result = WindowsRegEnumValue(hKey, valueIndex,
|
byte[] result = WindowsRegEnumValue(hKey, valueIndex,
|
||||||
maxValueNameLength);
|
maxValueNameLength);
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
return result;
|
return result;
|
||||||
} else {
|
} else {
|
||||||
long sleepTime = INIT_SLEEP_TIME;
|
long sleepTime = INIT_SLEEP_TIME;
|
||||||
for (int i = 0; i < MAX_ATTEMPTS; i++) {
|
for (int i = 0; i < MAX_ATTEMPTS; i++) {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(sleepTime);
|
Thread.sleep(sleepTime);
|
||||||
} catch(InterruptedException e) {
|
} catch(InterruptedException e) {
|
||||||
@ -378,9 +378,9 @@ class WindowsPreferences extends AbstractPreferences {
|
|||||||
}
|
}
|
||||||
sleepTime *= 2;
|
sleepTime *= 2;
|
||||||
result = WindowsRegEnumValue(hKey, valueIndex,
|
result = WindowsRegEnumValue(hKey, valueIndex,
|
||||||
maxValueNameLength);
|
maxValueNameLength);
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -404,11 +404,11 @@ class WindowsPreferences extends AbstractPreferences {
|
|||||||
int[] result =
|
int[] result =
|
||||||
WindowsRegCreateKeyEx1(parentNativeHandle, toWindowsName(name));
|
WindowsRegCreateKeyEx1(parentNativeHandle, toWindowsName(name));
|
||||||
if (result[ERROR_CODE] != ERROR_SUCCESS) {
|
if (result[ERROR_CODE] != ERROR_SUCCESS) {
|
||||||
logger().warning("Could not create windows registry "
|
logger().warning("Could not create windows registry node " +
|
||||||
+ "node " + byteArrayToString(windowsAbsolutePath()) +
|
byteArrayToString(windowsAbsolutePath()) +
|
||||||
" at root 0x" + Integer.toHexString(rootNativeHandle()) +
|
" at root 0x" + Integer.toHexString(rootNativeHandle()) +
|
||||||
". Windows RegCreateKeyEx(...) returned error code " +
|
". Windows RegCreateKeyEx(...) returned error code " +
|
||||||
result[ERROR_CODE] + ".");
|
result[ERROR_CODE] + ".");
|
||||||
isBackingStoreAvailable = false;
|
isBackingStoreAvailable = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -426,15 +426,15 @@ class WindowsPreferences extends AbstractPreferences {
|
|||||||
* @param rootDirectory Path to root directory, as a byte-encoded string.
|
* @param rootDirectory Path to root directory, as a byte-encoded string.
|
||||||
*/
|
*/
|
||||||
private WindowsPreferences(int rootNativeHandle, byte[] rootDirectory) {
|
private WindowsPreferences(int rootNativeHandle, byte[] rootDirectory) {
|
||||||
super(null,"");
|
super(null, "");
|
||||||
int[] result =
|
int[] result =
|
||||||
WindowsRegCreateKeyEx1(rootNativeHandle, rootDirectory);
|
WindowsRegCreateKeyEx1(rootNativeHandle, rootDirectory);
|
||||||
if (result[ERROR_CODE] != ERROR_SUCCESS) {
|
if (result[ERROR_CODE] != ERROR_SUCCESS) {
|
||||||
logger().warning("Could not open/create prefs root node " +
|
logger().warning("Could not open/create prefs root node " +
|
||||||
byteArrayToString(windowsAbsolutePath()) + " at root 0x" +
|
byteArrayToString(windowsAbsolutePath()) +
|
||||||
Integer.toHexString(rootNativeHandle()) +
|
" at root 0x" + Integer.toHexString(rootNativeHandle()) +
|
||||||
". Windows RegCreateKeyEx(...) returned error code " +
|
". Windows RegCreateKeyEx(...) returned error code " +
|
||||||
result[ERROR_CODE] + ".");
|
result[ERROR_CODE] + ".");
|
||||||
isBackingStoreAvailable = false;
|
isBackingStoreAvailable = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -451,7 +451,7 @@ class WindowsPreferences extends AbstractPreferences {
|
|||||||
private byte[] windowsAbsolutePath() {
|
private byte[] windowsAbsolutePath() {
|
||||||
ByteArrayOutputStream bstream = new ByteArrayOutputStream();
|
ByteArrayOutputStream bstream = new ByteArrayOutputStream();
|
||||||
bstream.write(WINDOWS_ROOT_PATH, 0, WINDOWS_ROOT_PATH.length-1);
|
bstream.write(WINDOWS_ROOT_PATH, 0, WINDOWS_ROOT_PATH.length-1);
|
||||||
StringTokenizer tokenizer = new StringTokenizer(absolutePath(),"/");
|
StringTokenizer tokenizer = new StringTokenizer(absolutePath(), "/");
|
||||||
while (tokenizer.hasMoreTokens()) {
|
while (tokenizer.hasMoreTokens()) {
|
||||||
bstream.write((byte)'\\');
|
bstream.write((byte)'\\');
|
||||||
String nextName = tokenizer.nextToken();
|
String nextName = tokenizer.nextToken();
|
||||||
@ -505,27 +505,30 @@ class WindowsPreferences extends AbstractPreferences {
|
|||||||
/* Check if key's path is short enough be opened at once
|
/* Check if key's path is short enough be opened at once
|
||||||
otherwise use a path-splitting procedure */
|
otherwise use a path-splitting procedure */
|
||||||
if (windowsAbsolutePath.length <= MAX_WINDOWS_PATH_LENGTH + 1) {
|
if (windowsAbsolutePath.length <= MAX_WINDOWS_PATH_LENGTH + 1) {
|
||||||
int[] result = WindowsRegOpenKey1(rootNativeHandle(),
|
int[] result = WindowsRegOpenKey1(rootNativeHandle(),
|
||||||
windowsAbsolutePath, mask1);
|
windowsAbsolutePath, mask1);
|
||||||
if (result[ERROR_CODE] == ERROR_ACCESS_DENIED && mask2 != mask1)
|
if (result[ERROR_CODE] == ERROR_ACCESS_DENIED && mask2 != mask1)
|
||||||
result = WindowsRegOpenKey1(rootNativeHandle(),
|
result = WindowsRegOpenKey1(rootNativeHandle(),
|
||||||
windowsAbsolutePath, mask2);
|
windowsAbsolutePath, mask2);
|
||||||
|
|
||||||
if (result[ERROR_CODE] != ERROR_SUCCESS) {
|
if (result[ERROR_CODE] != ERROR_SUCCESS) {
|
||||||
logger().warning("Could not open windows "
|
logger().warning("Could not open windows registry node " +
|
||||||
+ "registry node " + byteArrayToString(windowsAbsolutePath()) +
|
byteArrayToString(windowsAbsolutePath()) +
|
||||||
" at root 0x" + Integer.toHexString(rootNativeHandle()) +
|
" at root 0x" +
|
||||||
". Windows RegOpenKey(...) returned error code " +
|
Integer.toHexString(rootNativeHandle()) +
|
||||||
result[ERROR_CODE] + ".");
|
". Windows RegOpenKey(...) returned error code " +
|
||||||
|
result[ERROR_CODE] + ".");
|
||||||
result[NATIVE_HANDLE] = NULL_NATIVE_HANDLE;
|
result[NATIVE_HANDLE] = NULL_NATIVE_HANDLE;
|
||||||
if (result[ERROR_CODE] == ERROR_ACCESS_DENIED) {
|
if (result[ERROR_CODE] == ERROR_ACCESS_DENIED) {
|
||||||
throw new SecurityException("Could not open windows "
|
throw new SecurityException(
|
||||||
+ "registry node " + byteArrayToString(windowsAbsolutePath()) +
|
"Could not open windows registry node " +
|
||||||
" at root 0x" + Integer.toHexString(rootNativeHandle()) +
|
byteArrayToString(windowsAbsolutePath()) +
|
||||||
": Access denied");
|
" at root 0x" +
|
||||||
|
Integer.toHexString(rootNativeHandle()) +
|
||||||
|
": Access denied");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result[NATIVE_HANDLE];
|
return result[NATIVE_HANDLE];
|
||||||
} else {
|
} else {
|
||||||
return openKey(rootNativeHandle(), windowsAbsolutePath, mask1, mask2);
|
return openKey(rootNativeHandle(), windowsAbsolutePath, mask1, mask2);
|
||||||
}
|
}
|
||||||
@ -548,21 +551,21 @@ class WindowsPreferences extends AbstractPreferences {
|
|||||||
int mask1, int mask2) {
|
int mask1, int mask2) {
|
||||||
/* If the path is short enough open at once. Otherwise split the path */
|
/* If the path is short enough open at once. Otherwise split the path */
|
||||||
if (windowsRelativePath.length <= MAX_WINDOWS_PATH_LENGTH + 1 ) {
|
if (windowsRelativePath.length <= MAX_WINDOWS_PATH_LENGTH + 1 ) {
|
||||||
int[] result = WindowsRegOpenKey1(nativeHandle,
|
int[] result = WindowsRegOpenKey1(nativeHandle,
|
||||||
windowsRelativePath, mask1);
|
windowsRelativePath, mask1);
|
||||||
if (result[ERROR_CODE] == ERROR_ACCESS_DENIED && mask2 != mask1)
|
if (result[ERROR_CODE] == ERROR_ACCESS_DENIED && mask2 != mask1)
|
||||||
result = WindowsRegOpenKey1(nativeHandle,
|
result = WindowsRegOpenKey1(nativeHandle,
|
||||||
windowsRelativePath, mask2);
|
windowsRelativePath, mask2);
|
||||||
|
|
||||||
if (result[ERROR_CODE] != ERROR_SUCCESS) {
|
if (result[ERROR_CODE] != ERROR_SUCCESS) {
|
||||||
logger().warning("Could not open windows "
|
logger().warning("Could not open windows registry node " +
|
||||||
+ "registry node " + byteArrayToString(windowsAbsolutePath()) +
|
byteArrayToString(windowsAbsolutePath()) +
|
||||||
" at root 0x" + Integer.toHexString(nativeHandle) +
|
" at root 0x" + Integer.toHexString(nativeHandle) +
|
||||||
". Windows RegOpenKey(...) returned error code " +
|
". Windows RegOpenKey(...) returned error code " +
|
||||||
result[ERROR_CODE] + ".");
|
result[ERROR_CODE] + ".");
|
||||||
result[NATIVE_HANDLE] = NULL_NATIVE_HANDLE;
|
result[NATIVE_HANDLE] = NULL_NATIVE_HANDLE;
|
||||||
}
|
}
|
||||||
return result[NATIVE_HANDLE];
|
return result[NATIVE_HANDLE];
|
||||||
} else {
|
} else {
|
||||||
int separatorPosition = -1;
|
int separatorPosition = -1;
|
||||||
// Be greedy - open the longest possible path
|
// Be greedy - open the longest possible path
|
||||||
@ -604,10 +607,12 @@ class WindowsPreferences extends AbstractPreferences {
|
|||||||
private void closeKey(int nativeHandle) {
|
private void closeKey(int nativeHandle) {
|
||||||
int result = WindowsRegCloseKey(nativeHandle);
|
int result = WindowsRegCloseKey(nativeHandle);
|
||||||
if (result != ERROR_SUCCESS) {
|
if (result != ERROR_SUCCESS) {
|
||||||
logger().warning("Could not close windows "
|
logger().warning("Could not close windows registry node " +
|
||||||
+ "registry node " + byteArrayToString(windowsAbsolutePath()) +
|
byteArrayToString(windowsAbsolutePath()) +
|
||||||
" at root 0x" + Integer.toHexString(rootNativeHandle()) +
|
" at root 0x" +
|
||||||
". Windows RegCloseKey(...) returned error code " + result + ".");
|
Integer.toHexString(rootNativeHandle()) +
|
||||||
|
". Windows RegCloseKey(...) returned error code " +
|
||||||
|
result + ".");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -627,10 +632,13 @@ class WindowsPreferences extends AbstractPreferences {
|
|||||||
toWindowsName(javaName), toWindowsValueString(value));
|
toWindowsName(javaName), toWindowsValueString(value));
|
||||||
if (result != ERROR_SUCCESS) {
|
if (result != ERROR_SUCCESS) {
|
||||||
logger().warning("Could not assign value to key " +
|
logger().warning("Could not assign value to key " +
|
||||||
byteArrayToString(toWindowsName(javaName))+ " at Windows registry node "
|
byteArrayToString(toWindowsName(javaName)) +
|
||||||
+ byteArrayToString(windowsAbsolutePath()) + " at root 0x"
|
" at Windows registry node " +
|
||||||
+ Integer.toHexString(rootNativeHandle()) +
|
byteArrayToString(windowsAbsolutePath()) +
|
||||||
". Windows RegSetValueEx(...) returned error code " + result + ".");
|
" at root 0x" +
|
||||||
|
Integer.toHexString(rootNativeHandle()) +
|
||||||
|
". Windows RegSetValueEx(...) returned error code " +
|
||||||
|
result + ".");
|
||||||
isBackingStoreAvailable = false;
|
isBackingStoreAvailable = false;
|
||||||
}
|
}
|
||||||
closeKey(nativeHandle);
|
closeKey(nativeHandle);
|
||||||
@ -672,12 +680,12 @@ class WindowsPreferences extends AbstractPreferences {
|
|||||||
int result =
|
int result =
|
||||||
WindowsRegDeleteValue(nativeHandle, toWindowsName(key));
|
WindowsRegDeleteValue(nativeHandle, toWindowsName(key));
|
||||||
if (result != ERROR_SUCCESS && result != ERROR_FILE_NOT_FOUND) {
|
if (result != ERROR_SUCCESS && result != ERROR_FILE_NOT_FOUND) {
|
||||||
logger().warning("Could not delete windows registry "
|
logger().warning("Could not delete windows registry value " +
|
||||||
+ "value " + byteArrayToString(windowsAbsolutePath())+ "\\" +
|
byteArrayToString(windowsAbsolutePath()) + "\\" +
|
||||||
toWindowsName(key) + " at root 0x" +
|
toWindowsName(key) + " at root 0x" +
|
||||||
Integer.toHexString(rootNativeHandle()) +
|
Integer.toHexString(rootNativeHandle()) +
|
||||||
". Windows RegDeleteValue(...) returned error code " +
|
". Windows RegDeleteValue(...) returned error code " +
|
||||||
result + ".");
|
result + ".");
|
||||||
isBackingStoreAvailable = false;
|
isBackingStoreAvailable = false;
|
||||||
}
|
}
|
||||||
closeKey(nativeHandle);
|
closeKey(nativeHandle);
|
||||||
@ -693,17 +701,20 @@ class WindowsPreferences extends AbstractPreferences {
|
|||||||
// Find out the number of values
|
// Find out the number of values
|
||||||
int nativeHandle = openKey(KEY_QUERY_VALUE);
|
int nativeHandle = openKey(KEY_QUERY_VALUE);
|
||||||
if (nativeHandle == NULL_NATIVE_HANDLE) {
|
if (nativeHandle == NULL_NATIVE_HANDLE) {
|
||||||
throw new BackingStoreException("Could not open windows"
|
throw new BackingStoreException(
|
||||||
+ "registry node " + byteArrayToString(windowsAbsolutePath()) +
|
"Could not open windows registry node " +
|
||||||
" at root 0x" + Integer.toHexString(rootNativeHandle()) + ".");
|
byteArrayToString(windowsAbsolutePath()) +
|
||||||
|
" at root 0x" +
|
||||||
|
Integer.toHexString(rootNativeHandle()) + ".");
|
||||||
}
|
}
|
||||||
int[] result = WindowsRegQueryInfoKey1(nativeHandle);
|
int[] result = WindowsRegQueryInfoKey1(nativeHandle);
|
||||||
if (result[ERROR_CODE] != ERROR_SUCCESS) {
|
if (result[ERROR_CODE] != ERROR_SUCCESS) {
|
||||||
String info = "Could not query windows"
|
String info = "Could not query windows registry node " +
|
||||||
+ "registry node " + byteArrayToString(windowsAbsolutePath()) +
|
byteArrayToString(windowsAbsolutePath()) +
|
||||||
" at root 0x" + Integer.toHexString(rootNativeHandle()) +
|
" at root 0x" +
|
||||||
". Windows RegQueryInfoKeyEx(...) returned error code " +
|
Integer.toHexString(rootNativeHandle()) +
|
||||||
result[ERROR_CODE] + ".";
|
". Windows RegQueryInfoKeyEx(...) returned error code " +
|
||||||
|
result[ERROR_CODE] + ".";
|
||||||
logger().warning(info);
|
logger().warning(info);
|
||||||
throw new BackingStoreException(info);
|
throw new BackingStoreException(info);
|
||||||
}
|
}
|
||||||
@ -712,17 +723,17 @@ class WindowsPreferences extends AbstractPreferences {
|
|||||||
if (valuesNumber == 0) {
|
if (valuesNumber == 0) {
|
||||||
closeKey(nativeHandle);
|
closeKey(nativeHandle);
|
||||||
return new String[0];
|
return new String[0];
|
||||||
}
|
}
|
||||||
// Get the values
|
// Get the values
|
||||||
String[] valueNames = new String[valuesNumber];
|
String[] valueNames = new String[valuesNumber];
|
||||||
for (int i = 0; i < valuesNumber; i++) {
|
for (int i = 0; i < valuesNumber; i++) {
|
||||||
byte[] windowsName = WindowsRegEnumValue1(nativeHandle, i,
|
byte[] windowsName = WindowsRegEnumValue1(nativeHandle, i,
|
||||||
maxValueNameLength+1);
|
maxValueNameLength+1);
|
||||||
if (windowsName == null) {
|
if (windowsName == null) {
|
||||||
String info =
|
String info =
|
||||||
"Could not enumerate value #" + i + " of windows node " +
|
"Could not enumerate value #" + i + " of windows node " +
|
||||||
byteArrayToString(windowsAbsolutePath()) + " at root 0x" +
|
byteArrayToString(windowsAbsolutePath()) + " at root 0x" +
|
||||||
Integer.toHexString(rootNativeHandle()) + ".";
|
Integer.toHexString(rootNativeHandle()) + ".";
|
||||||
logger().warning(info);
|
logger().warning(info);
|
||||||
throw new BackingStoreException(info);
|
throw new BackingStoreException(info);
|
||||||
}
|
}
|
||||||
@ -740,20 +751,22 @@ class WindowsPreferences extends AbstractPreferences {
|
|||||||
*/
|
*/
|
||||||
protected String[] childrenNamesSpi() throws BackingStoreException {
|
protected String[] childrenNamesSpi() throws BackingStoreException {
|
||||||
// Open key
|
// Open key
|
||||||
int nativeHandle = openKey(KEY_ENUMERATE_SUB_KEYS| KEY_QUERY_VALUE);
|
int nativeHandle = openKey(KEY_ENUMERATE_SUB_KEYS | KEY_QUERY_VALUE);
|
||||||
if (nativeHandle == NULL_NATIVE_HANDLE) {
|
if (nativeHandle == NULL_NATIVE_HANDLE) {
|
||||||
throw new BackingStoreException("Could not open windows"
|
throw new BackingStoreException(
|
||||||
+ "registry node " + byteArrayToString(windowsAbsolutePath()) +
|
"Could not open windows registry node " +
|
||||||
" at root 0x" + Integer.toHexString(rootNativeHandle()) + ".");
|
byteArrayToString(windowsAbsolutePath()) +
|
||||||
|
" at root 0x" +
|
||||||
|
Integer.toHexString(rootNativeHandle()) + ".");
|
||||||
}
|
}
|
||||||
// Get number of children
|
// Get number of children
|
||||||
int[] result = WindowsRegQueryInfoKey1(nativeHandle);
|
int[] result = WindowsRegQueryInfoKey1(nativeHandle);
|
||||||
if (result[ERROR_CODE] != ERROR_SUCCESS) {
|
if (result[ERROR_CODE] != ERROR_SUCCESS) {
|
||||||
String info = "Could not query windows"
|
String info = "Could not query windows registry node " +
|
||||||
+ "registry node " + byteArrayToString(windowsAbsolutePath()) +
|
byteArrayToString(windowsAbsolutePath()) +
|
||||||
" at root 0x" + Integer.toHexString(rootNativeHandle()) +
|
" at root 0x" + Integer.toHexString(rootNativeHandle()) +
|
||||||
". Windows RegQueryInfoKeyEx(...) returned error code " +
|
". Windows RegQueryInfoKeyEx(...) returned error code " +
|
||||||
result[ERROR_CODE] + ".";
|
result[ERROR_CODE] + ".";
|
||||||
logger().warning(info);
|
logger().warning(info);
|
||||||
throw new BackingStoreException(info);
|
throw new BackingStoreException(info);
|
||||||
}
|
}
|
||||||
@ -768,12 +781,12 @@ class WindowsPreferences extends AbstractPreferences {
|
|||||||
// Get children
|
// Get children
|
||||||
for (int i = 0; i < subKeysNumber; i++) {
|
for (int i = 0; i < subKeysNumber; i++) {
|
||||||
byte[] windowsName = WindowsRegEnumKeyEx1(nativeHandle, i,
|
byte[] windowsName = WindowsRegEnumKeyEx1(nativeHandle, i,
|
||||||
maxKeyLength+1);
|
maxKeyLength+1);
|
||||||
if (windowsName == null) {
|
if (windowsName == null) {
|
||||||
String info =
|
String info =
|
||||||
"Could not enumerate key #" + i + " of windows node " +
|
"Could not enumerate key #" + i + " of windows node " +
|
||||||
byteArrayToString(windowsAbsolutePath()) + " at root 0x" +
|
byteArrayToString(windowsAbsolutePath()) + " at root 0x" +
|
||||||
Integer.toHexString(rootNativeHandle()) + ". ";
|
Integer.toHexString(rootNativeHandle()) + ". ";
|
||||||
logger().warning(info);
|
logger().warning(info);
|
||||||
throw new BackingStoreException(info);
|
throw new BackingStoreException(info);
|
||||||
}
|
}
|
||||||
@ -798,20 +811,24 @@ class WindowsPreferences extends AbstractPreferences {
|
|||||||
}
|
}
|
||||||
if (!isBackingStoreAvailable) {
|
if (!isBackingStoreAvailable) {
|
||||||
throw new BackingStoreException(
|
throw new BackingStoreException(
|
||||||
"flush(): Backing store not available.");
|
"flush(): Backing store not available.");
|
||||||
}
|
}
|
||||||
int nativeHandle = openKey(KEY_READ);
|
int nativeHandle = openKey(KEY_READ);
|
||||||
if (nativeHandle == NULL_NATIVE_HANDLE) {
|
if (nativeHandle == NULL_NATIVE_HANDLE) {
|
||||||
throw new BackingStoreException("Could not open windows"
|
throw new BackingStoreException(
|
||||||
+ "registry node " + byteArrayToString(windowsAbsolutePath()) +
|
"Could not open windows registry node " +
|
||||||
" at root 0x" + Integer.toHexString(rootNativeHandle()) + ".");
|
byteArrayToString(windowsAbsolutePath()) +
|
||||||
|
" at root 0x" +
|
||||||
|
Integer.toHexString(rootNativeHandle()) + ".");
|
||||||
}
|
}
|
||||||
int result = WindowsRegFlushKey1(nativeHandle);
|
int result = WindowsRegFlushKey1(nativeHandle);
|
||||||
if (result != ERROR_SUCCESS) {
|
if (result != ERROR_SUCCESS) {
|
||||||
String info = "Could not flush windows "
|
String info = "Could not flush windows registry node " +
|
||||||
+ "registry node " + byteArrayToString(windowsAbsolutePath())
|
byteArrayToString(windowsAbsolutePath()) +
|
||||||
+ " at root 0x" + Integer.toHexString(rootNativeHandle()) +
|
" at root 0x" +
|
||||||
". Windows RegFlushKey(...) returned error code " + result + ".";
|
Integer.toHexString(rootNativeHandle()) +
|
||||||
|
". Windows RegFlushKey(...) returned error code " +
|
||||||
|
result + ".";
|
||||||
logger().warning(info);
|
logger().warning(info);
|
||||||
throw new BackingStoreException(info);
|
throw new BackingStoreException(info);
|
||||||
}
|
}
|
||||||
@ -838,7 +855,7 @@ class WindowsPreferences extends AbstractPreferences {
|
|||||||
* Logs a warning message, if Windows Registry is unavailable.
|
* Logs a warning message, if Windows Registry is unavailable.
|
||||||
*/
|
*/
|
||||||
protected AbstractPreferences childSpi(String name) {
|
protected AbstractPreferences childSpi(String name) {
|
||||||
return new WindowsPreferences(this, name);
|
return new WindowsPreferences(this, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -849,20 +866,22 @@ class WindowsPreferences extends AbstractPreferences {
|
|||||||
*/
|
*/
|
||||||
public void removeNodeSpi() throws BackingStoreException {
|
public void removeNodeSpi() throws BackingStoreException {
|
||||||
int parentNativeHandle =
|
int parentNativeHandle =
|
||||||
((WindowsPreferences)parent()).openKey(DELETE);
|
((WindowsPreferences)parent()).openKey(DELETE);
|
||||||
if (parentNativeHandle == NULL_NATIVE_HANDLE) {
|
if (parentNativeHandle == NULL_NATIVE_HANDLE) {
|
||||||
throw new BackingStoreException("Could not open parent windows"
|
throw new BackingStoreException(
|
||||||
+ "registry node of " + byteArrayToString(windowsAbsolutePath()) +
|
"Could not open parent windows registry node of " +
|
||||||
" at root 0x" + Integer.toHexString(rootNativeHandle()) + ".");
|
byteArrayToString(windowsAbsolutePath()) +
|
||||||
|
" at root 0x" +
|
||||||
|
Integer.toHexString(rootNativeHandle()) + ".");
|
||||||
}
|
}
|
||||||
int result =
|
int result =
|
||||||
WindowsRegDeleteKey(parentNativeHandle, toWindowsName(name()));
|
WindowsRegDeleteKey(parentNativeHandle, toWindowsName(name()));
|
||||||
if (result != ERROR_SUCCESS) {
|
if (result != ERROR_SUCCESS) {
|
||||||
String info = "Could not delete windows "
|
String info = "Could not delete windows registry node " +
|
||||||
+ "registry node " + byteArrayToString(windowsAbsolutePath()) +
|
byteArrayToString(windowsAbsolutePath()) +
|
||||||
" at root 0x" + Integer.toHexString(rootNativeHandle()) +
|
" at root 0x" + Integer.toHexString(rootNativeHandle()) +
|
||||||
". Windows RegDeleteKeyEx(...) returned error code " +
|
". Windows RegDeleteKeyEx(...) returned error code " +
|
||||||
result + ".";
|
result + ".";
|
||||||
logger().warning(info);
|
logger().warning(info);
|
||||||
throw new BackingStoreException(info);
|
throw new BackingStoreException(info);
|
||||||
}
|
}
|
||||||
@ -879,23 +898,25 @@ class WindowsPreferences extends AbstractPreferences {
|
|||||||
private static String toJavaName(byte[] windowsNameArray) {
|
private static String toJavaName(byte[] windowsNameArray) {
|
||||||
String windowsName = byteArrayToString(windowsNameArray);
|
String windowsName = byteArrayToString(windowsNameArray);
|
||||||
// check if Alt64
|
// check if Alt64
|
||||||
if ((windowsName.length()>1) &&
|
if ((windowsName.length() > 1) &&
|
||||||
(windowsName.substring(0,2).equals("/!"))) {
|
(windowsName.substring(0, 2).equals("/!"))) {
|
||||||
return toJavaAlt64Name(windowsName);
|
return toJavaAlt64Name(windowsName);
|
||||||
}
|
}
|
||||||
StringBuffer javaName = new StringBuffer();
|
StringBuilder javaName = new StringBuilder();
|
||||||
char ch;
|
char ch;
|
||||||
// Decode from simple encoding
|
// Decode from simple encoding
|
||||||
for (int i = 0; i < windowsName.length(); i++){
|
for (int i = 0; i < windowsName.length(); i++) {
|
||||||
if ((ch = windowsName.charAt(i)) == '/') {
|
if ((ch = windowsName.charAt(i)) == '/') {
|
||||||
char next = ' ';
|
char next = ' ';
|
||||||
if ((windowsName.length() > i + 1) &&
|
if ((windowsName.length() > i + 1) &&
|
||||||
((next = windowsName.charAt(i+1)) >= 'A') && (next <= 'Z')) {
|
((next = windowsName.charAt(i+1)) >= 'A') &&
|
||||||
ch = next;
|
(next <= 'Z')) {
|
||||||
i++;
|
ch = next;
|
||||||
} else if ((windowsName.length() > i + 1) && (next == '/')) {
|
i++;
|
||||||
ch = '\\';
|
} else if ((windowsName.length() > i + 1) &&
|
||||||
i++;
|
(next == '/')) {
|
||||||
|
ch = '\\';
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
} else if (ch == '\\') {
|
} else if (ch == '\\') {
|
||||||
ch = '/';
|
ch = '/';
|
||||||
@ -914,8 +935,8 @@ class WindowsPreferences extends AbstractPreferences {
|
|||||||
|
|
||||||
private static String toJavaAlt64Name(String windowsName) {
|
private static String toJavaAlt64Name(String windowsName) {
|
||||||
byte[] byteBuffer =
|
byte[] byteBuffer =
|
||||||
Base64.altBase64ToByteArray(windowsName.substring(2));
|
Base64.altBase64ToByteArray(windowsName.substring(2));
|
||||||
StringBuffer result = new StringBuffer();
|
StringBuilder result = new StringBuilder();
|
||||||
for (int i = 0; i < byteBuffer.length; i++) {
|
for (int i = 0; i < byteBuffer.length; i++) {
|
||||||
int firstbyte = (byteBuffer[i++] & 0xff);
|
int firstbyte = (byteBuffer[i++] & 0xff);
|
||||||
int secondbyte = (byteBuffer[i] & 0xff);
|
int secondbyte = (byteBuffer[i] & 0xff);
|
||||||
@ -945,10 +966,10 @@ class WindowsPreferences extends AbstractPreferences {
|
|||||||
* Base64 class.
|
* Base64 class.
|
||||||
*/
|
*/
|
||||||
private static byte[] toWindowsName(String javaName) {
|
private static byte[] toWindowsName(String javaName) {
|
||||||
StringBuffer windowsName = new StringBuffer();
|
StringBuilder windowsName = new StringBuilder();
|
||||||
for (int i = 0; i < javaName.length(); i++) {
|
for (int i = 0; i < javaName.length(); i++) {
|
||||||
char ch =javaName.charAt(i);
|
char ch = javaName.charAt(i);
|
||||||
if ((ch < 0x0020)||(ch > 0x007f)) {
|
if ((ch < 0x0020) || (ch > 0x007f)) {
|
||||||
// If a non-trivial character encountered, use altBase64
|
// If a non-trivial character encountered, use altBase64
|
||||||
return toWindowsAlt64Name(javaName);
|
return toWindowsAlt64Name(javaName);
|
||||||
}
|
}
|
||||||
@ -957,7 +978,7 @@ class WindowsPreferences extends AbstractPreferences {
|
|||||||
} else if (ch == '/') {
|
} else if (ch == '/') {
|
||||||
windowsName.append('\\');
|
windowsName.append('\\');
|
||||||
} else if ((ch >= 'A') && (ch <='Z')) {
|
} else if ((ch >= 'A') && (ch <='Z')) {
|
||||||
windowsName.append("/" + ch);
|
windowsName.append('/').append(ch);
|
||||||
} else {
|
} else {
|
||||||
windowsName.append(ch);
|
windowsName.append(ch);
|
||||||
}
|
}
|
||||||
@ -976,13 +997,13 @@ class WindowsPreferences extends AbstractPreferences {
|
|||||||
// Convert to byte pairs
|
// Convert to byte pairs
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
for (int i = 0; i < javaName.length();i++) {
|
for (int i = 0; i < javaName.length();i++) {
|
||||||
int ch = javaName.charAt(i);
|
int ch = javaName.charAt(i);
|
||||||
javaNameArray[counter++] = (byte)(ch >>> 8);
|
javaNameArray[counter++] = (byte)(ch >>> 8);
|
||||||
javaNameArray[counter++] = (byte)ch;
|
javaNameArray[counter++] = (byte)ch;
|
||||||
}
|
}
|
||||||
|
|
||||||
return stringToByteArray(
|
return stringToByteArray("/!" +
|
||||||
"/!" + Base64.byteArrayToAltBase64(javaNameArray));
|
Base64.byteArrayToAltBase64(javaNameArray));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -994,30 +1015,31 @@ class WindowsPreferences extends AbstractPreferences {
|
|||||||
private static String toJavaValueString(byte[] windowsNameArray) {
|
private static String toJavaValueString(byte[] windowsNameArray) {
|
||||||
// Use modified native2ascii algorithm
|
// Use modified native2ascii algorithm
|
||||||
String windowsName = byteArrayToString(windowsNameArray);
|
String windowsName = byteArrayToString(windowsNameArray);
|
||||||
StringBuffer javaName = new StringBuffer();
|
StringBuilder javaName = new StringBuilder();
|
||||||
char ch;
|
char ch;
|
||||||
for (int i = 0; i < windowsName.length(); i++){
|
for (int i = 0; i < windowsName.length(); i++){
|
||||||
if ((ch = windowsName.charAt(i)) == '/') {
|
if ((ch = windowsName.charAt(i)) == '/') {
|
||||||
char next = ' ';
|
char next = ' ';
|
||||||
|
|
||||||
if (windowsName.length() > i + 1 &&
|
if (windowsName.length() > i + 1 &&
|
||||||
(next = windowsName.charAt(i + 1)) == 'u') {
|
(next = windowsName.charAt(i + 1)) == 'u') {
|
||||||
if (windowsName.length() < i + 6){
|
if (windowsName.length() < i + 6) {
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
ch = (char)Integer.parseInt
|
ch = (char)Integer.parseInt(
|
||||||
(windowsName.substring(i + 2, i + 6), 16);
|
windowsName.substring(i + 2, i + 6), 16);
|
||||||
i += 5;
|
i += 5;
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
if ((windowsName.length() > i + 1) &&
|
if ((windowsName.length() > i + 1) &&
|
||||||
((windowsName.charAt(i+1)) >= 'A') && (next <= 'Z')) {
|
((windowsName.charAt(i+1)) >= 'A') &&
|
||||||
ch = next;
|
(next <= 'Z')) {
|
||||||
i++;
|
ch = next;
|
||||||
} else if ((windowsName.length() > i + 1) &&
|
i++;
|
||||||
(next == '/')) {
|
} else if ((windowsName.length() > i + 1) &&
|
||||||
ch = '\\';
|
(next == '/')) {
|
||||||
i++;
|
ch = '\\';
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
} else if (ch == '\\') {
|
} else if (ch == '\\') {
|
||||||
ch = '/';
|
ch = '/';
|
||||||
@ -1037,14 +1059,14 @@ class WindowsPreferences extends AbstractPreferences {
|
|||||||
* to convert java string to a byte array of ASCII characters.
|
* to convert java string to a byte array of ASCII characters.
|
||||||
*/
|
*/
|
||||||
private static byte[] toWindowsValueString(String javaName) {
|
private static byte[] toWindowsValueString(String javaName) {
|
||||||
StringBuffer windowsName = new StringBuffer();
|
StringBuilder windowsName = new StringBuilder();
|
||||||
for (int i = 0; i < javaName.length(); i++) {
|
for (int i = 0; i < javaName.length(); i++) {
|
||||||
char ch =javaName.charAt(i);
|
char ch = javaName.charAt(i);
|
||||||
if ((ch < 0x0020)||(ch > 0x007f)){
|
if ((ch < 0x0020) || (ch > 0x007f)){
|
||||||
// write \udddd
|
// write \udddd
|
||||||
windowsName.append("/u");
|
windowsName.append("/u");
|
||||||
String hex = Integer.toHexString(javaName.charAt(i));
|
String hex = Integer.toHexString(javaName.charAt(i));
|
||||||
StringBuffer hex4 = new StringBuffer(hex);
|
StringBuilder hex4 = new StringBuilder(hex);
|
||||||
hex4.reverse();
|
hex4.reverse();
|
||||||
int len = 4 - hex4.length();
|
int len = 4 - hex4.length();
|
||||||
for (int j = 0; j < len; j++){
|
for (int j = 0; j < len; j++){
|
||||||
@ -1058,7 +1080,7 @@ class WindowsPreferences extends AbstractPreferences {
|
|||||||
} else if (ch == '/') {
|
} else if (ch == '/') {
|
||||||
windowsName.append('\\');
|
windowsName.append('\\');
|
||||||
} else if ((ch >= 'A') && (ch <='Z')) {
|
} else if ((ch >= 'A') && (ch <='Z')) {
|
||||||
windowsName.append("/" + ch);
|
windowsName.append('/').append(ch);
|
||||||
} else {
|
} else {
|
||||||
windowsName.append(ch);
|
windowsName.append(ch);
|
||||||
}
|
}
|
||||||
@ -1070,8 +1092,9 @@ class WindowsPreferences extends AbstractPreferences {
|
|||||||
* Returns native handle for the top Windows node for this node.
|
* Returns native handle for the top Windows node for this node.
|
||||||
*/
|
*/
|
||||||
private int rootNativeHandle() {
|
private int rootNativeHandle() {
|
||||||
return (isUserNode()? USER_ROOT_NATIVE_HANDLE :
|
return (isUserNode()
|
||||||
SYSTEM_ROOT_NATIVE_HANDLE);
|
? USER_ROOT_NATIVE_HANDLE
|
||||||
|
: SYSTEM_ROOT_NATIVE_HANDLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1090,7 +1113,7 @@ class WindowsPreferences extends AbstractPreferences {
|
|||||||
* Converts a null-terminated byte array to java string
|
* Converts a null-terminated byte array to java string
|
||||||
*/
|
*/
|
||||||
private static String byteArrayToString(byte[] array) {
|
private static String byteArrayToString(byte[] array) {
|
||||||
StringBuffer result = new StringBuffer();
|
StringBuilder result = new StringBuilder();
|
||||||
for (int i = 0; i < array.length - 1; i++) {
|
for (int i = 0; i < array.length - 1; i++) {
|
||||||
result.append((char)array[i]);
|
result.append((char)array[i]);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -67,7 +67,7 @@ public class SerialBlob implements Blob, Serializable, Cloneable {
|
|||||||
* value of this <code>SerialBlob</code> object.
|
* value of this <code>SerialBlob</code> object.
|
||||||
* @serial
|
* @serial
|
||||||
*/
|
*/
|
||||||
private byte buf[];
|
private byte[] buf;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The internal representation of the <code>Blob</code> object on which this
|
* The internal representation of the <code>Blob</code> object on which this
|
||||||
@ -103,12 +103,13 @@ public class SerialBlob implements Blob, Serializable, Cloneable {
|
|||||||
* @throws SerialException if an error occurs during serialization
|
* @throws SerialException if an error occurs during serialization
|
||||||
* @throws SQLException if a SQL errors occurs
|
* @throws SQLException if a SQL errors occurs
|
||||||
*/
|
*/
|
||||||
public SerialBlob(byte[] b) throws SerialException, SQLException {
|
public SerialBlob(byte[] b)
|
||||||
|
throws SerialException, SQLException {
|
||||||
|
|
||||||
len = b.length;
|
len = b.length;
|
||||||
buf = new byte[(int)len];
|
buf = new byte[(int)len];
|
||||||
for(int i = 0; i < len; i++) {
|
for(int i = 0; i < len; i++) {
|
||||||
buf[i] = b[i];
|
buf[i] = b[i];
|
||||||
}
|
}
|
||||||
origLen = len;
|
origLen = len;
|
||||||
}
|
}
|
||||||
@ -133,19 +134,17 @@ public class SerialBlob implements Blob, Serializable, Cloneable {
|
|||||||
* to this constructor is a <code>null</code>.
|
* to this constructor is a <code>null</code>.
|
||||||
* @see java.sql.Blob
|
* @see java.sql.Blob
|
||||||
*/
|
*/
|
||||||
public SerialBlob (Blob blob) throws SerialException, SQLException {
|
public SerialBlob (Blob blob)
|
||||||
|
throws SerialException, SQLException {
|
||||||
|
|
||||||
if (blob == null) {
|
if (blob == null) {
|
||||||
throw new SQLException("Cannot instantiate a SerialBlob " +
|
throw new SQLException(
|
||||||
"object with a null Blob object");
|
"Cannot instantiate a SerialBlob object with a null Blob object");
|
||||||
}
|
}
|
||||||
|
|
||||||
len = blob.length();
|
len = blob.length();
|
||||||
buf = blob.getBytes(1, (int)len );
|
buf = blob.getBytes(1, (int)len );
|
||||||
this.blob = blob;
|
this.blob = blob;
|
||||||
|
|
||||||
//if ( len < 10240000)
|
|
||||||
// len = 10240000;
|
|
||||||
origLen = len;
|
origLen = len;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -246,7 +245,8 @@ public class SerialBlob implements Blob, Serializable, Cloneable {
|
|||||||
* value from the database
|
* value from the database
|
||||||
*/
|
*/
|
||||||
public long position(byte[] pattern, long start)
|
public long position(byte[] pattern, long start)
|
||||||
throws SerialException, SQLException {
|
throws SerialException, SQLException {
|
||||||
|
|
||||||
isValid();
|
isValid();
|
||||||
if (start < 1 || start > len) {
|
if (start < 1 || start > len) {
|
||||||
return -1;
|
return -1;
|
||||||
@ -291,7 +291,7 @@ public class SerialBlob implements Blob, Serializable, Cloneable {
|
|||||||
* value from the database
|
* value from the database
|
||||||
*/
|
*/
|
||||||
public long position(Blob pattern, long start)
|
public long position(Blob pattern, long start)
|
||||||
throws SerialException, SQLException {
|
throws SerialException, SQLException {
|
||||||
isValid();
|
isValid();
|
||||||
return position(pattern.getBytes(1, (int)(pattern.length())), start);
|
return position(pattern.getBytes(1, (int)(pattern.length())), start);
|
||||||
}
|
}
|
||||||
@ -317,8 +317,8 @@ public class SerialBlob implements Blob, Serializable, Cloneable {
|
|||||||
* @see #getBytes
|
* @see #getBytes
|
||||||
*/
|
*/
|
||||||
public int setBytes(long pos, byte[] bytes)
|
public int setBytes(long pos, byte[] bytes)
|
||||||
throws SerialException, SQLException {
|
throws SerialException, SQLException {
|
||||||
return (setBytes(pos, bytes, 0, bytes.length));
|
return setBytes(pos, bytes, 0, bytes.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -353,7 +353,7 @@ public class SerialBlob implements Blob, Serializable, Cloneable {
|
|||||||
* @see #getBytes
|
* @see #getBytes
|
||||||
*/
|
*/
|
||||||
public int setBytes(long pos, byte[] bytes, int offset, int length)
|
public int setBytes(long pos, byte[] bytes, int offset, int length)
|
||||||
throws SerialException, SQLException {
|
throws SerialException, SQLException {
|
||||||
|
|
||||||
isValid();
|
isValid();
|
||||||
if (offset < 0 || offset > bytes.length) {
|
if (offset < 0 || offset > bytes.length) {
|
||||||
@ -370,7 +370,7 @@ public class SerialBlob implements Blob, Serializable, Cloneable {
|
|||||||
|
|
||||||
if ((length + offset) > bytes.length) {
|
if ((length + offset) > bytes.length) {
|
||||||
throw new SerialException("Invalid OffSet. Cannot have combined offset " +
|
throw new SerialException("Invalid OffSet. Cannot have combined offset " +
|
||||||
"and length that is greater that the Blob buffer");
|
"and length that is greater that the Blob buffer");
|
||||||
}
|
}
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
@ -403,7 +403,8 @@ public class SerialBlob implements Blob, Serializable, Cloneable {
|
|||||||
* @see #getBinaryStream
|
* @see #getBinaryStream
|
||||||
*/
|
*/
|
||||||
public java.io.OutputStream setBinaryStream(long pos)
|
public java.io.OutputStream setBinaryStream(long pos)
|
||||||
throws SerialException, SQLException {
|
throws SerialException, SQLException {
|
||||||
|
|
||||||
isValid();
|
isValid();
|
||||||
if (this.blob != null) {
|
if (this.blob != null) {
|
||||||
return this.blob.setBinaryStream(pos);
|
return this.blob.setBinaryStream(pos);
|
||||||
@ -426,17 +427,16 @@ public class SerialBlob implements Blob, Serializable, Cloneable {
|
|||||||
* if {@code free} had previously been called on this object
|
* if {@code free} had previously been called on this object
|
||||||
*/
|
*/
|
||||||
public void truncate(long length) throws SerialException {
|
public void truncate(long length) throws SerialException {
|
||||||
|
|
||||||
isValid();
|
isValid();
|
||||||
if (length > len) {
|
if (length > len) {
|
||||||
throw new SerialException
|
throw new SerialException(
|
||||||
("Length more than what can be truncated");
|
"Length more than what can be truncated");
|
||||||
} else if((int)length == 0) {
|
} else if((int)length == 0) {
|
||||||
buf = new byte[0];
|
buf = new byte[0];
|
||||||
len = length;
|
len = length;
|
||||||
} else {
|
} else {
|
||||||
len = length;
|
len = length;
|
||||||
buf = this.getBytes(1, (int)len);
|
buf = this.getBytes(1, (int)len);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -467,8 +467,8 @@ public class SerialBlob implements Blob, Serializable, Cloneable {
|
|||||||
throw new SerialException("Invalid position in BLOB object set");
|
throw new SerialException("Invalid position in BLOB object set");
|
||||||
}
|
}
|
||||||
if (length < 1 || length > len - pos + 1) {
|
if (length < 1 || length > len - pos + 1) {
|
||||||
throw new SerialException("length is < 1 or pos + length >"
|
throw new SerialException(
|
||||||
+ "total number of bytes");
|
"length is < 1 or pos + length > total number of bytes");
|
||||||
}
|
}
|
||||||
return new ByteArrayInputStream(buf, (int) pos - 1, (int) length);
|
return new ByteArrayInputStream(buf, (int) pos - 1, (int) length);
|
||||||
}
|
}
|
||||||
@ -537,14 +537,13 @@ public class SerialBlob implements Blob, Serializable, Cloneable {
|
|||||||
public Object clone() {
|
public Object clone() {
|
||||||
try {
|
try {
|
||||||
SerialBlob sb = (SerialBlob) super.clone();
|
SerialBlob sb = (SerialBlob) super.clone();
|
||||||
sb.buf = (buf != null) ? Arrays.copyOf(buf, (int)len) : null;
|
sb.buf = (buf != null) ? Arrays.copyOf(buf, (int)len) : null;
|
||||||
sb.blob = null;
|
sb.blob = null;
|
||||||
return sb;
|
return sb;
|
||||||
} catch (CloneNotSupportedException ex) {
|
} catch (CloneNotSupportedException ex) {
|
||||||
// this shouldn't happen, since we are Cloneable
|
// this shouldn't happen, since we are Cloneable
|
||||||
throw new InternalError();
|
throw new InternalError();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -555,15 +554,15 @@ public class SerialBlob implements Blob, Serializable, Cloneable {
|
|||||||
throws IOException, ClassNotFoundException {
|
throws IOException, ClassNotFoundException {
|
||||||
|
|
||||||
ObjectInputStream.GetField fields = s.readFields();
|
ObjectInputStream.GetField fields = s.readFields();
|
||||||
byte[] tmp = (byte[])fields.get("buf", null);
|
byte[] tmp = (byte[])fields.get("buf", null);
|
||||||
if (tmp == null)
|
if (tmp == null)
|
||||||
throw new InvalidObjectException("buf is null and should not be!");
|
throw new InvalidObjectException("buf is null and should not be!");
|
||||||
buf = tmp.clone();
|
buf = tmp.clone();
|
||||||
len = fields.get("len", 0L);
|
len = fields.get("len", 0L);
|
||||||
if (buf.length != len)
|
if (buf.length != len)
|
||||||
throw new InvalidObjectException("buf is not the expected size");
|
throw new InvalidObjectException("buf is not the expected size");
|
||||||
origLen = fields.get("origLen", 0L);
|
origLen = fields.get("origLen", 0L);
|
||||||
blob = (Blob) fields.get("blob", null);
|
blob = (Blob) fields.get("blob", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -591,8 +590,8 @@ public class SerialBlob implements Blob, Serializable, Cloneable {
|
|||||||
*/
|
*/
|
||||||
private void isValid() throws SerialException {
|
private void isValid() throws SerialException {
|
||||||
if (buf == null) {
|
if (buf == null) {
|
||||||
throw new SerialException("Error: You cannot call a method on a "
|
throw new SerialException("Error: You cannot call a method on a " +
|
||||||
+ "SerialBlob instance once free() has been called.");
|
"SerialBlob instance once free() has been called.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user