code
stringlengths
73
34.1k
label
stringclasses
1 value
public boolean removeRef(Object obj) throws IOException { if (_refs != null) { _refs.remove(obj); return true; } else return false; }
java
public boolean readRequest(MuxInputStream in, MuxOutputStream out) throws IOException { int channel = isClient ? 3 : 2; in.init(this, channel); out.init(this, channel); if (readChannel(channel) != null) { in.setInputStream(is); in.readToData(false); ...
java
OutputStream writeChannel(int channel) throws IOException { while (os != null) { boolean canWrite = false; synchronized (WRITE_LOCK) { if (!isWriteLocked) { isWriteLocked = true; canWrite = true; } ...
java
InputStream readChannel(int channel) throws IOException { while (!isClosed) { if (inputReady[channel]) { inputReady[channel] = false; return is; } boolean canRead = false; synchronized (READ_LOCK) { if (...
java
private void readData() throws IOException { while (!isClosed) { int code = is.read(); switch (code) { case ' ': case '\t': case '\n': case '\r': break; case 'C': { ...
java
public void close() throws IOException { isClosed = true; OutputStream os = this.os; this.os = null; InputStream is = this.is; this.is = null; if (os != null) os.close(); if (is != null) is.close(); }
java
public static ClassNameResolver buildDefault() { String enable = System.getProperty(Constants.SERIALIZE_BLACKLIST_ENABLE, Constants.DEFAULT_SERIALIZE_BLACKLIST_ENABLE); if (Boolean.TRUE.toString().equalsIgnoreCase(enable)) { ClassNameResolver resolver = new ClassNameResolver(); ...
java
private boolean schedule(Task task) { int index = bufferIndex(); int buffered = bufferLengths.incrementAndGet(index); if (task.isWrite()) { buffers[index].add(task); drainStatus.set(REQUIRED); return false; } // A buffer may discard a read ta...
java
boolean shouldDrainBuffers(boolean delayable) { if (executor.isShutdown()) { DrainStatus status = drainStatus.get(); return (status != PROCESSING) && (!delayable || (status == REQUIRED)); } return false; }
java
@GuardedBy("evictionLock") void drainBuffers(int maxToDrain) { // A mostly strict ordering is achieved by observing that each buffer // contains tasks in a weakly sorted order starting from the last drain. // The buffers can be merged into a sorted list in O(n) time by using // count...
java
@GuardedBy("evictionLock") void runTasksInChain(Task task) { while (task != null) { Task current = task; task = task.getNext(); current.setNext(null); current.run(); } }
java
protected String readStringImpl(int length) throws IOException { StringBuffer sb = new StringBuffer(); for (int i = 0; i < length; i++) { int ch = is.read(); if (ch < 0x80) sb.append((char) ch); else if ((ch & 0xe0) == 0xc0) { ...
java
public void startEnvelope(String method) throws IOException { int offset = _offset; if (SIZE < offset + 32) { flushBuffer(); offset = _offset; } _buffer[_offset++] = (byte) 'E'; writeString(method); }
java
@Override public int writeObjectBegin(String type) throws IOException { int newRef = _classRefs.size(); int ref = _classRefs.put(type, newRef, false); if (newRef != ref) { if (SIZE < _offset + 32) flushBuffer(); if (ref <= OBJECT_DIRECT_M...
java
public void writeNull() throws IOException { int offset = _offset; byte[] buffer = _buffer; if (SIZE <= offset + 16) { flushBuffer(); offset = _offset; } buffer[offset++] = 'N'; _offset = offset; }
java
@Override public void writeByteStream(InputStream is) throws IOException { while (true) { int len = SIZE - _offset - 3; if (len < 16) { flushBuffer(); len = SIZE - _offset - 3; } len = is.read(_buffer, _offset + 3,...
java
public void startPacket() throws IOException { if (_refs != null) { _refs.clear(); _refCount = 0; } flushBuffer(); _isPacket = true; _offset = 4; _buffer[0] = (byte) 0x05; // 0x05 = binary _buffer[1] = (byte) 0x55; _bu...
java
public void reset() { if (_refs != null) { _refs.clear(); _refCount = 0; } _classRefs.clear(); _typeRefs = null; _offset = 0; _isPacket = false; _isUnshared = false; }
java
public int read() throws IOException { int ch; InputStream is = _is; if (is == null) return -1; else { ch = is.read(); } _state.next(ch); return ch; }
java
public void freeHessian2Input(Hessian2Input in) { if (in == null) return; in.free(); _freeHessian2Input.free(in); }
java
public void freeHessian2Output(Hessian2Output out) { if (out == null) return; out.free(); _freeHessian2Output.free(out); }
java
public void init(InputStream is) { _is = is; _method = null; _isLastChunk = true; _chunkLength = 0; _peek = -1; _refs = null; _replyFault = null; if (_serializerFactory == null) _serializerFactory = new SerializerFactory(); }
java
public Object readReply(Class expectedClass) throws Throwable { int tag = read(); if (tag != 'r') error("expected hessian reply at " + codeName(tag)); int major = read(); int minor = read(); tag = read(); if (tag == 'f') throw prepar...
java
private Throwable prepareFault() throws IOException { HashMap fault = readFault(); Object detail = fault.get("detail"); String message = (String) fault.get("message"); if (detail instanceof Throwable) { _replyFault = (Throwable) detail; if (message ...
java
public String readHeader() throws IOException { int tag = read(); if (tag == 'H') { _isLastChunk = true; _chunkLength = (read() << 8) + read(); _sbuf.setLength(0); int ch; while ((ch = parseChar()) >= 0) _sbuf.appe...
java
public long readUTCDate() throws IOException { int tag = read(); if (tag != 'd') throw error("expected date at " + codeName(tag)); long b64 = read(); long b56 = read(); long b48 = read(); long b40 = read(); long b32 = read(); long...
java
public org.w3c.dom.Node readNode() throws IOException { int tag = read(); switch (tag) { case 'N': return null; case 'S': case 's': case 'X': case 'x': _isLastChunk = tag == 'S' || tag == 'X'; ...
java
private HashMap readFault() throws IOException { HashMap map = new HashMap(); int code = read(); for (; code > 0 && code != 'z'; code = read()) { _peek = code; Object key = readObject(); Object value = readObject(); if (key != null &...
java
public Object readObject(Class cl) throws IOException { if (cl == null || cl == Object.class) return readObject(); int tag = read(); switch (tag) { case 'N': return null; case 'M': { String type = readType(); ...
java
public Object readObject() throws IOException { int tag = read(); switch (tag) { case 'N': return null; case 'T': return Boolean.valueOf(true); case 'F': return Boolean.valueOf(false); case 'I...
java
public Object readRemote() throws IOException { String type = readType(); String url = readString(); return resolveRemote(type, url); }
java
public Object resolveRemote(String type, String url) throws IOException { HessianRemoteResolver resolver = getRemoteResolver(); if (resolver != null) return resolver.lookup(type, url); else return new HessianRemote(type, url); }
java
public String readType() throws IOException { int code = read(); if (code != 't') { _peek = code; return ""; } _isLastChunk = true; _chunkLength = (read() << 8) + read(); _sbuf.setLength(0); int ch; while ((ch = parse...
java
private int parseInt() throws IOException { int b32 = read(); int b24 = read(); int b16 = read(); int b8 = read(); return (b32 << 24) + (b24 << 16) + (b16 << 8) + b8; }
java
private long parseLong() throws IOException { long b64 = read(); long b56 = read(); long b48 = read(); long b40 = read(); long b32 = read(); long b24 = read(); long b16 = read(); long b8 = read(); return ((b64 << 56) + (b56...
java
private double parseDouble() throws IOException { long b64 = read(); long b56 = read(); long b48 = read(); long b40 = read(); long b32 = read(); long b24 = read(); long b16 = read(); long b8 = read(); long bits = ((b64 << 56) + ...
java
private int parseChar() throws IOException { while (_chunkLength <= 0) { if (_isLastChunk) return -1; int code = read(); switch (code) { case 's': case 'x': _isLastChunk = false; ...
java
private int parseUTF8Char() throws IOException { int ch = read(); if (ch < 0x80) return ch; else if ((ch & 0xe0) == 0xc0) { int ch1 = read(); int v = ((ch & 0x1f) << 6) + (ch1 & 0x3f); return v; } else if ((ch & 0xf0) ...
java
private int parseByte() throws IOException { while (_chunkLength <= 0) { if (_isLastChunk) { return -1; } int code = read(); switch (code) { case 'b': _isLastChunk = false; _chu...
java
public InputStream readInputStream() throws IOException { int tag = read(); switch (tag) { case 'N': return null; case 'B': case 'b': _isLastChunk = tag == 'B'; _chunkLength = (read() << 8) + read(); ...
java
int read(byte[] buffer, int offset, int length) throws IOException { int readLength = 0; while (length > 0) { while (_chunkLength <= 0) { if (_isLastChunk) return readLength == 0 ? -1 : readLength; int code = read(); ...
java
protected OutputStream getOutputStream() throws IOException { if (os == null && server != null) os = server.writeChannel(channel); return os; }
java
public void write(int ch) throws IOException { OutputStream os = getOutputStream(); os.write('D'); os.write(0); os.write(1); os.write(ch); }
java
public void write(byte[] buffer, int offset, int length) throws IOException { OutputStream os = getOutputStream(); for (; length > 0x8000; length -= 0x8000) { os.write('D'); os.write(0x80); os.write(0x00); os.write(buffer, offset, 0x8000); ...
java
public void close() throws IOException { if (server != null) { OutputStream os = getOutputStream(); this.os = null; MuxServer server = this.server; this.server = null; server.close(channel); } }
java
protected void writeUTF(int code, String string) throws IOException { OutputStream os = getOutputStream(); os.write(code); int charLength = string.length(); int length = 0; for (int i = 0; i < charLength; i++) { char ch = string.charAt(i); ...
java
public boolean readToOutputStream(OutputStream os) throws IOException { InputStream is = readInputStream(); if (is == null) return false; if (_buffer == null) _buffer = new byte[256]; try { int len; while ((len = is.read(_bu...
java
@Override public Object writeReplace(Object obj) { Calendar cal = (Calendar) obj; return new CalendarHandle(cal.getClass(), cal.getTimeInMillis()); }
java
public static String mangleName(Method method, boolean isFull) { StringBuffer sb = new StringBuffer(); sb.append(method.getName()); Class[] params = method.getParameterTypes(); for (int i = 0; i < params.length; i++) { sb.append('_'); sb.append(mangleClass(p...
java
public static String mangleClass(Class cl, boolean isFull) { String name = cl.getName(); if (name.equals("boolean") || name.equals("java.lang.Boolean")) return "boolean"; else if (name.equals("int") || name.equals("java.lang.Integer") || name.equals("short") || name....
java
@Override public void addHeader(String key, String value) { _conn.setRequestProperty(key, value); }
java
public void sendRequest() throws IOException { if (_conn instanceof HttpURLConnection) { HttpURLConnection httpConn = (HttpURLConnection) _conn; _statusCode = 500; try { _statusCode = httpConn.getResponseCode(); } catch (Exception e) ...
java
@Override public void destroy() { close(); URLConnection conn = _conn; _conn = null; if (conn instanceof HttpURLConnection) ((HttpURLConnection) conn).disconnect(); }
java
protected InputStream getInputStream() throws IOException { if (is == null && server != null) is = server.readChannel(channel); return is; }
java
private void skipToEnd() throws IOException { InputStream is = getInputStream(); if (is == null) return; if (chunkLength > 0) is.skip(chunkLength); for (int tag = is.read(); tag >= 0; tag = is.read()) { switch (tag) { cas...
java
void readToData(boolean returnOnYield) throws IOException { InputStream is = getInputStream(); if (is == null) return; for (int tag = is.read(); tag >= 0; tag = is.read()) { switch (tag) { case 'Y': server.freeReadLock(); ...
java
protected void readTag(int tag) throws IOException { int length = (is.read() << 8) + is.read(); is.skip(length); }
java
protected String readUTF() throws IOException { int len = (is.read() << 8) + is.read(); StringBuffer sb = new StringBuffer(); while (len > 0) { int d1 = is.read(); if (d1 < 0) return sb.toString(); else if (d1 < 0x80) { ...
java
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception { Reference ref = (Reference) obj; String api = null; String url = null; for (int i = 0; i < ref.size(); i++) { ...
java
private String base64(String value) { StringBuffer cb = new StringBuffer(); int i = 0; for (i = 0; i + 2 < value.length(); i += 3) { long chunk = (int) value.charAt(i); chunk = (chunk << 8) + (int) value.charAt(i + 1); chunk = (chunk << 8) + (int) value.c...
java
@Override public void writeObject(Object obj, AbstractHessianOutput out) throws IOException { if (out.addRef(obj)) { return; } int ref = out.writeObjectBegin(getClassName(obj)); if (ref < -1) { out.writeString("value"); InputStream i...
java
protected Object readObjectImpl(Class cl) throws IOException { try { Object obj = cl.newInstance(); if (_refs == null) _refs = new ArrayList(); _refs.add(obj); HashMap fieldMap = getFieldMap(cl); int code = read(); ...
java
public void setSendCollectionType(boolean isSendType) { if (_collectionSerializer == null) _collectionSerializer = new CollectionSerializer(); _collectionSerializer.setSendJavaType(isSendType); if (_mapSerializer == null) _mapSerializer = new MapSerializer(); _...
java
public Object readList(AbstractHessianInput in, int length, String type) throws HessianProtocolException, IOException { Deserializer deserializer = getDeserializer(type); if (deserializer != null) return deserializer.readList(in, length); else return new Collecti...
java
@Override public Object readMap(AbstractHessianInput in) throws IOException { Object value = null; while (!in.isEnd()) { String key = in.readString(); if (key.equals("value")) value = readStreamValue(in); else in.readO...
java
public void service(ServletRequest request, ServletResponse response) throws IOException, ServletException { HttpServletRequest req = (HttpServletRequest) request; HttpServletResponse res = (HttpServletResponse) response; if (!req.getMethod().equals("POST")) { res.setSta...
java
public void writeObjectImpl(Object obj) throws IOException { Class cl = obj.getClass(); try { Method method = cl.getMethod("writeReplace", new Class[0]); Object repl = method.invoke(obj, new Object[0]); writeObject(repl); return; } ca...
java
public boolean checkDuplicate(T obj) { int top = _top.get(); for (int i = top - 1; i >= 0; i--) { if (_freeStack.get(i) == obj) return true; } return false; }
java
public Serializer getSerializer(String className) { Serializer serializer = _serializerClassMap.get(className); if (serializer == AbstractSerializer.NULL) return null; else return serializer; }
java
public Deserializer getDeserializer(String className) { Deserializer deserializer = _deserializerClassMap.get(className); if (deserializer == AbstractDeserializer.NULL) return null; else return deserializer; }
java
public Deserializer getCustomDeserializer(Class cl) { Deserializer deserializer = _customDeserializerMap.get(cl.getName()); if (deserializer == AbstractDeserializer.NULL) return null; else if (deserializer != null) return deserializer; try { Clas...
java
private void init() { if (_parent != null) { _serializerFiles.addAll(_parent._serializerFiles); _deserializerFiles.addAll(_parent._deserializerFiles); _serializerClassMap.putAll(_parent._serializerClassMap); _deserializerClassMap.putAll(_parent._deserializerC...
java
protected HessianConnection sendRequest(String methodName, Object[] args) throws IOException { HessianConnection conn = null; conn = _factory.getConnectionFactory().open(_url); boolean isValid = false; try { addRequestHeaders(conn); OutputStream os ...
java
protected void addRequestHeaders(HessianConnection conn) { conn.addHeader("Content-Type", "x-application/hessian"); conn.addHeader("Accept-Encoding", "deflate"); String basicAuth = _factory.getBasicAuth(); if (basicAuth != null) conn.addHeader("Authorization", basicAuth...
java
public HessianConnection open(URL url) throws IOException { if (log.isLoggable(Level.FINER)) log.finer(this + " open(" + url + ")"); URLConnection conn = url.openConnection(); // HttpURLConnection httpConn = (HttpURLConnection) conn; // httpConn.setRequestMethod...
java
public static void begin(ServletRequest request, ServletResponse response, String serviceName, String objectId) throws ServletException { ServiceContext context = (ServiceContext) _localContext.get(); if ...
java
public static Object getContextHeader(String header) { ServiceContext context = (ServiceContext) _localContext.get(); if (context != null) return context.getHeader(header); else return null; }
java
public static void end() { ServiceContext context = (ServiceContext) _localContext.get(); if (context != null && --context._count == 0) { context._request = null; context._response = null; context._headers.clear(); _localContext.set(null); }...
java
private String getArrayType(Class cl) { if (cl.isArray()) return '[' + getArrayType(cl.getComponentType()); String name = cl.getName(); if (name.equals("java.lang.String")) return "string"; else if (name.equals("java.lang.Object")) return "object...
java
@Override public String doLayout(ILoggingEvent event) { // Format message String msg = super.doLayout(event).trim(); // prevent log forging msg = preventLogForging(msg); // Formatting of exception, remove line breaks IThrowableProxy throwableProxy = event.getThrowableProxy(); if (throwab...
java
private String preventLogForging(String logMsg) { String result = logMsg; // use precompiled pattern for performance reasons result = LINEBREAK_PATTERN.matcher(logMsg).replaceAll(SingleLinePatternLayout.LINE_SEP); return result; }
java
@PostConstruct public void initialize() { if (this.pojoDescriptorBuilderFactory == null) { this.pojoDescriptorBuilderFactory = PojoDescriptorBuilderFactoryImpl.getInstance(); } if (this.pojoDescriptorBuilder == null) { this.pojoDescriptorBuilder = this.pojoDescriptorBuilderFactory.createPriva...
java
protected Response handleSecurityError(Throwable exception, Throwable catched) { NlsRuntimeException error; if ((exception == catched) && (exception instanceof NlsRuntimeException)) { error = (NlsRuntimeException) exception; } else { error = new SecurityErrorUserException(catched); } LO...
java
protected Response handleValidationException(Throwable exception, Throwable catched) { Throwable t = catched; Map<String, List<String>> errorsMap = null; if (exception instanceof ConstraintViolationException) { ConstraintViolationException constraintViolationException = (ConstraintViolationException)...
java
protected Response createResponse(WebApplicationException exception) { Response response = exception.getResponse(); int statusCode = response.getStatus(); Status status = Status.fromStatusCode(statusCode); NlsRuntimeException error; if (exception instanceof ServerErrorException) { error = new...
java
protected void initialize(AccessControlSchema config) { LOG.debug("Initializing."); List<AccessControlGroup> groups = config.getGroups(); if (groups.size() == 0) { throw new IllegalStateException("AccessControlSchema is empty - please configure at least one group!"); } Set<AccessControlGroup>...
java
@SuppressWarnings("unchecked") public <T> T get(String key, Class<T> targetType, boolean required) throws WebApplicationException { String value = get(key); if (value == null) { if (required) { throw new BadRequestException("Missing parameter: " + key); } Object result = null; ...
java
@GET public String suspend() { AtmosphereResource r = (AtmosphereResource)req.getAttribute("org.atmosphere.cpr.AtmosphereResource"); r.setBroadcaster(r.getAtmosphereConfig().getBroadcasterFactory().lookup("/cxf-chat", true)).suspend(); return ""; }
java
public void doPost(AtmosphereResource ar) { Object msg = ar.getRequest().getAttribute(Constants.MESSAGE_OBJECT); if (msg != null) { logger.info("received RPC post: " + msg.toString()); // for demonstration purposes we will broadcast the message to all connections ar.getAt...
java
@POST public void broadcast(String message) { AtmosphereResource r = (AtmosphereResource) request.getAttribute(ApplicationConfig.ATMOSPHERE_RESOURCE); if (r != null) { r.getBroadcaster().broadcast(message); } else { throw new IllegalStateException(); } }
java
@Ready public void onReady(/* In you don't want injection AtmosphereResource r */) { logger.info("Browser {} connected", r.uuid()); logger.info("BroadcasterFactory used {}", factory.getClass().getName()); logger.info("Broadcaster injected {}", broadcaster.getID()); }
java
@POST @Produces("application/xml") @Broadcast public Broadcastable publishWithXML(@FormParam("message") String message) { return new Broadcastable(new JAXBBean(message), broadcaster); }
java
@GET @Suspend(period = 60, timeUnit = TimeUnit.SECONDS, listeners = {EventsLogger.class}) @Path("timeout") public Broadcastable timeout() { return new Broadcastable(broadcaster); }
java
public JSONObject addObject(JSONObject obj, RequestOptions requestOptions) throws AlgoliaException { return client.postRequest("/1/indexes/" + encodedIndexName, obj.toString(), true, false, requestOptions); }
java
public JSONObject addObjects(List<JSONObject> objects) throws AlgoliaException { return this.addObjects(objects, RequestOptions.empty); }
java
public JSONObject saveObject(JSONObject object, String objectID) throws AlgoliaException { return this.saveObject(object, objectID, RequestOptions.empty); }
java
public JSONObject saveObjects(List<JSONObject> objects) throws AlgoliaException { return this.saveObjects(objects, RequestOptions.empty); }
java
public JSONObject search(Query params, RequestOptions requestOptions) throws AlgoliaException { String paramsString = params.getQueryString(); JSONObject body = new JSONObject(); try { body.put("params", paramsString); } catch (JSONException e) { throw new RuntimeException(e); } retu...
java
public IndexBrowser browseFrom(Query params, String cursor, RequestOptions requestOptions) throws AlgoliaException { return new IndexBrowser(client, encodedIndexName, params, cursor, requestOptions); }
java
public JSONObject getSettings(RequestOptions requestOptions) throws AlgoliaException { return client.getRequest("/1/indexes/" + encodedIndexName + "/settings?getVersion=2", false, requestOptions); }
java