本文整理匯總了Java中java.lang.reflect.Field.getLong方法的典型用法代碼示例。如果您正苦於以下問題:Java Field.getLong方法的具體用法?Java Field.getLong怎麽用?Java Field.getLong使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.lang.reflect.Field
的用法示例。
在下文中一共展示了Field.getLong方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getLongVolatile
import java.lang.reflect.Field; //導入方法依賴的package包/類
public long getLongVolatile(Object obj, long offset)
{
if (obj instanceof cli.System.Array)
{
synchronized(this)
{
return ReadInt64(obj, offset);
}
}
else
{
Field field = getField(offset);
synchronized(field)
{
try
{
return field.getLong(obj);
}
catch(IllegalAccessException x)
{
throw (InternalError)new InternalError().initCause(x);
}
}
}
}
示例2: getWindowsProcessId
import java.lang.reflect.Field; //導入方法依賴的package包/類
/**
* @param process NiFi Registry Process Reference
* @param logger Logger Reference for Debug
* @return Returns pid or null in-case pid could not be determined
* This method takes {@link Process} and {@link Logger} and returns
* the platform specific Handle for Win32 Systems, a.k.a <b>pid</b>
* In-case it fails to determine the pid, it will return Null.
* Purpose for the Logger is to log any interaction for debugging.
*/
private static Long getWindowsProcessId(final Process process, final Logger logger) {
/* determine the pid on windows plattforms */
try {
Field f = process.getClass().getDeclaredField("handle");
f.setAccessible(true);
long handl = f.getLong(process);
Kernel32 kernel = Kernel32.INSTANCE;
WinNT.HANDLE handle = new WinNT.HANDLE();
handle.setPointer(Pointer.createConstant(handl));
int ret = kernel.GetProcessId(handle);
logger.debug("Detected pid: {}", ret);
return Long.valueOf(ret);
} catch (final IllegalAccessException | NoSuchFieldException nsfe) {
logger.debug("Could not find PID for child process due to {}", nsfe);
}
return null;
}
示例3: getProcessId
import java.lang.reflect.Field; //導入方法依賴的package包/類
@Override
protected long getProcessId(Process process) {
long result = super.getProcessId(process);
if (result == 0L) {
/* jtreg didn't find pid, most probably we are on JDK < 9
there is no Process::getPid */
if (HAS_NATIVE_LIBRARY && "windows".equals(OS.current().family)) {
try {
Field field = process.getClass().getDeclaredField("handle");
boolean old = field.isAccessible();
try {
field.setAccessible(true);
long handle = field.getLong(process);
result = getWin32Pid(handle);
} finally {
field.setAccessible(old);
}
} catch (ReflectiveOperationException e) {
e.printStackTrace(log);
}
}
}
return result;
}
示例4: serialize
import java.lang.reflect.Field; //導入方法依賴的package包/類
void serialize(AbstractHessianOutput out, Object obj, Field field)
throws IOException
{
long value = 0;
try {
value = field.getLong(obj);
} catch (IllegalAccessException e) {
log.log(Level.FINE, e.toString(), e);
}
out.writeLong(value);
}
示例5: getRowid
import java.lang.reflect.Field; //導入方法依賴的package包/類
public static <T extends ILKDBModel> long getRowid(T mode){
LKModelInfos infos = getModelInfos(mode.getClass());
String rowidName = infos.getDb_rowidAliasName();
if(TextUtils.isEmpty(rowidName)){
return 0;
}
Field field = infos.getFieldMaps().get(rowidName);
long rowid = 0;
try {
rowid = field.getLong(mode);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return rowid;
}
示例6: scanNotActiveChannel
import java.lang.reflect.Field; //導入方法依賴的package包/類
@Test
public void scanNotActiveChannel() throws Exception {
producerManager.registerProducer(group, clientInfo);
assertThat(producerManager.getGroupChannelTable().get(group).get(channel)).isNotNull();
Field field = ProducerManager.class.getDeclaredField("CHANNEL_EXPIRED_TIMEOUT");
field.setAccessible(true);
long CHANNEL_EXPIRED_TIMEOUT = field.getLong(producerManager);
clientInfo.setLastUpdateTimestamp(System.currentTimeMillis() - CHANNEL_EXPIRED_TIMEOUT - 10);
when(channel.close()).thenReturn(mock(ChannelFuture.class));
producerManager.scanNotActiveChannel();
assertThat(producerManager.getGroupChannelTable().get(group).get(channel)).isNull();
}
示例7: getLong
import java.lang.reflect.Field; //導入方法依賴的package包/類
private long getLong(Object object, String id) {
long value = 0l;
try {
Field field = object.getClass().getDeclaredField(id);
field.setAccessible(true);
value = field.getLong(object);
} catch (Exception e) {
e.printStackTrace();
}
return value;
}
示例8: initFx
import java.lang.reflect.Field; //導入方法依賴的package包/類
private static void initFx() {
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
System.setProperty("javafx.embed.isEventThread", "true");
System.setProperty("glass.win.uiScale", "100%");
System.setProperty("glass.win.renderScale", "100%");
return null;
});
Map map = Application.getDeviceDetails();
if (map == null) {
Application.setDeviceDetails(map = new HashMap());
}
if (map.get("javafx.embed.eventProc") == null) {
long eventProc = 0;
try {
Field field = Display.class.getDeclaredField("eventProc");
field.setAccessible(true);
if (field.getType() == int.class) {
eventProc = field.getLong(Display.getDefault());
} else {
if (field.getType() == long.class) {
eventProc = field.getLong(Display.getDefault());
}
}
} catch (Throwable th) {
//Fail silently
}
map.put("javafx.embed.eventProc", eventProc);
}
// Note that calling PlatformImpl.startup more than once is OK
PlatformImpl.startup(() -> {
Application.GetApplication().setName(Display.getAppName());
});
}
示例9: start
import java.lang.reflect.Field; //導入方法依賴的package包/類
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public void start() {
Log.d(TAG, "start vsync detect");
if (mRunning) {
return;
}
mRunning = true;
syncCheckThread = new Thread(new Runnable() {
@Override
public void run() {
for (;;) {
if (!mRunning) {
break;
}
syncCheckThread();
}
}
});
syncCheckThread.start();
Choreographer chor = Choreographer.getInstance();
Field field;
try {
field = chor.getClass().getDeclaredField("mFrameIntervalNanos");
field.setAccessible(true);
mFrameIntervalNanos = field.getLong(chor);
Log.d(TAG, "mFrameIntervalNanos " + mFrameIntervalNanos);
} catch (Exception e) {
Log.e(TAG, "error: " + e.getMessage());
}
chor.postFrameCallback(frameCallback);
}
示例10: init
import java.lang.reflect.Field; //導入方法依賴的package包/類
/**
* Test fails if it throws any exception.
*
* @throws Exception
*/
private void init() throws Exception {
if (!System.getProperty("os.name").startsWith("Windows")) {
System.out.println("This is Windows only test.");
return;
}
final Frame frame = new Frame("AWT Frame");
frame.pack();
frame.setSize(200, 200);
FramePeer frame_peer = AWTAccessor.getComponentAccessor()
.getPeer(frame);
Class comp_peer_class
= Class.forName("sun.awt.windows.WComponentPeer");
Field hwnd_field = comp_peer_class.getDeclaredField("hwnd");
hwnd_field.setAccessible(true);
long hwnd = hwnd_field.getLong(frame_peer);
Class clazz = Class.forName("sun.awt.windows.WEmbeddedFrame");
Constructor constructor
= clazz.getConstructor(new Class[]{long.class});
final Frame embedded_frame
= (Frame) constructor.newInstance(new Object[]{
new Long(hwnd)});;
final JComboBox<String> combo = new JComboBox<>(new String[]{
"Item 1", "Item 2"
});
combo.setSelectedIndex(1);
final Panel p = new Panel();
p.setLayout(new BorderLayout());
embedded_frame.add(p, BorderLayout.CENTER);
embedded_frame.validate();
p.add(combo);
p.validate();
frame.setVisible(true);
Robot robot = new Robot();
robot.delay(2000);
Rectangle clos = new Rectangle(
combo.getLocationOnScreen(), combo.getSize());
robot.mouseMove(clos.x + clos.width / 2, clos.y + clos.height / 2);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
robot.delay(1000);
if (!combo.isPopupVisible()) {
throw new RuntimeException("Combobox popup is not visible!");
}
robot.mouseMove(clos.x + clos.width / 2, clos.y + clos.height + 3);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
robot.delay(1000);
if (combo.getSelectedIndex() != 0) {
throw new RuntimeException("Combobox selection has not changed!");
}
embedded_frame.remove(p);
embedded_frame.dispose();
frame.dispose();
}
示例11: getProtocolVersion
import java.lang.reflect.Field; //導入方法依賴的package包/類
static long getProtocolVersion(Class<? extends VersionedProtocol> protocol)
throws NoSuchFieldException, IllegalAccessException {
Field versionField = protocol.getField("VERSION");
versionField.setAccessible(true);
return versionField.getLong(protocol);
}
示例12: createWin
import java.lang.reflect.Field; //導入方法依賴的package包/類
private void createWin() throws IOException, InterruptedException {
// Don't use shell wrapping on Windows...
// Mostly this is because exec works not as expected and we cannot
// control processes started with exec method....
// Suspend is not supported on Windows.
final ProcessBuilder pb = new ProcessBuilder(); // NOI18N
final MacroMap jointEnv = MacroMap.forExecEnv(ExecutionEnvironmentFactory.getLocal());
jointEnv.putAll(info.getEnvironment());
if (isInterrupted()) {
throw new InterruptedException();
}
if (info.isUnbuffer()) {
UnbufferSupport.initUnbuffer(info.getExecutionEnvironment(), jointEnv);
}
pb.environment().clear();
for (Entry<String, String> envEntry : jointEnv.entrySet()) {
pb.environment().put(envEntry.getKey(), envEntry.getValue());
}
pb.redirectErrorStream(info.isRedirectError());
pb.command(info.getCommand());
if (LOG.isLoggable(Level.FINEST)) {
LOG.finest(String.format("Command: %s", info.getCommand())); // NOI18N
}
String wdir = info.getWorkingDirectory(true);
if (wdir != null) {
File wd = new File(wdir);
if (!wd.exists()) {
throw new FileNotFoundException(loc("NativeProcess.noSuchDirectoryError.text", wd.getAbsolutePath())); // NOI18N
}
pb.directory(wd);
if (LOG.isLoggable(Level.FINEST)) {
LOG.finest(String.format("Working directory: %s", wdir)); // NOI18N
}
}
process = pb.start();
creation_ts = System.nanoTime();
errorPipedOutputStream = new PipedOutputStream();
errorPipedInputStream = new PipedInputStream(errorPipedOutputStream);
setErrorStream(new SequenceInputStream(process.getErrorStream(), errorPipedInputStream));
setInputStream(process.getInputStream());
setOutputStream(process.getOutputStream());
int newPid = 12345;
try {
String className = process.getClass().getName();
if ("java.lang.Win32Process".equals(className) || "java.lang.ProcessImpl".equals(className)) { // NOI18N
Field f = process.getClass().getDeclaredField("handle"); // NOI18N
f.setAccessible(true);
long phandle = f.getLong(process);
Win32APISupport kernel = Win32APISupport.instance;
Win32APISupport.HANDLE handle = new Win32APISupport.HANDLE();
handle.setPointer(Pointer.createConstant(phandle));
newPid = kernel.GetProcessId(handle);
}
} catch (Throwable e) {
}
ByteArrayInputStream bis = new ByteArrayInputStream(("" + newPid).getBytes()); // NOI18N
readPID(bis);
}
示例13: getField
import java.lang.reflect.Field; //導入方法依賴的package包/類
public static Object getField(Object instance, Field field) throws IllegalAccessException {
if (UNSAFE != null) {
if (int.class.equals(field.getType())) {
return ((sun.misc.Unsafe) UNSAFE).getInt(instance, ((sun.misc.Unsafe) UNSAFE).objectFieldOffset(field));
} else if (long.class.equals(field.getType())) {
return ((sun.misc.Unsafe) UNSAFE).getLong(instance, ((sun.misc.Unsafe) UNSAFE).objectFieldOffset(field));
} else if (double.class.equals(field.getType())) {
return ((sun.misc.Unsafe) UNSAFE).getDouble(instance, ((sun.misc.Unsafe) UNSAFE).objectFieldOffset(field));
} else if (void.class.equals(field.getType())) {
return null;
} else if (float.class.equals(field.getType())) {
return ((sun.misc.Unsafe) UNSAFE).getFloat(instance, ((sun.misc.Unsafe) UNSAFE).objectFieldOffset(field));
} else if (byte.class.equals(field.getType())) {
return ((sun.misc.Unsafe) UNSAFE).getByte(instance, ((sun.misc.Unsafe) UNSAFE).objectFieldOffset(field));
} else if (char.class.equals(field.getType())) {
return ((sun.misc.Unsafe) UNSAFE).getChar(instance, ((sun.misc.Unsafe) UNSAFE).objectFieldOffset(field));
} else if (boolean.class.equals(field.getType())) {
return ((sun.misc.Unsafe) UNSAFE).getBoolean(instance, ((sun.misc.Unsafe) UNSAFE).objectFieldOffset(field));
} else if (short.class.equals(field.getType())) {
return ((sun.misc.Unsafe) UNSAFE).getShort(instance, ((sun.misc.Unsafe) UNSAFE).objectFieldOffset(field));
} else {
return ((sun.misc.Unsafe) UNSAFE).getObject(instance, ((sun.misc.Unsafe) UNSAFE).objectFieldOffset(field));
}
} else { //Fallback if unsafe isn't available
field.setAccessible(true);
if (int.class.equals(field.getType())) {
return field.getInt(instance);
} else if (long.class.equals(field.getType())) {
return field.getLong(instance);
} else if (double.class.equals(field.getType())) {
return field.getDouble(instance);
} else if (void.class.equals(field.getType())) {
return null;
} else if (float.class.equals(field.getType())) {
return field.getFloat(instance);
} else if (byte.class.equals(field.getType())) {
return field.getByte(instance);
} else if (char.class.equals(field.getType())) {
return field.getChar(instance);
} else if (boolean.class.equals(field.getType())) {
return field.getBoolean(instance);
} else if (short.class.equals(field.getType())) {
return field.getShort(instance);
} else {
return field.get(instance);
}
}
}
示例14: equals
import java.lang.reflect.Field; //導入方法依賴的package包/類
/**
* An introspection based equality predicate for SIPObjects.
*@param other the other object to test against.
*/
public boolean equals(Object other) {
if (!this.getClass().equals(other.getClass()))
return false;
SIPObject that = (SIPObject) other;
Class myclass = this.getClass();
Class hisclass = other.getClass();
while (true) {
Field[] fields = myclass.getDeclaredFields();
if (!hisclass.equals(myclass))
return false;
Field[] hisfields = hisclass.getDeclaredFields();
for (int i = 0; i < fields.length; i++) {
Field f = fields[i];
Field g = hisfields[i];
// Only print protected and public members.
int modifier = f.getModifiers();
if ((modifier & Modifier.PRIVATE) == Modifier.PRIVATE)
continue;
Class fieldType = f.getType();
String fieldName = f.getName();
if (fieldName.compareTo("stringRepresentation") == 0) {
continue;
}
if (fieldName.compareTo("indentation") == 0) {
continue;
}
try {
// Primitive fields are printed with type: value
if (fieldType.isPrimitive()) {
String fname = fieldType.toString();
if (fname.compareTo("int") == 0) {
if (f.getInt(this) != g.getInt(that))
return false;
} else if (fname.compareTo("short") == 0) {
if (f.getShort(this) != g.getShort(that))
return false;
} else if (fname.compareTo("char") == 0) {
if (f.getChar(this) != g.getChar(that))
return false;
} else if (fname.compareTo("long") == 0) {
if (f.getLong(this) != g.getLong(that))
return false;
} else if (fname.compareTo("boolean") == 0) {
if (f.getBoolean(this) != g.getBoolean(that))
return false;
} else if (fname.compareTo("double") == 0) {
if (f.getDouble(this) != g.getDouble(that))
return false;
} else if (fname.compareTo("float") == 0) {
if (f.getFloat(this) != g.getFloat(that))
return false;
}
} else if (g.get(that) == f.get(this))
continue;
else if (f.get(this) == null && g.get(that) != null)
return false;
else if (g.get(that) == null && f.get(this) != null)
return false;
else if (!f.get(this).equals(g.get(that)))
return false;
} catch (IllegalAccessException ex1) {
System.out.println("accessed field " + fieldName);
System.out.println("modifier " + modifier);
System.out.println("modifier.private " + Modifier.PRIVATE);
InternalErrorHandler.handleException(ex1);
}
}
if (myclass.equals(SIPObject.class))
break;
else {
myclass = myclass.getSuperclass();
hisclass = hisclass.getSuperclass();
}
}
return true;
}