code
stringlengths
73
34.1k
label
stringclasses
1 value
private void scanAttributeForAnnotation(InputStream is) throws IOException { int nameIndex = readShort(is); // String name = _cp.getUtf8(nameIndex).getValue(); int length = readInt(is); if (! isNameAnnotation(nameIndex)) { is.skip(length); return; } int count = ...
java
public static long toPeriod(String value, long defaultUnits) throws ConfigException { if (value == null) return 0; long sign = 1; long period = 0; int i = 0; int length = value.length(); if (length > 0 && value.charAt(i) == '-') { sign = -1; i++; } whi...
java
static HttpStreamWrapper openRead(HttpPath path) throws IOException { HttpStream stream = createStream(path); stream._isPost = false; HttpStreamWrapper wrapper = new HttpStreamWrapper(stream); String status = (String) wrapper.getAttribute("status"); // ioc/23p0 if ("404".equals(stat...
java
static HttpStreamWrapper openReadWrite(HttpPath path) throws IOException { HttpStream stream = createStream(path); stream._isPost = true; return new HttpStreamWrapper(stream); }
java
static private HttpStream createStream(HttpPath path) throws IOException { String host = path.getHost(); int port = path.getPort(); HttpStream stream = null; long streamTime = 0; synchronized (LOCK) { if (_savedStream != null && host.equals(_savedStream.getHost()) && por...
java
private void init(PathImpl path) { _contentLength = -1; _isChunked = false; _isRequestDone = false; _didGet = false; _isPost = false; _isHead = false; _method = null; _attributes.clear(); //setPath(path); if (path instanceof HttpPath) _virtualHost = ((HttpPath) path...
java
private void getConnInput() throws IOException { if (_didGet) return; try { getConnInputImpl(); } catch (IOException e) { _isKeepalive = false; throw e; } catch (RuntimeException e) { _isKeepalive = false; throw e; } }
java
public void setPathFormat(String pathFormat) throws ConfigException { _pathFormat = pathFormat; if (pathFormat.endsWith(".zip")) { throw new ConfigException(L.l(".zip extension to path-format is not supported.")); } }
java
public void setArchiveFormat(String format) { if (format.endsWith(".gz")) { _archiveFormat = format.substring(0, format.length() - ".gz".length()); _archiveSuffix = ".gz"; } else if (format.endsWith(".zip")) { _archiveFormat = format.substring(0, format.length() - ".zip".length()); ...
java
public void setRolloverPeriod(Duration period) { _rolloverPeriod = period.toMillis(); if (_rolloverPeriod > 0) { _rolloverPeriod += 3600000L - 1; _rolloverPeriod -= _rolloverPeriod % 3600000L; } else _rolloverPeriod = Integer.MAX_VALUE; // Period.INFINITE; }
java
public void setRolloverCheckPeriod(long period) { if (period > 1000) _rolloverCheckPeriod = period; else if (period > 0) _rolloverCheckPeriod = 1000; if (DAY < _rolloverCheckPeriod) { log.info(this + " rollover-check-period " + _rolloverCheckPeriod + "ms is longer tha...
java
@Override public void write(byte []buffer, int offset, int length) throws IOException { synchronized (_logLock) { if (_isRollingOver && getTempStreamMax() < _tempStreamSize) { try { _logLock.wait(); } catch (Exception e) { } } if (! _isRollingOver) { ...
java
private void rolloverLogTask() { try { if (_isInit) { flush(); } } catch (Exception e) { log.log(Level.WARNING, e.toString(), e); } _isRollingOver = true; try { if (! _isInit) return; Path savedPath = null; long now = CurrentTime.cu...
java
private void openLog() { closeLogStream(); WriteStream os = _os; _os = null; IoUtil.close(os); Path path = getPath(); if (path == null) { path = getPath(CurrentTime.currentTime()); } Path parent = path.getParent(); try { if (! Files.isDirectory(parent)) { ...
java
private void removeOldLogs() { try { Path path = getPath(); Path parent = path.getParent(); ArrayList<String> matchList = new ArrayList<String>(); Pattern archiveRegexp = getArchiveRegexp(); Files.list(parent).forEach(child->{ String subPath = child.getFileName().toString()...
java
protected Path getPath(long time) { String formatString = getPathFormat(); if (formatString == null) throw new IllegalStateException(L.l("getPath requires a format path")); String pathString = getFormatName(formatString, time); return getPwd().resolve(pathString); }
java
public void close() throws IOException { _isClosed = true; _rolloverWorker.wake(); _rolloverWorker.close(); synchronized (_logLock) { closeLogStream(); } Alarm alarm = _rolloverAlarm; _rolloverAlarm = null; if (alarm != null) alarm.dequeue(); }
java
private void closeLogStream() { try { WriteStream os = _os; _os = null; if (os != null) os.close(); } catch (Throwable e) { // can't log in log routines } try { WriteStream zipOut = _zipOut; _zipOut = null; if (zipOut != null) zipOut.close()...
java
public ApplicationSummary getApplication(String brooklynId) throws IOException { Invocation invocation = getJerseyClient().target(getEndpoint() + "/v1/applications/" + brooklynId).request().buildGet(); return invocation.invoke().readEntity(ApplicationSummary.class); }
java
public JsonNode getApplicationsTree() throws IOException { Invocation invocation = getJerseyClient().target(getEndpoint() + "/v1/applications/fetch").request().buildGet(); return invocation.invoke().readEntity(JsonNode.class); }
java
public TaskSummary removeApplication(String brooklynId) throws IOException { Invocation invocation = getJerseyClient().target(getEndpoint() + "/v1/applications/" + brooklynId).request().buildDelete(); return invocation.invoke().readEntity(TaskSummary.class); }
java
public TaskSummary deployApplication(String tosca) throws IOException { Entity content = Entity.entity(tosca, "application/x-yaml"); Invocation invocation = getJerseyClient().target(getEndpoint() + "/v1/applications").request().buildPost(content); return invocation.invoke().readEntity(TaskSummar...
java
public List<EntitySummary> getEntitiesFromApplication(String brooklynId) throws IOException { Invocation invocation = getJerseyClient().target(getEndpoint() + "/v1/applications/" + brooklynId + "/entities") .request().buildGet(); return invocation.invoke().readEntity(new GenericType<Lis...
java
public PathImpl get(String scheme) { ConcurrentHashMap<String,SchemeRoot> map = getMap(); SchemeRoot root = map.get(scheme); if (root == null) { PathImpl rootPath = createLazyScheme(scheme); if (rootPath != null) { map.putIfAbsent(scheme, new SchemeRoot(rootPath)); ...
java
public PathImpl remove(String scheme) { SchemeRoot oldRoot = getUpdateMap().remove(scheme); return oldRoot != null ? oldRoot.getRoot() : null; }
java
@Override public int export(ConstantPool target) { int entryIndex = _entry.export(target); return target.addMethodHandle(_type, target.getEntry(entryIndex)).getIndex(); }
java
protected void initHttpSystem(SystemManager system, ServerBartender selfServer) throws IOException { //RootConfigBoot rootConfig = getRootConfig(); String clusterId = selfServer.getClusterId(); //ClusterConfigBoot clusterConfig = rootConfig.findCluster(clusterId); ...
java
@Override public boolean isModified() { if (_isDigestModified) { if (log.isLoggable(Level.FINE)) log.fine(_source.getNativePath() + " digest is modified."); return true; } long sourceLastModified = _source.getLastModified(); long sourceLength = _source.length(); // if ...
java
public boolean logModified(Logger log) { if (_isDigestModified) { log.info(_source.getNativePath() + " digest is modified."); return true; } long sourceLastModified = _source.getLastModified(); long sourceLength = _source.length(); // if the source was deleted and we need the source...
java
public static BaseType createGenericClass(Class<?> type) { TypeVariable<?> []typeParam = type.getTypeParameters(); if (typeParam == null || typeParam.length == 0) return ClassType.create(type); BaseType []args = new BaseType[typeParam.length]; HashMap<String,BaseType> newParamMap = new ...
java
@Override public int read(byte []buf, int offset, int length) throws IOException { if (buf == null) throw new NullPointerException(); else if (offset < 0 || buf.length < offset + length) throw new ArrayIndexOutOfBoundsException(); int result = nativeRead(_fd, buf, offset, length); ...
java
public boolean lock(boolean shared, boolean block) { if (shared && !_canRead) { // Invalid request for a shared "read" lock on a write only stream. return false; } if (!shared && !_canWrite) { // Invalid request for an exclusive "write" lock on a read only stream. return false; ...
java
public String getFullName() { StringBuilder name = new StringBuilder(); name.append(getName()); name.append("("); JClass []params = getParameterTypes(); for (int i = 0; i < params.length; i++) { if (i != 0) name.append(", "); name.append(params[i].getShortName()); } ...
java
@AfterBatch public void afterBatch() { if (_isGc) { return; } long gcSequence = _gcSequence; _gcSequence = 0; if (gcSequence <= 0) { return; } try { ArrayList<SegmentHeaderGc> collectList = findCollectList(gcSequence); if (collectList.size() < _tab...
java
public URL copyWithDevice(String deviceAddress, String attrName, String attrValue) { return new URL(this.protocol, this.adapterAddress, deviceAddress, Collections.singletonMap(attrName, attrValue), this.serviceUUID, this.characteristicUUID, this.fieldName); }
java
public URL getDeviceURL() { return new URL(this.protocol, this.adapterAddress, this.deviceAddress, this.deviceAttributes, null, null, null); }
java
public URL getServiceURL() { return new URL(this.protocol, this.adapterAddress, this.deviceAddress, this.deviceAttributes, this.serviceUUID, null, null); }
java
public URL getCharacteristicURL() { return new URL(this.protocol, this.adapterAddress, this.deviceAddress, this.deviceAttributes, this.serviceUUID, this.characteristicUUID, null); }
java
public URL getParent() { if (isField()) { return getCharacteristicURL(); } else if (isCharacteristic()) { return getServiceURL(); } else if (isService()) { return getDeviceURL(); } else if (isDevice()) { return getAdapterURL(); } el...
java
public boolean isDescendant(URL url) { if (url.protocol != null && protocol != null && !protocol.equals(url.protocol)) { return false; } if (adapterAddress != null && url.adapterAddress == null) { return true; } if (adapterAddress != null && !adapterAddr...
java
public Object putValue(String key, Object value) { return _valueMap.put(key, value); }
java
static JavaAnnotation []parseAnnotations(InputStream is, ConstantPool cp, JavaClassLoader loader) throws IOException { int n = readShort(is); JavaAnnotation []annArray = new JavaAnnotation[n]; for (int i = 0; i < n...
java
@Override public void run() { try { handleAlarm(); } catch (Throwable e) { log.log(Level.WARNING, e.toString(), e); } finally { _isRunning = false; _runningAlarmCount.decrementAndGet(); } }
java
private void handleAlarm() { AlarmListener listener = getListener(); if (listener == null) { return; } Thread thread = Thread.currentThread(); ClassLoader loader = getContextLoader(); if (loader != null) { thread.setContextClassLoader(loader); } else { thread.setCo...
java
private IDomain createDomainIfNotExist(String domainId){ IDomain foundDomain=findDomainByID(domainId); if(foundDomain==null){ foundDomain=user.createDomain(domainName); } return foundDomain; }
java
protected void configureEnv() { //TODO a sensor with the custom-environment variables? Map<String, String> envs=getEntity().getConfig(OpenShiftWebApp.ENV); if((envs!=null)&&(envs.size()!=0)){ deployedApp.addEnvironmentVariables(envs); deployedApp.restart(); } ...
java
@Override public void shutdown(DeployService2Impl<I> deploy, ShutdownModeAmp mode, Result<Boolean> result) { deploy.shutdownImpl(mode, result); }
java
public JavaClass readFromClassPath(String classFile) throws IOException { Thread thread = Thread.currentThread(); ClassLoader loader = thread.getContextClassLoader(); InputStream is = loader.getResourceAsStream(classFile); try { return parse(is); } finally { is.close(); } ...
java
private void updateLocalRepository() throws GitAPIException { try { Git.open(new File(paasifyRepositoryDirecory)).pull().call(); } catch (IOException e) { log.error("Cannot update local Git repository"); log.error(e.getMessage()); } }
java
private Offering getOfferingFromJSON(JSONObject obj) throws IOException { JSONArray infrastructures = (JSONArray) obj.get("infrastructures"); String name = (String) obj.get("name"); Offering offering = null; if (infrastructures == null || infrastructures.size() == 0) { Stri...
java
@Override public int acceptInitialRead(byte []buffer, int offset, int length) { synchronized (_readLock) { // initialize fields from the _fd int result = nativeAcceptInit(_socketFd, _localAddrBuffer, _remoteAddrBuffer, buffer, offset, length); return result...
java
@Override public String getRemoteHost() { if (_remoteName == null) { byte []remoteAddrBuffer = _remoteAddrBuffer; char []remoteAddrCharBuffer = _remoteAddrCharBuffer; if (_remoteAddrLength <= 0) { _remoteAddrLength = InetAddressUtil.createIpAddress(remoteAddrBuffer, ...
java
@Override public String getLocalHost() { if (_localName == null) { byte []localAddrBuffer = _localAddrBuffer; char []localAddrCharBuffer = _localAddrCharBuffer; if (_localAddrLength <= 0) { _localAddrLength = InetAddressUtil.createIpAddress(localAddrBuffer, ...
java
public int read(byte []buffer, int offset, int length, long timeout) throws IOException { if (length == 0) { throw new IllegalArgumentException(); } long requestExpireTime = _requestExpireTime; if (requestExpireTime > 0 && requestExpireTime < CurrentTime.currentTime()) { close(); ...
java
public int write(byte []buffer, int offset, int length, boolean isEnd) throws IOException { int result; long requestExpireTime = _requestExpireTime; if (requestExpireTime > 0 && requestExpireTime < CurrentTime.currentTime()) { close(); throw new ClientDisconnectException(L.l("{0}: reques...
java
@Override public StreamImpl stream() throws IOException { if (_stream == null) { _stream = new JniStream(this); } _stream.init(); return _stream; }
java
private boolean onLoad(Cursor cursor, T entity) { if (cursor == null) { if (log.isLoggable(Level.FINEST)) { log.finest(L.l("{0} load returned null", _entityInfo)); } _entityInfo.loadFail(entity); return false; } else { _entityInfo.load(cursor, entity); ...
java
@Override public void findOne(String sql, Object[] params, Result<Cursor> result) { _db.findOne(sql, result, params); }
java
@Override public void findAll(String sql, Object[] params, Result<Iterable<Cursor>> result) { _db.findAll(sql, result, params); }
java
public <V> Function<Cursor, V> cursorToBean(Class<V> api) { return (FindDataVault<ID,T,V>) _valueBeans.get(api); }
java
public static TempCharBuffer allocate() { TempCharBuffer next = _freeList.allocate(); if (next == null) return new TempCharBuffer(SIZE); next._next = null; next._offset = 0; next._length = 0; next._bufferCount = 0; return next; }
java
public static void free(TempCharBuffer buf) { buf._next = null; if (buf._buf.length == SIZE) _freeList.free(buf); }
java
@Override public void log(int level, String message) { switch (level) { case LogChute.WARN_ID: log.warn(message); break; case LogChute.INFO_ID: log.info(message); break; case LogChute.TRACE_ID: log.trace(message); ...
java
@Override public boolean isLevelEnabled(int level) { switch (level) { case LogChute.DEBUG_ID: return log.isDebugEnabled(); case LogChute.INFO_ID: return log.isInfoEnabled(); case LogChute.TRACE_ID: return log.isTraceEnabled(); case LogChute...
java
@Override public void onPut(byte[] key, TypePut type) { //_watchKey.init(key); WatchKey watchKey = new WatchKey(key); switch (type) { case LOCAL: ArrayList<WatchEntry> listLocal = _entryMapLocal.get(watchKey); onPut(listLocal, key); break; case REMOTE: { in...
java
private void onPut(ArrayList<WatchEntry> list, byte []key) { if (list != null) { int size = list.size(); for (int i = 0; i < size; i++) { WatchEntry entry = list.get(i); RowCursor rowCursor = _table.cursor(); rowCursor.setKey(key, 0); EnvKelp envKelp = null; ...
java
@Override public long skip(long n) throws IOException { if (_is == null) { if (_s == null) return -1; _is = _s.getInputStream(); } return _is.skip(n); }
java
@Override public int getAvailable() throws IOException { if (_is == null) { if (_s == null) return -1; _is = _s.getInputStream(); } return _is.available(); }
java
@Override public void flush() throws IOException { if (_os == null || ! _needsFlush) return; _needsFlush = false; try { _os.flush(); } catch (IOException e) { try { close(); } catch (IOException e1) { } throw ClientDisconnectException.create(e); ...
java
@Override public int available() throws IOException { if (_readOffset < _readLength) { return _readLength - _readOffset; } StreamImpl source = _source; if (source != null) { return source.getAvailable(); } else { return -1; } }
java
@Override public synchronized boolean addLogger(Logger logger) { EnvironmentLogger envLogger = addLogger(logger.getName(), logger.getResourceBundleName()); // handle custom logger if (! logger.getClass().equals(Logger.class)) { return envLogger.addC...
java
private EnvironmentLogger buildParentTree(String childName) { if (childName == null || childName.equals("")) return null; int p = childName.lastIndexOf('.'); String parentName; if (p > 0) parentName = childName.substring(0, p); else parentName = ""; EnvironmentLog...
java
@Override public synchronized Logger getLogger(String name) { SoftReference<EnvironmentLogger> envLoggerRef = _envLoggers.get(name); EnvironmentLogger envLogger = null; if (envLoggerRef != null) envLogger = envLoggerRef.get(); if (envLogger == null) envLogger = addLogger(name, null...
java
public static JavacConfig getLocalConfig() { JavacConfig config; config = _localJavac.get(); if (config != null) return config; else return new JavacConfig(); }
java
public ArrayList<InetAddress> getLocalAddresses() { synchronized (_addressCache) { ArrayList<InetAddress> localAddresses = _addressCache.get("addresses"); if (localAddresses == null) { localAddresses = new ArrayList<InetAddress>(); try { for (NetworkInterfaceB...
java
public byte[] getHardwareAddress() { if (CurrentTime.isTest() || System.getProperty("test.mac") != null) { return new byte[] { 10, 0, 0, 0, 0, 10 }; } for (NetworkInterfaceBase nic : getNetworkInterfaces()) { if (! nic.isLoopback()) { return nic.getHardwareAddress(); } }...
java
public void waitForExit() throws IOException { Thread thread = Thread.currentThread(); ClassLoader oldLoader = thread.getContextClassLoader(); try { thread.setContextClassLoader(_systemManager.getClassLoader()); _waitForExitService = new WaitForExitService3(this, ...
java
public boolean compareAndPut(V testValue, K key, V value) { V result = compareAndPut(testValue, key, value, true); return testValue == result; }
java
private void updateLru(CacheItem<K,V> item) { long lruCounter = _lruCounter; long itemCounter = item._lruCounter; long delta = (lruCounter - itemCounter) & 0x3fffffff; if (_lruTimeout < delta || delta < 0) { // update LRU only if not used recently updateLruImpl(item); } }
java
public boolean removeTail() { CacheItem<K,V> tail = null; if (_capacity1 <= _size1) tail = _tail1; if (tail == null) { tail = _tail2; if (tail == null) { tail = _tail1; if (tail == null) return false; } } V oldValue = tail._value; if (oldV...
java
public Iterator<K> keys() { KeyIterator<K,V> iter = new KeyIterator<K,V>(this); iter.init(this); return iter; }
java
public Iterator<K> keys(Iterator<K> oldIter) { KeyIterator<K,V> iter = (KeyIterator<K,V>) oldIter; iter.init(this); return oldIter; }
java
public Iterator<V> values() { ValueIterator<K,V> iter = new ValueIterator<K,V>(this); iter.init(this); return iter; }
java
@Override public void ssl(SSLFactory sslFactory) { try { Objects.requireNonNull(sslFactory); SocketChannel channel = _channel; Objects.requireNonNull(channel); _sslSocket = sslFactory.ssl(channel); _sslSocket.startHandshake(); } catch (IOException e) { e.printSt...
java
@Override public int portRemote() { if (_channel != null) { try { SocketAddress addr = _channel.getRemoteAddress(); return 0; } catch (Exception e) { e.printStackTrace(); return 0; } } else return 0; }
java
public Map<IGuaranteeTerm, GuaranteeTermEvaluationResult> evaluate(IAgreement agreement, Map<IGuaranteeTerm, List<IMonitoringMetric>> metricsMap) { checkInitialized(false); Map<IGuaranteeTerm,GuaranteeTermEvaluationResult> result = new HashMap<IGuaranteeTerm,Guaran...
java
public Map<IGuaranteeTerm, GuaranteeTermEvaluationResult> evaluateBusiness(IAgreement agreement, Map<IGuaranteeTerm, List<IViolation>> violationsMap) { checkInitialized(false); Map<IGuaranteeTerm,GuaranteeTermEvaluationResult> result = new HashMap<IGuarante...
java
@Override public Auction createAuction(String userId, long durationMs, long startPrice, String title, String description) { ResourceManager manager = getResourceManager(); ServiceRef ref = manager.create(userId, durationMs, startPrice, title...
java
public void read() { StateInPipe stateOld; StateInPipe stateNew; do { stateOld = _stateInRef.get(); stateNew = stateOld.toActive(); } while (! _stateInRef.compareAndSet(stateOld, stateNew)); while (stateNew.isActive()) { readPipe(); wakeOut(); ...
java
private void wakeIn() { StateInPipe stateOld; StateInPipe stateNew; do { stateOld = _stateInRef.get(); if (stateOld.isActive()) { return; } stateNew = stateOld.toWake(); } while (! _stateInRef.compareAndSet(stateOld, stateNew)); if (stateOld ...
java
void wakeOut() { OnAvailable outFlow = _outFlow; if (outFlow == null) { return; } if (_creditsIn <= _queue.head()) { return; } StateOutPipe stateOld; StateOutPipe stateNew; do { stateOld = _stateOutRef.get(); if (! stateOld.isFull()) { ...
java
public void flush() { int level = getLevel().intValue(); for (int i = 0; i < _handlers.length; i++) { Handler handler = _handlers[i]; if (level <= handler.getLevel().intValue()) handler.flush(); } }
java
public void checkpointStart() { if (_isWhileCheckpoint) { throw new IllegalStateException(); } _isWhileCheckpoint = true; long sequence = ++_sequence; setSequence(sequence); byte []headerBuffer = _headerBuffer; BitsUtil.writeInt16(headerBuffer, 0, CHECKPOINT_START...
java
public void checkpointEnd() { if (! _isWhileCheckpoint) { throw new IllegalStateException(); } _isWhileCheckpoint = false; byte []headerBuffer = _headerBuffer; BitsUtil.writeInt16(headerBuffer, 0, CHECKPOINT_END); writeImpl(headerBuffer, 0, 2); flush(); _lastC...
java
public void replay(ReplayCallback replayCallback) { TempBuffer tReadBuffer = TempBuffer.createLarge(); byte []readBuffer = tReadBuffer.buffer(); int bufferLength = readBuffer.length; try (InStore jIn = _blockStore.openRead(_startAddress, getSegmentSize())) { Replay replay = readReplay(jIn); ...
java
private long scanItem(InStore is, long address, byte []readBuffer, byte []tempBuffer) { startRead(); byte []headerBuffer = _headerBuffer; while (address + 2 < _tailAddress) { readImpl(is, address, readBuffer, headerBuffer, 0, 2); address += 2; ...
java
public static void main(String []argv) { EnvLoader.init(); ArgsServerBase args = new ArgsServerBaratine(argv); args.doMain(); }
java
public int getLine() { if (_line >= 0) return _line; Attribute attr = getAttribute("LineNumberTable"); if (attr == null) { _line = 0; return _line; } _line = 0; return _line; }
java
public JClass getReturnType() { String descriptor = getDescriptor(); int i = descriptor.lastIndexOf(')'); return getClassLoader().descriptorToClass(descriptor, i + 1); }
java
public Attribute removeAttribute(String name) { for (int i = _attributes.size() - 1; i >= 0; i--) { Attribute attr = _attributes.get(i); if (attr.getName().equals(name)) { _attributes.remove(i); return attr; } } return null; }
java