8242695: Enhanced buffer support
Reviewed-by: alanb, rhalade
This commit is contained in:
parent
a6723c8552
commit
fc5fca9ade
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2008, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -55,10 +55,15 @@ public class RegistryFileTypeDetector
|
||||
|
||||
// query HKEY_CLASSES_ROOT\<ext>
|
||||
String key = filename.substring(dot);
|
||||
NativeBuffer keyBuffer = WindowsNativeDispatcher.asNativeBuffer(key);
|
||||
NativeBuffer nameBuffer = WindowsNativeDispatcher.asNativeBuffer("Content Type");
|
||||
NativeBuffer keyBuffer = null;
|
||||
NativeBuffer nameBuffer = null;
|
||||
try {
|
||||
keyBuffer = WindowsNativeDispatcher.asNativeBuffer(key);
|
||||
nameBuffer = WindowsNativeDispatcher.asNativeBuffer("Content Type");
|
||||
return queryStringValue(keyBuffer.address(), nameBuffer.address());
|
||||
} catch (WindowsException we) {
|
||||
we.rethrowAsIOException(file.toString());
|
||||
return null; // keep compiler happy
|
||||
} finally {
|
||||
nameBuffer.release();
|
||||
keyBuffer.release();
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2008, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -1123,7 +1123,12 @@ class WindowsNativeDispatcher {
|
||||
|
||||
private static final Unsafe unsafe = Unsafe.getUnsafe();
|
||||
|
||||
static NativeBuffer asNativeBuffer(String s) {
|
||||
static NativeBuffer asNativeBuffer(String s) throws WindowsException {
|
||||
if (s.length() > (Integer.MAX_VALUE - 2)/2) {
|
||||
throw new WindowsException
|
||||
("String too long to convert to native buffer");
|
||||
}
|
||||
|
||||
int stringLengthInBytes = s.length() << 1;
|
||||
int sizeInBytes = stringLengthInBytes + 2; // char terminator
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user