/** * Returns this struct address. This method allows for structs * to be referenced (e.g. pointer) from other structs. * * @return the struct memory address. * @throws UnsupportedOperationException if the struct buffer is not * a direct buffer. * @see Reference32 * @see Reference64 */ public final long address() { ByteBuffer thisBuffer = this.getByteBuffer(); if (ADDRESS_METHOD != null) { Long start = (Long) ADDRESS_METHOD.invoke(thisBuffer); return start.longValue() + getByteBufferPosition(); } else { throw new UnsupportedOperationException( "Operation not supported for " + thisBuffer.getClass()); } } private static final Reflection.Method ADDRESS_METHOD = Reflection.getInstance().getMethod("sun.nio.ch.DirectBuffer.address()");
public void parse(String systemId) throws IOException, SAXException { InputStream inStream; try { Object url = NEW_URL.newInstance(systemId); inStream = (InputStream) OPEN_STREAM.invoke(url); } catch (Exception urlException) { // Try as filename. try { inStream = (InputStream) NEW_FILE_INPUT_STREAM.newInstance(systemId); } catch (Exception fileException) { throw new UnsupportedOperationException("Cannot parse " + systemId); } } parse(inStream); }
private static int availableProcessors() { Reflection.Method availableProcessors = Reflection.getInstance().getMethod("java.lang.Runtime.availableProcessors()"); if (availableProcessors != null) { Integer processors = (Integer) availableProcessors.invoke(Runtime.getRuntime()); return processors.intValue(); } else // J2ME. return 1; }