code
stringlengths
73
34.1k
label
stringclasses
1 value
public CodeAttribute getCode() { for (int i = 0; i < _attributes.size(); i++) { Attribute attr = _attributes.get(i); if (attr instanceof CodeAttribute) return (CodeAttribute) attr; } return null; }
java
public CodeAttribute createCode() { CodeAttribute code = new CodeAttribute(); for (int i = 0; i < _attributes.size(); i++) { Attribute attr = _attributes.get(i); if (attr instanceof CodeAttribute) return (CodeAttribute) attr; } return null; }
java
public JavaMethod export(JavaClass source, JavaClass target) { JavaMethod method = new JavaMethod(_loader); method.setName(_name); method.setDescriptor(_descriptor); method.setAccessFlags(_accessFlags); target.getConstantPool().addUTF8(_name); target.getConstantPool().addUTF8(_descriptor); for (int i = 0; i < _attributes.size(); i++) { Attribute attr = _attributes.get(i); method.addAttribute(attr.export(source, target)); } return method; }
java
public void concatenate(JavaMethod tail) { CodeAttribute codeAttr = getCode(); CodeAttribute tailCodeAttr = tail.getCode(); byte []code = codeAttr.getCode(); byte []tailCode = tailCodeAttr.getCode(); int codeLength = code.length; if ((code[codeLength - 1] & 0xff) == CodeVisitor.RETURN) codeLength = codeLength - 1; byte []newCode = new byte[codeLength + tailCode.length]; System.arraycopy(code, 0, newCode, 0, codeLength); System.arraycopy(tailCode, 0, newCode, codeLength, tailCode.length); codeAttr.setCode(newCode); if (codeAttr.getMaxStack() < tailCodeAttr.getMaxStack()) codeAttr.setMaxStack(tailCodeAttr.getMaxStack()); if (codeAttr.getMaxLocals() < tailCodeAttr.getMaxLocals()) codeAttr.setMaxLocals(tailCodeAttr.getMaxLocals()); ArrayList<CodeAttribute.ExceptionItem> exns = tailCodeAttr.getExceptions(); for (int i = 0; i < exns.size(); i++) { CodeAttribute.ExceptionItem exn = exns.get(i); CodeAttribute.ExceptionItem newExn = new CodeAttribute.ExceptionItem(); newExn.setType(exn.getType()); newExn.setStart(exn.getStart() + codeLength); newExn.setEnd(exn.getEnd() + codeLength); newExn.setHandler(exn.getHandler() + codeLength); } }
java
public PodAppHandle getPodAppHandle(String id) { PodAppHandle handle = _podAppHandleMap.get(id); if (handle == null) { // handle = _podsDeployService.getPodAppHandle(id); _podAppHandleMap.putIfAbsent(id, handle); } return handle; }
java
public boolean stop(ShutdownModeAmp mode) { Objects.requireNonNull(mode); if (! _lifecycle.toStop()) { return false; } _shutdownMode = mode; /* if (_podBuilder != null) { ServiceRefAmp.toServiceRef(_podBuilder).shutdown(mode); ServiceRefAmp.toServiceRef(_podsDeployService).shutdown(mode); ServiceRefAmp.toServiceRef(_podsConfigService).shutdown(mode); } */ return true; }
java
@SuppressWarnings("unchecked") public final E remove() { Thread thread = Thread.currentThread(); ClassLoader loader = thread.getContextClassLoader(); for (; loader != null; loader = loader.getParent()) { if (loader instanceof EnvironmentClassLoader) { EnvironmentClassLoader envLoader = (EnvironmentClassLoader) loader; return (E) envLoader.removeAttribute(_varName); } } return setGlobal(null); }
java
@SuppressWarnings("unchecked") public final E remove(ClassLoader loader) { for (; loader != null; loader = loader.getParent()) { if (loader instanceof EnvironmentClassLoader) { EnvironmentClassLoader envLoader = (EnvironmentClassLoader) loader; return (E) envLoader.removeAttribute(_varName); } } return setGlobal(null); }
java
public E setGlobal(E value) { E oldValue = _globalValue; _globalValue = value; ClassLoader systemLoader = getSystemClassLoader(); if (systemLoader instanceof EnvironmentClassLoader) ((EnvironmentClassLoader) systemLoader).setAttribute(_varName, value); else _globalValue = value; return oldValue; }
java
@SuppressWarnings("unchecked") public E getGlobal() { ClassLoader systemLoader = getSystemClassLoader(); if (systemLoader instanceof EnvironmentClassLoader) return (E) ((EnvironmentClassLoader) systemLoader).getAttribute(_varName); else return _globalValue; }
java
public String getSimpleName() { String name = getName(); int p = name.lastIndexOf('.'); return name.substring(p + 1); }
java
public Class getJavaClass() { try { ClassLoader loader = Thread.currentThread().getContextClassLoader(); return Class.forName(getName(), false, loader); } catch (Exception e) { throw new RuntimeException(e); } }
java
public JMethod getConstructor(JClass []param) { JMethod []ctors = getConstructors(); loop: for (int i = 0; i < ctors.length; i++) { JClass []args = ctors[i].getParameterTypes(); if (args.length != param.length) continue loop; for (int j = 0; j < args.length; j++) if (! args[i].equals(param[j])) continue loop; return ctors[i]; } return null; }
java
public String getShortName() { if (isArray()) return getComponentType().getShortName() + "[]"; else { String name = getName().replace('$', '.'); int p = name.lastIndexOf('.'); if (p >= 0) return name.substring(p + 1); else return name; } }
java
@Override public void dispatch() { Result<InputStreamClient> result = _result; if (result != null) { result.ok(_is); } }
java
public void init(boolean isSecure, CharSequence host, int port, byte []uri, int uriLength) { _isSecure = isSecure; _host = host; _port = port; _uri = uri; _uriLength = uriLength; }
java
public HashMap<String,Object> getValueMap() { try { if (_values == null) { _values = new HashMap<String,Object>(); Method []methods = _ann.annotationType().getMethods(); for (int i = 0; i < methods.length; i++) { Method method = methods[i]; if (method.getDeclaringClass().equals(Class.class)) continue; if (method.getDeclaringClass().equals(Object.class)) continue; if (method.getParameterTypes().length != 0) continue; _values.put(method.getName(), method.invoke(_ann)); } } return _values; } catch (Exception e) { throw new RuntimeException(e); } }
java
public JavaClass parse(InputStream is) throws IOException { _is = is; if (_loader == null) _loader = new JavaClassLoader(); if (_class == null) _class = new JavaClass(_loader); _cp = _class.getConstantPool(); parseClass(); return _class; }
java
private void parseClass() throws IOException { int magic = readInt(); if (magic != JavaClass.MAGIC) throw error(L.l("bad magic number in class file")); int minor = readShort(); int major = readShort(); _class.setMajor(major); _class.setMinor(minor); parseConstantPool(); int accessFlags = readShort(); _class.setAccessFlags(accessFlags); int thisClassIndex = readShort(); _class.setThisClass(_cp.getClass(thisClassIndex).getName()); int superClassIndex = readShort(); if (superClassIndex > 0) _class.setSuperClass(_cp.getClass(superClassIndex).getName()); int interfaceCount = readShort(); for (int i = 0; i < interfaceCount; i++) { int classIndex = readShort(); _class.addInterface(_cp.getClass(classIndex).getName()); } int fieldCount = readShort(); for (int i = 0; i < fieldCount; i++) { parseField(); } int methodCount = readShort(); for (int i = 0; i < methodCount; i++) parseMethod(); int attrCount = readShort(); for (int i = 0; i < attrCount; i++) { Attribute attr = parseAttribute(); _class.addAttribute(attr); } }
java
private ConstantPoolEntry parseConstantPoolEntry(int index) throws IOException { int tag = read(); switch (tag) { case CP_CLASS: return parseClassConstant(index); case CP_FIELD_REF: return parseFieldRefConstant(index); case CP_METHOD_REF: return parseMethodRefConstant(index); case CP_INTERFACE_METHOD_REF: return parseInterfaceMethodRefConstant(index); case CP_STRING: return parseStringConstant(index); case CP_INTEGER: return parseIntegerConstant(index); case CP_FLOAT: return parseFloatConstant(index); case CP_LONG: return parseLongConstant(index); case CP_DOUBLE: return parseDoubleConstant(index); case CP_NAME_AND_TYPE: return parseNameAndTypeConstant(index); case CP_UTF8: return parseUtf8Constant(index); default: throw error(L.l("'{0}' is an unknown constant pool type.", tag)); } }
java
private ClassConstant parseClassConstant(int index) throws IOException { int nameIndex = readShort(); return new ClassConstant(_class.getConstantPool(), index, nameIndex); }
java
private FieldRefConstant parseFieldRefConstant(int index) throws IOException { int classIndex = readShort(); int nameAndTypeIndex = readShort(); return new FieldRefConstant(_class.getConstantPool(), index, classIndex, nameAndTypeIndex); }
java
private MethodRefConstant parseMethodRefConstant(int index) throws IOException { int classIndex = readShort(); int nameAndTypeIndex = readShort(); return new MethodRefConstant(_class.getConstantPool(), index, classIndex, nameAndTypeIndex); }
java
private InterfaceMethodRefConstant parseInterfaceMethodRefConstant(int index) throws IOException { int classIndex = readShort(); int nameAndTypeIndex = readShort(); return new InterfaceMethodRefConstant(_class.getConstantPool(), index, classIndex, nameAndTypeIndex); }
java
private StringConstant parseStringConstant(int index) throws IOException { int stringIndex = readShort(); return new StringConstant(_class.getConstantPool(), index, stringIndex); }
java
private IntegerConstant parseIntegerConstant(int index) throws IOException { int value = readInt(); return new IntegerConstant(_class.getConstantPool(), index, value); }
java
private FloatConstant parseFloatConstant(int index) throws IOException { int bits = readInt(); float value = Float.intBitsToFloat(bits); return new FloatConstant(_class.getConstantPool(), index, value); }
java
private LongConstant parseLongConstant(int index) throws IOException { long value = readLong(); return new LongConstant(_class.getConstantPool(), index, value); }
java
private DoubleConstant parseDoubleConstant(int index) throws IOException { long bits = readLong(); double value = Double.longBitsToDouble(bits); return new DoubleConstant(_class.getConstantPool(), index, value); }
java
private NameAndTypeConstant parseNameAndTypeConstant(int index) throws IOException { int nameIndex = readShort(); int descriptorIndex = readShort(); return new NameAndTypeConstant(_class.getConstantPool(), index, nameIndex, descriptorIndex); }
java
private Utf8Constant parseUtf8Constant(int index) throws IOException { int length = readShort(); StringBuilder cb = new StringBuilder(); for (int i = 0; i < length; i++) { int ch = read(); if (ch < 0x80) { cb.append((char) ch); } else if ((ch & 0xe0) == 0xc0) { int ch2 = read(); i++; cb.append((char) (((ch & 0x1f) << 6)+ (ch2 & 0x3f))); } else { int ch2 = read(); int ch3 = read(); i += 2; cb.append((char) (((ch & 0xf) << 12)+ ((ch2 & 0x3f) << 6) + ((ch3 & 0x3f)))); } } return new Utf8Constant(_class.getConstantPool(), index, cb.toString()); }
java
private void parseMethod() throws IOException { int accessFlags = readShort(); int nameIndex = readShort(); int descriptorIndex = readShort(); JavaMethod method = new JavaMethod(_loader); method.setJavaClass(_class); method.setName(_cp.getUtf8(nameIndex).getValue()); method.setDescriptor(_cp.getUtf8(descriptorIndex).getValue()); method.setAccessFlags(accessFlags); int attributesCount = readShort(); for (int i = 0; i < attributesCount; i++) { Attribute attr = parseAttribute(); method.addAttribute(attr); if (attr instanceof ExceptionsAttribute) { ExceptionsAttribute exn = (ExceptionsAttribute) attr; ArrayList<String> exnNames = exn.getExceptionList(); if (exnNames.size() > 0) { JClass []exnClasses = new JClass[exnNames.size()]; for (int j = 0; j < exnNames.size(); j++) { String exnName = exnNames.get(j).replace('/', '.'); exnClasses[j] = _loader.forName(exnName); } method.setExceptionTypes(exnClasses); } } } _class.addMethod(method); }
java
public Attribute parseAttribute() throws IOException { int nameIndex = readShort(); String name = _cp.getUtf8(nameIndex).getValue(); if (name.equals("Code")) { CodeAttribute code = new CodeAttribute(name); code.read(this); return code; } else if (name.equals("Exceptions")) { ExceptionsAttribute code = new ExceptionsAttribute(name); code.read(this); return code; } else if (name.equals("Signature")) { SignatureAttribute attr = new SignatureAttribute(); attr.read(this); return attr; } else if (name.equals("BootstrapMethods")) { BootstrapMethodAttribute attr = new BootstrapMethodAttribute(); attr.read(this); return attr; } OpaqueAttribute attr = new OpaqueAttribute(name); int length = readInt(); byte []bytes = new byte[length]; read(bytes, 0, bytes.length); attr.setValue(bytes); return attr; }
java
long readLong() throws IOException { return (((long) _is.read() << 56) | ((long) _is.read() << 48) | ((long) _is.read() << 40) | ((long) _is.read() << 32) | ((long) _is.read() << 24) | ((long) _is.read() << 16) | ((long) _is.read() << 8) | ((long) _is.read())); }
java
public int readInt() throws IOException { return ((_is.read() << 24) | (_is.read() << 16) | (_is.read() << 8) | (_is.read())); }
java
public int read(byte []buffer, int offset, int length) throws IOException { int readLength = 0; while (length > 0) { int sublen = _is.read(buffer, offset, length); if (sublen < 0) return readLength == 0 ? -1 : readLength; offset += sublen; length -= sublen; readLength += sublen; } return readLength; }
java
@Override public void start() { try { JournalClientEndpoint endpoint = connect(); if (endpoint != null) { OutputStream os; _os = os = endpoint.startMessage(); if (os != null) { os.write('M'); } } } catch (Exception e) { log.finer(e.toString()); //e.printStackTrace(); // // throw new RuntimeException(e); } }
java
@Override public void write(byte[] buffer, int offset, int length) { try { OutputStream os = _os; if (os != null) { os.write(buffer, offset, length); } } catch (Exception e) { log.log(Level.FINER, e.toString(), e); } }
java
@Override public boolean complete() { OutputStream os = _os; _os = null; IoUtil.close(os); return true; }
java
private static void printStackTraceElement(StackTraceElement trace, PrintWriter out, ClassLoader loader) { try { LineMap map = getScriptLineMap(trace.getClassName(), loader); if (map != null) { LineMap.Line line = map.getLine(trace.getLineNumber()); if (line != null) { out.print(trace.getClassName() + "." + trace.getMethodName()); out.print("(" + line.getSourceFilename() + ":"); out.println(line.getSourceLine(trace.getLineNumber()) + ")"); return; } } } catch (Throwable e) { } out.println(trace); }
java
public static LineMap getScriptLineMap(String className, ClassLoader loader) { try { Class cl = loader.loadClass(className); LineMap map = _scriptMap.get(cl); if (map == null) { map = loadScriptMap(cl); _scriptMap.put(cl, map); } return map; } catch (Throwable e) { return null; } }
java
private static LineMap loadScriptMap(Class cl) { ClassLoader loader = cl.getClassLoader(); if (loader == null) return new LineMap(); // null map try { String pathName = cl.getName().replace('.', '/') + ".class"; InputStream is = loader.getResourceAsStream(pathName); if (is == null) return null; try { JavaClass jClass = new ByteCodeParser().parse(is); Attribute attr = jClass.getAttribute("SourceDebugExtension"); if (attr == null) { int p = cl.getName().indexOf('$'); if (p > 0) { String className = cl.getName().substring(0, p); return loadScriptMap(loader.loadClass(className)); } return new LineMap(); } else if (attr instanceof OpaqueAttribute) { byte []value = ((OpaqueAttribute) attr).getValue(); ByteArrayInputStream bis = new ByteArrayInputStream(value); ReadStreamOld rs = VfsOld.openRead(bis); rs.setEncoding("UTF-8"); try { return parseSmap(rs); } finally { rs.close(); } } else throw new IllegalStateException(L.l("Expected opaque attribute at '{0}'", attr)); } finally { if (is != null) is.close(); } } catch (Throwable e) { log.finer(e.toString()); log.log(Level.FINEST, e.toString(), e); return new LineMap(); // null map } }
java
private List<IPolicy> getPoliciesOrDefault(final IGuaranteeTerm term) { if (term.getPolicies() != null && term.getPolicies().size() > 0) { return term.getPolicies(); } return Collections.singletonList(defaultPolicy); }
java
protected final void doStart(Collection<? extends Location> locations) { ServiceStateLogic.setExpectedState(this, Lifecycle.STARTING); try { preStart(); driver.start(); log.info("Entity {} was started with driver {}", new Object[]{this, driver}); postDriverStart(); connectSensors(); postStart(); ServiceStateLogic.setExpectedState(this, Lifecycle.RUNNING); } catch (Throwable t) { ServiceStateLogic.setExpectedState(this, Lifecycle.ON_FIRE); log.error("Error error starting entity {}", this); throw Exceptions.propagate(t); } }
java
private DNode findFrontendNode() { DNode frontend = getNode(requirements.getFrontend()); if (frontend == DNode.NOT_FOUND) { frontend = searchFrontendNode(); if (frontend == DNode.NOT_FOUND) { frontend = calculateSourceNode(); } } return frontend; }
java
private DNode searchFrontendNode() { DNode result = DNode.NOT_FOUND; for (DNode node : nodes) { if (node.getFrontend()) { result = node; break; } } return result; }
java
private DNode calculateSourceNode() { DNode result = DNode.NOT_FOUND; for (DNode node : nodes) { List<DLink> links = getLinksTo(node); if (links.size() == 0) { result = node; break; } } return result; }
java
public Reader create(InputStream is) throws UnsupportedEncodingException { Reader reader = create(is, getJavaEncoding()); if (reader != null) return reader; else return new ISO8859_1Reader(is); }
java
@Override protected void initRequest() { super.initRequest(); _uri.clear(); _host.clear(); _headerSize = 0; _remoteHost.clear(); _remoteAddr.clear(); _serverName.clear(); _serverPort.clear(); _remotePort.clear(); _clientCert.clear(); // _isSecure = getConnection().isSecure(); }
java
@Override protected CharBuffer getHost() { if (_host.length() > 0) { return _host; } _host.append(_serverName); _host.toLowerCase(); return _host; }
java
@ConfigArg(0) public void setPath(PathImpl path) { if (path.getPath().endsWith(".jar") || path.getPath().endsWith(".zip")) { path = JarPath.create(path); } _path = path; }
java
public void setPrefix(String prefix) { _prefix = prefix; if (prefix != null) _pathPrefix = prefix.replace('.', '/'); }
java
@PostConstruct @Override public void init() throws ConfigException { try { _codeSource = new CodeSource(new URL(_path.getURL()), (Certificate []) null); } catch (Exception e) { log.log(Level.FINE, e.toString(), e); } super.init(); getClassLoader().addURL(_path, _isScanned); }
java
@Override protected void buildClassPath(ArrayList<String> pathList) { String path = null; if (_path instanceof JarPath) path = ((JarPath) _path).getContainer().getNativePath(); else if (_path.isDirectory()) path = _path.getNativePath(); if (path != null && ! pathList.contains(path)) pathList.add(path); }
java
@PostConstruct public void init() throws Exception { if (_encoding == null) throw new ConfigException(L.l("character-encoding requires a 'value' attribute with the character encoding.")); _localEncoding.set(_encoding); }
java
@Override public PathImpl schemeWalk(String userPath, Map<String,Object> newAttributes, String uri, int offset) { int length = uri.length(); if (length < 2 + offset || uri.charAt(offset) != '/' || uri.charAt(1 + offset) != '/') throw new RuntimeException("bad scheme"); CharBuffer buf = new CharBuffer(); int i = 2 + offset; int ch = 0; boolean isIpv6 = false; for (; (i < length && (ch = uri.charAt(i)) != '/' && ch != '?' && ! (ch == ':' && ! isIpv6)); i++) { if (ch == '[') isIpv6 = true; else if (ch == ']') isIpv6 = false; buf.append((char) ch); } String host = buf.toString(); if (host.length() == 0) throw new RuntimeException("bad host"); int port = 0; if (ch == ':') { for (i++; i < length && (ch = uri.charAt(i)) >= '0' && ch <= '9'; i++) { port = 10 * port + uri.charAt(i) - '0'; } } return create(this, userPath, newAttributes, host, port); }
java
public int read(byte []buf, int offset, int length) throws IOException { if (_is == null) return -1; int len = _is.read(buf, offset, length); return len; }
java
public void close() throws IOException { unlock(); _fileChannel = null; InputStream is = _is; _is = null; if (is != null) is.close(); }
java
public static OutboxAmp getOutboxCurrent() { OutboxAmp outbox = OutboxAmp.current(); if (outbox != null) { // OutboxAmp outbox = (OutboxAmp) outboxDeliver; return outbox; } else { return OutboxAmpNull.NULL; } }
java
public void write(ByteAppendable os, char ch) throws IOException { os.write(ch >> 8); os.write(ch); }
java
static JClassLoader getSystemClassLoader() { if (_staticClassLoader == null) _staticClassLoader = JClassLoaderWrapper.create(ClassLoader.getSystemClassLoader()); return _staticClassLoader; }
java
public Offering fetchOffer(String cloudOfferingId) { if (cloudOfferingId == null) return null; return offeringManager.getOffering(cloudOfferingId); }
java
public String addOffering(Offering newOffering) { if (newOffering == null) return null; String offeringName = newOffering.getName(); /* if the offering was already present in the repository it is removed */ if (offeringManager.getOffering(offeringName) != null) { offeringManager.removeOffering(offeringName); } offeringManager.addOffering(newOffering); /* updates the list of all node templates */ this.offeringNodeTemplates.add(newOffering.getNodeTemplate()); totalCrawledOfferings++; return offeringName; }
java
public void print(int i) { if (i == 0x80000000) { print("-2147483648"); return; } if (i < 0) { write('-'); i = -i; } else if (i < 9) { write('0' + i); return; } int length = 0; int exp = 10; if (i >= 1000000000) length = 9; else { for (; i >= exp; length++) exp = 10 * exp; } int j = 31; while (i > 0) { _tempCharBuffer[--j] = (char) ((i % 10) + '0'); i /= 10; } write(_tempCharBuffer, j, 31 - j); }
java
public void print(long v) { if (v == 0x8000000000000000L) { print("-9223372036854775808"); return; } if (v < 0) { write('-'); v = -v; } else if (v == 0) { write('0'); return; } int j = 31; while (v > 0) { _tempCharBuffer[--j] = (char) ((v % 10) + '0'); v /= 10; } write(_tempCharBuffer, j, 31 - j); }
java
final public void print(Object v) { if (v == null) write(_nullChars, 0, _nullChars.length); else { String s = v.toString(); write(s, 0, s.length()); } }
java
final public void println(float v) { String s = String.valueOf(v); write(s, 0, s.length()); println(); }
java
final public void println(String s) { if (s == null) write(_nullChars, 0, _nullChars.length); else write(s, 0, s.length()); println(); }
java
private void configureServer(ServerBartender server) { // XXX: mixing server/client ServerNetwork serverNet = _serverMap.get(server.getId()); if (serverNet == null) { serverNet = new ServerNetwork(_system, server); configServer(serverNet, server); serverNet.init(); _serverMap.put(server.getId(), serverNet); } }
java
public JType []getActualTypeArguments() { Type []rawArgs = _type.getActualTypeArguments(); JType []args = new JType[rawArgs.length]; for (int i = 0; i < args.length; i++) { Type type = rawArgs[i]; if (type instanceof Class) { args[i] = _loader.forName(((Class) type).getName()); } else if (type instanceof ParameterizedType) args[i] = new JTypeWrapper(_loader, (ParameterizedType) type); else { args[i] = _loader.forName("java.lang.Object"); // jpa/0gg0 // throw new IllegalStateException(type.toString()); } } return args; }
java
public void close() { if (_isClosed) { return; } _isClosed = true; KelpManager backing = _kelpBacking; // _localBacking = null; if (backing != null) { backing.close(); } }
java
public void map(MethodRef method, String sql, Object []args) { QueryBuilderKraken builder = QueryParserKraken.parse(this, sql); if (builder.isTableLoaded()) { QueryKraken query = builder.build(); query.map(method, args); } else { String tableName = builder.getTableName(); _tableService.loadTable(tableName, Result.of(t->builder.build().map(method, args))); } }
java
public static StderrStream create() { if (_stderr == null) { _stderr = new StderrStream(); ConstPath path = new ConstPath(null, _stderr); path.setScheme("stderr"); //_stderr.setPath(path); } return _stderr; }
java
public static long generate(long hash, final CharSequence value) { final long m = 0xc6a4a7935bd1e995L; final int r = 47; int strlen = value.length(); int length = 2 * strlen; hash ^= length * m; int len4 = strlen / 4; int offset = 0; for (int i = 0; i < len4; i++) { final int index = i * 4 + offset; long k = (value.charAt(index + 0) | ((long) value.charAt(index + 1) << 16) | ((long) value.charAt(index + 2) << 32) | ((long) value.charAt(index + 3) << 48)); k *= m; k ^= k >>> r; k *= m; hash ^= k; hash *= m; } final int off = offset + (strlen & ~0x3); switch (strlen % 4) { case 3: hash ^= (long) value.charAt(off + 2) << 48; case 2: hash ^= (long) value.charAt(off + 1) << 32; case 1: hash ^= (long) value.charAt(off + 0) << 16; hash *= m; } hash ^= hash >>> r; hash *= m; hash ^= hash >>> r; return hash; }
java
public static byte[] process(CharSequence html) { ByteArrayOutputStream baos = null; try { baos = new ByteArrayOutputStream(); process(html, baos); return baos.toByteArray(); } finally { if (baos != null) { try { baos.close(); } catch (IOException e) { log.warn("Close Byte Array Inpout Stream Error Caused.", e); } } } }
java
public static void process(CharSequence html, OutputStream output) { new TableToXls().doProcess( html instanceof String ? (String) html : html.toString(), output); }
java
@Override public void writeSend(StubAmp actor, String methodName, Object[] args, InboxAmp inbox) { try (OutputStream os = openItem(inbox)) { // XXX: should keep open try (OutH3 out = _serializer.out(os)) { String key = actor.journalKey(); out.writeLong(CODE_SEND); out.writeString(key); out.writeString(methodName); out.writeLong(args.length); for (Object arg : args) { out.writeObject(arg); } } //_count++; } catch (IOException e) { log.log(Level.FINER, e.toString(), e); } }
java
protected boolean addDependencies(DependencyContainer container) { /* XXX: if (_classPath instanceof JarPath) { container.add(_depend); return false; } else */ if (_hasJNIReload) { container.add(this); return true; } else if (_sourcePath == null) { container.add(_depend); return false; } else { container.add(this); return true; } }
java
public boolean reloadIsModified() { if (_classIsModified) { return true; } if (! _hasJNIReload || ! _classPath.canRead()) { return true; } try { long length = _classPath.length(); Class<?> cl = _clRef != null ? _clRef.get() : null; if (cl == null) { return false; } /* if (cl.isAnnotationPresent(RequireReload.class)) return true; */ byte []bytecode = new byte[(int) length]; try (InputStream is = _classPath.inputStream()) { IoUtil.readAll(is, bytecode, 0, bytecode.length); } int result = reloadNative(cl, bytecode, 0, bytecode.length); if (result != 0) { _classIsModified = true; return true; } // XXX: setDependPath(_classPath); if (_sourcePath != null) { _sourceLastModified = _sourcePath.getLastModified(); _sourceLength = _sourcePath.length(); } log.info("Reloading " + cl.getName()); return false; } catch (Exception e) { log.log(Level.WARNING, e.toString(), e); _classIsModified = true; return true; } }
java
public void load(ByteArrayBuffer buffer) throws IOException { synchronized (this) { Source classPath = getClassPath(); buffer.clear(); int retry = 3; for (int i = 0; i < retry; i++) { long length = -1; try (InputStream is = classPath.inputStream()) { length = classPath.length(); long lastModified = classPath.getLastModified(); if (length < 0) throw new IOException("class loading failed because class file '" + classPath + "' does not have a positive length. Possibly the file has been overwritten"); buffer.setLength((int) length); int results = IoUtil.readAll(is, buffer.getBuffer(), 0, (int) length); if (results == length && length == classPath.length() && lastModified == classPath.getLastModified()) { return; } log.warning(L.l("{0}: class file length mismatch expected={1} received={2}. The class file may have been modified concurrently.", this, length, results)); } } } }
java
public static SystemManager getCurrent() { SystemManager system = _systemLocal.get(); if (system == null) { WeakReference<SystemManager> globalRef = _globalSystemRef; if (globalRef != null) { system = globalRef.get(); } } return system; }
java
public static <T extends SubSystem> T getCurrentSystem(Class<T> systemClass) { SystemManager manager = getCurrent(); if (manager != null) return manager.getSystem(systemClass); else return null; }
java
public static String getCurrentId() { SystemManager system = getCurrent(); if (system == null) { ClassLoader loader = Thread.currentThread().getContextClassLoader(); throw new IllegalStateException(L.l("{0} is not available in this context.\n {1}", SystemManager.class.getSimpleName(), loader)); } return system.getId(); }
java
public <T extends SubSystem> T addSystemIfAbsent(T system) { return addSystemIfAbsent(system.getClass(), system); }
java
@SuppressWarnings("unchecked") public <T extends SubSystem> T getSystem(Class<T> cl) { return (T) _systemMap.get(cl); }
java
private void stop(ShutdownModeAmp mode) { _shutdownMode = mode; Thread thread = Thread.currentThread(); ClassLoader oldLoader = thread.getContextClassLoader(); try { thread.setContextClassLoader(_classLoader); if (! _lifecycle.toStopping()) { return; } TreeSet<SubSystem> systems = new TreeSet<SubSystem>(new StopComparator()); systems.addAll(_systemMap.values()); // sort for (SubSystem system : systems) { try { thread.setContextClassLoader(_classLoader); if (log.isLoggable(Level.FINEST)) { log.finest(system + " stopping"); } system.stop(mode); } catch (Throwable e) { log.log(Level.WARNING, e.toString(), e); } } } finally { _lifecycle.toStop(); thread.setContextClassLoader(oldLoader); } }
java
public void shutdown(ShutdownModeAmp mode) { stop(mode); if (! _lifecycle.toDestroy()) { return; } Thread thread = Thread.currentThread(); ClassLoader oldLoader = thread.getContextClassLoader(); try { thread.setContextClassLoader(_classLoader); TreeSet<SubSystem> systems = new TreeSet<SubSystem>(new StopComparator()); systems.addAll(_systemMap.values()); _systemMap.clear(); for (SubSystem system : systems) { try { system.destroy(); } catch (Throwable e) { log.log(Level.WARNING, e.toString(), e); } } WeakReference<SystemManager> globalRef = _globalSystemRef; if (globalRef != null && globalRef.get() == this) { _globalSystemRef = null; } /* * destroy */ log.fine(this + " destroyed"); _classLoader.destroy(); } finally { // DynamicClassLoader.setOldLoader(thread, oldLoader); thread.setContextClassLoader(oldLoader); _classLoader = null; } }
java
public boolean addProperty(String propertyName, String property) { boolean ret = this.properties.containsKey(propertyName); this.properties.put(propertyName, property); return ret; }
java
public static String sanitizeName(String name) { if (name == null) throw new NullPointerException("Parameter name cannot be null"); name = name.trim(); if (name.length() == 0) throw new IllegalArgumentException("Parameter name cannot be empty"); StringBuilder ret = new StringBuilder(""); for (int i = 0; i < name.length(); i++) { char ch = name.charAt(i); if (Character.isLetter(ch) || Character.isDigit(ch)) { ret.append(ch); } else { ret.append("_"); } } return ret.toString(); }
java
public String getUtf8AsString(int index) { Utf8Constant utf8 = (Utf8Constant) _entries.get(index); if (utf8 == null) return null; else return utf8.getValue(); }
java
public void addConstant(ConstantPoolEntry entry) { if (entry instanceof Utf8Constant) { Utf8Constant utf8 = (Utf8Constant) entry; _utf8Map.put(utf8.getValue(), utf8); } _entries.add(entry); }
java
public Utf8Constant addUTF8(String value) { Utf8Constant entry = getUTF8(value); if (entry != null) return entry; entry = new Utf8Constant(this, _entries.size(), value); addConstant(entry); return entry; }
java
public StringConstant getString(String name) { for (int i = 0; i < _entries.size(); i++) { ConstantPoolEntry entry = _entries.get(i); if (! (entry instanceof StringConstant)) continue; StringConstant stringEntry = (StringConstant) entry; if (stringEntry.getString().equals(name)) return stringEntry; } return null; }
java
public StringConstant addString(String name) { StringConstant entry = getString(name); if (entry != null) { return entry; } Utf8Constant utf8 = addUTF8(name); entry = new StringConstant(this, _entries.size(), utf8.getIndex()); addConstant(entry); return entry; }
java
public IntegerConstant getIntegerByValue(int value) { for (int i = 0; i < _entries.size(); i++) { ConstantPoolEntry entry = _entries.get(i); if (! (entry instanceof IntegerConstant)) continue; IntegerConstant integerEntry = (IntegerConstant) entry; if (integerEntry.getValue() == value) return integerEntry; } return null; }
java
public IntegerConstant addInteger(int value) { IntegerConstant entry = getIntegerByValue(value); if (entry != null) return entry; entry = new IntegerConstant(this, _entries.size(), value); addConstant(entry); return entry; }
java
public LongConstant getLongByValue(long value) { for (int i = 0; i < _entries.size(); i++) { ConstantPoolEntry entry = _entries.get(i); if (! (entry instanceof LongConstant)) continue; LongConstant longEntry = (LongConstant) entry; if (longEntry.getValue() == value) return longEntry; } return null; }
java
public LongConstant addLong(long value) { LongConstant entry = getLongByValue(value); if (entry != null) return entry; entry = new LongConstant(this, _entries.size(), value); addConstant(entry); addConstant(null); return entry; }
java
public FloatConstant getFloatByValue(float value) { for (int i = 0; i < _entries.size(); i++) { ConstantPoolEntry entry = _entries.get(i); if (! (entry instanceof FloatConstant)) continue; FloatConstant floatEntry = (FloatConstant) entry; if (floatEntry.getValue() == value) return floatEntry; } return null; }
java
public FloatConstant addFloat(float value) { FloatConstant entry = getFloatByValue(value); if (entry != null) return entry; entry = new FloatConstant(this, _entries.size(), value); addConstant(entry); return entry; }
java