List of usage examples for java.lang.reflect Field getInt
@CallerSensitive @ForceInline public int getInt(Object obj) throws IllegalArgumentException, IllegalAccessException
From source file:org.acra.collector.DisplayManagerCollector.java
@NonNull private String collectFlags(@NonNull Display display) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { final int flags = display.getFlags(); for (Field field : display.getClass().getFields()) { if (field.getName().startsWith("FLAG_")) { try { flagNames.put(field.getInt(null), field.getName()); } catch (IllegalAccessException ignored) { }// ww w . java2 s . c om } } return display.getDisplayId() + ".flags=" + activeFlags(flags) + '\n'; } return ""; }
From source file:me.wimanacra.collector.DisplayManagerCollector.java
private void collectFlags(@NonNull Display display, @NonNull JSONObject container) throws JSONException { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { final int flags = display.getFlags(); for (Field field : display.getClass().getFields()) { if (field.getName().startsWith("FLAG_")) { try { flagNames.put(field.getInt(null), field.getName()); } catch (IllegalAccessException ignored) { }/* w ww . ja va2 s. co m*/ } } container.put("flags", activeFlags(flags)); } }
From source file:org.jgentleframework.utils.ReflectUtils.java
/** * Sets new value to static final field. * <p>/*w w w . ja v a 2s. c om*/ * <b>Note</b>: this method only run on Sun JDK * * @param field * the field * @param value * the new value * @throws NoSuchFieldException * the no such field exception * @throws IllegalAccessException * the illegal access exception */ public static void setStaticFinalField(Field field, Object value) throws NoSuchFieldException, IllegalAccessException { field.setAccessible(true); Field modifiersField = Field.class.getDeclaredField(MODIFIERS_FIELD); modifiersField.setAccessible(true); int modifiers = modifiersField.getInt(field); modifiers &= ~Modifier.FINAL; modifiersField.setInt(field, modifiers); FieldAccessor fa = reflection.newFieldAccessor(field, false); fa.set(null, value); }
From source file:com.netflix.genie.core.jobs.workflow.impl.JobKickoffTask.java
/** * Helper method to get process id for the given process. * * @param proc java process object representing the job launcher * @return pid for this process//from w ww . j a va 2 s .c o m * @throws GenieException if there is an error getting the process id */ private int getProcessId(final Process proc) throws GenieException { log.debug("called"); try { final Field f = proc.getClass().getDeclaredField(JobConstants.PID); f.setAccessible(true); return f.getInt(proc); } catch (final IllegalAccessException | IllegalArgumentException | NoSuchFieldException | SecurityException e) { final String msg = "Can't get process id for job"; log.error(msg, e); throw new GenieServerException(msg, e); } }
From source file:org.apache.hadoop.hdfs.qjournal.client.TestQuorumJournalManagerInputStream.java
/** * Get the journal node we are tailing from, and indicate which stream this is. */// w ww . ja va 2 s . c o m private JournalNode getTailingJN(EditLogInputStream str, URLLogInputStream[] tailingStream) throws Exception { RedundantEditLogInputStream is = (RedundantEditLogInputStream) str; Field curIdxF = RedundantEditLogInputStream.class.getDeclaredField("curIdx"); curIdxF.setAccessible(true); int curIdx = curIdxF.getInt(is); URLLogInputStream[] streams = getStreams(is); JournalNode jn = null; for (JournalNode j : cluster.getJournalNodes()) { if (streams[curIdx].getName().contains(Integer.toString(j.getBoundHttpAddress().getPort()))) { jn = j; break; } } tailingStream[0] = streams[curIdx]; return jn; }
From source file:org.eclipse.jubula.rc.swt.utils.SwtUtils.java
/** * GTK-specific workaround for getting the bounds of a TabItem. * //from ww w. j a v a2 s . c o m * @param tabItem The TabItem to find the bounds for. * @return the bounding rectangle */ static Rectangle gtkgetBounds(TabItem tabItem) { Rectangle bounds = new Rectangle(0, 0, 0, 0); try { Class clazz = Class.forName("org.eclipse.swt.widgets.Widget"); //$NON-NLS-1$ Field f = clazz.getDeclaredField("handle"); //$NON-NLS-1$ f.setAccessible(true); int handle = f.getInt(tabItem); gtkgetBounds(handle, bounds); return tabItem.getDisplay().map(tabItem.getParent(), null, bounds); } catch (Exception e) { return handleBoundsError(e); } }
From source file:metadata.etl.dataset.hdfs.HdfsMetadataEtl.java
private void extractLocal() throws Exception { URL localJarUrl = classLoader.getResource("jar/schemaFetch.jar"); String homeDir = System.getProperty("user.home"); String remoteJarFile = homeDir + "/.wherehows/schemaFetch.jar"; File dest = new File(remoteJarFile); try {// w w w. ja v a 2s . co m FileUtils.copyURLToFile(localJarUrl, dest); } catch (Exception e) { logger.error(e.toString()); } String outputSchemaFile = prop.getProperty(Constant.HDFS_SCHEMA_LOCAL_PATH_KEY); String outputSampleDataFile = prop.getProperty(Constant.HDFS_SAMPLE_LOCAL_PATH_KEY); String cluster = prop.getProperty(Constant.HDFS_CLUSTER_KEY); String whiteList = prop.getProperty(Constant.HDFS_WHITE_LIST_KEY); String numOfThread = prop.getProperty(Constant.HDFS_NUM_OF_THREAD_KEY, String.valueOf(1)); String hdfsUser = prop.getProperty(Constant.HDFS_REMOTE_USER_KEY); // String hdfsKeyTab = prop.getProperty(Constant.HDFS_REMOTE_KEYTAB_LOCATION_KEY); String hdfsExtractLogFile = outputSchemaFile + ".log"; String[] hadoopCmd = { "hadoop", "jar", remoteJarFile, "-D" + Constant.HDFS_SCHEMA_REMOTE_PATH_KEY + "=" + outputSchemaFile, "-D" + Constant.HDFS_SAMPLE_REMOTE_PATH_KEY + "=" + outputSampleDataFile, "-D" + Constant.HDFS_CLUSTER_KEY + "=" + cluster, "-D" + Constant.HDFS_WHITE_LIST_KEY + "=" + whiteList, "-D" + Constant.HDFS_NUM_OF_THREAD_KEY + "=" + numOfThread, "-D" + Constant.HDFS_REMOTE_USER_KEY + "=" + hdfsUser, "-Dlog.file.name=hdfs_schema_fetch" }; // delete the line (no kerberos needed): "-D" + Constant.HDFS_REMOTE_KEYTAB_LOCATION_KEY + "=" + hdfsKeyTab, ProcessBuilder pb = new ProcessBuilder(hadoopCmd); File logFile = new File(hdfsExtractLogFile); pb.redirectErrorStream(true); pb.redirectOutput(ProcessBuilder.Redirect.appendTo(logFile)); Process process = pb.start(); int pid = -1; if (process.getClass().getName().equals("java.lang.UNIXProcess")) { /* get the PID on unix/linux systems */ try { Field f = process.getClass().getDeclaredField("pid"); f.setAccessible(true); pid = f.getInt(process); } catch (Throwable e) { } } logger.info("executue command [PID=" + pid + "]: " + hadoopCmd); // wait until this process finished. int execResult = process.waitFor(); // if the process failed, log the error and throw exception if (execResult > 0) { BufferedReader br = new BufferedReader(new InputStreamReader(process.getErrorStream())); String errString = "HDFS Metadata Extract Error:\n"; String line = ""; while ((line = br.readLine()) != null) errString = errString.concat(line).concat("\n"); logger.error("*** Process failed, status: " + execResult); logger.error(errString); throw new Exception("Process + " + pid + " failed"); } }
From source file:com.xperia64.timidityae.Globals.java
@SuppressLint("NewApi") public static int getBackgroundColor(TextView textView) { Drawable drawable = textView.getBackground(); if (drawable instanceof ColorDrawable) { ColorDrawable colorDrawable = (ColorDrawable) drawable; if (Build.VERSION.SDK_INT >= 11) { return colorDrawable.getColor(); }// w w w. j a v a 2 s .c o m try { Field field = colorDrawable.getClass().getDeclaredField("mState"); field.setAccessible(true); Object object = field.get(colorDrawable); field = object.getClass().getDeclaredField("mUseColor"); field.setAccessible(true); return field.getInt(object); } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } } return 0; }
From source file:de.anderdonau.hackersdiet.MonthDetailFragment.java
/** * Search a widget by its name and return its ID. *//*from ww w .j ava2 s .co m*/ public int getIdByName(String name) { Class res = R.id.class; int id; try { Field field = res.getField(name); id = field.getInt(null); } catch (Exception e) { Log.d("getIdByName", "Cant get " + name); return -1; } return id; }
From source file:org.eclipse.jubula.rc.swt.utils.SwtUtils.java
/** * GTK-specific workaround for getting the bounds of a TableColumn. * /*from ww w .j a v a 2 s . com*/ * @param tableColumn The TableColumn to find the bounds for. * @return the bounding rectangle */ static Rectangle gtkgetBounds(TableColumn tableColumn) { Rectangle bounds = new Rectangle(0, 0, 0, 0); try { Class clazz = tableColumn.getClass(); Field f = clazz.getDeclaredField("buttonHandle"); //$NON-NLS-1$ f.setAccessible(true); int handle = f.getInt(tableColumn); gtkgetBounds(handle, bounds); bounds.y -= tableColumn.getParent().getHeaderHeight(); return tableColumn.getDisplay().map(tableColumn.getParent(), null, bounds); } catch (Exception e) { return handleBoundsError(e); } }