id
int32
0
165k
repo
stringlengths
7
58
path
stringlengths
12
218
func_name
stringlengths
3
140
original_string
stringlengths
73
34.1k
language
stringclasses
1 value
code
stringlengths
73
34.1k
code_tokens
list
docstring
stringlengths
3
16k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
105
339
160,500
adyliu/jafka
src/main/java/io/jafka/log/Log.java
Log.validateSegments
private void validateSegments(List<LogSegment> segments) { synchronized (lock) { for (int i = 0; i < segments.size() - 1; i++) { LogSegment curr = segments.get(i); LogSegment next = segments.get(i + 1); if (curr.start() + curr.size() != next.start()) { throw new IllegalStateException("The following segments don't validate: " + curr.getFile() .getAbsolutePath() + ", " + next.getFile().getAbsolutePath()); } } } }
java
private void validateSegments(List<LogSegment> segments) { synchronized (lock) { for (int i = 0; i < segments.size() - 1; i++) { LogSegment curr = segments.get(i); LogSegment next = segments.get(i + 1); if (curr.start() + curr.size() != next.start()) { throw new IllegalStateException("The following segments don't validate: " + curr.getFile() .getAbsolutePath() + ", " + next.getFile().getAbsolutePath()); } } } }
[ "private", "void", "validateSegments", "(", "List", "<", "LogSegment", ">", "segments", ")", "{", "synchronized", "(", "lock", ")", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "segments", ".", "size", "(", ")", "-", "1", ";", "i", "++", ")", "{", "LogSegment", "curr", "=", "segments", ".", "get", "(", "i", ")", ";", "LogSegment", "next", "=", "segments", ".", "get", "(", "i", "+", "1", ")", ";", "if", "(", "curr", ".", "start", "(", ")", "+", "curr", ".", "size", "(", ")", "!=", "next", ".", "start", "(", ")", ")", "{", "throw", "new", "IllegalStateException", "(", "\"The following segments don't validate: \"", "+", "curr", ".", "getFile", "(", ")", ".", "getAbsolutePath", "(", ")", "+", "\", \"", "+", "next", ".", "getFile", "(", ")", ".", "getAbsolutePath", "(", ")", ")", ";", "}", "}", "}", "}" ]
Check that the ranges and sizes add up, otherwise we have lost some data somewhere
[ "Check", "that", "the", "ranges", "and", "sizes", "add", "up", "otherwise", "we", "have", "lost", "some", "data", "somewhere" ]
cc14d2ed60c039b12d7b106bb5269ef21d0add7e
https://github.com/adyliu/jafka/blob/cc14d2ed60c039b12d7b106bb5269ef21d0add7e/src/main/java/io/jafka/log/Log.java#L151-L162
160,501
adyliu/jafka
src/main/java/io/jafka/log/Log.java
Log.read
public MessageSet read(long offset, int length) throws IOException { List<LogSegment> views = segments.getView(); LogSegment found = findRange(views, offset, views.size()); if (found == null) { if (logger.isTraceEnabled()) { logger.trace(format("NOT FOUND MessageSet from Log[%s], offset=%d, length=%d", name, offset, length)); } return MessageSet.Empty; } return found.getMessageSet().read(offset - found.start(), length); }
java
public MessageSet read(long offset, int length) throws IOException { List<LogSegment> views = segments.getView(); LogSegment found = findRange(views, offset, views.size()); if (found == null) { if (logger.isTraceEnabled()) { logger.trace(format("NOT FOUND MessageSet from Log[%s], offset=%d, length=%d", name, offset, length)); } return MessageSet.Empty; } return found.getMessageSet().read(offset - found.start(), length); }
[ "public", "MessageSet", "read", "(", "long", "offset", ",", "int", "length", ")", "throws", "IOException", "{", "List", "<", "LogSegment", ">", "views", "=", "segments", ".", "getView", "(", ")", ";", "LogSegment", "found", "=", "findRange", "(", "views", ",", "offset", ",", "views", ".", "size", "(", ")", ")", ";", "if", "(", "found", "==", "null", ")", "{", "if", "(", "logger", ".", "isTraceEnabled", "(", ")", ")", "{", "logger", ".", "trace", "(", "format", "(", "\"NOT FOUND MessageSet from Log[%s], offset=%d, length=%d\"", ",", "name", ",", "offset", ",", "length", ")", ")", ";", "}", "return", "MessageSet", ".", "Empty", ";", "}", "return", "found", ".", "getMessageSet", "(", ")", ".", "read", "(", "offset", "-", "found", ".", "start", "(", ")", ",", "length", ")", ";", "}" ]
read messages beginning from offset @param offset next message offset @param length the max package size @return a MessageSet object with length data or empty @see MessageSet#Empty @throws IOException any exception
[ "read", "messages", "beginning", "from", "offset" ]
cc14d2ed60c039b12d7b106bb5269ef21d0add7e
https://github.com/adyliu/jafka/blob/cc14d2ed60c039b12d7b106bb5269ef21d0add7e/src/main/java/io/jafka/log/Log.java#L203-L213
160,502
adyliu/jafka
src/main/java/io/jafka/log/Log.java
Log.flush
public void flush() throws IOException { if (unflushed.get() == 0) return; synchronized (lock) { if (logger.isTraceEnabled()) { logger.debug("Flushing log '" + name + "' last flushed: " + getLastFlushedTime() + " current time: " + System .currentTimeMillis()); } segments.getLastView().getMessageSet().flush(); unflushed.set(0); lastflushedTime.set(System.currentTimeMillis()); } }
java
public void flush() throws IOException { if (unflushed.get() == 0) return; synchronized (lock) { if (logger.isTraceEnabled()) { logger.debug("Flushing log '" + name + "' last flushed: " + getLastFlushedTime() + " current time: " + System .currentTimeMillis()); } segments.getLastView().getMessageSet().flush(); unflushed.set(0); lastflushedTime.set(System.currentTimeMillis()); } }
[ "public", "void", "flush", "(", ")", "throws", "IOException", "{", "if", "(", "unflushed", ".", "get", "(", ")", "==", "0", ")", "return", ";", "synchronized", "(", "lock", ")", "{", "if", "(", "logger", ".", "isTraceEnabled", "(", ")", ")", "{", "logger", ".", "debug", "(", "\"Flushing log '\"", "+", "name", "+", "\"' last flushed: \"", "+", "getLastFlushedTime", "(", ")", "+", "\" current time: \"", "+", "System", ".", "currentTimeMillis", "(", ")", ")", ";", "}", "segments", ".", "getLastView", "(", ")", ".", "getMessageSet", "(", ")", ".", "flush", "(", ")", ";", "unflushed", ".", "set", "(", "0", ")", ";", "lastflushedTime", ".", "set", "(", "System", ".", "currentTimeMillis", "(", ")", ")", ";", "}", "}" ]
Flush this log file to the physical disk @throws IOException file read error
[ "Flush", "this", "log", "file", "to", "the", "physical", "disk" ]
cc14d2ed60c039b12d7b106bb5269ef21d0add7e
https://github.com/adyliu/jafka/blob/cc14d2ed60c039b12d7b106bb5269ef21d0add7e/src/main/java/io/jafka/log/Log.java#L308-L320
160,503
adyliu/jafka
src/main/java/io/jafka/log/Log.java
Log.findRange
public static <T extends Range> T findRange(List<T> ranges, long value, int arraySize) { if (ranges.size() < 1) return null; T first = ranges.get(0); T last = ranges.get(arraySize - 1); // check out of bounds if (value < first.start() || value > last.start() + last.size()) { throw new OffsetOutOfRangeException(format("offset %s is out of range (%s, %s)",// value,first.start(),last.start()+last.size())); } // check at the end if (value == last.start() + last.size()) return null; int low = 0; int high = arraySize - 1; while (low <= high) { int mid = (high + low) / 2; T found = ranges.get(mid); if (found.contains(value)) { return found; } else if (value < found.start()) { high = mid - 1; } else { low = mid + 1; } } return null; }
java
public static <T extends Range> T findRange(List<T> ranges, long value, int arraySize) { if (ranges.size() < 1) return null; T first = ranges.get(0); T last = ranges.get(arraySize - 1); // check out of bounds if (value < first.start() || value > last.start() + last.size()) { throw new OffsetOutOfRangeException(format("offset %s is out of range (%s, %s)",// value,first.start(),last.start()+last.size())); } // check at the end if (value == last.start() + last.size()) return null; int low = 0; int high = arraySize - 1; while (low <= high) { int mid = (high + low) / 2; T found = ranges.get(mid); if (found.contains(value)) { return found; } else if (value < found.start()) { high = mid - 1; } else { low = mid + 1; } } return null; }
[ "public", "static", "<", "T", "extends", "Range", ">", "T", "findRange", "(", "List", "<", "T", ">", "ranges", ",", "long", "value", ",", "int", "arraySize", ")", "{", "if", "(", "ranges", ".", "size", "(", ")", "<", "1", ")", "return", "null", ";", "T", "first", "=", "ranges", ".", "get", "(", "0", ")", ";", "T", "last", "=", "ranges", ".", "get", "(", "arraySize", "-", "1", ")", ";", "// check out of bounds", "if", "(", "value", "<", "first", ".", "start", "(", ")", "||", "value", ">", "last", ".", "start", "(", ")", "+", "last", ".", "size", "(", ")", ")", "{", "throw", "new", "OffsetOutOfRangeException", "(", "format", "(", "\"offset %s is out of range (%s, %s)\"", ",", "//", "value", ",", "first", ".", "start", "(", ")", ",", "last", ".", "start", "(", ")", "+", "last", ".", "size", "(", ")", ")", ")", ";", "}", "// check at the end", "if", "(", "value", "==", "last", ".", "start", "(", ")", "+", "last", ".", "size", "(", ")", ")", "return", "null", ";", "int", "low", "=", "0", ";", "int", "high", "=", "arraySize", "-", "1", ";", "while", "(", "low", "<=", "high", ")", "{", "int", "mid", "=", "(", "high", "+", "low", ")", "/", "2", ";", "T", "found", "=", "ranges", ".", "get", "(", "mid", ")", ";", "if", "(", "found", ".", "contains", "(", "value", ")", ")", "{", "return", "found", ";", "}", "else", "if", "(", "value", "<", "found", ".", "start", "(", ")", ")", "{", "high", "=", "mid", "-", "1", ";", "}", "else", "{", "low", "=", "mid", "+", "1", ";", "}", "}", "return", "null", ";", "}" ]
Find a given range object in a list of ranges by a value in that range. Does a binary search over the ranges but instead of checking for equality looks within the range. Takes the array size as an option in case the array grows while searching happens @param <T> Range type @param ranges data list @param value value in the list @param arraySize the max search index of the list @return search result of range TODO: This should move into SegmentList.scala
[ "Find", "a", "given", "range", "object", "in", "a", "list", "of", "ranges", "by", "a", "value", "in", "that", "range", ".", "Does", "a", "binary", "search", "over", "the", "ranges", "but", "instead", "of", "checking", "for", "equality", "looks", "within", "the", "range", ".", "Takes", "the", "array", "size", "as", "an", "option", "in", "case", "the", "array", "grows", "while", "searching", "happens" ]
cc14d2ed60c039b12d7b106bb5269ef21d0add7e
https://github.com/adyliu/jafka/blob/cc14d2ed60c039b12d7b106bb5269ef21d0add7e/src/main/java/io/jafka/log/Log.java#L334-L361
160,504
adyliu/jafka
src/main/java/io/jafka/log/Log.java
Log.nameFromOffset
public static String nameFromOffset(long offset) { NumberFormat nf = NumberFormat.getInstance(); nf.setMinimumIntegerDigits(20); nf.setMaximumFractionDigits(0); nf.setGroupingUsed(false); return nf.format(offset) + Log.FileSuffix; }
java
public static String nameFromOffset(long offset) { NumberFormat nf = NumberFormat.getInstance(); nf.setMinimumIntegerDigits(20); nf.setMaximumFractionDigits(0); nf.setGroupingUsed(false); return nf.format(offset) + Log.FileSuffix; }
[ "public", "static", "String", "nameFromOffset", "(", "long", "offset", ")", "{", "NumberFormat", "nf", "=", "NumberFormat", ".", "getInstance", "(", ")", ";", "nf", ".", "setMinimumIntegerDigits", "(", "20", ")", ";", "nf", ".", "setMaximumFractionDigits", "(", "0", ")", ";", "nf", ".", "setGroupingUsed", "(", "false", ")", ";", "return", "nf", ".", "format", "(", "offset", ")", "+", "Log", ".", "FileSuffix", ";", "}" ]
Make log segment file name from offset bytes. All this does is pad out the offset number with zeros so that ls sorts the files numerically @param offset offset value (padding with zero) @return filename with offset
[ "Make", "log", "segment", "file", "name", "from", "offset", "bytes", ".", "All", "this", "does", "is", "pad", "out", "the", "offset", "number", "with", "zeros", "so", "that", "ls", "sorts", "the", "files", "numerically" ]
cc14d2ed60c039b12d7b106bb5269ef21d0add7e
https://github.com/adyliu/jafka/blob/cc14d2ed60c039b12d7b106bb5269ef21d0add7e/src/main/java/io/jafka/log/Log.java#L373-L379
160,505
adyliu/jafka
src/main/java/io/jafka/log/Log.java
Log.markDeletedWhile
List<LogSegment> markDeletedWhile(LogSegmentFilter filter) throws IOException { synchronized (lock) { List<LogSegment> view = segments.getView(); List<LogSegment> deletable = new ArrayList<LogSegment>(); for (LogSegment seg : view) { if (filter.filter(seg)) { deletable.add(seg); } } for (LogSegment seg : deletable) { seg.setDeleted(true); } int numToDelete = deletable.size(); // // if we are deleting everything, create a new empty segment if (numToDelete == view.size()) { if (view.get(numToDelete - 1).size() > 0) { roll(); } else { // If the last segment to be deleted is empty and we roll the log, the new segment will have the same // file name. So simply reuse the last segment and reset the modified time. view.get(numToDelete - 1).getFile().setLastModified(System.currentTimeMillis()); numToDelete -= 1; } } return segments.trunc(numToDelete); } }
java
List<LogSegment> markDeletedWhile(LogSegmentFilter filter) throws IOException { synchronized (lock) { List<LogSegment> view = segments.getView(); List<LogSegment> deletable = new ArrayList<LogSegment>(); for (LogSegment seg : view) { if (filter.filter(seg)) { deletable.add(seg); } } for (LogSegment seg : deletable) { seg.setDeleted(true); } int numToDelete = deletable.size(); // // if we are deleting everything, create a new empty segment if (numToDelete == view.size()) { if (view.get(numToDelete - 1).size() > 0) { roll(); } else { // If the last segment to be deleted is empty and we roll the log, the new segment will have the same // file name. So simply reuse the last segment and reset the modified time. view.get(numToDelete - 1).getFile().setLastModified(System.currentTimeMillis()); numToDelete -= 1; } } return segments.trunc(numToDelete); } }
[ "List", "<", "LogSegment", ">", "markDeletedWhile", "(", "LogSegmentFilter", "filter", ")", "throws", "IOException", "{", "synchronized", "(", "lock", ")", "{", "List", "<", "LogSegment", ">", "view", "=", "segments", ".", "getView", "(", ")", ";", "List", "<", "LogSegment", ">", "deletable", "=", "new", "ArrayList", "<", "LogSegment", ">", "(", ")", ";", "for", "(", "LogSegment", "seg", ":", "view", ")", "{", "if", "(", "filter", ".", "filter", "(", "seg", ")", ")", "{", "deletable", ".", "add", "(", "seg", ")", ";", "}", "}", "for", "(", "LogSegment", "seg", ":", "deletable", ")", "{", "seg", ".", "setDeleted", "(", "true", ")", ";", "}", "int", "numToDelete", "=", "deletable", ".", "size", "(", ")", ";", "//", "// if we are deleting everything, create a new empty segment", "if", "(", "numToDelete", "==", "view", ".", "size", "(", ")", ")", "{", "if", "(", "view", ".", "get", "(", "numToDelete", "-", "1", ")", ".", "size", "(", ")", ">", "0", ")", "{", "roll", "(", ")", ";", "}", "else", "{", "// If the last segment to be deleted is empty and we roll the log, the new segment will have the same", "// file name. So simply reuse the last segment and reset the modified time.", "view", ".", "get", "(", "numToDelete", "-", "1", ")", ".", "getFile", "(", ")", ".", "setLastModified", "(", "System", ".", "currentTimeMillis", "(", ")", ")", ";", "numToDelete", "-=", "1", ";", "}", "}", "return", "segments", ".", "trunc", "(", "numToDelete", ")", ";", "}", "}" ]
Delete any log segments matching the given predicate function @throws IOException
[ "Delete", "any", "log", "segments", "matching", "the", "given", "predicate", "function" ]
cc14d2ed60c039b12d7b106bb5269ef21d0add7e
https://github.com/adyliu/jafka/blob/cc14d2ed60c039b12d7b106bb5269ef21d0add7e/src/main/java/io/jafka/log/Log.java#L415-L442
160,506
adyliu/jafka
src/main/java/io/jafka/message/ByteBufferMessageSet.java
ByteBufferMessageSet.verifyMessageSize
public void verifyMessageSize(int maxMessageSize) { Iterator<MessageAndOffset> shallowIter = internalIterator(true); while(shallowIter.hasNext()) { MessageAndOffset messageAndOffset = shallowIter.next(); int payloadSize = messageAndOffset.message.payloadSize(); if(payloadSize > maxMessageSize) { throw new MessageSizeTooLargeException("payload size of " + payloadSize + " larger than " + maxMessageSize); } } }
java
public void verifyMessageSize(int maxMessageSize) { Iterator<MessageAndOffset> shallowIter = internalIterator(true); while(shallowIter.hasNext()) { MessageAndOffset messageAndOffset = shallowIter.next(); int payloadSize = messageAndOffset.message.payloadSize(); if(payloadSize > maxMessageSize) { throw new MessageSizeTooLargeException("payload size of " + payloadSize + " larger than " + maxMessageSize); } } }
[ "public", "void", "verifyMessageSize", "(", "int", "maxMessageSize", ")", "{", "Iterator", "<", "MessageAndOffset", ">", "shallowIter", "=", "internalIterator", "(", "true", ")", ";", "while", "(", "shallowIter", ".", "hasNext", "(", ")", ")", "{", "MessageAndOffset", "messageAndOffset", "=", "shallowIter", ".", "next", "(", ")", ";", "int", "payloadSize", "=", "messageAndOffset", ".", "message", ".", "payloadSize", "(", ")", ";", "if", "(", "payloadSize", ">", "maxMessageSize", ")", "{", "throw", "new", "MessageSizeTooLargeException", "(", "\"payload size of \"", "+", "payloadSize", "+", "\" larger than \"", "+", "maxMessageSize", ")", ";", "}", "}", "}" ]
check max size of each message @param maxMessageSize the max size for each message
[ "check", "max", "size", "of", "each", "message" ]
cc14d2ed60c039b12d7b106bb5269ef21d0add7e
https://github.com/adyliu/jafka/blob/cc14d2ed60c039b12d7b106bb5269ef21d0add7e/src/main/java/io/jafka/message/ByteBufferMessageSet.java#L206-L215
160,507
adyliu/jafka
src/main/java/io/jafka/network/SocketServer.java
SocketServer.close
public void close() { Closer.closeQuietly(acceptor); for (Processor processor : processors) { Closer.closeQuietly(processor); } }
java
public void close() { Closer.closeQuietly(acceptor); for (Processor processor : processors) { Closer.closeQuietly(processor); } }
[ "public", "void", "close", "(", ")", "{", "Closer", ".", "closeQuietly", "(", "acceptor", ")", ";", "for", "(", "Processor", "processor", ":", "processors", ")", "{", "Closer", ".", "closeQuietly", "(", "processor", ")", ";", "}", "}" ]
Shutdown the socket server
[ "Shutdown", "the", "socket", "server" ]
cc14d2ed60c039b12d7b106bb5269ef21d0add7e
https://github.com/adyliu/jafka/blob/cc14d2ed60c039b12d7b106bb5269ef21d0add7e/src/main/java/io/jafka/network/SocketServer.java#L69-L74
160,508
adyliu/jafka
src/main/java/io/jafka/network/SocketServer.java
SocketServer.startup
public void startup() throws InterruptedException { final int maxCacheConnectionPerThread = serverConfig.getMaxConnections() / processors.length; logger.debug("start {} Processor threads",processors.length); for (int i = 0; i < processors.length; i++) { processors[i] = new Processor(handlerFactory, stats, maxRequestSize, maxCacheConnectionPerThread); Utils.newThread("jafka-processor-" + i, processors[i], false).start(); } Utils.newThread("jafka-acceptor", acceptor, false).start(); acceptor.awaitStartup(); }
java
public void startup() throws InterruptedException { final int maxCacheConnectionPerThread = serverConfig.getMaxConnections() / processors.length; logger.debug("start {} Processor threads",processors.length); for (int i = 0; i < processors.length; i++) { processors[i] = new Processor(handlerFactory, stats, maxRequestSize, maxCacheConnectionPerThread); Utils.newThread("jafka-processor-" + i, processors[i], false).start(); } Utils.newThread("jafka-acceptor", acceptor, false).start(); acceptor.awaitStartup(); }
[ "public", "void", "startup", "(", ")", "throws", "InterruptedException", "{", "final", "int", "maxCacheConnectionPerThread", "=", "serverConfig", ".", "getMaxConnections", "(", ")", "/", "processors", ".", "length", ";", "logger", ".", "debug", "(", "\"start {} Processor threads\"", ",", "processors", ".", "length", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "processors", ".", "length", ";", "i", "++", ")", "{", "processors", "[", "i", "]", "=", "new", "Processor", "(", "handlerFactory", ",", "stats", ",", "maxRequestSize", ",", "maxCacheConnectionPerThread", ")", ";", "Utils", ".", "newThread", "(", "\"jafka-processor-\"", "+", "i", ",", "processors", "[", "i", "]", ",", "false", ")", ".", "start", "(", ")", ";", "}", "Utils", ".", "newThread", "(", "\"jafka-acceptor\"", ",", "acceptor", ",", "false", ")", ".", "start", "(", ")", ";", "acceptor", ".", "awaitStartup", "(", ")", ";", "}" ]
Start the socket server and waiting for finished @throws InterruptedException thread interrupted
[ "Start", "the", "socket", "server", "and", "waiting", "for", "finished" ]
cc14d2ed60c039b12d7b106bb5269ef21d0add7e
https://github.com/adyliu/jafka/blob/cc14d2ed60c039b12d7b106bb5269ef21d0add7e/src/main/java/io/jafka/network/SocketServer.java#L81-L90
160,509
adyliu/jafka
src/main/java/io/jafka/utils/zookeeper/ZkUtils.java
ZkUtils.getChildrenParentMayNotExist
public static List<String> getChildrenParentMayNotExist(ZkClient zkClient, String path) { try { return zkClient.getChildren(path); } catch (ZkNoNodeException e) { return null; } }
java
public static List<String> getChildrenParentMayNotExist(ZkClient zkClient, String path) { try { return zkClient.getChildren(path); } catch (ZkNoNodeException e) { return null; } }
[ "public", "static", "List", "<", "String", ">", "getChildrenParentMayNotExist", "(", "ZkClient", "zkClient", ",", "String", "path", ")", "{", "try", "{", "return", "zkClient", ".", "getChildren", "(", "path", ")", ";", "}", "catch", "(", "ZkNoNodeException", "e", ")", "{", "return", "null", ";", "}", "}" ]
get children nodes name @param zkClient zkClient @param path full path @return children nodes name or null while path not exist
[ "get", "children", "nodes", "name" ]
cc14d2ed60c039b12d7b106bb5269ef21d0add7e
https://github.com/adyliu/jafka/blob/cc14d2ed60c039b12d7b106bb5269ef21d0add7e/src/main/java/io/jafka/utils/zookeeper/ZkUtils.java#L60-L66
160,510
adyliu/jafka
src/main/java/io/jafka/utils/zookeeper/ZkUtils.java
ZkUtils.getCluster
public static Cluster getCluster(ZkClient zkClient) { Cluster cluster = new Cluster(); List<String> nodes = getChildrenParentMayNotExist(zkClient, BrokerIdsPath); for (String node : nodes) { final String brokerInfoString = readData(zkClient, BrokerIdsPath + "/" + node); cluster.add(Broker.createBroker(Integer.valueOf(node), brokerInfoString)); } return cluster; }
java
public static Cluster getCluster(ZkClient zkClient) { Cluster cluster = new Cluster(); List<String> nodes = getChildrenParentMayNotExist(zkClient, BrokerIdsPath); for (String node : nodes) { final String brokerInfoString = readData(zkClient, BrokerIdsPath + "/" + node); cluster.add(Broker.createBroker(Integer.valueOf(node), brokerInfoString)); } return cluster; }
[ "public", "static", "Cluster", "getCluster", "(", "ZkClient", "zkClient", ")", "{", "Cluster", "cluster", "=", "new", "Cluster", "(", ")", ";", "List", "<", "String", ">", "nodes", "=", "getChildrenParentMayNotExist", "(", "zkClient", ",", "BrokerIdsPath", ")", ";", "for", "(", "String", "node", ":", "nodes", ")", "{", "final", "String", "brokerInfoString", "=", "readData", "(", "zkClient", ",", "BrokerIdsPath", "+", "\"/\"", "+", "node", ")", ";", "cluster", ".", "add", "(", "Broker", ".", "createBroker", "(", "Integer", ".", "valueOf", "(", "node", ")", ",", "brokerInfoString", ")", ")", ";", "}", "return", "cluster", ";", "}" ]
read all brokers in the zookeeper @param zkClient zookeeper client @return all brokers
[ "read", "all", "brokers", "in", "the", "zookeeper" ]
cc14d2ed60c039b12d7b106bb5269ef21d0add7e
https://github.com/adyliu/jafka/blob/cc14d2ed60c039b12d7b106bb5269ef21d0add7e/src/main/java/io/jafka/utils/zookeeper/ZkUtils.java#L102-L110
160,511
adyliu/jafka
src/main/java/io/jafka/utils/zookeeper/ZkUtils.java
ZkUtils.getPartitionsForTopics
public static Map<String, List<String>> getPartitionsForTopics(ZkClient zkClient, Collection<String> topics) { Map<String, List<String>> ret = new HashMap<String, List<String>>(); for (String topic : topics) { List<String> partList = new ArrayList<String>(); List<String> brokers = getChildrenParentMayNotExist(zkClient, BrokerTopicsPath + "/" + topic); if (brokers != null) { for (String broker : brokers) { final String parts = readData(zkClient, BrokerTopicsPath + "/" + topic + "/" + broker); int nParts = Integer.parseInt(parts); for (int i = 0; i < nParts; i++) { partList.add(broker + "-" + i); } } } Collections.sort(partList); ret.put(topic, partList); } return ret; }
java
public static Map<String, List<String>> getPartitionsForTopics(ZkClient zkClient, Collection<String> topics) { Map<String, List<String>> ret = new HashMap<String, List<String>>(); for (String topic : topics) { List<String> partList = new ArrayList<String>(); List<String> brokers = getChildrenParentMayNotExist(zkClient, BrokerTopicsPath + "/" + topic); if (brokers != null) { for (String broker : brokers) { final String parts = readData(zkClient, BrokerTopicsPath + "/" + topic + "/" + broker); int nParts = Integer.parseInt(parts); for (int i = 0; i < nParts; i++) { partList.add(broker + "-" + i); } } } Collections.sort(partList); ret.put(topic, partList); } return ret; }
[ "public", "static", "Map", "<", "String", ",", "List", "<", "String", ">", ">", "getPartitionsForTopics", "(", "ZkClient", "zkClient", ",", "Collection", "<", "String", ">", "topics", ")", "{", "Map", "<", "String", ",", "List", "<", "String", ">", ">", "ret", "=", "new", "HashMap", "<", "String", ",", "List", "<", "String", ">", ">", "(", ")", ";", "for", "(", "String", "topic", ":", "topics", ")", "{", "List", "<", "String", ">", "partList", "=", "new", "ArrayList", "<", "String", ">", "(", ")", ";", "List", "<", "String", ">", "brokers", "=", "getChildrenParentMayNotExist", "(", "zkClient", ",", "BrokerTopicsPath", "+", "\"/\"", "+", "topic", ")", ";", "if", "(", "brokers", "!=", "null", ")", "{", "for", "(", "String", "broker", ":", "brokers", ")", "{", "final", "String", "parts", "=", "readData", "(", "zkClient", ",", "BrokerTopicsPath", "+", "\"/\"", "+", "topic", "+", "\"/\"", "+", "broker", ")", ";", "int", "nParts", "=", "Integer", ".", "parseInt", "(", "parts", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "nParts", ";", "i", "++", ")", "{", "partList", ".", "add", "(", "broker", "+", "\"-\"", "+", "i", ")", ";", "}", "}", "}", "Collections", ".", "sort", "(", "partList", ")", ";", "ret", ".", "put", "(", "topic", ",", "partList", ")", ";", "}", "return", "ret", ";", "}" ]
read broker info for watching topics @param zkClient the zookeeper client @param topics topic names @return topic-&gt;(brokerid-0,brokerid-1...brokerid2-0,brokerid2-1...)
[ "read", "broker", "info", "for", "watching", "topics" ]
cc14d2ed60c039b12d7b106bb5269ef21d0add7e
https://github.com/adyliu/jafka/blob/cc14d2ed60c039b12d7b106bb5269ef21d0add7e/src/main/java/io/jafka/utils/zookeeper/ZkUtils.java#L125-L143
160,512
adyliu/jafka
src/main/java/io/jafka/utils/zookeeper/ZkUtils.java
ZkUtils.getConsumersPerTopic
public static Map<String, List<String>> getConsumersPerTopic(ZkClient zkClient, String group) { ZkGroupDirs dirs = new ZkGroupDirs(group); List<String> consumers = getChildrenParentMayNotExist(zkClient, dirs.consumerRegistryDir); // Map<String, List<String>> consumersPerTopicMap = new HashMap<String, List<String>>(); for (String consumer : consumers) { TopicCount topicCount = getTopicCount(zkClient, group, consumer); for (Map.Entry<String, Set<String>> e : topicCount.getConsumerThreadIdsPerTopic().entrySet()) { final String topic = e.getKey(); for (String consumerThreadId : e.getValue()) { List<String> list = consumersPerTopicMap.get(topic); if (list == null) { list = new ArrayList<String>(); consumersPerTopicMap.put(topic, list); } // list.add(consumerThreadId); } } } // for (Map.Entry<String, List<String>> e : consumersPerTopicMap.entrySet()) { Collections.sort(e.getValue()); } return consumersPerTopicMap; }
java
public static Map<String, List<String>> getConsumersPerTopic(ZkClient zkClient, String group) { ZkGroupDirs dirs = new ZkGroupDirs(group); List<String> consumers = getChildrenParentMayNotExist(zkClient, dirs.consumerRegistryDir); // Map<String, List<String>> consumersPerTopicMap = new HashMap<String, List<String>>(); for (String consumer : consumers) { TopicCount topicCount = getTopicCount(zkClient, group, consumer); for (Map.Entry<String, Set<String>> e : topicCount.getConsumerThreadIdsPerTopic().entrySet()) { final String topic = e.getKey(); for (String consumerThreadId : e.getValue()) { List<String> list = consumersPerTopicMap.get(topic); if (list == null) { list = new ArrayList<String>(); consumersPerTopicMap.put(topic, list); } // list.add(consumerThreadId); } } } // for (Map.Entry<String, List<String>> e : consumersPerTopicMap.entrySet()) { Collections.sort(e.getValue()); } return consumersPerTopicMap; }
[ "public", "static", "Map", "<", "String", ",", "List", "<", "String", ">", ">", "getConsumersPerTopic", "(", "ZkClient", "zkClient", ",", "String", "group", ")", "{", "ZkGroupDirs", "dirs", "=", "new", "ZkGroupDirs", "(", "group", ")", ";", "List", "<", "String", ">", "consumers", "=", "getChildrenParentMayNotExist", "(", "zkClient", ",", "dirs", ".", "consumerRegistryDir", ")", ";", "//", "Map", "<", "String", ",", "List", "<", "String", ">", ">", "consumersPerTopicMap", "=", "new", "HashMap", "<", "String", ",", "List", "<", "String", ">", ">", "(", ")", ";", "for", "(", "String", "consumer", ":", "consumers", ")", "{", "TopicCount", "topicCount", "=", "getTopicCount", "(", "zkClient", ",", "group", ",", "consumer", ")", ";", "for", "(", "Map", ".", "Entry", "<", "String", ",", "Set", "<", "String", ">", ">", "e", ":", "topicCount", ".", "getConsumerThreadIdsPerTopic", "(", ")", ".", "entrySet", "(", ")", ")", "{", "final", "String", "topic", "=", "e", ".", "getKey", "(", ")", ";", "for", "(", "String", "consumerThreadId", ":", "e", ".", "getValue", "(", ")", ")", "{", "List", "<", "String", ">", "list", "=", "consumersPerTopicMap", ".", "get", "(", "topic", ")", ";", "if", "(", "list", "==", "null", ")", "{", "list", "=", "new", "ArrayList", "<", "String", ">", "(", ")", ";", "consumersPerTopicMap", ".", "put", "(", "topic", ",", "list", ")", ";", "}", "//", "list", ".", "add", "(", "consumerThreadId", ")", ";", "}", "}", "}", "//", "for", "(", "Map", ".", "Entry", "<", "String", ",", "List", "<", "String", ">", ">", "e", ":", "consumersPerTopicMap", ".", "entrySet", "(", ")", ")", "{", "Collections", ".", "sort", "(", "e", ".", "getValue", "(", ")", ")", ";", "}", "return", "consumersPerTopicMap", ";", "}" ]
get all consumers for the group @param zkClient the zookeeper client @param group the group name @return topic-&gt;(consumerIdStringA-0,consumerIdStringA-1...consumerIdStringB-0,consumerIdStringB-1)
[ "get", "all", "consumers", "for", "the", "group" ]
cc14d2ed60c039b12d7b106bb5269ef21d0add7e
https://github.com/adyliu/jafka/blob/cc14d2ed60c039b12d7b106bb5269ef21d0add7e/src/main/java/io/jafka/utils/zookeeper/ZkUtils.java#L152-L177
160,513
adyliu/jafka
src/main/java/io/jafka/utils/zookeeper/ZkUtils.java
ZkUtils.createEphemeralPath
public static void createEphemeralPath(ZkClient zkClient, String path, String data) { try { zkClient.createEphemeral(path, Utils.getBytes(data)); } catch (ZkNoNodeException e) { createParentPath(zkClient, path); zkClient.createEphemeral(path, Utils.getBytes(data)); } }
java
public static void createEphemeralPath(ZkClient zkClient, String path, String data) { try { zkClient.createEphemeral(path, Utils.getBytes(data)); } catch (ZkNoNodeException e) { createParentPath(zkClient, path); zkClient.createEphemeral(path, Utils.getBytes(data)); } }
[ "public", "static", "void", "createEphemeralPath", "(", "ZkClient", "zkClient", ",", "String", "path", ",", "String", "data", ")", "{", "try", "{", "zkClient", ".", "createEphemeral", "(", "path", ",", "Utils", ".", "getBytes", "(", "data", ")", ")", ";", "}", "catch", "(", "ZkNoNodeException", "e", ")", "{", "createParentPath", "(", "zkClient", ",", "path", ")", ";", "zkClient", ".", "createEphemeral", "(", "path", ",", "Utils", ".", "getBytes", "(", "data", ")", ")", ";", "}", "}" ]
Create an ephemeral node with the given path and data. Create parents if necessary. @param zkClient client of zookeeper @param path node path of zookeeper @param data node data
[ "Create", "an", "ephemeral", "node", "with", "the", "given", "path", "and", "data", ".", "Create", "parents", "if", "necessary", "." ]
cc14d2ed60c039b12d7b106bb5269ef21d0add7e
https://github.com/adyliu/jafka/blob/cc14d2ed60c039b12d7b106bb5269ef21d0add7e/src/main/java/io/jafka/utils/zookeeper/ZkUtils.java#L197-L204
160,514
adyliu/jafka
src/main/java/io/jafka/producer/ProducerPool.java
ProducerPool.addProducer
public void addProducer(Broker broker) { Properties props = new Properties(); props.put("host", broker.host); props.put("port", "" + broker.port); props.putAll(config.getProperties()); if (sync) { SyncProducer producer = new SyncProducer(new SyncProducerConfig(props)); logger.info("Creating sync producer for broker id = " + broker.id + " at " + broker.host + ":" + broker.port); syncProducers.put(broker.id, producer); } else { AsyncProducer<V> producer = new AsyncProducer<V>(new AsyncProducerConfig(props),// new SyncProducer(new SyncProducerConfig(props)),// serializer,// eventHandler,// config.getEventHandlerProperties(),// this.callbackHandler, // config.getCbkHandlerProperties()); producer.start(); logger.info("Creating async producer for broker id = " + broker.id + " at " + broker.host + ":" + broker.port); asyncProducers.put(broker.id, producer); } }
java
public void addProducer(Broker broker) { Properties props = new Properties(); props.put("host", broker.host); props.put("port", "" + broker.port); props.putAll(config.getProperties()); if (sync) { SyncProducer producer = new SyncProducer(new SyncProducerConfig(props)); logger.info("Creating sync producer for broker id = " + broker.id + " at " + broker.host + ":" + broker.port); syncProducers.put(broker.id, producer); } else { AsyncProducer<V> producer = new AsyncProducer<V>(new AsyncProducerConfig(props),// new SyncProducer(new SyncProducerConfig(props)),// serializer,// eventHandler,// config.getEventHandlerProperties(),// this.callbackHandler, // config.getCbkHandlerProperties()); producer.start(); logger.info("Creating async producer for broker id = " + broker.id + " at " + broker.host + ":" + broker.port); asyncProducers.put(broker.id, producer); } }
[ "public", "void", "addProducer", "(", "Broker", "broker", ")", "{", "Properties", "props", "=", "new", "Properties", "(", ")", ";", "props", ".", "put", "(", "\"host\"", ",", "broker", ".", "host", ")", ";", "props", ".", "put", "(", "\"port\"", ",", "\"\"", "+", "broker", ".", "port", ")", ";", "props", ".", "putAll", "(", "config", ".", "getProperties", "(", ")", ")", ";", "if", "(", "sync", ")", "{", "SyncProducer", "producer", "=", "new", "SyncProducer", "(", "new", "SyncProducerConfig", "(", "props", ")", ")", ";", "logger", ".", "info", "(", "\"Creating sync producer for broker id = \"", "+", "broker", ".", "id", "+", "\" at \"", "+", "broker", ".", "host", "+", "\":\"", "+", "broker", ".", "port", ")", ";", "syncProducers", ".", "put", "(", "broker", ".", "id", ",", "producer", ")", ";", "}", "else", "{", "AsyncProducer", "<", "V", ">", "producer", "=", "new", "AsyncProducer", "<", "V", ">", "(", "new", "AsyncProducerConfig", "(", "props", ")", ",", "//", "new", "SyncProducer", "(", "new", "SyncProducerConfig", "(", "props", ")", ")", ",", "//", "serializer", ",", "//", "eventHandler", ",", "//", "config", ".", "getEventHandlerProperties", "(", ")", ",", "//", "this", ".", "callbackHandler", ",", "//", "config", ".", "getCbkHandlerProperties", "(", ")", ")", ";", "producer", ".", "start", "(", ")", ";", "logger", ".", "info", "(", "\"Creating async producer for broker id = \"", "+", "broker", ".", "id", "+", "\" at \"", "+", "broker", ".", "host", "+", "\":\"", "+", "broker", ".", "port", ")", ";", "asyncProducers", ".", "put", "(", "broker", ".", "id", ",", "producer", ")", ";", "}", "}" ]
add a new producer, either synchronous or asynchronous, connecting to the specified broker @param broker broker to producer
[ "add", "a", "new", "producer", "either", "synchronous", "or", "asynchronous", "connecting", "to", "the", "specified", "broker" ]
cc14d2ed60c039b12d7b106bb5269ef21d0add7e
https://github.com/adyliu/jafka/blob/cc14d2ed60c039b12d7b106bb5269ef21d0add7e/src/main/java/io/jafka/producer/ProducerPool.java#L117-L138
160,515
adyliu/jafka
src/main/java/io/jafka/producer/ProducerPool.java
ProducerPool.send
public void send(ProducerPoolData<V> ppd) { if (logger.isDebugEnabled()) { logger.debug("send message: " + ppd); } if (sync) { Message[] messages = new Message[ppd.data.size()]; int index = 0; for (V v : ppd.data) { messages[index] = serializer.toMessage(v); index++; } ByteBufferMessageSet bbms = new ByteBufferMessageSet(config.getCompressionCodec(), messages); ProducerRequest request = new ProducerRequest(ppd.topic, ppd.partition.partId, bbms); SyncProducer producer = syncProducers.get(ppd.partition.brokerId); if (producer == null) { throw new UnavailableProducerException("Producer pool has not been initialized correctly. " + "Sync Producer for broker " + ppd.partition.brokerId + " does not exist in the pool"); } producer.send(request.topic, request.partition, request.messages); } else { AsyncProducer<V> asyncProducer = asyncProducers.get(ppd.partition.brokerId); for (V v : ppd.data) { asyncProducer.send(ppd.topic, v, ppd.partition.partId); } } }
java
public void send(ProducerPoolData<V> ppd) { if (logger.isDebugEnabled()) { logger.debug("send message: " + ppd); } if (sync) { Message[] messages = new Message[ppd.data.size()]; int index = 0; for (V v : ppd.data) { messages[index] = serializer.toMessage(v); index++; } ByteBufferMessageSet bbms = new ByteBufferMessageSet(config.getCompressionCodec(), messages); ProducerRequest request = new ProducerRequest(ppd.topic, ppd.partition.partId, bbms); SyncProducer producer = syncProducers.get(ppd.partition.brokerId); if (producer == null) { throw new UnavailableProducerException("Producer pool has not been initialized correctly. " + "Sync Producer for broker " + ppd.partition.brokerId + " does not exist in the pool"); } producer.send(request.topic, request.partition, request.messages); } else { AsyncProducer<V> asyncProducer = asyncProducers.get(ppd.partition.brokerId); for (V v : ppd.data) { asyncProducer.send(ppd.topic, v, ppd.partition.partId); } } }
[ "public", "void", "send", "(", "ProducerPoolData", "<", "V", ">", "ppd", ")", "{", "if", "(", "logger", ".", "isDebugEnabled", "(", ")", ")", "{", "logger", ".", "debug", "(", "\"send message: \"", "+", "ppd", ")", ";", "}", "if", "(", "sync", ")", "{", "Message", "[", "]", "messages", "=", "new", "Message", "[", "ppd", ".", "data", ".", "size", "(", ")", "]", ";", "int", "index", "=", "0", ";", "for", "(", "V", "v", ":", "ppd", ".", "data", ")", "{", "messages", "[", "index", "]", "=", "serializer", ".", "toMessage", "(", "v", ")", ";", "index", "++", ";", "}", "ByteBufferMessageSet", "bbms", "=", "new", "ByteBufferMessageSet", "(", "config", ".", "getCompressionCodec", "(", ")", ",", "messages", ")", ";", "ProducerRequest", "request", "=", "new", "ProducerRequest", "(", "ppd", ".", "topic", ",", "ppd", ".", "partition", ".", "partId", ",", "bbms", ")", ";", "SyncProducer", "producer", "=", "syncProducers", ".", "get", "(", "ppd", ".", "partition", ".", "brokerId", ")", ";", "if", "(", "producer", "==", "null", ")", "{", "throw", "new", "UnavailableProducerException", "(", "\"Producer pool has not been initialized correctly. \"", "+", "\"Sync Producer for broker \"", "+", "ppd", ".", "partition", ".", "brokerId", "+", "\" does not exist in the pool\"", ")", ";", "}", "producer", ".", "send", "(", "request", ".", "topic", ",", "request", ".", "partition", ",", "request", ".", "messages", ")", ";", "}", "else", "{", "AsyncProducer", "<", "V", ">", "asyncProducer", "=", "asyncProducers", ".", "get", "(", "ppd", ".", "partition", ".", "brokerId", ")", ";", "for", "(", "V", "v", ":", "ppd", ".", "data", ")", "{", "asyncProducer", ".", "send", "(", "ppd", ".", "topic", ",", "v", ",", "ppd", ".", "partition", ".", "partId", ")", ";", "}", "}", "}" ]
selects either a synchronous or an asynchronous producer, for the specified broker id and calls the send API on the selected producer to publish the data to the specified broker partition @param ppd the producer pool request object
[ "selects", "either", "a", "synchronous", "or", "an", "asynchronous", "producer", "for", "the", "specified", "broker", "id", "and", "calls", "the", "send", "API", "on", "the", "selected", "producer", "to", "publish", "the", "data", "to", "the", "specified", "broker", "partition" ]
cc14d2ed60c039b12d7b106bb5269ef21d0add7e
https://github.com/adyliu/jafka/blob/cc14d2ed60c039b12d7b106bb5269ef21d0add7e/src/main/java/io/jafka/producer/ProducerPool.java#L147-L172
160,516
adyliu/jafka
src/main/java/io/jafka/producer/ProducerPool.java
ProducerPool.close
public void close() { logger.info("Closing all sync producers"); if (sync) { for (SyncProducer p : syncProducers.values()) { p.close(); } } else { for (AsyncProducer<V> p : asyncProducers.values()) { p.close(); } } }
java
public void close() { logger.info("Closing all sync producers"); if (sync) { for (SyncProducer p : syncProducers.values()) { p.close(); } } else { for (AsyncProducer<V> p : asyncProducers.values()) { p.close(); } } }
[ "public", "void", "close", "(", ")", "{", "logger", ".", "info", "(", "\"Closing all sync producers\"", ")", ";", "if", "(", "sync", ")", "{", "for", "(", "SyncProducer", "p", ":", "syncProducers", ".", "values", "(", ")", ")", "{", "p", ".", "close", "(", ")", ";", "}", "}", "else", "{", "for", "(", "AsyncProducer", "<", "V", ">", "p", ":", "asyncProducers", ".", "values", "(", ")", ")", "{", "p", ".", "close", "(", ")", ";", "}", "}", "}" ]
Closes all the producers in the pool
[ "Closes", "all", "the", "producers", "in", "the", "pool" ]
cc14d2ed60c039b12d7b106bb5269ef21d0add7e
https://github.com/adyliu/jafka/blob/cc14d2ed60c039b12d7b106bb5269ef21d0add7e/src/main/java/io/jafka/producer/ProducerPool.java#L226-L238
160,517
adyliu/jafka
src/main/java/io/jafka/producer/ProducerPool.java
ProducerPool.getProducerPoolData
public ProducerPoolData<V> getProducerPoolData(String topic, Partition bidPid, List<V> data) { return new ProducerPoolData<V>(topic, bidPid, data); }
java
public ProducerPoolData<V> getProducerPoolData(String topic, Partition bidPid, List<V> data) { return new ProducerPoolData<V>(topic, bidPid, data); }
[ "public", "ProducerPoolData", "<", "V", ">", "getProducerPoolData", "(", "String", "topic", ",", "Partition", "bidPid", ",", "List", "<", "V", ">", "data", ")", "{", "return", "new", "ProducerPoolData", "<", "V", ">", "(", "topic", ",", "bidPid", ",", "data", ")", ";", "}" ]
This constructs and returns the request object for the producer pool @param topic the topic to which the data should be published @param bidPid the broker id and partition id @param data the data to be published @return producer data of builder
[ "This", "constructs", "and", "returns", "the", "request", "object", "for", "the", "producer", "pool" ]
cc14d2ed60c039b12d7b106bb5269ef21d0add7e
https://github.com/adyliu/jafka/blob/cc14d2ed60c039b12d7b106bb5269ef21d0add7e/src/main/java/io/jafka/producer/ProducerPool.java#L248-L250
160,518
adyliu/jafka
src/main/java/io/jafka/api/ProducerRequest.java
ProducerRequest.readFrom
public static ProducerRequest readFrom(ByteBuffer buffer) { String topic = Utils.readShortString(buffer); int partition = buffer.getInt(); int messageSetSize = buffer.getInt(); ByteBuffer messageSetBuffer = buffer.slice(); messageSetBuffer.limit(messageSetSize); buffer.position(buffer.position() + messageSetSize); return new ProducerRequest(topic, partition, new ByteBufferMessageSet(messageSetBuffer)); }
java
public static ProducerRequest readFrom(ByteBuffer buffer) { String topic = Utils.readShortString(buffer); int partition = buffer.getInt(); int messageSetSize = buffer.getInt(); ByteBuffer messageSetBuffer = buffer.slice(); messageSetBuffer.limit(messageSetSize); buffer.position(buffer.position() + messageSetSize); return new ProducerRequest(topic, partition, new ByteBufferMessageSet(messageSetBuffer)); }
[ "public", "static", "ProducerRequest", "readFrom", "(", "ByteBuffer", "buffer", ")", "{", "String", "topic", "=", "Utils", ".", "readShortString", "(", "buffer", ")", ";", "int", "partition", "=", "buffer", ".", "getInt", "(", ")", ";", "int", "messageSetSize", "=", "buffer", ".", "getInt", "(", ")", ";", "ByteBuffer", "messageSetBuffer", "=", "buffer", ".", "slice", "(", ")", ";", "messageSetBuffer", ".", "limit", "(", "messageSetSize", ")", ";", "buffer", ".", "position", "(", "buffer", ".", "position", "(", ")", "+", "messageSetSize", ")", ";", "return", "new", "ProducerRequest", "(", "topic", ",", "partition", ",", "new", "ByteBufferMessageSet", "(", "messageSetBuffer", ")", ")", ";", "}" ]
read a producer request from buffer @param buffer data buffer @return parsed producer request
[ "read", "a", "producer", "request", "from", "buffer" ]
cc14d2ed60c039b12d7b106bb5269ef21d0add7e
https://github.com/adyliu/jafka/blob/cc14d2ed60c039b12d7b106bb5269ef21d0add7e/src/main/java/io/jafka/api/ProducerRequest.java#L57-L65
160,519
greenmail-mail-test/greenmail
greenmail-core/src/main/java/com/icegreen/greenmail/imap/commands/CommandTemplate.java
CommandTemplate.getExpectedMessage
protected String getExpectedMessage() { StringBuilder syntax = new StringBuilder("<tag> "); syntax.append(getName()); String args = getArgSyntax(); if (args != null && args.length() > 0) { syntax.append(' '); syntax.append(args); } return syntax.toString(); }
java
protected String getExpectedMessage() { StringBuilder syntax = new StringBuilder("<tag> "); syntax.append(getName()); String args = getArgSyntax(); if (args != null && args.length() > 0) { syntax.append(' '); syntax.append(args); } return syntax.toString(); }
[ "protected", "String", "getExpectedMessage", "(", ")", "{", "StringBuilder", "syntax", "=", "new", "StringBuilder", "(", "\"<tag> \"", ")", ";", "syntax", ".", "append", "(", "getName", "(", ")", ")", ";", "String", "args", "=", "getArgSyntax", "(", ")", ";", "if", "(", "args", "!=", "null", "&&", "args", ".", "length", "(", ")", ">", "0", ")", "{", "syntax", ".", "append", "(", "'", "'", ")", ";", "syntax", ".", "append", "(", "args", ")", ";", "}", "return", "syntax", ".", "toString", "(", ")", ";", "}" ]
Provides a message which describes the expected format and arguments for this command. This is used to provide user feedback when a command request is malformed. @return A message describing the command protocol format.
[ "Provides", "a", "message", "which", "describes", "the", "expected", "format", "and", "arguments", "for", "this", "command", ".", "This", "is", "used", "to", "provide", "user", "feedback", "when", "a", "command", "request", "is", "malformed", "." ]
6d19a62233d1ef6fedbbd1f6fdde2d28e713834a
https://github.com/greenmail-mail-test/greenmail/blob/6d19a62233d1ef6fedbbd1f6fdde2d28e713834a/greenmail-core/src/main/java/com/icegreen/greenmail/imap/commands/CommandTemplate.java#L93-L104
160,520
greenmail-mail-test/greenmail
greenmail-core/src/main/java/com/icegreen/greenmail/util/ServerSetup.java
ServerSetup.createCopy
public ServerSetup createCopy(String bindAddress) { ServerSetup setup = new ServerSetup(getPort(), bindAddress, getProtocol()); setup.setServerStartupTimeout(getServerStartupTimeout()); setup.setConnectionTimeout(getConnectionTimeout()); setup.setReadTimeout(getReadTimeout()); setup.setWriteTimeout(getWriteTimeout()); setup.setVerbose(isVerbose()); return setup; }
java
public ServerSetup createCopy(String bindAddress) { ServerSetup setup = new ServerSetup(getPort(), bindAddress, getProtocol()); setup.setServerStartupTimeout(getServerStartupTimeout()); setup.setConnectionTimeout(getConnectionTimeout()); setup.setReadTimeout(getReadTimeout()); setup.setWriteTimeout(getWriteTimeout()); setup.setVerbose(isVerbose()); return setup; }
[ "public", "ServerSetup", "createCopy", "(", "String", "bindAddress", ")", "{", "ServerSetup", "setup", "=", "new", "ServerSetup", "(", "getPort", "(", ")", ",", "bindAddress", ",", "getProtocol", "(", ")", ")", ";", "setup", ".", "setServerStartupTimeout", "(", "getServerStartupTimeout", "(", ")", ")", ";", "setup", ".", "setConnectionTimeout", "(", "getConnectionTimeout", "(", ")", ")", ";", "setup", ".", "setReadTimeout", "(", "getReadTimeout", "(", ")", ")", ";", "setup", ".", "setWriteTimeout", "(", "getWriteTimeout", "(", ")", ")", ";", "setup", ".", "setVerbose", "(", "isVerbose", "(", ")", ")", ";", "return", "setup", ";", "}" ]
Create a deep copy. @param bindAddress overwrites bind address when creating deep copy. @return a copy of the server setup configuration.
[ "Create", "a", "deep", "copy", "." ]
6d19a62233d1ef6fedbbd1f6fdde2d28e713834a
https://github.com/greenmail-mail-test/greenmail/blob/6d19a62233d1ef6fedbbd1f6fdde2d28e713834a/greenmail-core/src/main/java/com/icegreen/greenmail/util/ServerSetup.java#L300-L309
160,521
greenmail-mail-test/greenmail
greenmail-core/src/main/java/com/icegreen/greenmail/util/ServerSetup.java
ServerSetup.verbose
public static ServerSetup[] verbose(ServerSetup[] serverSetups) { ServerSetup[] copies = new ServerSetup[serverSetups.length]; for (int i = 0; i < serverSetups.length; i++) { copies[i] = serverSetups[i].createCopy().setVerbose(true); } return copies; }
java
public static ServerSetup[] verbose(ServerSetup[] serverSetups) { ServerSetup[] copies = new ServerSetup[serverSetups.length]; for (int i = 0; i < serverSetups.length; i++) { copies[i] = serverSetups[i].createCopy().setVerbose(true); } return copies; }
[ "public", "static", "ServerSetup", "[", "]", "verbose", "(", "ServerSetup", "[", "]", "serverSetups", ")", "{", "ServerSetup", "[", "]", "copies", "=", "new", "ServerSetup", "[", "serverSetups", ".", "length", "]", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "serverSetups", ".", "length", ";", "i", "++", ")", "{", "copies", "[", "i", "]", "=", "serverSetups", "[", "i", "]", ".", "createCopy", "(", ")", ".", "setVerbose", "(", "true", ")", ";", "}", "return", "copies", ";", "}" ]
Creates a copy with verbose mode enabled. @param serverSetups the server setups. @return copies of server setups with verbose mode enabled.
[ "Creates", "a", "copy", "with", "verbose", "mode", "enabled", "." ]
6d19a62233d1ef6fedbbd1f6fdde2d28e713834a
https://github.com/greenmail-mail-test/greenmail/blob/6d19a62233d1ef6fedbbd1f6fdde2d28e713834a/greenmail-core/src/main/java/com/icegreen/greenmail/util/ServerSetup.java#L317-L323
160,522
greenmail-mail-test/greenmail
greenmail-standalone/src/main/java/com/icegreen/greenmail/standalone/GreenMailStandaloneRunner.java
GreenMailStandaloneRunner.doRun
public void doRun(Properties properties) { ServerSetup[] serverSetup = new PropertiesBasedServerSetupBuilder().build(properties); if (serverSetup.length == 0) { printUsage(System.out); } else { greenMail = new GreenMail(serverSetup); log.info("Starting GreenMail standalone v{} using {}", BuildInfo.INSTANCE.getProjectVersion(), Arrays.toString(serverSetup)); greenMail.withConfiguration(new PropertiesBasedGreenMailConfigurationBuilder().build(properties)) .start(); } }
java
public void doRun(Properties properties) { ServerSetup[] serverSetup = new PropertiesBasedServerSetupBuilder().build(properties); if (serverSetup.length == 0) { printUsage(System.out); } else { greenMail = new GreenMail(serverSetup); log.info("Starting GreenMail standalone v{} using {}", BuildInfo.INSTANCE.getProjectVersion(), Arrays.toString(serverSetup)); greenMail.withConfiguration(new PropertiesBasedGreenMailConfigurationBuilder().build(properties)) .start(); } }
[ "public", "void", "doRun", "(", "Properties", "properties", ")", "{", "ServerSetup", "[", "]", "serverSetup", "=", "new", "PropertiesBasedServerSetupBuilder", "(", ")", ".", "build", "(", "properties", ")", ";", "if", "(", "serverSetup", ".", "length", "==", "0", ")", "{", "printUsage", "(", "System", ".", "out", ")", ";", "}", "else", "{", "greenMail", "=", "new", "GreenMail", "(", "serverSetup", ")", ";", "log", ".", "info", "(", "\"Starting GreenMail standalone v{} using {}\"", ",", "BuildInfo", ".", "INSTANCE", ".", "getProjectVersion", "(", ")", ",", "Arrays", ".", "toString", "(", "serverSetup", ")", ")", ";", "greenMail", ".", "withConfiguration", "(", "new", "PropertiesBasedGreenMailConfigurationBuilder", "(", ")", ".", "build", "(", "properties", ")", ")", ".", "start", "(", ")", ";", "}", "}" ]
Start and configure GreenMail using given properties. @param properties the properties such as System.getProperties()
[ "Start", "and", "configure", "GreenMail", "using", "given", "properties", "." ]
6d19a62233d1ef6fedbbd1f6fdde2d28e713834a
https://github.com/greenmail-mail-test/greenmail/blob/6d19a62233d1ef6fedbbd1f6fdde2d28e713834a/greenmail-standalone/src/main/java/com/icegreen/greenmail/standalone/GreenMailStandaloneRunner.java#L34-L47
160,523
greenmail-mail-test/greenmail
greenmail-core/src/main/java/com/icegreen/greenmail/mail/MailAddress.java
MailAddress.decodeStr
private String decodeStr(String str) { try { return MimeUtility.decodeText(str); } catch (UnsupportedEncodingException e) { return str; } }
java
private String decodeStr(String str) { try { return MimeUtility.decodeText(str); } catch (UnsupportedEncodingException e) { return str; } }
[ "private", "String", "decodeStr", "(", "String", "str", ")", "{", "try", "{", "return", "MimeUtility", ".", "decodeText", "(", "str", ")", ";", "}", "catch", "(", "UnsupportedEncodingException", "e", ")", "{", "return", "str", ";", "}", "}" ]
Returns the decoded string, in case it contains non us-ascii characters. Returns the same string if it doesn't or the passed value in case of an UnsupportedEncodingException. @param str string to be decoded @return the decoded string, in case it contains non us-ascii characters; or the same string if it doesn't or the passed value in case of an UnsupportedEncodingException.
[ "Returns", "the", "decoded", "string", "in", "case", "it", "contains", "non", "us", "-", "ascii", "characters", ".", "Returns", "the", "same", "string", "if", "it", "doesn", "t", "or", "the", "passed", "value", "in", "case", "of", "an", "UnsupportedEncodingException", "." ]
6d19a62233d1ef6fedbbd1f6fdde2d28e713834a
https://github.com/greenmail-mail-test/greenmail/blob/6d19a62233d1ef6fedbbd1f6fdde2d28e713834a/greenmail-core/src/main/java/com/icegreen/greenmail/mail/MailAddress.java#L72-L78
160,524
greenmail-mail-test/greenmail
greenmail-core/src/main/java/com/icegreen/greenmail/util/GreenMailUtil.java
GreenMailUtil.copyStream
public static void copyStream(final InputStream src, OutputStream dest) throws IOException { byte[] buffer = new byte[1024]; int read; while ((read = src.read(buffer)) > -1) { dest.write(buffer, 0, read); } dest.flush(); }
java
public static void copyStream(final InputStream src, OutputStream dest) throws IOException { byte[] buffer = new byte[1024]; int read; while ((read = src.read(buffer)) > -1) { dest.write(buffer, 0, read); } dest.flush(); }
[ "public", "static", "void", "copyStream", "(", "final", "InputStream", "src", ",", "OutputStream", "dest", ")", "throws", "IOException", "{", "byte", "[", "]", "buffer", "=", "new", "byte", "[", "1024", "]", ";", "int", "read", ";", "while", "(", "(", "read", "=", "src", ".", "read", "(", "buffer", ")", ")", ">", "-", "1", ")", "{", "dest", ".", "write", "(", "buffer", ",", "0", ",", "read", ")", ";", "}", "dest", ".", "flush", "(", ")", ";", "}" ]
Writes the content of an input stream to an output stream @throws IOException
[ "Writes", "the", "content", "of", "an", "input", "stream", "to", "an", "output", "stream" ]
6d19a62233d1ef6fedbbd1f6fdde2d28e713834a
https://github.com/greenmail-mail-test/greenmail/blob/6d19a62233d1ef6fedbbd1f6fdde2d28e713834a/greenmail-core/src/main/java/com/icegreen/greenmail/util/GreenMailUtil.java#L56-L63
160,525
greenmail-mail-test/greenmail
greenmail-core/src/main/java/com/icegreen/greenmail/util/GreenMailUtil.java
GreenMailUtil.getLineCount
public static int getLineCount(String str) { if (null == str || str.isEmpty()) { return 0; } int count = 1; for (char c : str.toCharArray()) { if ('\n' == c) { count++; } } return count; }
java
public static int getLineCount(String str) { if (null == str || str.isEmpty()) { return 0; } int count = 1; for (char c : str.toCharArray()) { if ('\n' == c) { count++; } } return count; }
[ "public", "static", "int", "getLineCount", "(", "String", "str", ")", "{", "if", "(", "null", "==", "str", "||", "str", ".", "isEmpty", "(", ")", ")", "{", "return", "0", ";", "}", "int", "count", "=", "1", ";", "for", "(", "char", "c", ":", "str", ".", "toCharArray", "(", ")", ")", "{", "if", "(", "'", "'", "==", "c", ")", "{", "count", "++", ";", "}", "}", "return", "count", ";", "}" ]
Counts the number of lines. @param str the input string @return Returns the number of lines terminated by '\n' in string
[ "Counts", "the", "number", "of", "lines", "." ]
6d19a62233d1ef6fedbbd1f6fdde2d28e713834a
https://github.com/greenmail-mail-test/greenmail/blob/6d19a62233d1ef6fedbbd1f6fdde2d28e713834a/greenmail-core/src/main/java/com/icegreen/greenmail/util/GreenMailUtil.java#L113-L124
160,526
greenmail-mail-test/greenmail
greenmail-core/src/main/java/com/icegreen/greenmail/util/GreenMailUtil.java
GreenMailUtil.sendTextEmail
public static void sendTextEmail(String to, String from, String subject, String msg, final ServerSetup setup) { sendMimeMessage(createTextEmail(to, from, subject, msg, setup)); }
java
public static void sendTextEmail(String to, String from, String subject, String msg, final ServerSetup setup) { sendMimeMessage(createTextEmail(to, from, subject, msg, setup)); }
[ "public", "static", "void", "sendTextEmail", "(", "String", "to", ",", "String", "from", ",", "String", "subject", ",", "String", "msg", ",", "final", "ServerSetup", "setup", ")", "{", "sendMimeMessage", "(", "createTextEmail", "(", "to", ",", "from", ",", "subject", ",", "msg", ",", "setup", ")", ")", ";", "}" ]
Sends a text message using given server setup for SMTP. @param to the to address. @param from the from address. @param subject the subject. @param msg the test message. @param setup the SMTP setup.
[ "Sends", "a", "text", "message", "using", "given", "server", "setup", "for", "SMTP", "." ]
6d19a62233d1ef6fedbbd1f6fdde2d28e713834a
https://github.com/greenmail-mail-test/greenmail/blob/6d19a62233d1ef6fedbbd1f6fdde2d28e713834a/greenmail-core/src/main/java/com/icegreen/greenmail/util/GreenMailUtil.java#L262-L264
160,527
greenmail-mail-test/greenmail
greenmail-core/src/main/java/com/icegreen/greenmail/util/GreenMailUtil.java
GreenMailUtil.sendMimeMessage
public static void sendMimeMessage(MimeMessage mimeMessage) { try { Transport.send(mimeMessage); } catch (MessagingException e) { throw new IllegalStateException("Can not send message " + mimeMessage, e); } }
java
public static void sendMimeMessage(MimeMessage mimeMessage) { try { Transport.send(mimeMessage); } catch (MessagingException e) { throw new IllegalStateException("Can not send message " + mimeMessage, e); } }
[ "public", "static", "void", "sendMimeMessage", "(", "MimeMessage", "mimeMessage", ")", "{", "try", "{", "Transport", ".", "send", "(", "mimeMessage", ")", ";", "}", "catch", "(", "MessagingException", "e", ")", "{", "throw", "new", "IllegalStateException", "(", "\"Can not send message \"", "+", "mimeMessage", ",", "e", ")", ";", "}", "}" ]
Send the message using the JavaMail session defined in the message @param mimeMessage Message to send
[ "Send", "the", "message", "using", "the", "JavaMail", "session", "defined", "in", "the", "message" ]
6d19a62233d1ef6fedbbd1f6fdde2d28e713834a
https://github.com/greenmail-mail-test/greenmail/blob/6d19a62233d1ef6fedbbd1f6fdde2d28e713834a/greenmail-core/src/main/java/com/icegreen/greenmail/util/GreenMailUtil.java#L271-L277
160,528
greenmail-mail-test/greenmail
greenmail-core/src/main/java/com/icegreen/greenmail/util/GreenMailUtil.java
GreenMailUtil.sendMessageBody
public static void sendMessageBody(String to, String from, String subject, Object body, String contentType, ServerSetup serverSetup) { try { Session smtpSession = getSession(serverSetup); MimeMessage mimeMessage = new MimeMessage(smtpSession); mimeMessage.setRecipients(Message.RecipientType.TO, to); mimeMessage.setFrom(from); mimeMessage.setSubject(subject); mimeMessage.setContent(body, contentType); sendMimeMessage(mimeMessage); } catch (MessagingException e) { throw new IllegalStateException("Can not send message", e); } }
java
public static void sendMessageBody(String to, String from, String subject, Object body, String contentType, ServerSetup serverSetup) { try { Session smtpSession = getSession(serverSetup); MimeMessage mimeMessage = new MimeMessage(smtpSession); mimeMessage.setRecipients(Message.RecipientType.TO, to); mimeMessage.setFrom(from); mimeMessage.setSubject(subject); mimeMessage.setContent(body, contentType); sendMimeMessage(mimeMessage); } catch (MessagingException e) { throw new IllegalStateException("Can not send message", e); } }
[ "public", "static", "void", "sendMessageBody", "(", "String", "to", ",", "String", "from", ",", "String", "subject", ",", "Object", "body", ",", "String", "contentType", ",", "ServerSetup", "serverSetup", ")", "{", "try", "{", "Session", "smtpSession", "=", "getSession", "(", "serverSetup", ")", ";", "MimeMessage", "mimeMessage", "=", "new", "MimeMessage", "(", "smtpSession", ")", ";", "mimeMessage", ".", "setRecipients", "(", "Message", ".", "RecipientType", ".", "TO", ",", "to", ")", ";", "mimeMessage", ".", "setFrom", "(", "from", ")", ";", "mimeMessage", ".", "setSubject", "(", "subject", ")", ";", "mimeMessage", ".", "setContent", "(", "body", ",", "contentType", ")", ";", "sendMimeMessage", "(", "mimeMessage", ")", ";", "}", "catch", "(", "MessagingException", "e", ")", "{", "throw", "new", "IllegalStateException", "(", "\"Can not send message\"", ",", "e", ")", ";", "}", "}" ]
Send the message with the given attributes and the given body using the specified SMTP settings @param to Destination address(es) @param from Sender address @param subject Message subject @param body Message content. May either be a MimeMultipart or another body that java mail recognizes @param contentType MIME content type of body @param serverSetup Server settings to use for connecting to the SMTP server
[ "Send", "the", "message", "with", "the", "given", "attributes", "and", "the", "given", "body", "using", "the", "specified", "SMTP", "settings" ]
6d19a62233d1ef6fedbbd1f6fdde2d28e713834a
https://github.com/greenmail-mail-test/greenmail/blob/6d19a62233d1ef6fedbbd1f6fdde2d28e713834a/greenmail-core/src/main/java/com/icegreen/greenmail/util/GreenMailUtil.java#L289-L302
160,529
greenmail-mail-test/greenmail
greenmail-core/src/main/java/com/icegreen/greenmail/util/GreenMailUtil.java
GreenMailUtil.createMultipartWithAttachment
public static MimeMultipart createMultipartWithAttachment(String msg, final byte[] attachment, final String contentType, final String filename, String description) { try { MimeMultipart multiPart = new MimeMultipart(); MimeBodyPart textPart = new MimeBodyPart(); multiPart.addBodyPart(textPart); textPart.setText(msg); MimeBodyPart binaryPart = new MimeBodyPart(); multiPart.addBodyPart(binaryPart); DataSource ds = new DataSource() { @Override public InputStream getInputStream() throws IOException { return new ByteArrayInputStream(attachment); } @Override public OutputStream getOutputStream() throws IOException { ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); byteStream.write(attachment); return byteStream; } @Override public String getContentType() { return contentType; } @Override public String getName() { return filename; } }; binaryPart.setDataHandler(new DataHandler(ds)); binaryPart.setFileName(filename); binaryPart.setDescription(description); return multiPart; } catch (MessagingException e) { throw new IllegalArgumentException("Can not create multipart message with attachment", e); } }
java
public static MimeMultipart createMultipartWithAttachment(String msg, final byte[] attachment, final String contentType, final String filename, String description) { try { MimeMultipart multiPart = new MimeMultipart(); MimeBodyPart textPart = new MimeBodyPart(); multiPart.addBodyPart(textPart); textPart.setText(msg); MimeBodyPart binaryPart = new MimeBodyPart(); multiPart.addBodyPart(binaryPart); DataSource ds = new DataSource() { @Override public InputStream getInputStream() throws IOException { return new ByteArrayInputStream(attachment); } @Override public OutputStream getOutputStream() throws IOException { ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); byteStream.write(attachment); return byteStream; } @Override public String getContentType() { return contentType; } @Override public String getName() { return filename; } }; binaryPart.setDataHandler(new DataHandler(ds)); binaryPart.setFileName(filename); binaryPart.setDescription(description); return multiPart; } catch (MessagingException e) { throw new IllegalArgumentException("Can not create multipart message with attachment", e); } }
[ "public", "static", "MimeMultipart", "createMultipartWithAttachment", "(", "String", "msg", ",", "final", "byte", "[", "]", "attachment", ",", "final", "String", "contentType", ",", "final", "String", "filename", ",", "String", "description", ")", "{", "try", "{", "MimeMultipart", "multiPart", "=", "new", "MimeMultipart", "(", ")", ";", "MimeBodyPart", "textPart", "=", "new", "MimeBodyPart", "(", ")", ";", "multiPart", ".", "addBodyPart", "(", "textPart", ")", ";", "textPart", ".", "setText", "(", "msg", ")", ";", "MimeBodyPart", "binaryPart", "=", "new", "MimeBodyPart", "(", ")", ";", "multiPart", ".", "addBodyPart", "(", "binaryPart", ")", ";", "DataSource", "ds", "=", "new", "DataSource", "(", ")", "{", "@", "Override", "public", "InputStream", "getInputStream", "(", ")", "throws", "IOException", "{", "return", "new", "ByteArrayInputStream", "(", "attachment", ")", ";", "}", "@", "Override", "public", "OutputStream", "getOutputStream", "(", ")", "throws", "IOException", "{", "ByteArrayOutputStream", "byteStream", "=", "new", "ByteArrayOutputStream", "(", ")", ";", "byteStream", ".", "write", "(", "attachment", ")", ";", "return", "byteStream", ";", "}", "@", "Override", "public", "String", "getContentType", "(", ")", "{", "return", "contentType", ";", "}", "@", "Override", "public", "String", "getName", "(", ")", "{", "return", "filename", ";", "}", "}", ";", "binaryPart", ".", "setDataHandler", "(", "new", "DataHandler", "(", "ds", ")", ")", ";", "binaryPart", ".", "setFileName", "(", "filename", ")", ";", "binaryPart", ".", "setDescription", "(", "description", ")", ";", "return", "multiPart", ";", "}", "catch", "(", "MessagingException", "e", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Can not create multipart message with attachment\"", ",", "e", ")", ";", "}", "}" ]
Create new multipart with a text part and an attachment @param msg Message text @param attachment Attachment data @param contentType MIME content type of body @param filename File name of the attachment @param description Description of the attachment @return New multipart
[ "Create", "new", "multipart", "with", "a", "text", "part", "and", "an", "attachment" ]
6d19a62233d1ef6fedbbd1f6fdde2d28e713834a
https://github.com/greenmail-mail-test/greenmail/blob/6d19a62233d1ef6fedbbd1f6fdde2d28e713834a/greenmail-core/src/main/java/com/icegreen/greenmail/util/GreenMailUtil.java#L322-L364
160,530
greenmail-mail-test/greenmail
greenmail-core/src/main/java/com/icegreen/greenmail/util/GreenMailUtil.java
GreenMailUtil.getSession
public static Session getSession(final ServerSetup setup, Properties mailProps) { Properties props = setup.configureJavaMailSessionProperties(mailProps, false); log.debug("Mail session properties are {}", props); return Session.getInstance(props, null); }
java
public static Session getSession(final ServerSetup setup, Properties mailProps) { Properties props = setup.configureJavaMailSessionProperties(mailProps, false); log.debug("Mail session properties are {}", props); return Session.getInstance(props, null); }
[ "public", "static", "Session", "getSession", "(", "final", "ServerSetup", "setup", ",", "Properties", "mailProps", ")", "{", "Properties", "props", "=", "setup", ".", "configureJavaMailSessionProperties", "(", "mailProps", ",", "false", ")", ";", "log", ".", "debug", "(", "\"Mail session properties are {}\"", ",", "props", ")", ";", "return", "Session", ".", "getInstance", "(", "props", ",", "null", ")", ";", "}" ]
Gets a JavaMail Session for given server type such as IMAP and additional props for JavaMail. @param setup the setup type, such as <code>ServerSetup.IMAP</code> @param mailProps additional mail properties. @return the JavaMail session.
[ "Gets", "a", "JavaMail", "Session", "for", "given", "server", "type", "such", "as", "IMAP", "and", "additional", "props", "for", "JavaMail", "." ]
6d19a62233d1ef6fedbbd1f6fdde2d28e713834a
https://github.com/greenmail-mail-test/greenmail/blob/6d19a62233d1ef6fedbbd1f6fdde2d28e713834a/greenmail-core/src/main/java/com/icegreen/greenmail/util/GreenMailUtil.java#L377-L383
160,531
greenmail-mail-test/greenmail
greenmail-core/src/main/java/com/icegreen/greenmail/util/GreenMailUtil.java
GreenMailUtil.setQuota
public static void setQuota(final GreenMailUser user, final Quota quota) { Session session = GreenMailUtil.getSession(ServerSetupTest.IMAP); try { Store store = session.getStore("imap"); store.connect(user.getEmail(), user.getPassword()); try { ((QuotaAwareStore) store).setQuota(quota); } finally { store.close(); } } catch (Exception ex) { throw new IllegalStateException("Can not set quota " + quota + " for user " + user, ex); } }
java
public static void setQuota(final GreenMailUser user, final Quota quota) { Session session = GreenMailUtil.getSession(ServerSetupTest.IMAP); try { Store store = session.getStore("imap"); store.connect(user.getEmail(), user.getPassword()); try { ((QuotaAwareStore) store).setQuota(quota); } finally { store.close(); } } catch (Exception ex) { throw new IllegalStateException("Can not set quota " + quota + " for user " + user, ex); } }
[ "public", "static", "void", "setQuota", "(", "final", "GreenMailUser", "user", ",", "final", "Quota", "quota", ")", "{", "Session", "session", "=", "GreenMailUtil", ".", "getSession", "(", "ServerSetupTest", ".", "IMAP", ")", ";", "try", "{", "Store", "store", "=", "session", ".", "getStore", "(", "\"imap\"", ")", ";", "store", ".", "connect", "(", "user", ".", "getEmail", "(", ")", ",", "user", ".", "getPassword", "(", ")", ")", ";", "try", "{", "(", "(", "QuotaAwareStore", ")", "store", ")", ".", "setQuota", "(", "quota", ")", ";", "}", "finally", "{", "store", ".", "close", "(", ")", ";", "}", "}", "catch", "(", "Exception", "ex", ")", "{", "throw", "new", "IllegalStateException", "(", "\"Can not set quota \"", "+", "quota", "+", "\" for user \"", "+", "user", ",", "ex", ")", ";", "}", "}" ]
Sets a quota for a users. @param user the user. @param quota the quota.
[ "Sets", "a", "quota", "for", "a", "users", "." ]
6d19a62233d1ef6fedbbd1f6fdde2d28e713834a
https://github.com/greenmail-mail-test/greenmail/blob/6d19a62233d1ef6fedbbd1f6fdde2d28e713834a/greenmail-core/src/main/java/com/icegreen/greenmail/util/GreenMailUtil.java#L391-L405
160,532
greenmail-mail-test/greenmail
greenmail-core/src/main/java/com/icegreen/greenmail/user/UserManager.java
UserManager.hasUser
public boolean hasUser(String userId) { String normalized = normalizerUserName(userId); return loginToUser.containsKey(normalized) || emailToUser.containsKey(normalized); }
java
public boolean hasUser(String userId) { String normalized = normalizerUserName(userId); return loginToUser.containsKey(normalized) || emailToUser.containsKey(normalized); }
[ "public", "boolean", "hasUser", "(", "String", "userId", ")", "{", "String", "normalized", "=", "normalizerUserName", "(", "userId", ")", ";", "return", "loginToUser", ".", "containsKey", "(", "normalized", ")", "||", "emailToUser", ".", "containsKey", "(", "normalized", ")", ";", "}" ]
Checks if user exists. @param userId the user id, which can be an email or the login. @return true, if user exists.
[ "Checks", "if", "user", "exists", "." ]
6d19a62233d1ef6fedbbd1f6fdde2d28e713834a
https://github.com/greenmail-mail-test/greenmail/blob/6d19a62233d1ef6fedbbd1f6fdde2d28e713834a/greenmail-core/src/main/java/com/icegreen/greenmail/user/UserManager.java#L110-L113
160,533
greenmail-mail-test/greenmail
greenmail-core/src/main/java/com/icegreen/greenmail/server/AbstractServer.java
AbstractServer.closeServerSocket
protected void closeServerSocket() { // Close server socket, we do not accept new requests anymore. // This also terminates the server thread if blocking on socket.accept. if (null != serverSocket) { try { if (!serverSocket.isClosed()) { serverSocket.close(); if (log.isTraceEnabled()) { log.trace("Closed server socket " + serverSocket + "/ref=" + Integer.toHexString(System.identityHashCode(serverSocket)) + " for " + getName()); } } } catch (IOException e) { throw new IllegalStateException("Failed to successfully quit server " + getName(), e); } } }
java
protected void closeServerSocket() { // Close server socket, we do not accept new requests anymore. // This also terminates the server thread if blocking on socket.accept. if (null != serverSocket) { try { if (!serverSocket.isClosed()) { serverSocket.close(); if (log.isTraceEnabled()) { log.trace("Closed server socket " + serverSocket + "/ref=" + Integer.toHexString(System.identityHashCode(serverSocket)) + " for " + getName()); } } } catch (IOException e) { throw new IllegalStateException("Failed to successfully quit server " + getName(), e); } } }
[ "protected", "void", "closeServerSocket", "(", ")", "{", "// Close server socket, we do not accept new requests anymore.", "// This also terminates the server thread if blocking on socket.accept.", "if", "(", "null", "!=", "serverSocket", ")", "{", "try", "{", "if", "(", "!", "serverSocket", ".", "isClosed", "(", ")", ")", "{", "serverSocket", ".", "close", "(", ")", ";", "if", "(", "log", ".", "isTraceEnabled", "(", ")", ")", "{", "log", ".", "trace", "(", "\"Closed server socket \"", "+", "serverSocket", "+", "\"/ref=\"", "+", "Integer", ".", "toHexString", "(", "System", ".", "identityHashCode", "(", "serverSocket", ")", ")", "+", "\" for \"", "+", "getName", "(", ")", ")", ";", "}", "}", "}", "catch", "(", "IOException", "e", ")", "{", "throw", "new", "IllegalStateException", "(", "\"Failed to successfully quit server \"", "+", "getName", "(", ")", ",", "e", ")", ";", "}", "}", "}" ]
Closes the server socket.
[ "Closes", "the", "server", "socket", "." ]
6d19a62233d1ef6fedbbd1f6fdde2d28e713834a
https://github.com/greenmail-mail-test/greenmail/blob/6d19a62233d1ef6fedbbd1f6fdde2d28e713834a/greenmail-core/src/main/java/com/icegreen/greenmail/server/AbstractServer.java#L126-L143
160,534
greenmail-mail-test/greenmail
greenmail-core/src/main/java/com/icegreen/greenmail/server/AbstractServer.java
AbstractServer.quit
protected synchronized void quit() { log.debug("Stopping {}", getName()); closeServerSocket(); // Close all handlers. Handler threads terminate if run loop exits synchronized (handlers) { for (ProtocolHandler handler : handlers) { handler.close(); } handlers.clear(); } log.debug("Stopped {}", getName()); }
java
protected synchronized void quit() { log.debug("Stopping {}", getName()); closeServerSocket(); // Close all handlers. Handler threads terminate if run loop exits synchronized (handlers) { for (ProtocolHandler handler : handlers) { handler.close(); } handlers.clear(); } log.debug("Stopped {}", getName()); }
[ "protected", "synchronized", "void", "quit", "(", ")", "{", "log", ".", "debug", "(", "\"Stopping {}\"", ",", "getName", "(", ")", ")", ";", "closeServerSocket", "(", ")", ";", "// Close all handlers. Handler threads terminate if run loop exits", "synchronized", "(", "handlers", ")", "{", "for", "(", "ProtocolHandler", "handler", ":", "handlers", ")", "{", "handler", ".", "close", "(", ")", ";", "}", "handlers", ".", "clear", "(", ")", ";", "}", "log", ".", "debug", "(", "\"Stopped {}\"", ",", "getName", "(", ")", ")", ";", "}" ]
Quits server by closing server socket and closing client socket handlers.
[ "Quits", "server", "by", "closing", "server", "socket", "and", "closing", "client", "socket", "handlers", "." ]
6d19a62233d1ef6fedbbd1f6fdde2d28e713834a
https://github.com/greenmail-mail-test/greenmail/blob/6d19a62233d1ef6fedbbd1f6fdde2d28e713834a/greenmail-core/src/main/java/com/icegreen/greenmail/server/AbstractServer.java#L186-L198
160,535
greenmail-mail-test/greenmail
greenmail-core/src/main/java/com/icegreen/greenmail/server/AbstractServer.java
AbstractServer.stopService
@Override public final synchronized void stopService(long millis) { running = false; try { if (keepRunning) { keepRunning = false; interrupt(); quit(); if (0L == millis) { join(); } else { join(millis); } } } catch (InterruptedException e) { //its possible that the thread exits between the lines keepRunning=false and interrupt above log.warn("Got interrupted while stopping {}", this, e); Thread.currentThread().interrupt(); } }
java
@Override public final synchronized void stopService(long millis) { running = false; try { if (keepRunning) { keepRunning = false; interrupt(); quit(); if (0L == millis) { join(); } else { join(millis); } } } catch (InterruptedException e) { //its possible that the thread exits between the lines keepRunning=false and interrupt above log.warn("Got interrupted while stopping {}", this, e); Thread.currentThread().interrupt(); } }
[ "@", "Override", "public", "final", "synchronized", "void", "stopService", "(", "long", "millis", ")", "{", "running", "=", "false", ";", "try", "{", "if", "(", "keepRunning", ")", "{", "keepRunning", "=", "false", ";", "interrupt", "(", ")", ";", "quit", "(", ")", ";", "if", "(", "0L", "==", "millis", ")", "{", "join", "(", ")", ";", "}", "else", "{", "join", "(", "millis", ")", ";", "}", "}", "}", "catch", "(", "InterruptedException", "e", ")", "{", "//its possible that the thread exits between the lines keepRunning=false and interrupt above", "log", ".", "warn", "(", "\"Got interrupted while stopping {}\"", ",", "this", ",", "e", ")", ";", "Thread", ".", "currentThread", "(", ")", ".", "interrupt", "(", ")", ";", "}", "}" ]
Stops the service. If a timeout is given and the service has still not gracefully been stopped after timeout ms the service is stopped by force. @param millis value in ms
[ "Stops", "the", "service", ".", "If", "a", "timeout", "is", "given", "and", "the", "service", "has", "still", "not", "gracefully", "been", "stopped", "after", "timeout", "ms", "the", "service", "is", "stopped", "by", "force", "." ]
6d19a62233d1ef6fedbbd1f6fdde2d28e713834a
https://github.com/greenmail-mail-test/greenmail/blob/6d19a62233d1ef6fedbbd1f6fdde2d28e713834a/greenmail-core/src/main/java/com/icegreen/greenmail/server/AbstractServer.java#L255-L275
160,536
greenmail-mail-test/greenmail
greenmail-core/src/main/java/com/icegreen/greenmail/store/SimpleMessageAttributes.java
SimpleMessageAttributes.getSentDate
private static Date getSentDate(MimeMessage msg, Date defaultVal) { if (msg == null) { return defaultVal; } try { Date sentDate = msg.getSentDate(); if (sentDate == null) { return defaultVal; } else { return sentDate; } } catch (MessagingException me) { return new Date(); } }
java
private static Date getSentDate(MimeMessage msg, Date defaultVal) { if (msg == null) { return defaultVal; } try { Date sentDate = msg.getSentDate(); if (sentDate == null) { return defaultVal; } else { return sentDate; } } catch (MessagingException me) { return new Date(); } }
[ "private", "static", "Date", "getSentDate", "(", "MimeMessage", "msg", ",", "Date", "defaultVal", ")", "{", "if", "(", "msg", "==", "null", ")", "{", "return", "defaultVal", ";", "}", "try", "{", "Date", "sentDate", "=", "msg", ".", "getSentDate", "(", ")", ";", "if", "(", "sentDate", "==", "null", ")", "{", "return", "defaultVal", ";", "}", "else", "{", "return", "sentDate", ";", "}", "}", "catch", "(", "MessagingException", "me", ")", "{", "return", "new", "Date", "(", ")", ";", "}", "}" ]
Compute "sent" date @param msg Message to take sent date from. May be null to use default @param defaultVal Default if sent date is not present @return Sent date or now if no date could be found
[ "Compute", "sent", "date" ]
6d19a62233d1ef6fedbbd1f6fdde2d28e713834a
https://github.com/greenmail-mail-test/greenmail/blob/6d19a62233d1ef6fedbbd1f6fdde2d28e713834a/greenmail-core/src/main/java/com/icegreen/greenmail/store/SimpleMessageAttributes.java#L102-L116
160,537
greenmail-mail-test/greenmail
greenmail-core/src/main/java/com/icegreen/greenmail/store/SimpleMessageAttributes.java
SimpleMessageAttributes.parseEnvelope
private String parseEnvelope() { List<String> response = new ArrayList<>(); //1. Date --------------- response.add(LB + Q + sentDateEnvelopeString + Q + SP); //2. Subject --------------- if (subject != null && (subject.length() != 0)) { response.add(Q + escapeHeader(subject) + Q + SP); } else { response.add(NIL + SP); } //3. From --------------- addAddressToEnvelopeIfAvailable(from, response); response.add(SP); //4. Sender --------------- addAddressToEnvelopeIfAvailableWithNetscapeFeature(sender, response); response.add(SP); addAddressToEnvelopeIfAvailableWithNetscapeFeature(replyTo, response); response.add(SP); addAddressToEnvelopeIfAvailable(to, response); response.add(SP); addAddressToEnvelopeIfAvailable(cc, response); response.add(SP); addAddressToEnvelopeIfAvailable(bcc, response); response.add(SP); if (inReplyTo != null && inReplyTo.length > 0) { response.add(inReplyTo[0]); } else { response.add(NIL); } response.add(SP); if (messageID != null && messageID.length > 0) { messageID[0] = escapeHeader(messageID[0]); response.add(Q + messageID[0] + Q); } else { response.add(NIL); } response.add(RB); StringBuilder buf = new StringBuilder(16 * response.size()); for (String aResponse : response) { buf.append(aResponse); } return buf.toString(); }
java
private String parseEnvelope() { List<String> response = new ArrayList<>(); //1. Date --------------- response.add(LB + Q + sentDateEnvelopeString + Q + SP); //2. Subject --------------- if (subject != null && (subject.length() != 0)) { response.add(Q + escapeHeader(subject) + Q + SP); } else { response.add(NIL + SP); } //3. From --------------- addAddressToEnvelopeIfAvailable(from, response); response.add(SP); //4. Sender --------------- addAddressToEnvelopeIfAvailableWithNetscapeFeature(sender, response); response.add(SP); addAddressToEnvelopeIfAvailableWithNetscapeFeature(replyTo, response); response.add(SP); addAddressToEnvelopeIfAvailable(to, response); response.add(SP); addAddressToEnvelopeIfAvailable(cc, response); response.add(SP); addAddressToEnvelopeIfAvailable(bcc, response); response.add(SP); if (inReplyTo != null && inReplyTo.length > 0) { response.add(inReplyTo[0]); } else { response.add(NIL); } response.add(SP); if (messageID != null && messageID.length > 0) { messageID[0] = escapeHeader(messageID[0]); response.add(Q + messageID[0] + Q); } else { response.add(NIL); } response.add(RB); StringBuilder buf = new StringBuilder(16 * response.size()); for (String aResponse : response) { buf.append(aResponse); } return buf.toString(); }
[ "private", "String", "parseEnvelope", "(", ")", "{", "List", "<", "String", ">", "response", "=", "new", "ArrayList", "<>", "(", ")", ";", "//1. Date ---------------\r", "response", ".", "add", "(", "LB", "+", "Q", "+", "sentDateEnvelopeString", "+", "Q", "+", "SP", ")", ";", "//2. Subject ---------------\r", "if", "(", "subject", "!=", "null", "&&", "(", "subject", ".", "length", "(", ")", "!=", "0", ")", ")", "{", "response", ".", "add", "(", "Q", "+", "escapeHeader", "(", "subject", ")", "+", "Q", "+", "SP", ")", ";", "}", "else", "{", "response", ".", "add", "(", "NIL", "+", "SP", ")", ";", "}", "//3. From ---------------\r", "addAddressToEnvelopeIfAvailable", "(", "from", ",", "response", ")", ";", "response", ".", "add", "(", "SP", ")", ";", "//4. Sender ---------------\r", "addAddressToEnvelopeIfAvailableWithNetscapeFeature", "(", "sender", ",", "response", ")", ";", "response", ".", "add", "(", "SP", ")", ";", "addAddressToEnvelopeIfAvailableWithNetscapeFeature", "(", "replyTo", ",", "response", ")", ";", "response", ".", "add", "(", "SP", ")", ";", "addAddressToEnvelopeIfAvailable", "(", "to", ",", "response", ")", ";", "response", ".", "add", "(", "SP", ")", ";", "addAddressToEnvelopeIfAvailable", "(", "cc", ",", "response", ")", ";", "response", ".", "add", "(", "SP", ")", ";", "addAddressToEnvelopeIfAvailable", "(", "bcc", ",", "response", ")", ";", "response", ".", "add", "(", "SP", ")", ";", "if", "(", "inReplyTo", "!=", "null", "&&", "inReplyTo", ".", "length", ">", "0", ")", "{", "response", ".", "add", "(", "inReplyTo", "[", "0", "]", ")", ";", "}", "else", "{", "response", ".", "add", "(", "NIL", ")", ";", "}", "response", ".", "add", "(", "SP", ")", ";", "if", "(", "messageID", "!=", "null", "&&", "messageID", ".", "length", ">", "0", ")", "{", "messageID", "[", "0", "]", "=", "escapeHeader", "(", "messageID", "[", "0", "]", ")", ";", "response", ".", "add", "(", "Q", "+", "messageID", "[", "0", "]", "+", "Q", ")", ";", "}", "else", "{", "response", ".", "add", "(", "NIL", ")", ";", "}", "response", ".", "add", "(", "RB", ")", ";", "StringBuilder", "buf", "=", "new", "StringBuilder", "(", "16", "*", "response", ".", "size", "(", ")", ")", ";", "for", "(", "String", "aResponse", ":", "response", ")", "{", "buf", ".", "append", "(", "aResponse", ")", ";", "}", "return", "buf", ".", "toString", "(", ")", ";", "}" ]
Builds IMAP envelope String from pre-parsed data.
[ "Builds", "IMAP", "envelope", "String", "from", "pre", "-", "parsed", "data", "." ]
6d19a62233d1ef6fedbbd1f6fdde2d28e713834a
https://github.com/greenmail-mail-test/greenmail/blob/6d19a62233d1ef6fedbbd1f6fdde2d28e713834a/greenmail-core/src/main/java/com/icegreen/greenmail/store/SimpleMessageAttributes.java#L276-L320
160,538
greenmail-mail-test/greenmail
greenmail-core/src/main/java/com/icegreen/greenmail/store/SimpleMessageAttributes.java
SimpleMessageAttributes.parseAddress
private String parseAddress(String address) { try { StringBuilder buf = new StringBuilder(); InternetAddress[] netAddrs = InternetAddress.parseHeader(address, false); for (InternetAddress netAddr : netAddrs) { if (buf.length() > 0) { buf.append(SP); } buf.append(LB); String personal = netAddr.getPersonal(); if (personal != null && (personal.length() != 0)) { buf.append(Q).append(personal).append(Q); } else { buf.append(NIL); } buf.append(SP); buf.append(NIL); // should add route-addr buf.append(SP); try { // Remove quotes to avoid double quoting MailAddress mailAddr = new MailAddress(netAddr.getAddress().replaceAll("\"", "\\\\\"")); buf.append(Q).append(mailAddr.getUser()).append(Q); buf.append(SP); buf.append(Q).append(mailAddr.getHost()).append(Q); } catch (Exception pe) { buf.append(NIL + SP + NIL); } buf.append(RB); } return buf.toString(); } catch (AddressException e) { throw new RuntimeException("Failed to parse address: " + address, e); } }
java
private String parseAddress(String address) { try { StringBuilder buf = new StringBuilder(); InternetAddress[] netAddrs = InternetAddress.parseHeader(address, false); for (InternetAddress netAddr : netAddrs) { if (buf.length() > 0) { buf.append(SP); } buf.append(LB); String personal = netAddr.getPersonal(); if (personal != null && (personal.length() != 0)) { buf.append(Q).append(personal).append(Q); } else { buf.append(NIL); } buf.append(SP); buf.append(NIL); // should add route-addr buf.append(SP); try { // Remove quotes to avoid double quoting MailAddress mailAddr = new MailAddress(netAddr.getAddress().replaceAll("\"", "\\\\\"")); buf.append(Q).append(mailAddr.getUser()).append(Q); buf.append(SP); buf.append(Q).append(mailAddr.getHost()).append(Q); } catch (Exception pe) { buf.append(NIL + SP + NIL); } buf.append(RB); } return buf.toString(); } catch (AddressException e) { throw new RuntimeException("Failed to parse address: " + address, e); } }
[ "private", "String", "parseAddress", "(", "String", "address", ")", "{", "try", "{", "StringBuilder", "buf", "=", "new", "StringBuilder", "(", ")", ";", "InternetAddress", "[", "]", "netAddrs", "=", "InternetAddress", ".", "parseHeader", "(", "address", ",", "false", ")", ";", "for", "(", "InternetAddress", "netAddr", ":", "netAddrs", ")", "{", "if", "(", "buf", ".", "length", "(", ")", ">", "0", ")", "{", "buf", ".", "append", "(", "SP", ")", ";", "}", "buf", ".", "append", "(", "LB", ")", ";", "String", "personal", "=", "netAddr", ".", "getPersonal", "(", ")", ";", "if", "(", "personal", "!=", "null", "&&", "(", "personal", ".", "length", "(", ")", "!=", "0", ")", ")", "{", "buf", ".", "append", "(", "Q", ")", ".", "append", "(", "personal", ")", ".", "append", "(", "Q", ")", ";", "}", "else", "{", "buf", ".", "append", "(", "NIL", ")", ";", "}", "buf", ".", "append", "(", "SP", ")", ";", "buf", ".", "append", "(", "NIL", ")", ";", "// should add route-addr\r", "buf", ".", "append", "(", "SP", ")", ";", "try", "{", "// Remove quotes to avoid double quoting\r", "MailAddress", "mailAddr", "=", "new", "MailAddress", "(", "netAddr", ".", "getAddress", "(", ")", ".", "replaceAll", "(", "\"\\\"\"", ",", "\"\\\\\\\\\\\"\"", ")", ")", ";", "buf", ".", "append", "(", "Q", ")", ".", "append", "(", "mailAddr", ".", "getUser", "(", ")", ")", ".", "append", "(", "Q", ")", ";", "buf", ".", "append", "(", "SP", ")", ";", "buf", ".", "append", "(", "Q", ")", ".", "append", "(", "mailAddr", ".", "getHost", "(", ")", ")", ".", "append", "(", "Q", ")", ";", "}", "catch", "(", "Exception", "pe", ")", "{", "buf", ".", "append", "(", "NIL", "+", "SP", "+", "NIL", ")", ";", "}", "buf", ".", "append", "(", "RB", ")", ";", "}", "return", "buf", ".", "toString", "(", ")", ";", "}", "catch", "(", "AddressException", "e", ")", "{", "throw", "new", "RuntimeException", "(", "\"Failed to parse address: \"", "+", "address", ",", "e", ")", ";", "}", "}" ]
Parses a String email address to an IMAP address string.
[ "Parses", "a", "String", "email", "address", "to", "an", "IMAP", "address", "string", "." ]
6d19a62233d1ef6fedbbd1f6fdde2d28e713834a
https://github.com/greenmail-mail-test/greenmail/blob/6d19a62233d1ef6fedbbd1f6fdde2d28e713834a/greenmail-core/src/main/java/com/icegreen/greenmail/store/SimpleMessageAttributes.java#L361-L397
160,539
greenmail-mail-test/greenmail
greenmail-core/src/main/java/com/icegreen/greenmail/store/SimpleMessageAttributes.java
SimpleMessageAttributes.decodeContentType
void decodeContentType(String rawLine) { int slash = rawLine.indexOf('/'); if (slash == -1) { // if (DEBUG) getLogger().debug("decoding ... no slash found"); return; } else { primaryType = rawLine.substring(0, slash).trim(); } int semicolon = rawLine.indexOf(';'); if (semicolon == -1) { // if (DEBUG) getLogger().debug("decoding ... no semicolon found"); secondaryType = rawLine.substring(slash + 1).trim(); return; } // have parameters secondaryType = rawLine.substring(slash + 1, semicolon).trim(); Header h = new Header(rawLine); parameters = h.getParams(); }
java
void decodeContentType(String rawLine) { int slash = rawLine.indexOf('/'); if (slash == -1) { // if (DEBUG) getLogger().debug("decoding ... no slash found"); return; } else { primaryType = rawLine.substring(0, slash).trim(); } int semicolon = rawLine.indexOf(';'); if (semicolon == -1) { // if (DEBUG) getLogger().debug("decoding ... no semicolon found"); secondaryType = rawLine.substring(slash + 1).trim(); return; } // have parameters secondaryType = rawLine.substring(slash + 1, semicolon).trim(); Header h = new Header(rawLine); parameters = h.getParams(); }
[ "void", "decodeContentType", "(", "String", "rawLine", ")", "{", "int", "slash", "=", "rawLine", ".", "indexOf", "(", "'", "'", ")", ";", "if", "(", "slash", "==", "-", "1", ")", "{", "// if (DEBUG) getLogger().debug(\"decoding ... no slash found\");\r", "return", ";", "}", "else", "{", "primaryType", "=", "rawLine", ".", "substring", "(", "0", ",", "slash", ")", ".", "trim", "(", ")", ";", "}", "int", "semicolon", "=", "rawLine", ".", "indexOf", "(", "'", "'", ")", ";", "if", "(", "semicolon", "==", "-", "1", ")", "{", "// if (DEBUG) getLogger().debug(\"decoding ... no semicolon found\");\r", "secondaryType", "=", "rawLine", ".", "substring", "(", "slash", "+", "1", ")", ".", "trim", "(", ")", ";", "return", ";", "}", "// have parameters\r", "secondaryType", "=", "rawLine", ".", "substring", "(", "slash", "+", "1", ",", "semicolon", ")", ".", "trim", "(", ")", ";", "Header", "h", "=", "new", "Header", "(", "rawLine", ")", ";", "parameters", "=", "h", ".", "getParams", "(", ")", ";", "}" ]
Decode a content Type header line into types and parameters pairs
[ "Decode", "a", "content", "Type", "header", "line", "into", "types", "and", "parameters", "pairs" ]
6d19a62233d1ef6fedbbd1f6fdde2d28e713834a
https://github.com/greenmail-mail-test/greenmail/blob/6d19a62233d1ef6fedbbd1f6fdde2d28e713834a/greenmail-core/src/main/java/com/icegreen/greenmail/store/SimpleMessageAttributes.java#L402-L420
160,540
greenmail-mail-test/greenmail
greenmail-core/src/main/java/com/icegreen/greenmail/configuration/ConfiguredGreenMail.java
ConfiguredGreenMail.doConfigure
protected void doConfigure() { if (config != null) { for (UserBean user : config.getUsersToCreate()) { setUser(user.getEmail(), user.getLogin(), user.getPassword()); } getManagers().getUserManager().setAuthRequired(!config.isAuthenticationDisabled()); } }
java
protected void doConfigure() { if (config != null) { for (UserBean user : config.getUsersToCreate()) { setUser(user.getEmail(), user.getLogin(), user.getPassword()); } getManagers().getUserManager().setAuthRequired(!config.isAuthenticationDisabled()); } }
[ "protected", "void", "doConfigure", "(", ")", "{", "if", "(", "config", "!=", "null", ")", "{", "for", "(", "UserBean", "user", ":", "config", ".", "getUsersToCreate", "(", ")", ")", "{", "setUser", "(", "user", ".", "getEmail", "(", ")", ",", "user", ".", "getLogin", "(", ")", ",", "user", ".", "getPassword", "(", ")", ")", ";", "}", "getManagers", "(", ")", ".", "getUserManager", "(", ")", ".", "setAuthRequired", "(", "!", "config", ".", "isAuthenticationDisabled", "(", ")", ")", ";", "}", "}" ]
This method can be used by child classes to apply the configuration that is stored in config.
[ "This", "method", "can", "be", "used", "by", "child", "classes", "to", "apply", "the", "configuration", "that", "is", "stored", "in", "config", "." ]
6d19a62233d1ef6fedbbd1f6fdde2d28e713834a
https://github.com/greenmail-mail-test/greenmail/blob/6d19a62233d1ef6fedbbd1f6fdde2d28e713834a/greenmail-core/src/main/java/com/icegreen/greenmail/configuration/ConfiguredGreenMail.java#L20-L27
160,541
greenmail-mail-test/greenmail
greenmail-core/src/main/java/com/icegreen/greenmail/util/InternetPrintWriter.java
InternetPrintWriter.createForEncoding
public static InternetPrintWriter createForEncoding(OutputStream outputStream, boolean autoFlush, Charset charset) { return new InternetPrintWriter(new OutputStreamWriter(outputStream, charset), autoFlush); }
java
public static InternetPrintWriter createForEncoding(OutputStream outputStream, boolean autoFlush, Charset charset) { return new InternetPrintWriter(new OutputStreamWriter(outputStream, charset), autoFlush); }
[ "public", "static", "InternetPrintWriter", "createForEncoding", "(", "OutputStream", "outputStream", ",", "boolean", "autoFlush", ",", "Charset", "charset", ")", "{", "return", "new", "InternetPrintWriter", "(", "new", "OutputStreamWriter", "(", "outputStream", ",", "charset", ")", ",", "autoFlush", ")", ";", "}" ]
Creates a new InternetPrintWriter for given charset encoding. @param outputStream the wrapped output stream. @param charset the charset. @return a new InternetPrintWriter.
[ "Creates", "a", "new", "InternetPrintWriter", "for", "given", "charset", "encoding", "." ]
6d19a62233d1ef6fedbbd1f6fdde2d28e713834a
https://github.com/greenmail-mail-test/greenmail/blob/6d19a62233d1ef6fedbbd1f6fdde2d28e713834a/greenmail-core/src/main/java/com/icegreen/greenmail/util/InternetPrintWriter.java#L79-L81
160,542
greenmail-mail-test/greenmail
greenmail-core/src/main/java/com/icegreen/greenmail/util/GreenMail.java
GreenMail.createServices
protected Map<String, AbstractServer> createServices(ServerSetup[] config, Managers mgr) { Map<String, AbstractServer> srvc = new HashMap<>(); for (ServerSetup setup : config) { if (srvc.containsKey(setup.getProtocol())) { throw new IllegalArgumentException("Server '" + setup.getProtocol() + "' was found at least twice in the array"); } final String protocol = setup.getProtocol(); if (protocol.startsWith(ServerSetup.PROTOCOL_SMTP)) { srvc.put(protocol, new SmtpServer(setup, mgr)); } else if (protocol.startsWith(ServerSetup.PROTOCOL_POP3)) { srvc.put(protocol, new Pop3Server(setup, mgr)); } else if (protocol.startsWith(ServerSetup.PROTOCOL_IMAP)) { srvc.put(protocol, new ImapServer(setup, mgr)); } } return srvc; }
java
protected Map<String, AbstractServer> createServices(ServerSetup[] config, Managers mgr) { Map<String, AbstractServer> srvc = new HashMap<>(); for (ServerSetup setup : config) { if (srvc.containsKey(setup.getProtocol())) { throw new IllegalArgumentException("Server '" + setup.getProtocol() + "' was found at least twice in the array"); } final String protocol = setup.getProtocol(); if (protocol.startsWith(ServerSetup.PROTOCOL_SMTP)) { srvc.put(protocol, new SmtpServer(setup, mgr)); } else if (protocol.startsWith(ServerSetup.PROTOCOL_POP3)) { srvc.put(protocol, new Pop3Server(setup, mgr)); } else if (protocol.startsWith(ServerSetup.PROTOCOL_IMAP)) { srvc.put(protocol, new ImapServer(setup, mgr)); } } return srvc; }
[ "protected", "Map", "<", "String", ",", "AbstractServer", ">", "createServices", "(", "ServerSetup", "[", "]", "config", ",", "Managers", "mgr", ")", "{", "Map", "<", "String", ",", "AbstractServer", ">", "srvc", "=", "new", "HashMap", "<>", "(", ")", ";", "for", "(", "ServerSetup", "setup", ":", "config", ")", "{", "if", "(", "srvc", ".", "containsKey", "(", "setup", ".", "getProtocol", "(", ")", ")", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Server '\"", "+", "setup", ".", "getProtocol", "(", ")", "+", "\"' was found at least twice in the array\"", ")", ";", "}", "final", "String", "protocol", "=", "setup", ".", "getProtocol", "(", ")", ";", "if", "(", "protocol", ".", "startsWith", "(", "ServerSetup", ".", "PROTOCOL_SMTP", ")", ")", "{", "srvc", ".", "put", "(", "protocol", ",", "new", "SmtpServer", "(", "setup", ",", "mgr", ")", ")", ";", "}", "else", "if", "(", "protocol", ".", "startsWith", "(", "ServerSetup", ".", "PROTOCOL_POP3", ")", ")", "{", "srvc", ".", "put", "(", "protocol", ",", "new", "Pop3Server", "(", "setup", ",", "mgr", ")", ")", ";", "}", "else", "if", "(", "protocol", ".", "startsWith", "(", "ServerSetup", ".", "PROTOCOL_IMAP", ")", ")", "{", "srvc", ".", "put", "(", "protocol", ",", "new", "ImapServer", "(", "setup", ",", "mgr", ")", ")", ";", "}", "}", "return", "srvc", ";", "}" ]
Create the required services according to the server setup @param config Service configuration @return Services map
[ "Create", "the", "required", "services", "according", "to", "the", "server", "setup" ]
6d19a62233d1ef6fedbbd1f6fdde2d28e713834a
https://github.com/greenmail-mail-test/greenmail/blob/6d19a62233d1ef6fedbbd1f6fdde2d28e713834a/greenmail-core/src/main/java/com/icegreen/greenmail/util/GreenMail.java#L138-L154
160,543
greenmail-mail-test/greenmail
greenmail-core/src/main/java/com/icegreen/greenmail/imap/ImapResponse.java
ImapResponse.okResponse
public void okResponse(String responseCode, String message) { untagged(); message(OK); responseCode(responseCode); message(message); end(); }
java
public void okResponse(String responseCode, String message) { untagged(); message(OK); responseCode(responseCode); message(message); end(); }
[ "public", "void", "okResponse", "(", "String", "responseCode", ",", "String", "message", ")", "{", "untagged", "(", ")", ";", "message", "(", "OK", ")", ";", "responseCode", "(", "responseCode", ")", ";", "message", "(", "message", ")", ";", "end", "(", ")", ";", "}" ]
Writes an untagged OK response, with the supplied response code, and an optional message. @param responseCode The response code, included in []. @param message The message to follow the []
[ "Writes", "an", "untagged", "OK", "response", "with", "the", "supplied", "response", "code", "and", "an", "optional", "message", "." ]
6d19a62233d1ef6fedbbd1f6fdde2d28e713834a
https://github.com/greenmail-mail-test/greenmail/blob/6d19a62233d1ef6fedbbd1f6fdde2d28e713834a/greenmail-core/src/main/java/com/icegreen/greenmail/imap/ImapResponse.java#L129-L135
160,544
greenmail-mail-test/greenmail
greenmail-core/src/main/java/com/icegreen/greenmail/imap/ImapHandler.java
ImapHandler.close
@Override public void close() { // Use monitor to avoid race between external close and handler thread run() synchronized (closeMonitor) { // Close and clear streams, sockets etc. if (socket != null) { try { // Terminates thread blocking on socket read // and automatically closed depending streams socket.close(); } catch (IOException e) { log.warn("Can not close socket", e); } finally { socket = null; } } // Clear user data session = null; response = null; } }
java
@Override public void close() { // Use monitor to avoid race between external close and handler thread run() synchronized (closeMonitor) { // Close and clear streams, sockets etc. if (socket != null) { try { // Terminates thread blocking on socket read // and automatically closed depending streams socket.close(); } catch (IOException e) { log.warn("Can not close socket", e); } finally { socket = null; } } // Clear user data session = null; response = null; } }
[ "@", "Override", "public", "void", "close", "(", ")", "{", "// Use monitor to avoid race between external close and handler thread run()\r", "synchronized", "(", "closeMonitor", ")", "{", "// Close and clear streams, sockets etc.\r", "if", "(", "socket", "!=", "null", ")", "{", "try", "{", "// Terminates thread blocking on socket read\r", "// and automatically closed depending streams\r", "socket", ".", "close", "(", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "log", ".", "warn", "(", "\"Can not close socket\"", ",", "e", ")", ";", "}", "finally", "{", "socket", "=", "null", ";", "}", "}", "// Clear user data\r", "session", "=", "null", ";", "response", "=", "null", ";", "}", "}" ]
Resets the handler data to a basic state.
[ "Resets", "the", "handler", "data", "to", "a", "basic", "state", "." ]
6d19a62233d1ef6fedbbd1f6fdde2d28e713834a
https://github.com/greenmail-mail-test/greenmail/blob/6d19a62233d1ef6fedbbd1f6fdde2d28e713834a/greenmail-core/src/main/java/com/icegreen/greenmail/imap/ImapHandler.java#L85-L106
160,545
greenmail-mail-test/greenmail
greenmail-core/src/main/java/com/icegreen/greenmail/util/EncodingUtil.java
EncodingUtil.toStream
public static InputStream toStream(String content, Charset charset) { byte[] bytes = content.getBytes(charset); return new ByteArrayInputStream(bytes); }
java
public static InputStream toStream(String content, Charset charset) { byte[] bytes = content.getBytes(charset); return new ByteArrayInputStream(bytes); }
[ "public", "static", "InputStream", "toStream", "(", "String", "content", ",", "Charset", "charset", ")", "{", "byte", "[", "]", "bytes", "=", "content", ".", "getBytes", "(", "charset", ")", ";", "return", "new", "ByteArrayInputStream", "(", "bytes", ")", ";", "}" ]
Converts the string of given content to an input stream. @param content the string content. @param charset the charset for conversion. @return the stream (should be closed by invoker).
[ "Converts", "the", "string", "of", "given", "content", "to", "an", "input", "stream", "." ]
6d19a62233d1ef6fedbbd1f6fdde2d28e713834a
https://github.com/greenmail-mail-test/greenmail/blob/6d19a62233d1ef6fedbbd1f6fdde2d28e713834a/greenmail-core/src/main/java/com/icegreen/greenmail/util/EncodingUtil.java#L33-L36
160,546
greenmail-mail-test/greenmail
greenmail-core/src/main/java/com/icegreen/greenmail/configuration/PropertiesBasedGreenMailConfigurationBuilder.java
PropertiesBasedGreenMailConfigurationBuilder.build
public GreenMailConfiguration build(Properties properties) { GreenMailConfiguration configuration = new GreenMailConfiguration(); String usersParam = properties.getProperty(GREENMAIL_USERS); if (null != usersParam) { String[] usersArray = usersParam.split(","); for (String user : usersArray) { extractAndAddUser(configuration, user); } } String disabledAuthentication = properties.getProperty(GREENMAIL_AUTH_DISABLED); if (null != disabledAuthentication) { configuration.withDisabledAuthentication(); } return configuration; }
java
public GreenMailConfiguration build(Properties properties) { GreenMailConfiguration configuration = new GreenMailConfiguration(); String usersParam = properties.getProperty(GREENMAIL_USERS); if (null != usersParam) { String[] usersArray = usersParam.split(","); for (String user : usersArray) { extractAndAddUser(configuration, user); } } String disabledAuthentication = properties.getProperty(GREENMAIL_AUTH_DISABLED); if (null != disabledAuthentication) { configuration.withDisabledAuthentication(); } return configuration; }
[ "public", "GreenMailConfiguration", "build", "(", "Properties", "properties", ")", "{", "GreenMailConfiguration", "configuration", "=", "new", "GreenMailConfiguration", "(", ")", ";", "String", "usersParam", "=", "properties", ".", "getProperty", "(", "GREENMAIL_USERS", ")", ";", "if", "(", "null", "!=", "usersParam", ")", "{", "String", "[", "]", "usersArray", "=", "usersParam", ".", "split", "(", "\",\"", ")", ";", "for", "(", "String", "user", ":", "usersArray", ")", "{", "extractAndAddUser", "(", "configuration", ",", "user", ")", ";", "}", "}", "String", "disabledAuthentication", "=", "properties", ".", "getProperty", "(", "GREENMAIL_AUTH_DISABLED", ")", ";", "if", "(", "null", "!=", "disabledAuthentication", ")", "{", "configuration", ".", "withDisabledAuthentication", "(", ")", ";", "}", "return", "configuration", ";", "}" ]
Builds a configuration object based on given properties. @param properties the properties. @return a configuration and never null.
[ "Builds", "a", "configuration", "object", "based", "on", "given", "properties", "." ]
6d19a62233d1ef6fedbbd1f6fdde2d28e713834a
https://github.com/greenmail-mail-test/greenmail/blob/6d19a62233d1ef6fedbbd1f6fdde2d28e713834a/greenmail-core/src/main/java/com/icegreen/greenmail/configuration/PropertiesBasedGreenMailConfigurationBuilder.java#L36-L50
160,547
greenmail-mail-test/greenmail
greenmail-spring/src/main/java/com/icegreen/greenmail/spring/GreenMailBean.java
GreenMailBean.createServerSetup
private ServerSetup[] createServerSetup() { List<ServerSetup> setups = new ArrayList<>(); if (smtpProtocol) { smtpServerSetup = createTestServerSetup(ServerSetup.SMTP); setups.add(smtpServerSetup); } if (smtpsProtocol) { smtpsServerSetup = createTestServerSetup(ServerSetup.SMTPS); setups.add(smtpsServerSetup); } if (pop3Protocol) { setups.add(createTestServerSetup(ServerSetup.POP3)); } if (pop3sProtocol) { setups.add(createTestServerSetup(ServerSetup.POP3S)); } if (imapProtocol) { setups.add(createTestServerSetup(ServerSetup.IMAP)); } if (imapsProtocol) { setups.add(createTestServerSetup(ServerSetup.IMAPS)); } return setups.toArray(new ServerSetup[setups.size()]); }
java
private ServerSetup[] createServerSetup() { List<ServerSetup> setups = new ArrayList<>(); if (smtpProtocol) { smtpServerSetup = createTestServerSetup(ServerSetup.SMTP); setups.add(smtpServerSetup); } if (smtpsProtocol) { smtpsServerSetup = createTestServerSetup(ServerSetup.SMTPS); setups.add(smtpsServerSetup); } if (pop3Protocol) { setups.add(createTestServerSetup(ServerSetup.POP3)); } if (pop3sProtocol) { setups.add(createTestServerSetup(ServerSetup.POP3S)); } if (imapProtocol) { setups.add(createTestServerSetup(ServerSetup.IMAP)); } if (imapsProtocol) { setups.add(createTestServerSetup(ServerSetup.IMAPS)); } return setups.toArray(new ServerSetup[setups.size()]); }
[ "private", "ServerSetup", "[", "]", "createServerSetup", "(", ")", "{", "List", "<", "ServerSetup", ">", "setups", "=", "new", "ArrayList", "<>", "(", ")", ";", "if", "(", "smtpProtocol", ")", "{", "smtpServerSetup", "=", "createTestServerSetup", "(", "ServerSetup", ".", "SMTP", ")", ";", "setups", ".", "add", "(", "smtpServerSetup", ")", ";", "}", "if", "(", "smtpsProtocol", ")", "{", "smtpsServerSetup", "=", "createTestServerSetup", "(", "ServerSetup", ".", "SMTPS", ")", ";", "setups", ".", "add", "(", "smtpsServerSetup", ")", ";", "}", "if", "(", "pop3Protocol", ")", "{", "setups", ".", "add", "(", "createTestServerSetup", "(", "ServerSetup", ".", "POP3", ")", ")", ";", "}", "if", "(", "pop3sProtocol", ")", "{", "setups", ".", "add", "(", "createTestServerSetup", "(", "ServerSetup", ".", "POP3S", ")", ")", ";", "}", "if", "(", "imapProtocol", ")", "{", "setups", ".", "add", "(", "createTestServerSetup", "(", "ServerSetup", ".", "IMAP", ")", ")", ";", "}", "if", "(", "imapsProtocol", ")", "{", "setups", ".", "add", "(", "createTestServerSetup", "(", "ServerSetup", ".", "IMAPS", ")", ")", ";", "}", "return", "setups", ".", "toArray", "(", "new", "ServerSetup", "[", "setups", ".", "size", "(", ")", "]", ")", ";", "}" ]
Creates the server setup, depending on the protocol flags. @return the configured server setups.
[ "Creates", "the", "server", "setup", "depending", "on", "the", "protocol", "flags", "." ]
6d19a62233d1ef6fedbbd1f6fdde2d28e713834a
https://github.com/greenmail-mail-test/greenmail/blob/6d19a62233d1ef6fedbbd1f6fdde2d28e713834a/greenmail-spring/src/main/java/com/icegreen/greenmail/spring/GreenMailBean.java#L102-L125
160,548
greenmail-mail-test/greenmail
greenmail-core/src/main/java/com/icegreen/greenmail/imap/commands/CommandParser.java
CommandParser.tag
public String tag(ImapRequestLineReader request) throws ProtocolException { CharacterValidator validator = new TagCharValidator(); return consumeWord(request, validator); }
java
public String tag(ImapRequestLineReader request) throws ProtocolException { CharacterValidator validator = new TagCharValidator(); return consumeWord(request, validator); }
[ "public", "String", "tag", "(", "ImapRequestLineReader", "request", ")", "throws", "ProtocolException", "{", "CharacterValidator", "validator", "=", "new", "TagCharValidator", "(", ")", ";", "return", "consumeWord", "(", "request", ",", "validator", ")", ";", "}" ]
Reads a command "tag" from the request.
[ "Reads", "a", "command", "tag", "from", "the", "request", "." ]
6d19a62233d1ef6fedbbd1f6fdde2d28e713834a
https://github.com/greenmail-mail-test/greenmail/blob/6d19a62233d1ef6fedbbd1f6fdde2d28e713834a/greenmail-core/src/main/java/com/icegreen/greenmail/imap/commands/CommandParser.java#L47-L50
160,549
greenmail-mail-test/greenmail
greenmail-core/src/main/java/com/icegreen/greenmail/imap/commands/CommandParser.java
CommandParser.astring
public String astring(ImapRequestLineReader request) throws ProtocolException { char next = request.nextWordChar(); switch (next) { case '"': return consumeQuoted(request); case '{': return consumeLiteral(request); default: return atom(request); } }
java
public String astring(ImapRequestLineReader request) throws ProtocolException { char next = request.nextWordChar(); switch (next) { case '"': return consumeQuoted(request); case '{': return consumeLiteral(request); default: return atom(request); } }
[ "public", "String", "astring", "(", "ImapRequestLineReader", "request", ")", "throws", "ProtocolException", "{", "char", "next", "=", "request", ".", "nextWordChar", "(", ")", ";", "switch", "(", "next", ")", "{", "case", "'", "'", ":", "return", "consumeQuoted", "(", "request", ")", ";", "case", "'", "'", ":", "return", "consumeLiteral", "(", "request", ")", ";", "default", ":", "return", "atom", "(", "request", ")", ";", "}", "}" ]
Reads an argument of type "astring" from the request.
[ "Reads", "an", "argument", "of", "type", "astring", "from", "the", "request", "." ]
6d19a62233d1ef6fedbbd1f6fdde2d28e713834a
https://github.com/greenmail-mail-test/greenmail/blob/6d19a62233d1ef6fedbbd1f6fdde2d28e713834a/greenmail-core/src/main/java/com/icegreen/greenmail/imap/commands/CommandParser.java#L55-L65
160,550
greenmail-mail-test/greenmail
greenmail-core/src/main/java/com/icegreen/greenmail/imap/commands/CommandParser.java
CommandParser.nstring
public String nstring(ImapRequestLineReader request) throws ProtocolException { char next = request.nextWordChar(); switch (next) { case '"': return consumeQuoted(request); case '{': return consumeLiteral(request); default: String value = atom(request); if ("NIL".equals(value)) { return null; } else { throw new ProtocolException("Invalid nstring value: valid values are '\"...\"', '{12} CRLF *CHAR8', and 'NIL'."); } } }
java
public String nstring(ImapRequestLineReader request) throws ProtocolException { char next = request.nextWordChar(); switch (next) { case '"': return consumeQuoted(request); case '{': return consumeLiteral(request); default: String value = atom(request); if ("NIL".equals(value)) { return null; } else { throw new ProtocolException("Invalid nstring value: valid values are '\"...\"', '{12} CRLF *CHAR8', and 'NIL'."); } } }
[ "public", "String", "nstring", "(", "ImapRequestLineReader", "request", ")", "throws", "ProtocolException", "{", "char", "next", "=", "request", ".", "nextWordChar", "(", ")", ";", "switch", "(", "next", ")", "{", "case", "'", "'", ":", "return", "consumeQuoted", "(", "request", ")", ";", "case", "'", "'", ":", "return", "consumeLiteral", "(", "request", ")", ";", "default", ":", "String", "value", "=", "atom", "(", "request", ")", ";", "if", "(", "\"NIL\"", ".", "equals", "(", "value", ")", ")", "{", "return", "null", ";", "}", "else", "{", "throw", "new", "ProtocolException", "(", "\"Invalid nstring value: valid values are '\\\"...\\\"', '{12} CRLF *CHAR8', and 'NIL'.\"", ")", ";", "}", "}", "}" ]
Reads an argument of type "nstring" from the request.
[ "Reads", "an", "argument", "of", "type", "nstring", "from", "the", "request", "." ]
6d19a62233d1ef6fedbbd1f6fdde2d28e713834a
https://github.com/greenmail-mail-test/greenmail/blob/6d19a62233d1ef6fedbbd1f6fdde2d28e713834a/greenmail-core/src/main/java/com/icegreen/greenmail/imap/commands/CommandParser.java#L70-L85
160,551
greenmail-mail-test/greenmail
greenmail-core/src/main/java/com/icegreen/greenmail/imap/commands/CommandParser.java
CommandParser.dateTime
public Date dateTime(ImapRequestLineReader request) throws ProtocolException { char next = request.nextWordChar(); String dateString; // From https://tools.ietf.org/html/rfc3501 : // date-time = DQUOTE date-day-fixed "-" date-month "-" date-year // SP time SP zone DQUOTE // zone = ("+" / "-") 4DIGIT if (next == '"') { dateString = consumeQuoted(request); } else { throw new ProtocolException("DateTime values must be quoted."); } try { // You can use Z or zzzz return new SimpleDateFormat("dd-MMM-yyyy hh:mm:ss Z", Locale.US).parse(dateString); } catch (ParseException e) { throw new ProtocolException("Invalid date format <" + dateString + ">, should comply to dd-MMM-yyyy hh:mm:ss Z"); } }
java
public Date dateTime(ImapRequestLineReader request) throws ProtocolException { char next = request.nextWordChar(); String dateString; // From https://tools.ietf.org/html/rfc3501 : // date-time = DQUOTE date-day-fixed "-" date-month "-" date-year // SP time SP zone DQUOTE // zone = ("+" / "-") 4DIGIT if (next == '"') { dateString = consumeQuoted(request); } else { throw new ProtocolException("DateTime values must be quoted."); } try { // You can use Z or zzzz return new SimpleDateFormat("dd-MMM-yyyy hh:mm:ss Z", Locale.US).parse(dateString); } catch (ParseException e) { throw new ProtocolException("Invalid date format <" + dateString + ">, should comply to dd-MMM-yyyy hh:mm:ss Z"); } }
[ "public", "Date", "dateTime", "(", "ImapRequestLineReader", "request", ")", "throws", "ProtocolException", "{", "char", "next", "=", "request", ".", "nextWordChar", "(", ")", ";", "String", "dateString", ";", "// From https://tools.ietf.org/html/rfc3501 :", "// date-time = DQUOTE date-day-fixed \"-\" date-month \"-\" date-year", "// SP time SP zone DQUOTE", "// zone = (\"+\" / \"-\") 4DIGIT", "if", "(", "next", "==", "'", "'", ")", "{", "dateString", "=", "consumeQuoted", "(", "request", ")", ";", "}", "else", "{", "throw", "new", "ProtocolException", "(", "\"DateTime values must be quoted.\"", ")", ";", "}", "try", "{", "// You can use Z or zzzz", "return", "new", "SimpleDateFormat", "(", "\"dd-MMM-yyyy hh:mm:ss Z\"", ",", "Locale", ".", "US", ")", ".", "parse", "(", "dateString", ")", ";", "}", "catch", "(", "ParseException", "e", ")", "{", "throw", "new", "ProtocolException", "(", "\"Invalid date format <\"", "+", "dateString", "+", "\">, should comply to dd-MMM-yyyy hh:mm:ss Z\"", ")", ";", "}", "}" ]
Reads a "date-time" argument from the request.
[ "Reads", "a", "date", "-", "time", "argument", "from", "the", "request", "." ]
6d19a62233d1ef6fedbbd1f6fdde2d28e713834a
https://github.com/greenmail-mail-test/greenmail/blob/6d19a62233d1ef6fedbbd1f6fdde2d28e713834a/greenmail-core/src/main/java/com/icegreen/greenmail/imap/commands/CommandParser.java#L109-L128
160,552
greenmail-mail-test/greenmail
greenmail-core/src/main/java/com/icegreen/greenmail/imap/commands/CommandParser.java
CommandParser.consumeWord
protected String consumeWord(ImapRequestLineReader request, CharacterValidator validator) throws ProtocolException { StringBuilder atom = new StringBuilder(); char next = request.nextWordChar(); while (!isWhitespace(next)) { if (validator.isValid(next)) { atom.append(next); request.consume(); } else { throw new ProtocolException("Invalid character: '" + next + '\''); } next = request.nextChar(); } return atom.toString(); }
java
protected String consumeWord(ImapRequestLineReader request, CharacterValidator validator) throws ProtocolException { StringBuilder atom = new StringBuilder(); char next = request.nextWordChar(); while (!isWhitespace(next)) { if (validator.isValid(next)) { atom.append(next); request.consume(); } else { throw new ProtocolException("Invalid character: '" + next + '\''); } next = request.nextChar(); } return atom.toString(); }
[ "protected", "String", "consumeWord", "(", "ImapRequestLineReader", "request", ",", "CharacterValidator", "validator", ")", "throws", "ProtocolException", "{", "StringBuilder", "atom", "=", "new", "StringBuilder", "(", ")", ";", "char", "next", "=", "request", ".", "nextWordChar", "(", ")", ";", "while", "(", "!", "isWhitespace", "(", "next", ")", ")", "{", "if", "(", "validator", ".", "isValid", "(", "next", ")", ")", "{", "atom", ".", "append", "(", "next", ")", ";", "request", ".", "consume", "(", ")", ";", "}", "else", "{", "throw", "new", "ProtocolException", "(", "\"Invalid character: '\"", "+", "next", "+", "'", "'", ")", ";", "}", "next", "=", "request", ".", "nextChar", "(", ")", ";", "}", "return", "atom", ".", "toString", "(", ")", ";", "}" ]
Reads the next "word from the request, comprising all characters up to the next SPACE. Characters are tested by the supplied CharacterValidator, and an exception is thrown if invalid characters are encountered.
[ "Reads", "the", "next", "word", "from", "the", "request", "comprising", "all", "characters", "up", "to", "the", "next", "SPACE", ".", "Characters", "are", "tested", "by", "the", "supplied", "CharacterValidator", "and", "an", "exception", "is", "thrown", "if", "invalid", "characters", "are", "encountered", "." ]
6d19a62233d1ef6fedbbd1f6fdde2d28e713834a
https://github.com/greenmail-mail-test/greenmail/blob/6d19a62233d1ef6fedbbd1f6fdde2d28e713834a/greenmail-core/src/main/java/com/icegreen/greenmail/imap/commands/CommandParser.java#L135-L151
160,553
greenmail-mail-test/greenmail
greenmail-core/src/main/java/com/icegreen/greenmail/imap/commands/CommandParser.java
CommandParser.consumeChar
protected void consumeChar(ImapRequestLineReader request, char expected) throws ProtocolException { char consumed = request.consume(); if (consumed != expected) { throw new ProtocolException("Expected:'" + expected + "' found:'" + consumed + '\''); } }
java
protected void consumeChar(ImapRequestLineReader request, char expected) throws ProtocolException { char consumed = request.consume(); if (consumed != expected) { throw new ProtocolException("Expected:'" + expected + "' found:'" + consumed + '\''); } }
[ "protected", "void", "consumeChar", "(", "ImapRequestLineReader", "request", ",", "char", "expected", ")", "throws", "ProtocolException", "{", "char", "consumed", "=", "request", ".", "consume", "(", ")", ";", "if", "(", "consumed", "!=", "expected", ")", "{", "throw", "new", "ProtocolException", "(", "\"Expected:'\"", "+", "expected", "+", "\"' found:'\"", "+", "consumed", "+", "'", "'", ")", ";", "}", "}" ]
Consumes the next character in the request, checking that it matches the expected one. This method should be used when the
[ "Consumes", "the", "next", "character", "in", "the", "request", "checking", "that", "it", "matches", "the", "expected", "one", ".", "This", "method", "should", "be", "used", "when", "the" ]
6d19a62233d1ef6fedbbd1f6fdde2d28e713834a
https://github.com/greenmail-mail-test/greenmail/blob/6d19a62233d1ef6fedbbd1f6fdde2d28e713834a/greenmail-core/src/main/java/com/icegreen/greenmail/imap/commands/CommandParser.java#L237-L243
160,554
greenmail-mail-test/greenmail
greenmail-core/src/main/java/com/icegreen/greenmail/imap/commands/CommandParser.java
CommandParser.consumeQuoted
protected String consumeQuoted(ImapRequestLineReader request) throws ProtocolException { // The 1st character must be '"' consumeChar(request, '"'); StringBuilder quoted = new StringBuilder(); char next = request.nextChar(); while (next != '"') { if (next == '\\') { request.consume(); next = request.nextChar(); if (!isQuotedSpecial(next)) { throw new ProtocolException("Invalid escaped character in quote: '" + next + '\''); } } quoted.append(next); request.consume(); next = request.nextChar(); } consumeChar(request, '"'); return quoted.toString(); }
java
protected String consumeQuoted(ImapRequestLineReader request) throws ProtocolException { // The 1st character must be '"' consumeChar(request, '"'); StringBuilder quoted = new StringBuilder(); char next = request.nextChar(); while (next != '"') { if (next == '\\') { request.consume(); next = request.nextChar(); if (!isQuotedSpecial(next)) { throw new ProtocolException("Invalid escaped character in quote: '" + next + '\''); } } quoted.append(next); request.consume(); next = request.nextChar(); } consumeChar(request, '"'); return quoted.toString(); }
[ "protected", "String", "consumeQuoted", "(", "ImapRequestLineReader", "request", ")", "throws", "ProtocolException", "{", "// The 1st character must be '\"'", "consumeChar", "(", "request", ",", "'", "'", ")", ";", "StringBuilder", "quoted", "=", "new", "StringBuilder", "(", ")", ";", "char", "next", "=", "request", ".", "nextChar", "(", ")", ";", "while", "(", "next", "!=", "'", "'", ")", "{", "if", "(", "next", "==", "'", "'", ")", "{", "request", ".", "consume", "(", ")", ";", "next", "=", "request", ".", "nextChar", "(", ")", ";", "if", "(", "!", "isQuotedSpecial", "(", "next", ")", ")", "{", "throw", "new", "ProtocolException", "(", "\"Invalid escaped character in quote: '\"", "+", "next", "+", "'", "'", ")", ";", "}", "}", "quoted", ".", "append", "(", "next", ")", ";", "request", ".", "consume", "(", ")", ";", "next", "=", "request", ".", "nextChar", "(", ")", ";", "}", "consumeChar", "(", "request", ",", "'", "'", ")", ";", "return", "quoted", ".", "toString", "(", ")", ";", "}" ]
Reads a quoted string value from the request.
[ "Reads", "a", "quoted", "string", "value", "from", "the", "request", "." ]
6d19a62233d1ef6fedbbd1f6fdde2d28e713834a
https://github.com/greenmail-mail-test/greenmail/blob/6d19a62233d1ef6fedbbd1f6fdde2d28e713834a/greenmail-core/src/main/java/com/icegreen/greenmail/imap/commands/CommandParser.java#L248-L272
160,555
greenmail-mail-test/greenmail
greenmail-core/src/main/java/com/icegreen/greenmail/imap/commands/CommandParser.java
CommandParser.flagList
public Flags flagList(ImapRequestLineReader request) throws ProtocolException { Flags flags = new Flags(); request.nextWordChar(); consumeChar(request, '('); CharacterValidator validator = new NoopCharValidator(); String nextWord = consumeWord(request, validator); while (!nextWord.endsWith(")")) { setFlag(nextWord, flags); nextWord = consumeWord(request, validator); } // Got the closing ")", may be attached to a word. if (nextWord.length() > 1) { setFlag(nextWord.substring(0, nextWord.length() - 1), flags); } return flags; }
java
public Flags flagList(ImapRequestLineReader request) throws ProtocolException { Flags flags = new Flags(); request.nextWordChar(); consumeChar(request, '('); CharacterValidator validator = new NoopCharValidator(); String nextWord = consumeWord(request, validator); while (!nextWord.endsWith(")")) { setFlag(nextWord, flags); nextWord = consumeWord(request, validator); } // Got the closing ")", may be attached to a word. if (nextWord.length() > 1) { setFlag(nextWord.substring(0, nextWord.length() - 1), flags); } return flags; }
[ "public", "Flags", "flagList", "(", "ImapRequestLineReader", "request", ")", "throws", "ProtocolException", "{", "Flags", "flags", "=", "new", "Flags", "(", ")", ";", "request", ".", "nextWordChar", "(", ")", ";", "consumeChar", "(", "request", ",", "'", "'", ")", ";", "CharacterValidator", "validator", "=", "new", "NoopCharValidator", "(", ")", ";", "String", "nextWord", "=", "consumeWord", "(", "request", ",", "validator", ")", ";", "while", "(", "!", "nextWord", ".", "endsWith", "(", "\")\"", ")", ")", "{", "setFlag", "(", "nextWord", ",", "flags", ")", ";", "nextWord", "=", "consumeWord", "(", "request", ",", "validator", ")", ";", "}", "// Got the closing \")\", may be attached to a word.", "if", "(", "nextWord", ".", "length", "(", ")", ">", "1", ")", "{", "setFlag", "(", "nextWord", ".", "substring", "(", "0", ",", "nextWord", ".", "length", "(", ")", "-", "1", ")", ",", "flags", ")", ";", "}", "return", "flags", ";", "}" ]
Reads a "flags" argument from the request.
[ "Reads", "a", "flags", "argument", "from", "the", "request", "." ]
6d19a62233d1ef6fedbbd1f6fdde2d28e713834a
https://github.com/greenmail-mail-test/greenmail/blob/6d19a62233d1ef6fedbbd1f6fdde2d28e713834a/greenmail-core/src/main/java/com/icegreen/greenmail/imap/commands/CommandParser.java#L277-L293
160,556
greenmail-mail-test/greenmail
greenmail-core/src/main/java/com/icegreen/greenmail/imap/commands/CommandParser.java
CommandParser.number
public long number(ImapRequestLineReader request) throws ProtocolException { String digits = consumeWord(request, new DigitCharValidator()); return Long.parseLong(digits); }
java
public long number(ImapRequestLineReader request) throws ProtocolException { String digits = consumeWord(request, new DigitCharValidator()); return Long.parseLong(digits); }
[ "public", "long", "number", "(", "ImapRequestLineReader", "request", ")", "throws", "ProtocolException", "{", "String", "digits", "=", "consumeWord", "(", "request", ",", "new", "DigitCharValidator", "(", ")", ")", ";", "return", "Long", ".", "parseLong", "(", "digits", ")", ";", "}" ]
Reads an argument of type "number" from the request.
[ "Reads", "an", "argument", "of", "type", "number", "from", "the", "request", "." ]
6d19a62233d1ef6fedbbd1f6fdde2d28e713834a
https://github.com/greenmail-mail-test/greenmail/blob/6d19a62233d1ef6fedbbd1f6fdde2d28e713834a/greenmail-core/src/main/java/com/icegreen/greenmail/imap/commands/CommandParser.java#L317-L320
160,557
greenmail-mail-test/greenmail
greenmail-core/src/main/java/com/icegreen/greenmail/imap/commands/CommandParser.java
CommandParser.parseIdRange
public IdRange[] parseIdRange(ImapRequestLineReader request) throws ProtocolException { CharacterValidator validator = new MessageSetCharValidator(); String nextWord = consumeWord(request, validator); int commaPos = nextWord.indexOf(','); if (commaPos == -1) { return new IdRange[]{IdRange.parseRange(nextWord)}; } List<IdRange> rangeList = new ArrayList<>(); int pos = 0; while (commaPos != -1) { String range = nextWord.substring(pos, commaPos); IdRange set = IdRange.parseRange(range); rangeList.add(set); pos = commaPos + 1; commaPos = nextWord.indexOf(',', pos); } String range = nextWord.substring(pos); rangeList.add(IdRange.parseRange(range)); return rangeList.toArray(new IdRange[rangeList.size()]); }
java
public IdRange[] parseIdRange(ImapRequestLineReader request) throws ProtocolException { CharacterValidator validator = new MessageSetCharValidator(); String nextWord = consumeWord(request, validator); int commaPos = nextWord.indexOf(','); if (commaPos == -1) { return new IdRange[]{IdRange.parseRange(nextWord)}; } List<IdRange> rangeList = new ArrayList<>(); int pos = 0; while (commaPos != -1) { String range = nextWord.substring(pos, commaPos); IdRange set = IdRange.parseRange(range); rangeList.add(set); pos = commaPos + 1; commaPos = nextWord.indexOf(',', pos); } String range = nextWord.substring(pos); rangeList.add(IdRange.parseRange(range)); return rangeList.toArray(new IdRange[rangeList.size()]); }
[ "public", "IdRange", "[", "]", "parseIdRange", "(", "ImapRequestLineReader", "request", ")", "throws", "ProtocolException", "{", "CharacterValidator", "validator", "=", "new", "MessageSetCharValidator", "(", ")", ";", "String", "nextWord", "=", "consumeWord", "(", "request", ",", "validator", ")", ";", "int", "commaPos", "=", "nextWord", ".", "indexOf", "(", "'", "'", ")", ";", "if", "(", "commaPos", "==", "-", "1", ")", "{", "return", "new", "IdRange", "[", "]", "{", "IdRange", ".", "parseRange", "(", "nextWord", ")", "}", ";", "}", "List", "<", "IdRange", ">", "rangeList", "=", "new", "ArrayList", "<>", "(", ")", ";", "int", "pos", "=", "0", ";", "while", "(", "commaPos", "!=", "-", "1", ")", "{", "String", "range", "=", "nextWord", ".", "substring", "(", "pos", ",", "commaPos", ")", ";", "IdRange", "set", "=", "IdRange", ".", "parseRange", "(", "range", ")", ";", "rangeList", ".", "add", "(", "set", ")", ";", "pos", "=", "commaPos", "+", "1", ";", "commaPos", "=", "nextWord", ".", "indexOf", "(", "'", "'", ",", "pos", ")", ";", "}", "String", "range", "=", "nextWord", ".", "substring", "(", "pos", ")", ";", "rangeList", ".", "add", "(", "IdRange", ".", "parseRange", "(", "range", ")", ")", ";", "return", "rangeList", ".", "toArray", "(", "new", "IdRange", "[", "rangeList", ".", "size", "(", ")", "]", ")", ";", "}" ]
Reads a "message set" argument, and parses into an IdSet. Currently only supports a single range of values.
[ "Reads", "a", "message", "set", "argument", "and", "parses", "into", "an", "IdSet", ".", "Currently", "only", "supports", "a", "single", "range", "of", "values", "." ]
6d19a62233d1ef6fedbbd1f6fdde2d28e713834a
https://github.com/greenmail-mail-test/greenmail/blob/6d19a62233d1ef6fedbbd1f6fdde2d28e713834a/greenmail-core/src/main/java/com/icegreen/greenmail/imap/commands/CommandParser.java#L372-L395
160,558
greenmail-mail-test/greenmail
greenmail-core/src/main/java/com/icegreen/greenmail/util/PropertiesBasedServerSetupBuilder.java
PropertiesBasedServerSetupBuilder.build
public ServerSetup[] build(Properties properties) { List<ServerSetup> serverSetups = new ArrayList<>(); String hostname = properties.getProperty("greenmail.hostname", ServerSetup.getLocalHostAddress()); long serverStartupTimeout = Long.parseLong(properties.getProperty("greenmail.startup.timeout", "-1")); // Default setups addDefaultSetups(hostname, properties, serverSetups); // Default setups for test addTestSetups(hostname, properties, serverSetups); // Default setups for (String protocol : ServerSetup.PROTOCOLS) { addSetup(hostname, protocol, properties, serverSetups); } for (ServerSetup setup : serverSetups) { if (properties.containsKey(GREENMAIL_VERBOSE)) { setup.setVerbose(true); } if (serverStartupTimeout >= 0L) { setup.setServerStartupTimeout(serverStartupTimeout); } } return serverSetups.toArray(new ServerSetup[serverSetups.size()]); }
java
public ServerSetup[] build(Properties properties) { List<ServerSetup> serverSetups = new ArrayList<>(); String hostname = properties.getProperty("greenmail.hostname", ServerSetup.getLocalHostAddress()); long serverStartupTimeout = Long.parseLong(properties.getProperty("greenmail.startup.timeout", "-1")); // Default setups addDefaultSetups(hostname, properties, serverSetups); // Default setups for test addTestSetups(hostname, properties, serverSetups); // Default setups for (String protocol : ServerSetup.PROTOCOLS) { addSetup(hostname, protocol, properties, serverSetups); } for (ServerSetup setup : serverSetups) { if (properties.containsKey(GREENMAIL_VERBOSE)) { setup.setVerbose(true); } if (serverStartupTimeout >= 0L) { setup.setServerStartupTimeout(serverStartupTimeout); } } return serverSetups.toArray(new ServerSetup[serverSetups.size()]); }
[ "public", "ServerSetup", "[", "]", "build", "(", "Properties", "properties", ")", "{", "List", "<", "ServerSetup", ">", "serverSetups", "=", "new", "ArrayList", "<>", "(", ")", ";", "String", "hostname", "=", "properties", ".", "getProperty", "(", "\"greenmail.hostname\"", ",", "ServerSetup", ".", "getLocalHostAddress", "(", ")", ")", ";", "long", "serverStartupTimeout", "=", "Long", ".", "parseLong", "(", "properties", ".", "getProperty", "(", "\"greenmail.startup.timeout\"", ",", "\"-1\"", ")", ")", ";", "// Default setups", "addDefaultSetups", "(", "hostname", ",", "properties", ",", "serverSetups", ")", ";", "// Default setups for test", "addTestSetups", "(", "hostname", ",", "properties", ",", "serverSetups", ")", ";", "// Default setups", "for", "(", "String", "protocol", ":", "ServerSetup", ".", "PROTOCOLS", ")", "{", "addSetup", "(", "hostname", ",", "protocol", ",", "properties", ",", "serverSetups", ")", ";", "}", "for", "(", "ServerSetup", "setup", ":", "serverSetups", ")", "{", "if", "(", "properties", ".", "containsKey", "(", "GREENMAIL_VERBOSE", ")", ")", "{", "setup", ".", "setVerbose", "(", "true", ")", ";", "}", "if", "(", "serverStartupTimeout", ">=", "0L", ")", "{", "setup", ".", "setServerStartupTimeout", "(", "serverStartupTimeout", ")", ";", "}", "}", "return", "serverSetups", ".", "toArray", "(", "new", "ServerSetup", "[", "serverSetups", ".", "size", "(", ")", "]", ")", ";", "}" ]
Creates a server setup based on provided properties. @param properties the properties. @return the server setup, or an empty array.
[ "Creates", "a", "server", "setup", "based", "on", "provided", "properties", "." ]
6d19a62233d1ef6fedbbd1f6fdde2d28e713834a
https://github.com/greenmail-mail-test/greenmail/blob/6d19a62233d1ef6fedbbd1f6fdde2d28e713834a/greenmail-core/src/main/java/com/icegreen/greenmail/util/PropertiesBasedServerSetupBuilder.java#L58-L86
160,559
greenmail-mail-test/greenmail
greenmail-core/src/main/java/com/icegreen/greenmail/store/MessageFlags.java
MessageFlags.format
public static String format(Flags flags) { StringBuilder buf = new StringBuilder(); buf.append('('); if (flags.contains(Flags.Flag.ANSWERED)) { buf.append("\\Answered "); } if (flags.contains(Flags.Flag.DELETED)) { buf.append("\\Deleted "); } if (flags.contains(Flags.Flag.DRAFT)) { buf.append("\\Draft "); } if (flags.contains(Flags.Flag.FLAGGED)) { buf.append("\\Flagged "); } if (flags.contains(Flags.Flag.RECENT)) { buf.append("\\Recent "); } if (flags.contains(Flags.Flag.SEEN)) { buf.append("\\Seen "); } String[] userFlags = flags.getUserFlags(); if(null!=userFlags) { for(String uf: userFlags) { buf.append(uf).append(' '); } } // Remove the trailing space, if necessary. if (buf.length() > 1) { buf.setLength(buf.length() - 1); } buf.append(')'); return buf.toString(); }
java
public static String format(Flags flags) { StringBuilder buf = new StringBuilder(); buf.append('('); if (flags.contains(Flags.Flag.ANSWERED)) { buf.append("\\Answered "); } if (flags.contains(Flags.Flag.DELETED)) { buf.append("\\Deleted "); } if (flags.contains(Flags.Flag.DRAFT)) { buf.append("\\Draft "); } if (flags.contains(Flags.Flag.FLAGGED)) { buf.append("\\Flagged "); } if (flags.contains(Flags.Flag.RECENT)) { buf.append("\\Recent "); } if (flags.contains(Flags.Flag.SEEN)) { buf.append("\\Seen "); } String[] userFlags = flags.getUserFlags(); if(null!=userFlags) { for(String uf: userFlags) { buf.append(uf).append(' '); } } // Remove the trailing space, if necessary. if (buf.length() > 1) { buf.setLength(buf.length() - 1); } buf.append(')'); return buf.toString(); }
[ "public", "static", "String", "format", "(", "Flags", "flags", ")", "{", "StringBuilder", "buf", "=", "new", "StringBuilder", "(", ")", ";", "buf", ".", "append", "(", "'", "'", ")", ";", "if", "(", "flags", ".", "contains", "(", "Flags", ".", "Flag", ".", "ANSWERED", ")", ")", "{", "buf", ".", "append", "(", "\"\\\\Answered \"", ")", ";", "}", "if", "(", "flags", ".", "contains", "(", "Flags", ".", "Flag", ".", "DELETED", ")", ")", "{", "buf", ".", "append", "(", "\"\\\\Deleted \"", ")", ";", "}", "if", "(", "flags", ".", "contains", "(", "Flags", ".", "Flag", ".", "DRAFT", ")", ")", "{", "buf", ".", "append", "(", "\"\\\\Draft \"", ")", ";", "}", "if", "(", "flags", ".", "contains", "(", "Flags", ".", "Flag", ".", "FLAGGED", ")", ")", "{", "buf", ".", "append", "(", "\"\\\\Flagged \"", ")", ";", "}", "if", "(", "flags", ".", "contains", "(", "Flags", ".", "Flag", ".", "RECENT", ")", ")", "{", "buf", ".", "append", "(", "\"\\\\Recent \"", ")", ";", "}", "if", "(", "flags", ".", "contains", "(", "Flags", ".", "Flag", ".", "SEEN", ")", ")", "{", "buf", ".", "append", "(", "\"\\\\Seen \"", ")", ";", "}", "String", "[", "]", "userFlags", "=", "flags", ".", "getUserFlags", "(", ")", ";", "if", "(", "null", "!=", "userFlags", ")", "{", "for", "(", "String", "uf", ":", "userFlags", ")", "{", "buf", ".", "append", "(", "uf", ")", ".", "append", "(", "'", "'", ")", ";", "}", "}", "// Remove the trailing space, if necessary.\r", "if", "(", "buf", ".", "length", "(", ")", ">", "1", ")", "{", "buf", ".", "setLength", "(", "buf", ".", "length", "(", ")", "-", "1", ")", ";", "}", "buf", ".", "append", "(", "'", "'", ")", ";", "return", "buf", ".", "toString", "(", ")", ";", "}" ]
Returns IMAP formatted String of MessageFlags for named user
[ "Returns", "IMAP", "formatted", "String", "of", "MessageFlags", "for", "named", "user" ]
6d19a62233d1ef6fedbbd1f6fdde2d28e713834a
https://github.com/greenmail-mail-test/greenmail/blob/6d19a62233d1ef6fedbbd1f6fdde2d28e713834a/greenmail-core/src/main/java/com/icegreen/greenmail/store/MessageFlags.java#L47-L80
160,560
greenmail-mail-test/greenmail
greenmail-core/src/main/java/com/icegreen/greenmail/imap/ImapRequestLineReader.java
ImapRequestLineReader.eol
public void eol() throws ProtocolException { char next = nextChar(); // Ignore trailing spaces. while (next == ' ') { consume(); next = nextChar(); } // handle DOS and unix end-of-lines if (next == '\r') { consume(); next = nextChar(); } // Check if we found extra characters. if (next != '\n') { throw new ProtocolException("Expected end-of-line, found more character(s): "+next); } dumpLine(); }
java
public void eol() throws ProtocolException { char next = nextChar(); // Ignore trailing spaces. while (next == ' ') { consume(); next = nextChar(); } // handle DOS and unix end-of-lines if (next == '\r') { consume(); next = nextChar(); } // Check if we found extra characters. if (next != '\n') { throw new ProtocolException("Expected end-of-line, found more character(s): "+next); } dumpLine(); }
[ "public", "void", "eol", "(", ")", "throws", "ProtocolException", "{", "char", "next", "=", "nextChar", "(", ")", ";", "// Ignore trailing spaces.\r", "while", "(", "next", "==", "'", "'", ")", "{", "consume", "(", ")", ";", "next", "=", "nextChar", "(", ")", ";", "}", "// handle DOS and unix end-of-lines\r", "if", "(", "next", "==", "'", "'", ")", "{", "consume", "(", ")", ";", "next", "=", "nextChar", "(", ")", ";", "}", "// Check if we found extra characters.\r", "if", "(", "next", "!=", "'", "'", ")", "{", "throw", "new", "ProtocolException", "(", "\"Expected end-of-line, found more character(s): \"", "+", "next", ")", ";", "}", "dumpLine", "(", ")", ";", "}" ]
Moves the request line reader to end of the line, checking that no non-space character are found. @throws ProtocolException If more non-space tokens are found in this line, or the end-of-file is reached.
[ "Moves", "the", "request", "line", "reader", "to", "end", "of", "the", "line", "checking", "that", "no", "non", "-", "space", "character", "are", "found", "." ]
6d19a62233d1ef6fedbbd1f6fdde2d28e713834a
https://github.com/greenmail-mail-test/greenmail/blob/6d19a62233d1ef6fedbbd1f6fdde2d28e713834a/greenmail-core/src/main/java/com/icegreen/greenmail/imap/ImapRequestLineReader.java#L104-L124
160,561
greenmail-mail-test/greenmail
greenmail-core/src/main/java/com/icegreen/greenmail/imap/ImapRequestLineReader.java
ImapRequestLineReader.read
public void read(byte[] holder) throws ProtocolException { int readTotal = 0; try { while (readTotal < holder.length) { int count = input.read(holder, readTotal, holder.length - readTotal); if (count == -1) { throw new ProtocolException("Unexpected end of stream."); } readTotal += count; } // Unset the next char. nextSeen = false; nextChar = 0; } catch (IOException e) { throw new ProtocolException("Error reading from stream.", e); } }
java
public void read(byte[] holder) throws ProtocolException { int readTotal = 0; try { while (readTotal < holder.length) { int count = input.read(holder, readTotal, holder.length - readTotal); if (count == -1) { throw new ProtocolException("Unexpected end of stream."); } readTotal += count; } // Unset the next char. nextSeen = false; nextChar = 0; } catch (IOException e) { throw new ProtocolException("Error reading from stream.", e); } }
[ "public", "void", "read", "(", "byte", "[", "]", "holder", ")", "throws", "ProtocolException", "{", "int", "readTotal", "=", "0", ";", "try", "{", "while", "(", "readTotal", "<", "holder", ".", "length", ")", "{", "int", "count", "=", "input", ".", "read", "(", "holder", ",", "readTotal", ",", "holder", ".", "length", "-", "readTotal", ")", ";", "if", "(", "count", "==", "-", "1", ")", "{", "throw", "new", "ProtocolException", "(", "\"Unexpected end of stream.\"", ")", ";", "}", "readTotal", "+=", "count", ";", "}", "// Unset the next char.\r", "nextSeen", "=", "false", ";", "nextChar", "=", "0", ";", "}", "catch", "(", "IOException", "e", ")", "{", "throw", "new", "ProtocolException", "(", "\"Error reading from stream.\"", ",", "e", ")", ";", "}", "}" ]
Reads and consumes a number of characters from the underlying reader, filling the byte array provided. @param holder A byte array which will be filled with bytes read from the underlying reader. @throws ProtocolException If a char can't be read into each array element.
[ "Reads", "and", "consumes", "a", "number", "of", "characters", "from", "the", "underlying", "reader", "filling", "the", "byte", "array", "provided", "." ]
6d19a62233d1ef6fedbbd1f6fdde2d28e713834a
https://github.com/greenmail-mail-test/greenmail/blob/6d19a62233d1ef6fedbbd1f6fdde2d28e713834a/greenmail-core/src/main/java/com/icegreen/greenmail/imap/ImapRequestLineReader.java#L150-L166
160,562
greenmail-mail-test/greenmail
greenmail-core/src/main/java/com/icegreen/greenmail/imap/ImapRequestLineReader.java
ImapRequestLineReader.commandContinuationRequest
public void commandContinuationRequest() throws ProtocolException { try { output.write('+'); output.write(' '); output.write('O'); output.write('K'); output.write('\r'); output.write('\n'); output.flush(); } catch (IOException e) { throw new ProtocolException("Unexpected exception in sending command continuation request.", e); } }
java
public void commandContinuationRequest() throws ProtocolException { try { output.write('+'); output.write(' '); output.write('O'); output.write('K'); output.write('\r'); output.write('\n'); output.flush(); } catch (IOException e) { throw new ProtocolException("Unexpected exception in sending command continuation request.", e); } }
[ "public", "void", "commandContinuationRequest", "(", ")", "throws", "ProtocolException", "{", "try", "{", "output", ".", "write", "(", "'", "'", ")", ";", "output", ".", "write", "(", "'", "'", ")", ";", "output", ".", "write", "(", "'", "'", ")", ";", "output", ".", "write", "(", "'", "'", ")", ";", "output", ".", "write", "(", "'", "'", ")", ";", "output", ".", "write", "(", "'", "'", ")", ";", "output", ".", "flush", "(", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "throw", "new", "ProtocolException", "(", "\"Unexpected exception in sending command continuation request.\"", ",", "e", ")", ";", "}", "}" ]
Sends a server command continuation request '+' back to the client, requesting more data to be sent.
[ "Sends", "a", "server", "command", "continuation", "request", "+", "back", "to", "the", "client", "requesting", "more", "data", "to", "be", "sent", "." ]
6d19a62233d1ef6fedbbd1f6fdde2d28e713834a
https://github.com/greenmail-mail-test/greenmail/blob/6d19a62233d1ef6fedbbd1f6fdde2d28e713834a/greenmail-core/src/main/java/com/icegreen/greenmail/imap/ImapRequestLineReader.java#L172-L185
160,563
greenmail-mail-test/greenmail
greenmail-core/src/main/java/com/icegreen/greenmail/util/UserUtil.java
UserUtil.createUsers
public static void createUsers(GreenMailOperations greenMail, InternetAddress... addresses) { for (InternetAddress address : addresses) { greenMail.setUser(address.getAddress(), address.getAddress()); } }
java
public static void createUsers(GreenMailOperations greenMail, InternetAddress... addresses) { for (InternetAddress address : addresses) { greenMail.setUser(address.getAddress(), address.getAddress()); } }
[ "public", "static", "void", "createUsers", "(", "GreenMailOperations", "greenMail", ",", "InternetAddress", "...", "addresses", ")", "{", "for", "(", "InternetAddress", "address", ":", "addresses", ")", "{", "greenMail", ".", "setUser", "(", "address", ".", "getAddress", "(", ")", ",", "address", ".", "getAddress", "(", ")", ")", ";", "}", "}" ]
Create users for the given array of addresses. The passwords will be set to the email addresses. @param greenMail Greenmail instance to create users for @param addresses Addresses
[ "Create", "users", "for", "the", "given", "array", "of", "addresses", ".", "The", "passwords", "will", "be", "set", "to", "the", "email", "addresses", "." ]
6d19a62233d1ef6fedbbd1f6fdde2d28e713834a
https://github.com/greenmail-mail-test/greenmail/blob/6d19a62233d1ef6fedbbd1f6fdde2d28e713834a/greenmail-core/src/main/java/com/icegreen/greenmail/util/UserUtil.java#L23-L27
160,564
greenmail-mail-test/greenmail
greenmail-core/src/main/java/com/icegreen/greenmail/imap/commands/IdRange.java
IdRange.containsUid
public static boolean containsUid(IdRange[] idRanges, long uid) { if (null != idRanges && idRanges.length > 0) { for (IdRange range : idRanges) { if (range.includes(uid)) { return true; } } } return false; }
java
public static boolean containsUid(IdRange[] idRanges, long uid) { if (null != idRanges && idRanges.length > 0) { for (IdRange range : idRanges) { if (range.includes(uid)) { return true; } } } return false; }
[ "public", "static", "boolean", "containsUid", "(", "IdRange", "[", "]", "idRanges", ",", "long", "uid", ")", "{", "if", "(", "null", "!=", "idRanges", "&&", "idRanges", ".", "length", ">", "0", ")", "{", "for", "(", "IdRange", "range", ":", "idRanges", ")", "{", "if", "(", "range", ".", "includes", "(", "uid", ")", ")", "{", "return", "true", ";", "}", "}", "}", "return", "false", ";", "}" ]
Checks if ranges contain the uid @param idRanges the id ranges @param uid the uid @return true, if ranges contain given uid
[ "Checks", "if", "ranges", "contain", "the", "uid" ]
6d19a62233d1ef6fedbbd1f6fdde2d28e713834a
https://github.com/greenmail-mail-test/greenmail/blob/6d19a62233d1ef6fedbbd1f6fdde2d28e713834a/greenmail-core/src/main/java/com/icegreen/greenmail/imap/commands/IdRange.java#L149-L158
160,565
osiegmar/logback-gelf
src/main/java/de/siegmar/logbackgelf/SimpleJsonEncoder.java
SimpleJsonEncoder.appendToJSON
SimpleJsonEncoder appendToJSON(final String key, final Object value) { if (closed) { throw new IllegalStateException("Encoder already closed"); } if (value != null) { appendKey(key); if (value instanceof Number) { sb.append(value.toString()); } else { sb.append(QUOTE).append(escapeString(value.toString())).append(QUOTE); } } return this; }
java
SimpleJsonEncoder appendToJSON(final String key, final Object value) { if (closed) { throw new IllegalStateException("Encoder already closed"); } if (value != null) { appendKey(key); if (value instanceof Number) { sb.append(value.toString()); } else { sb.append(QUOTE).append(escapeString(value.toString())).append(QUOTE); } } return this; }
[ "SimpleJsonEncoder", "appendToJSON", "(", "final", "String", "key", ",", "final", "Object", "value", ")", "{", "if", "(", "closed", ")", "{", "throw", "new", "IllegalStateException", "(", "\"Encoder already closed\"", ")", ";", "}", "if", "(", "value", "!=", "null", ")", "{", "appendKey", "(", "key", ")", ";", "if", "(", "value", "instanceof", "Number", ")", "{", "sb", ".", "append", "(", "value", ".", "toString", "(", ")", ")", ";", "}", "else", "{", "sb", ".", "append", "(", "QUOTE", ")", ".", "append", "(", "escapeString", "(", "value", ".", "toString", "(", ")", ")", ")", ".", "append", "(", "QUOTE", ")", ";", "}", "}", "return", "this", ";", "}" ]
Append field with quotes and escape characters added, if required. @return this
[ "Append", "field", "with", "quotes", "and", "escape", "characters", "added", "if", "required", "." ]
35c41eda363db803c8c4570f31d518451e9a879b
https://github.com/osiegmar/logback-gelf/blob/35c41eda363db803c8c4570f31d518451e9a879b/src/main/java/de/siegmar/logbackgelf/SimpleJsonEncoder.java#L53-L66
160,566
osiegmar/logback-gelf
src/main/java/de/siegmar/logbackgelf/SimpleJsonEncoder.java
SimpleJsonEncoder.appendToJSONUnquoted
SimpleJsonEncoder appendToJSONUnquoted(final String key, final Object value) { if (closed) { throw new IllegalStateException("Encoder already closed"); } if (value != null) { appendKey(key); sb.append(value); } return this; }
java
SimpleJsonEncoder appendToJSONUnquoted(final String key, final Object value) { if (closed) { throw new IllegalStateException("Encoder already closed"); } if (value != null) { appendKey(key); sb.append(value); } return this; }
[ "SimpleJsonEncoder", "appendToJSONUnquoted", "(", "final", "String", "key", ",", "final", "Object", "value", ")", "{", "if", "(", "closed", ")", "{", "throw", "new", "IllegalStateException", "(", "\"Encoder already closed\"", ")", ";", "}", "if", "(", "value", "!=", "null", ")", "{", "appendKey", "(", "key", ")", ";", "sb", ".", "append", "(", "value", ")", ";", "}", "return", "this", ";", "}" ]
Append field with quotes and escape characters added in the key, if required. The value is added without quotes and any escape characters. @return this
[ "Append", "field", "with", "quotes", "and", "escape", "characters", "added", "in", "the", "key", "if", "required", ".", "The", "value", "is", "added", "without", "quotes", "and", "any", "escape", "characters", "." ]
35c41eda363db803c8c4570f31d518451e9a879b
https://github.com/osiegmar/logback-gelf/blob/35c41eda363db803c8c4570f31d518451e9a879b/src/main/java/de/siegmar/logbackgelf/SimpleJsonEncoder.java#L74-L83
160,567
osiegmar/logback-gelf
src/main/java/de/siegmar/logbackgelf/GelfTcpAppender.java
GelfTcpAppender.sendMessage
@SuppressWarnings("checkstyle:illegalcatch") private boolean sendMessage(final byte[] messageToSend) { try { connectionPool.execute(new PooledObjectConsumer<TcpConnection>() { @Override public void accept(final TcpConnection tcpConnection) throws IOException { tcpConnection.write(messageToSend); } }); } catch (final Exception e) { addError(String.format("Error sending message via tcp://%s:%s", getGraylogHost(), getGraylogPort()), e); return false; } return true; }
java
@SuppressWarnings("checkstyle:illegalcatch") private boolean sendMessage(final byte[] messageToSend) { try { connectionPool.execute(new PooledObjectConsumer<TcpConnection>() { @Override public void accept(final TcpConnection tcpConnection) throws IOException { tcpConnection.write(messageToSend); } }); } catch (final Exception e) { addError(String.format("Error sending message via tcp://%s:%s", getGraylogHost(), getGraylogPort()), e); return false; } return true; }
[ "@", "SuppressWarnings", "(", "\"checkstyle:illegalcatch\"", ")", "private", "boolean", "sendMessage", "(", "final", "byte", "[", "]", "messageToSend", ")", "{", "try", "{", "connectionPool", ".", "execute", "(", "new", "PooledObjectConsumer", "<", "TcpConnection", ">", "(", ")", "{", "@", "Override", "public", "void", "accept", "(", "final", "TcpConnection", "tcpConnection", ")", "throws", "IOException", "{", "tcpConnection", ".", "write", "(", "messageToSend", ")", ";", "}", "}", ")", ";", "}", "catch", "(", "final", "Exception", "e", ")", "{", "addError", "(", "String", ".", "format", "(", "\"Error sending message via tcp://%s:%s\"", ",", "getGraylogHost", "(", ")", ",", "getGraylogPort", "(", ")", ")", ",", "e", ")", ";", "return", "false", ";", "}", "return", "true", ";", "}" ]
Send message to socket's output stream. @param messageToSend message to send. @return {@code true} if message was sent successfully, {@code false} otherwise.
[ "Send", "message", "to", "socket", "s", "output", "stream", "." ]
35c41eda363db803c8c4570f31d518451e9a879b
https://github.com/osiegmar/logback-gelf/blob/35c41eda363db803c8c4570f31d518451e9a879b/src/main/java/de/siegmar/logbackgelf/GelfTcpAppender.java#L170-L187
160,568
brettwooldridge/NuProcess
src/main/java/com/zaxxer/nuprocess/internal/BaseEventProcessor.java
BaseEventProcessor.run
@Override public void run() { try { startBarrier.await(); int idleCount = 0; while (!isRunning.compareAndSet(idleCount > lingerIterations && pidToProcessMap.isEmpty(), false)) { idleCount = (!shutdown && process()) ? 0 : (idleCount + 1); } } catch (Exception e) { // TODO: how to handle this error? isRunning.set(false); } }
java
@Override public void run() { try { startBarrier.await(); int idleCount = 0; while (!isRunning.compareAndSet(idleCount > lingerIterations && pidToProcessMap.isEmpty(), false)) { idleCount = (!shutdown && process()) ? 0 : (idleCount + 1); } } catch (Exception e) { // TODO: how to handle this error? isRunning.set(false); } }
[ "@", "Override", "public", "void", "run", "(", ")", "{", "try", "{", "startBarrier", ".", "await", "(", ")", ";", "int", "idleCount", "=", "0", ";", "while", "(", "!", "isRunning", ".", "compareAndSet", "(", "idleCount", ">", "lingerIterations", "&&", "pidToProcessMap", ".", "isEmpty", "(", ")", ",", "false", ")", ")", "{", "idleCount", "=", "(", "!", "shutdown", "&&", "process", "(", ")", ")", "?", "0", ":", "(", "idleCount", "+", "1", ")", ";", "}", "}", "catch", "(", "Exception", "e", ")", "{", "// TODO: how to handle this error?", "isRunning", ".", "set", "(", "false", ")", ";", "}", "}" ]
The primary run loop of the event processor.
[ "The", "primary", "run", "loop", "of", "the", "event", "processor", "." ]
d4abdd195367fce7375a0b45cb2f5eeff1c74d03
https://github.com/brettwooldridge/NuProcess/blob/d4abdd195367fce7375a0b45cb2f5eeff1c74d03/src/main/java/com/zaxxer/nuprocess/internal/BaseEventProcessor.java#L70-L85
160,569
brettwooldridge/NuProcess
src/main/java/com/zaxxer/nuprocess/internal/HexDumpElf.java
HexDumpElf.dump
public static String dump(final int displayOffset, final byte[] data, final int offset, final int len) { StringBuilder sb = new StringBuilder(); Formatter formatter = new Formatter(sb); StringBuilder ascii = new StringBuilder(); int dataNdx = offset; final int maxDataNdx = offset + len; final int lines = (len + 16) / 16; for (int i = 0; i < lines; i++) { ascii.append(" |"); formatter.format("%08x ", displayOffset + (i * 16)); for (int j = 0; j < 16; j++) { if (dataNdx < maxDataNdx) { byte b = data[dataNdx++]; formatter.format("%02x ", b); ascii.append((b > MIN_VISIBLE && b < MAX_VISIBLE) ? (char) b : ' '); } else { sb.append(" "); } if (j == 7) { sb.append(' '); } } ascii.append('|'); sb.append(ascii).append('\n'); ascii.setLength(0); } formatter.close(); return sb.toString(); }
java
public static String dump(final int displayOffset, final byte[] data, final int offset, final int len) { StringBuilder sb = new StringBuilder(); Formatter formatter = new Formatter(sb); StringBuilder ascii = new StringBuilder(); int dataNdx = offset; final int maxDataNdx = offset + len; final int lines = (len + 16) / 16; for (int i = 0; i < lines; i++) { ascii.append(" |"); formatter.format("%08x ", displayOffset + (i * 16)); for (int j = 0; j < 16; j++) { if (dataNdx < maxDataNdx) { byte b = data[dataNdx++]; formatter.format("%02x ", b); ascii.append((b > MIN_VISIBLE && b < MAX_VISIBLE) ? (char) b : ' '); } else { sb.append(" "); } if (j == 7) { sb.append(' '); } } ascii.append('|'); sb.append(ascii).append('\n'); ascii.setLength(0); } formatter.close(); return sb.toString(); }
[ "public", "static", "String", "dump", "(", "final", "int", "displayOffset", ",", "final", "byte", "[", "]", "data", ",", "final", "int", "offset", ",", "final", "int", "len", ")", "{", "StringBuilder", "sb", "=", "new", "StringBuilder", "(", ")", ";", "Formatter", "formatter", "=", "new", "Formatter", "(", "sb", ")", ";", "StringBuilder", "ascii", "=", "new", "StringBuilder", "(", ")", ";", "int", "dataNdx", "=", "offset", ";", "final", "int", "maxDataNdx", "=", "offset", "+", "len", ";", "final", "int", "lines", "=", "(", "len", "+", "16", ")", "/", "16", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "lines", ";", "i", "++", ")", "{", "ascii", ".", "append", "(", "\" |\"", ")", ";", "formatter", ".", "format", "(", "\"%08x \"", ",", "displayOffset", "+", "(", "i", "*", "16", ")", ")", ";", "for", "(", "int", "j", "=", "0", ";", "j", "<", "16", ";", "j", "++", ")", "{", "if", "(", "dataNdx", "<", "maxDataNdx", ")", "{", "byte", "b", "=", "data", "[", "dataNdx", "++", "]", ";", "formatter", ".", "format", "(", "\"%02x \"", ",", "b", ")", ";", "ascii", ".", "append", "(", "(", "b", ">", "MIN_VISIBLE", "&&", "b", "<", "MAX_VISIBLE", ")", "?", "(", "char", ")", "b", ":", "'", "'", ")", ";", "}", "else", "{", "sb", ".", "append", "(", "\" \"", ")", ";", "}", "if", "(", "j", "==", "7", ")", "{", "sb", ".", "append", "(", "'", "'", ")", ";", "}", "}", "ascii", ".", "append", "(", "'", "'", ")", ";", "sb", ".", "append", "(", "ascii", ")", ".", "append", "(", "'", "'", ")", ";", "ascii", ".", "setLength", "(", "0", ")", ";", "}", "formatter", ".", "close", "(", ")", ";", "return", "sb", ".", "toString", "(", ")", ";", "}" ]
Dump an array of bytes in hexadecimal. @param displayOffset the display offset (left column) @param data the byte array of data @param offset the offset to start dumping in the byte array @param len the length of data to dump @return the dump string
[ "Dump", "an", "array", "of", "bytes", "in", "hexadecimal", "." ]
d4abdd195367fce7375a0b45cb2f5eeff1c74d03
https://github.com/brettwooldridge/NuProcess/blob/d4abdd195367fce7375a0b45cb2f5eeff1c74d03/src/main/java/com/zaxxer/nuprocess/internal/HexDumpElf.java#L44-L79
160,570
brettwooldridge/NuProcess
src/main/java/com/zaxxer/nuprocess/windows/ProcessCompletions.java
ProcessCompletions.run
@Override public void run() { try { startBarrier.await(); int idleCount = 0; while (!isRunning.compareAndSet(idleCount > LINGER_ITERATIONS && deadPool.isEmpty() && completionKeyToProcessMap.isEmpty(), false)) { idleCount = (!shutdown && process()) ? 0 : (idleCount + 1); } } catch (Exception e) { // TODO: how to handle this error? e.printStackTrace(); isRunning.set(false); } }
java
@Override public void run() { try { startBarrier.await(); int idleCount = 0; while (!isRunning.compareAndSet(idleCount > LINGER_ITERATIONS && deadPool.isEmpty() && completionKeyToProcessMap.isEmpty(), false)) { idleCount = (!shutdown && process()) ? 0 : (idleCount + 1); } } catch (Exception e) { // TODO: how to handle this error? e.printStackTrace(); isRunning.set(false); } }
[ "@", "Override", "public", "void", "run", "(", ")", "{", "try", "{", "startBarrier", ".", "await", "(", ")", ";", "int", "idleCount", "=", "0", ";", "while", "(", "!", "isRunning", ".", "compareAndSet", "(", "idleCount", ">", "LINGER_ITERATIONS", "&&", "deadPool", ".", "isEmpty", "(", ")", "&&", "completionKeyToProcessMap", ".", "isEmpty", "(", ")", ",", "false", ")", ")", "{", "idleCount", "=", "(", "!", "shutdown", "&&", "process", "(", ")", ")", "?", "0", ":", "(", "idleCount", "+", "1", ")", ";", "}", "}", "catch", "(", "Exception", "e", ")", "{", "// TODO: how to handle this error?", "e", ".", "printStackTrace", "(", ")", ";", "isRunning", ".", "set", "(", "false", ")", ";", "}", "}" ]
The primary run loop of the kqueue event processor.
[ "The", "primary", "run", "loop", "of", "the", "kqueue", "event", "processor", "." ]
d4abdd195367fce7375a0b45cb2f5eeff1c74d03
https://github.com/brettwooldridge/NuProcess/blob/d4abdd195367fce7375a0b45cb2f5eeff1c74d03/src/main/java/com/zaxxer/nuprocess/windows/ProcessCompletions.java#L88-L104
160,571
nispok/snackbar
lib/src/main/java/com/nispok/snackbar/Snackbar.java
Snackbar.actionLabel
public Snackbar actionLabel(CharSequence actionButtonLabel) { mActionLabel = actionButtonLabel; if (snackbarAction != null) { snackbarAction.setText(mActionLabel); } return this; }
java
public Snackbar actionLabel(CharSequence actionButtonLabel) { mActionLabel = actionButtonLabel; if (snackbarAction != null) { snackbarAction.setText(mActionLabel); } return this; }
[ "public", "Snackbar", "actionLabel", "(", "CharSequence", "actionButtonLabel", ")", "{", "mActionLabel", "=", "actionButtonLabel", ";", "if", "(", "snackbarAction", "!=", "null", ")", "{", "snackbarAction", ".", "setText", "(", "mActionLabel", ")", ";", "}", "return", "this", ";", "}" ]
Sets the action label to be displayed, if any. Note that if this is not set, the action button will not be displayed @param actionButtonLabel @return
[ "Sets", "the", "action", "label", "to", "be", "displayed", "if", "any", ".", "Note", "that", "if", "this", "is", "not", "set", "the", "action", "button", "will", "not", "be", "displayed" ]
a4e0449874423031107f6aaa7e97d0f1714a1d3b
https://github.com/nispok/snackbar/blob/a4e0449874423031107f6aaa7e97d0f1714a1d3b/lib/src/main/java/com/nispok/snackbar/Snackbar.java#L264-L270
160,572
nispok/snackbar
lib/src/main/java/com/nispok/snackbar/Snackbar.java
Snackbar.setBackgroundDrawable
public static void setBackgroundDrawable(View view, Drawable drawable) { if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) { view.setBackgroundDrawable(drawable); } else { view.setBackground(drawable); } }
java
public static void setBackgroundDrawable(View view, Drawable drawable) { if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) { view.setBackgroundDrawable(drawable); } else { view.setBackground(drawable); } }
[ "public", "static", "void", "setBackgroundDrawable", "(", "View", "view", ",", "Drawable", "drawable", ")", "{", "if", "(", "android", ".", "os", ".", "Build", ".", "VERSION", ".", "SDK_INT", "<", "android", ".", "os", ".", "Build", ".", "VERSION_CODES", ".", "JELLY_BEAN", ")", "{", "view", ".", "setBackgroundDrawable", "(", "drawable", ")", ";", "}", "else", "{", "view", ".", "setBackground", "(", "drawable", ")", ";", "}", "}" ]
Set a Background Drawable using the appropriate Android version api call @param view @param drawable
[ "Set", "a", "Background", "Drawable", "using", "the", "appropriate", "Android", "version", "api", "call" ]
a4e0449874423031107f6aaa7e97d0f1714a1d3b
https://github.com/nispok/snackbar/blob/a4e0449874423031107f6aaa7e97d0f1714a1d3b/lib/src/main/java/com/nispok/snackbar/Snackbar.java#L1222-L1228
160,573
redkale/redkale
src/org/redkale/asm/ModuleVisitor.java
ModuleVisitor.visitRequire
public void visitRequire(String module, int access, String version) { if (mv != null) { mv.visitRequire(module, access, version); } }
java
public void visitRequire(String module, int access, String version) { if (mv != null) { mv.visitRequire(module, access, version); } }
[ "public", "void", "visitRequire", "(", "String", "module", ",", "int", "access", ",", "String", "version", ")", "{", "if", "(", "mv", "!=", "null", ")", "{", "mv", ".", "visitRequire", "(", "module", ",", "access", ",", "version", ")", ";", "}", "}" ]
Visits a dependence of the current module. @param module the qualified name of the dependence. @param access the access flag of the dependence among ACC_TRANSITIVE, ACC_STATIC_PHASE, ACC_SYNTHETIC and ACC_MANDATED. @param version the module version at compile time or null.
[ "Visits", "a", "dependence", "of", "the", "current", "module", "." ]
ea5169b5c5ea7412fd762331c0c497165832e901
https://github.com/redkale/redkale/blob/ea5169b5c5ea7412fd762331c0c497165832e901/src/org/redkale/asm/ModuleVisitor.java#L145-L149
160,574
redkale/redkale
src/org/redkale/asm/ModuleVisitor.java
ModuleVisitor.visitExport
public void visitExport(String packaze, int access, String... modules) { if (mv != null) { mv.visitExport(packaze, access, modules); } }
java
public void visitExport(String packaze, int access, String... modules) { if (mv != null) { mv.visitExport(packaze, access, modules); } }
[ "public", "void", "visitExport", "(", "String", "packaze", ",", "int", "access", ",", "String", "...", "modules", ")", "{", "if", "(", "mv", "!=", "null", ")", "{", "mv", ".", "visitExport", "(", "packaze", ",", "access", ",", "modules", ")", ";", "}", "}" ]
Visit an exported package of the current module. @param packaze the qualified name of the exported package. @param access the access flag of the exported package, valid values are among {@code ACC_SYNTHETIC} and {@code ACC_MANDATED}. @param modules the qualified names of the modules that can access to the public classes of the exported package or <tt>null</tt>.
[ "Visit", "an", "exported", "package", "of", "the", "current", "module", "." ]
ea5169b5c5ea7412fd762331c0c497165832e901
https://github.com/redkale/redkale/blob/ea5169b5c5ea7412fd762331c0c497165832e901/src/org/redkale/asm/ModuleVisitor.java#L162-L166
160,575
redkale/redkale
src/org/redkale/asm/ModuleVisitor.java
ModuleVisitor.visitOpen
public void visitOpen(String packaze, int access, String... modules) { if (mv != null) { mv.visitOpen(packaze, access, modules); } }
java
public void visitOpen(String packaze, int access, String... modules) { if (mv != null) { mv.visitOpen(packaze, access, modules); } }
[ "public", "void", "visitOpen", "(", "String", "packaze", ",", "int", "access", ",", "String", "...", "modules", ")", "{", "if", "(", "mv", "!=", "null", ")", "{", "mv", ".", "visitOpen", "(", "packaze", ",", "access", ",", "modules", ")", ";", "}", "}" ]
Visit an open package of the current module. @param packaze the qualified name of the opened package. @param access the access flag of the opened package, valid values are among {@code ACC_SYNTHETIC} and {@code ACC_MANDATED}. @param modules the qualified names of the modules that can use deep reflection to the classes of the open package or <tt>null</tt>.
[ "Visit", "an", "open", "package", "of", "the", "current", "module", "." ]
ea5169b5c5ea7412fd762331c0c497165832e901
https://github.com/redkale/redkale/blob/ea5169b5c5ea7412fd762331c0c497165832e901/src/org/redkale/asm/ModuleVisitor.java#L179-L183
160,576
redkale/redkale
src/org/redkale/asm/ClassReader.java
ClassReader.readTypeAnnotations
private int[] readTypeAnnotations(final MethodVisitor mv, final Context context, int u, boolean visible) { char[] c = context.buffer; int[] offsets = new int[readUnsignedShort(u)]; u += 2; for (int i = 0; i < offsets.length; ++i) { offsets[i] = u; int target = readInt(u); switch (target >>> 24) { case 0x00: // CLASS_TYPE_PARAMETER case 0x01: // METHOD_TYPE_PARAMETER case 0x16: // METHOD_FORMAL_PARAMETER u += 2; break; case 0x13: // FIELD case 0x14: // METHOD_RETURN case 0x15: // METHOD_RECEIVER u += 1; break; case 0x40: // LOCAL_VARIABLE case 0x41: // RESOURCE_VARIABLE for (int j = readUnsignedShort(u + 1); j > 0; --j) { int start = readUnsignedShort(u + 3); int length = readUnsignedShort(u + 5); createLabel(start, context.labels); createLabel(start + length, context.labels); u += 6; } u += 3; break; case 0x47: // CAST case 0x48: // CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT case 0x49: // METHOD_INVOCATION_TYPE_ARGUMENT case 0x4A: // CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT case 0x4B: // METHOD_REFERENCE_TYPE_ARGUMENT u += 4; break; // case 0x10: // CLASS_EXTENDS // case 0x11: // CLASS_TYPE_PARAMETER_BOUND // case 0x12: // METHOD_TYPE_PARAMETER_BOUND // case 0x17: // THROWS // case 0x42: // EXCEPTION_PARAMETER // case 0x43: // INSTANCEOF // case 0x44: // NEW // case 0x45: // CONSTRUCTOR_REFERENCE // case 0x46: // METHOD_REFERENCE default: u += 3; break; } int pathLength = readByte(u); if ((target >>> 24) == 0x42) { TypePath path = pathLength == 0 ? null : new TypePath(b, u); u += 1 + 2 * pathLength; u = readAnnotationValues(u + 2, c, true, mv.visitTryCatchAnnotation(target, path, readUTF8(u, c), visible)); } else { u = readAnnotationValues(u + 3 + 2 * pathLength, c, true, null); } } return offsets; }
java
private int[] readTypeAnnotations(final MethodVisitor mv, final Context context, int u, boolean visible) { char[] c = context.buffer; int[] offsets = new int[readUnsignedShort(u)]; u += 2; for (int i = 0; i < offsets.length; ++i) { offsets[i] = u; int target = readInt(u); switch (target >>> 24) { case 0x00: // CLASS_TYPE_PARAMETER case 0x01: // METHOD_TYPE_PARAMETER case 0x16: // METHOD_FORMAL_PARAMETER u += 2; break; case 0x13: // FIELD case 0x14: // METHOD_RETURN case 0x15: // METHOD_RECEIVER u += 1; break; case 0x40: // LOCAL_VARIABLE case 0x41: // RESOURCE_VARIABLE for (int j = readUnsignedShort(u + 1); j > 0; --j) { int start = readUnsignedShort(u + 3); int length = readUnsignedShort(u + 5); createLabel(start, context.labels); createLabel(start + length, context.labels); u += 6; } u += 3; break; case 0x47: // CAST case 0x48: // CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT case 0x49: // METHOD_INVOCATION_TYPE_ARGUMENT case 0x4A: // CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT case 0x4B: // METHOD_REFERENCE_TYPE_ARGUMENT u += 4; break; // case 0x10: // CLASS_EXTENDS // case 0x11: // CLASS_TYPE_PARAMETER_BOUND // case 0x12: // METHOD_TYPE_PARAMETER_BOUND // case 0x17: // THROWS // case 0x42: // EXCEPTION_PARAMETER // case 0x43: // INSTANCEOF // case 0x44: // NEW // case 0x45: // CONSTRUCTOR_REFERENCE // case 0x46: // METHOD_REFERENCE default: u += 3; break; } int pathLength = readByte(u); if ((target >>> 24) == 0x42) { TypePath path = pathLength == 0 ? null : new TypePath(b, u); u += 1 + 2 * pathLength; u = readAnnotationValues(u + 2, c, true, mv.visitTryCatchAnnotation(target, path, readUTF8(u, c), visible)); } else { u = readAnnotationValues(u + 3 + 2 * pathLength, c, true, null); } } return offsets; }
[ "private", "int", "[", "]", "readTypeAnnotations", "(", "final", "MethodVisitor", "mv", ",", "final", "Context", "context", ",", "int", "u", ",", "boolean", "visible", ")", "{", "char", "[", "]", "c", "=", "context", ".", "buffer", ";", "int", "[", "]", "offsets", "=", "new", "int", "[", "readUnsignedShort", "(", "u", ")", "]", ";", "u", "+=", "2", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "offsets", ".", "length", ";", "++", "i", ")", "{", "offsets", "[", "i", "]", "=", "u", ";", "int", "target", "=", "readInt", "(", "u", ")", ";", "switch", "(", "target", ">>>", "24", ")", "{", "case", "0x00", ":", "// CLASS_TYPE_PARAMETER", "case", "0x01", ":", "// METHOD_TYPE_PARAMETER", "case", "0x16", ":", "// METHOD_FORMAL_PARAMETER", "u", "+=", "2", ";", "break", ";", "case", "0x13", ":", "// FIELD", "case", "0x14", ":", "// METHOD_RETURN", "case", "0x15", ":", "// METHOD_RECEIVER", "u", "+=", "1", ";", "break", ";", "case", "0x40", ":", "// LOCAL_VARIABLE", "case", "0x41", ":", "// RESOURCE_VARIABLE", "for", "(", "int", "j", "=", "readUnsignedShort", "(", "u", "+", "1", ")", ";", "j", ">", "0", ";", "--", "j", ")", "{", "int", "start", "=", "readUnsignedShort", "(", "u", "+", "3", ")", ";", "int", "length", "=", "readUnsignedShort", "(", "u", "+", "5", ")", ";", "createLabel", "(", "start", ",", "context", ".", "labels", ")", ";", "createLabel", "(", "start", "+", "length", ",", "context", ".", "labels", ")", ";", "u", "+=", "6", ";", "}", "u", "+=", "3", ";", "break", ";", "case", "0x47", ":", "// CAST", "case", "0x48", ":", "// CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT", "case", "0x49", ":", "// METHOD_INVOCATION_TYPE_ARGUMENT", "case", "0x4A", ":", "// CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT", "case", "0x4B", ":", "// METHOD_REFERENCE_TYPE_ARGUMENT", "u", "+=", "4", ";", "break", ";", "// case 0x10: // CLASS_EXTENDS", "// case 0x11: // CLASS_TYPE_PARAMETER_BOUND", "// case 0x12: // METHOD_TYPE_PARAMETER_BOUND", "// case 0x17: // THROWS", "// case 0x42: // EXCEPTION_PARAMETER", "// case 0x43: // INSTANCEOF", "// case 0x44: // NEW", "// case 0x45: // CONSTRUCTOR_REFERENCE", "// case 0x46: // METHOD_REFERENCE", "default", ":", "u", "+=", "3", ";", "break", ";", "}", "int", "pathLength", "=", "readByte", "(", "u", ")", ";", "if", "(", "(", "target", ">>>", "24", ")", "==", "0x42", ")", "{", "TypePath", "path", "=", "pathLength", "==", "0", "?", "null", ":", "new", "TypePath", "(", "b", ",", "u", ")", ";", "u", "+=", "1", "+", "2", "*", "pathLength", ";", "u", "=", "readAnnotationValues", "(", "u", "+", "2", ",", "c", ",", "true", ",", "mv", ".", "visitTryCatchAnnotation", "(", "target", ",", "path", ",", "readUTF8", "(", "u", ",", "c", ")", ",", "visible", ")", ")", ";", "}", "else", "{", "u", "=", "readAnnotationValues", "(", "u", "+", "3", "+", "2", "*", "pathLength", ",", "c", ",", "true", ",", "null", ")", ";", "}", "}", "return", "offsets", ";", "}" ]
Parses a type annotation table to find the labels, and to visit the try catch block annotations. @param u the start offset of a type annotation table. @param mv the method visitor to be used to visit the try catch block annotations. @param context information about the class being parsed. @param visible if the type annotation table to parse contains runtime visible annotations. @return the start offset of each type annotation in the parsed table.
[ "Parses", "a", "type", "annotation", "table", "to", "find", "the", "labels", "and", "to", "visit", "the", "try", "catch", "block", "annotations", "." ]
ea5169b5c5ea7412fd762331c0c497165832e901
https://github.com/redkale/redkale/blob/ea5169b5c5ea7412fd762331c0c497165832e901/src/org/redkale/asm/ClassReader.java#L1786-L1848
160,577
redkale/redkale
src/org/redkale/asm/MethodWriter.java
MethodWriter.visitImplicitFirstFrame
private void visitImplicitFirstFrame() { // There can be at most descriptor.length() + 1 locals int frameIndex = startFrame(0, descriptor.length() + 1, 0); if ((access & Opcodes.ACC_STATIC) == 0) { if ((access & ACC_CONSTRUCTOR) == 0) { frame[frameIndex++] = Frame.OBJECT | cw.addType(cw.thisName); } else { frame[frameIndex++] = Frame.UNINITIALIZED_THIS; } } int i = 1; loop: while (true) { int j = i; switch (descriptor.charAt(i++)) { case 'Z': case 'C': case 'B': case 'S': case 'I': frame[frameIndex++] = Frame.INTEGER; break; case 'F': frame[frameIndex++] = Frame.FLOAT; break; case 'J': frame[frameIndex++] = Frame.LONG; break; case 'D': frame[frameIndex++] = Frame.DOUBLE; break; case '[': while (descriptor.charAt(i) == '[') { ++i; } if (descriptor.charAt(i) == 'L') { ++i; while (descriptor.charAt(i) != ';') { ++i; } } frame[frameIndex++] = Frame.type(cw, descriptor.substring(j, ++i)); break; case 'L': while (descriptor.charAt(i) != ';') { ++i; } frame[frameIndex++] = Frame.OBJECT | cw.addType(descriptor.substring(j + 1, i++)); break; default: break loop; } } frame[1] = frameIndex - 3; endFrame(); }
java
private void visitImplicitFirstFrame() { // There can be at most descriptor.length() + 1 locals int frameIndex = startFrame(0, descriptor.length() + 1, 0); if ((access & Opcodes.ACC_STATIC) == 0) { if ((access & ACC_CONSTRUCTOR) == 0) { frame[frameIndex++] = Frame.OBJECT | cw.addType(cw.thisName); } else { frame[frameIndex++] = Frame.UNINITIALIZED_THIS; } } int i = 1; loop: while (true) { int j = i; switch (descriptor.charAt(i++)) { case 'Z': case 'C': case 'B': case 'S': case 'I': frame[frameIndex++] = Frame.INTEGER; break; case 'F': frame[frameIndex++] = Frame.FLOAT; break; case 'J': frame[frameIndex++] = Frame.LONG; break; case 'D': frame[frameIndex++] = Frame.DOUBLE; break; case '[': while (descriptor.charAt(i) == '[') { ++i; } if (descriptor.charAt(i) == 'L') { ++i; while (descriptor.charAt(i) != ';') { ++i; } } frame[frameIndex++] = Frame.type(cw, descriptor.substring(j, ++i)); break; case 'L': while (descriptor.charAt(i) != ';') { ++i; } frame[frameIndex++] = Frame.OBJECT | cw.addType(descriptor.substring(j + 1, i++)); break; default: break loop; } } frame[1] = frameIndex - 3; endFrame(); }
[ "private", "void", "visitImplicitFirstFrame", "(", ")", "{", "// There can be at most descriptor.length() + 1 locals", "int", "frameIndex", "=", "startFrame", "(", "0", ",", "descriptor", ".", "length", "(", ")", "+", "1", ",", "0", ")", ";", "if", "(", "(", "access", "&", "Opcodes", ".", "ACC_STATIC", ")", "==", "0", ")", "{", "if", "(", "(", "access", "&", "ACC_CONSTRUCTOR", ")", "==", "0", ")", "{", "frame", "[", "frameIndex", "++", "]", "=", "Frame", ".", "OBJECT", "|", "cw", ".", "addType", "(", "cw", ".", "thisName", ")", ";", "}", "else", "{", "frame", "[", "frameIndex", "++", "]", "=", "Frame", ".", "UNINITIALIZED_THIS", ";", "}", "}", "int", "i", "=", "1", ";", "loop", ":", "while", "(", "true", ")", "{", "int", "j", "=", "i", ";", "switch", "(", "descriptor", ".", "charAt", "(", "i", "++", ")", ")", "{", "case", "'", "'", ":", "case", "'", "'", ":", "case", "'", "'", ":", "case", "'", "'", ":", "case", "'", "'", ":", "frame", "[", "frameIndex", "++", "]", "=", "Frame", ".", "INTEGER", ";", "break", ";", "case", "'", "'", ":", "frame", "[", "frameIndex", "++", "]", "=", "Frame", ".", "FLOAT", ";", "break", ";", "case", "'", "'", ":", "frame", "[", "frameIndex", "++", "]", "=", "Frame", ".", "LONG", ";", "break", ";", "case", "'", "'", ":", "frame", "[", "frameIndex", "++", "]", "=", "Frame", ".", "DOUBLE", ";", "break", ";", "case", "'", "'", ":", "while", "(", "descriptor", ".", "charAt", "(", "i", ")", "==", "'", "'", ")", "{", "++", "i", ";", "}", "if", "(", "descriptor", ".", "charAt", "(", "i", ")", "==", "'", "'", ")", "{", "++", "i", ";", "while", "(", "descriptor", ".", "charAt", "(", "i", ")", "!=", "'", "'", ")", "{", "++", "i", ";", "}", "}", "frame", "[", "frameIndex", "++", "]", "=", "Frame", ".", "type", "(", "cw", ",", "descriptor", ".", "substring", "(", "j", ",", "++", "i", ")", ")", ";", "break", ";", "case", "'", "'", ":", "while", "(", "descriptor", ".", "charAt", "(", "i", ")", "!=", "'", "'", ")", "{", "++", "i", ";", "}", "frame", "[", "frameIndex", "++", "]", "=", "Frame", ".", "OBJECT", "|", "cw", ".", "addType", "(", "descriptor", ".", "substring", "(", "j", "+", "1", ",", "i", "++", ")", ")", ";", "break", ";", "default", ":", "break", "loop", ";", "}", "}", "frame", "[", "1", "]", "=", "frameIndex", "-", "3", ";", "endFrame", "(", ")", ";", "}" ]
Visit the implicit first frame of this method.
[ "Visit", "the", "implicit", "first", "frame", "of", "this", "method", "." ]
ea5169b5c5ea7412fd762331c0c497165832e901
https://github.com/redkale/redkale/blob/ea5169b5c5ea7412fd762331c0c497165832e901/src/org/redkale/asm/MethodWriter.java#L1809-L1864
160,578
redkale/redkale
src/org/redkale/asm/ClassWriter.java
ClassWriter.newStringishItem
Item newStringishItem(final int type, final String value) { key2.set(type, value, null, null); Item result = get(key2); if (result == null) { pool.put12(type, newUTF8(value)); result = new Item(index++, key2); put(result); } return result; }
java
Item newStringishItem(final int type, final String value) { key2.set(type, value, null, null); Item result = get(key2); if (result == null) { pool.put12(type, newUTF8(value)); result = new Item(index++, key2); put(result); } return result; }
[ "Item", "newStringishItem", "(", "final", "int", "type", ",", "final", "String", "value", ")", "{", "key2", ".", "set", "(", "type", ",", "value", ",", "null", ",", "null", ")", ";", "Item", "result", "=", "get", "(", "key2", ")", ";", "if", "(", "result", "==", "null", ")", "{", "pool", ".", "put12", "(", "type", ",", "newUTF8", "(", "value", ")", ")", ";", "result", "=", "new", "Item", "(", "index", "++", ",", "key2", ")", ";", "put", "(", "result", ")", ";", "}", "return", "result", ";", "}" ]
Adds a string reference, a class reference, a method type, a module or a package to the constant pool of the class being build. Does nothing if the constant pool already contains a similar item. @param type a type among STR, CLASS, MTYPE, MODULE or PACKAGE @param value string value of the reference. @return a new or already existing reference item.
[ "Adds", "a", "string", "reference", "a", "class", "reference", "a", "method", "type", "a", "module", "or", "a", "package", "to", "the", "constant", "pool", "of", "the", "class", "being", "build", ".", "Does", "nothing", "if", "the", "constant", "pool", "already", "contains", "a", "similar", "item", "." ]
ea5169b5c5ea7412fd762331c0c497165832e901
https://github.com/redkale/redkale/blob/ea5169b5c5ea7412fd762331c0c497165832e901/src/org/redkale/asm/ClassWriter.java#L1188-L1197
160,579
redkale/redkale
src/org/redkale/asm/MethodVisitor.java
MethodVisitor.visitParameter
public void visitParameter(String name, int access) { if (mv != null) { mv.visitParameter(name, access); } }
java
public void visitParameter(String name, int access) { if (mv != null) { mv.visitParameter(name, access); } }
[ "public", "void", "visitParameter", "(", "String", "name", ",", "int", "access", ")", "{", "if", "(", "mv", "!=", "null", ")", "{", "mv", ".", "visitParameter", "(", "name", ",", "access", ")", ";", "}", "}" ]
Visits a parameter of this method. @param name parameter name or null if none is provided. @param access the parameter's access flags, only <tt>ACC_FINAL</tt>, <tt>ACC_SYNTHETIC</tt> or/and <tt>ACC_MANDATED</tt> are allowed (see {@link Opcodes}).
[ "Visits", "a", "parameter", "of", "this", "method", "." ]
ea5169b5c5ea7412fd762331c0c497165832e901
https://github.com/redkale/redkale/blob/ea5169b5c5ea7412fd762331c0c497165832e901/src/org/redkale/asm/MethodVisitor.java#L139-L143
160,580
redkale/redkale
src/org/redkale/asm/MethodVisitor.java
MethodVisitor.visitMethodInsn
public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) { if (mv != null) { mv.visitMethodInsn(opcode, owner, name, desc, itf); } }
java
public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) { if (mv != null) { mv.visitMethodInsn(opcode, owner, name, desc, itf); } }
[ "public", "void", "visitMethodInsn", "(", "int", "opcode", ",", "String", "owner", ",", "String", "name", ",", "String", "desc", ",", "boolean", "itf", ")", "{", "if", "(", "mv", "!=", "null", ")", "{", "mv", ".", "visitMethodInsn", "(", "opcode", ",", "owner", ",", "name", ",", "desc", ",", "itf", ")", ";", "}", "}" ]
Visits a method instruction. A method instruction is an instruction that invokes a method. @param opcode the opcode of the type instruction to be visited. This opcode is either INVOKEVIRTUAL, INVOKESPECIAL, INVOKESTATIC or INVOKEINTERFACE. @param owner the internal name of the method's owner class (see {@link Type#getInternalName() getInternalName}). @param name the method's name. @param desc the method's descriptor (see {@link Type Type}). @param itf if the method's owner class is an interface.
[ "Visits", "a", "method", "instruction", ".", "A", "method", "instruction", "is", "an", "instruction", "that", "invokes", "a", "method", "." ]
ea5169b5c5ea7412fd762331c0c497165832e901
https://github.com/redkale/redkale/blob/ea5169b5c5ea7412fd762331c0c497165832e901/src/org/redkale/asm/MethodVisitor.java#L466-L471
160,581
redkale/redkale
src/org/redkale/asm/MethodVisitor.java
MethodVisitor.visitLocalVariableAnnotation
public AnnotationVisitor visitLocalVariableAnnotation(int typeRef, TypePath typePath, Label[] start, Label[] end, int[] index, String desc, boolean visible) { if (mv != null) { return mv.visitLocalVariableAnnotation(typeRef, typePath, start, end, index, desc, visible); } return null; }
java
public AnnotationVisitor visitLocalVariableAnnotation(int typeRef, TypePath typePath, Label[] start, Label[] end, int[] index, String desc, boolean visible) { if (mv != null) { return mv.visitLocalVariableAnnotation(typeRef, typePath, start, end, index, desc, visible); } return null; }
[ "public", "AnnotationVisitor", "visitLocalVariableAnnotation", "(", "int", "typeRef", ",", "TypePath", "typePath", ",", "Label", "[", "]", "start", ",", "Label", "[", "]", "end", ",", "int", "[", "]", "index", ",", "String", "desc", ",", "boolean", "visible", ")", "{", "if", "(", "mv", "!=", "null", ")", "{", "return", "mv", ".", "visitLocalVariableAnnotation", "(", "typeRef", ",", "typePath", ",", "start", ",", "end", ",", "index", ",", "desc", ",", "visible", ")", ";", "}", "return", "null", ";", "}" ]
Visits an annotation on a local variable type. @param typeRef a reference to the annotated type. The sort of this type reference must be {@link TypeReference#LOCAL_VARIABLE LOCAL_VARIABLE} or {@link TypeReference#RESOURCE_VARIABLE RESOURCE_VARIABLE}. See {@link TypeReference}. @param typePath the path to the annotated type argument, wildcard bound, array element type, or static inner type within 'typeRef'. May be <tt>null</tt> if the annotation targets 'typeRef' as a whole. @param start the fist instructions corresponding to the continuous ranges that make the scope of this local variable (inclusive). @param end the last instructions corresponding to the continuous ranges that make the scope of this local variable (exclusive). This array must have the same size as the 'start' array. @param index the local variable's index in each range. This array must have the same size as the 'start' array. @param desc the class descriptor of the annotation class. @param visible <tt>true</tt> if the annotation is visible at runtime. @return a visitor to visit the annotation values, or <tt>null</tt> if this visitor is not interested in visiting this annotation.
[ "Visits", "an", "annotation", "on", "a", "local", "variable", "type", "." ]
ea5169b5c5ea7412fd762331c0c497165832e901
https://github.com/redkale/redkale/blob/ea5169b5c5ea7412fd762331c0c497165832e901/src/org/redkale/asm/MethodVisitor.java#L803-L811
160,582
GwtMaterialDesign/gwt-material
gwt-material/src/main/java/gwt/material/design/client/ui/MaterialCollection.java
MaterialCollection.setHeader
public void setHeader(String header) { headerLabel.getElement().setInnerSafeHtml(SafeHtmlUtils.fromString(header)); addStyleName(CssName.WITH_HEADER); ListItem item = new ListItem(headerLabel); UiHelper.addMousePressedHandlers(item); item.setStyleName(CssName.COLLECTION_HEADER); insert(item, 0); }
java
public void setHeader(String header) { headerLabel.getElement().setInnerSafeHtml(SafeHtmlUtils.fromString(header)); addStyleName(CssName.WITH_HEADER); ListItem item = new ListItem(headerLabel); UiHelper.addMousePressedHandlers(item); item.setStyleName(CssName.COLLECTION_HEADER); insert(item, 0); }
[ "public", "void", "setHeader", "(", "String", "header", ")", "{", "headerLabel", ".", "getElement", "(", ")", ".", "setInnerSafeHtml", "(", "SafeHtmlUtils", ".", "fromString", "(", "header", ")", ")", ";", "addStyleName", "(", "CssName", ".", "WITH_HEADER", ")", ";", "ListItem", "item", "=", "new", "ListItem", "(", "headerLabel", ")", ";", "UiHelper", ".", "addMousePressedHandlers", "(", "item", ")", ";", "item", ".", "setStyleName", "(", "CssName", ".", "COLLECTION_HEADER", ")", ";", "insert", "(", "item", ",", "0", ")", ";", "}" ]
Sets the header of the collection component.
[ "Sets", "the", "header", "of", "the", "collection", "component", "." ]
86feefb282b007c0a44784c09e651a50f257138e
https://github.com/GwtMaterialDesign/gwt-material/blob/86feefb282b007c0a44784c09e651a50f257138e/gwt-material/src/main/java/gwt/material/design/client/ui/MaterialCollection.java#L147-L154
160,583
GwtMaterialDesign/gwt-material
gwt-material/src/main/java/gwt/material/design/client/ui/MaterialTooltip.java
MaterialTooltip.setHtml
public void setHtml(String html) { this.html = html; if (widget != null) { if (widget.isAttached()) { tooltipElement.find("span") .html(html != null ? html : ""); } else { widget.addAttachHandler(event -> tooltipElement.find("span") .html(html != null ? html : "")); } } else { GWT.log("Please initialize the Target widget.", new IllegalStateException()); } }
java
public void setHtml(String html) { this.html = html; if (widget != null) { if (widget.isAttached()) { tooltipElement.find("span") .html(html != null ? html : ""); } else { widget.addAttachHandler(event -> tooltipElement.find("span") .html(html != null ? html : "")); } } else { GWT.log("Please initialize the Target widget.", new IllegalStateException()); } }
[ "public", "void", "setHtml", "(", "String", "html", ")", "{", "this", ".", "html", "=", "html", ";", "if", "(", "widget", "!=", "null", ")", "{", "if", "(", "widget", ".", "isAttached", "(", ")", ")", "{", "tooltipElement", ".", "find", "(", "\"span\"", ")", ".", "html", "(", "html", "!=", "null", "?", "html", ":", "\"\"", ")", ";", "}", "else", "{", "widget", ".", "addAttachHandler", "(", "event", "->", "tooltipElement", ".", "find", "(", "\"span\"", ")", ".", "html", "(", "html", "!=", "null", "?", "html", ":", "\"\"", ")", ")", ";", "}", "}", "else", "{", "GWT", ".", "log", "(", "\"Please initialize the Target widget.\"", ",", "new", "IllegalStateException", "(", ")", ")", ";", "}", "}" ]
Set the html as value inside the tooltip.
[ "Set", "the", "html", "as", "value", "inside", "the", "tooltip", "." ]
86feefb282b007c0a44784c09e651a50f257138e
https://github.com/GwtMaterialDesign/gwt-material/blob/86feefb282b007c0a44784c09e651a50f257138e/gwt-material/src/main/java/gwt/material/design/client/ui/MaterialTooltip.java#L325-L340
160,584
GwtMaterialDesign/gwt-material
gwt-material/src/main/java/gwt/material/design/client/ui/MaterialListValueBox.java
MaterialListValueBox.addItem
public void addItem(T value, String text, boolean reload) { values.add(value); listBox.addItem(text, keyFactory.generateKey(value)); if (reload) { reload(); } }
java
public void addItem(T value, String text, boolean reload) { values.add(value); listBox.addItem(text, keyFactory.generateKey(value)); if (reload) { reload(); } }
[ "public", "void", "addItem", "(", "T", "value", ",", "String", "text", ",", "boolean", "reload", ")", "{", "values", ".", "add", "(", "value", ")", ";", "listBox", ".", "addItem", "(", "text", ",", "keyFactory", ".", "generateKey", "(", "value", ")", ")", ";", "if", "(", "reload", ")", "{", "reload", "(", ")", ";", "}", "}" ]
Adds an item to the list box, specifying an initial value for the item. @param value the item's value, to be submitted if it is part of a {@link FormPanel}; cannot be <code>null</code> @param text the text of the item to be added @param reload perform a 'material select' reload to update the DOM.
[ "Adds", "an", "item", "to", "the", "list", "box", "specifying", "an", "initial", "value", "for", "the", "item", "." ]
86feefb282b007c0a44784c09e651a50f257138e
https://github.com/GwtMaterialDesign/gwt-material/blob/86feefb282b007c0a44784c09e651a50f257138e/gwt-material/src/main/java/gwt/material/design/client/ui/MaterialListValueBox.java#L258-L265
160,585
GwtMaterialDesign/gwt-material
gwt-material/src/main/java/gwt/material/design/client/ui/MaterialListValueBox.java
MaterialListValueBox.addItem
public void addItem(T value, Direction dir, String text) { addItem(value, dir, text, true); }
java
public void addItem(T value, Direction dir, String text) { addItem(value, dir, text, true); }
[ "public", "void", "addItem", "(", "T", "value", ",", "Direction", "dir", ",", "String", "text", ")", "{", "addItem", "(", "value", ",", "dir", ",", "text", ",", "true", ")", ";", "}" ]
Adds an item to the list box, specifying its direction and an initial value for the item. @param value the item's value, to be submitted if it is part of a {@link FormPanel}; cannot be <code>null</code> @param dir the item's direction @param text the text of the item to be added
[ "Adds", "an", "item", "to", "the", "list", "box", "specifying", "its", "direction", "and", "an", "initial", "value", "for", "the", "item", "." ]
86feefb282b007c0a44784c09e651a50f257138e
https://github.com/GwtMaterialDesign/gwt-material/blob/86feefb282b007c0a44784c09e651a50f257138e/gwt-material/src/main/java/gwt/material/design/client/ui/MaterialListValueBox.java#L276-L278
160,586
GwtMaterialDesign/gwt-material
gwt-material/src/main/java/gwt/material/design/client/ui/MaterialListValueBox.java
MaterialListValueBox.removeValue
public void removeValue(T value, boolean reload) { int idx = getIndex(value); if (idx >= 0) { removeItemInternal(idx, reload); } }
java
public void removeValue(T value, boolean reload) { int idx = getIndex(value); if (idx >= 0) { removeItemInternal(idx, reload); } }
[ "public", "void", "removeValue", "(", "T", "value", ",", "boolean", "reload", ")", "{", "int", "idx", "=", "getIndex", "(", "value", ")", ";", "if", "(", "idx", ">=", "0", ")", "{", "removeItemInternal", "(", "idx", ",", "reload", ")", ";", "}", "}" ]
Removes a value from the list box. Nothing is done if the value isn't on the list box. @param value the value to be removed from the list @param reload perform a 'material select' reload to update the DOM.
[ "Removes", "a", "value", "from", "the", "list", "box", ".", "Nothing", "is", "done", "if", "the", "value", "isn", "t", "on", "the", "list", "box", "." ]
86feefb282b007c0a44784c09e651a50f257138e
https://github.com/GwtMaterialDesign/gwt-material/blob/86feefb282b007c0a44784c09e651a50f257138e/gwt-material/src/main/java/gwt/material/design/client/ui/MaterialListValueBox.java#L507-L512
160,587
GwtMaterialDesign/gwt-material
gwt-material/src/main/java/gwt/material/design/client/ui/MaterialListValueBox.java
MaterialListValueBox.clear
@Override public void clear() { values.clear(); listBox.clear(); clearStatusText(); if (emptyPlaceHolder != null) { insertEmptyPlaceHolder(emptyPlaceHolder); } reload(); if (isAllowBlank()) { addBlankItemIfNeeded(); } }
java
@Override public void clear() { values.clear(); listBox.clear(); clearStatusText(); if (emptyPlaceHolder != null) { insertEmptyPlaceHolder(emptyPlaceHolder); } reload(); if (isAllowBlank()) { addBlankItemIfNeeded(); } }
[ "@", "Override", "public", "void", "clear", "(", ")", "{", "values", ".", "clear", "(", ")", ";", "listBox", ".", "clear", "(", ")", ";", "clearStatusText", "(", ")", ";", "if", "(", "emptyPlaceHolder", "!=", "null", ")", "{", "insertEmptyPlaceHolder", "(", "emptyPlaceHolder", ")", ";", "}", "reload", "(", ")", ";", "if", "(", "isAllowBlank", "(", ")", ")", "{", "addBlankItemIfNeeded", "(", ")", ";", "}", "}" ]
Removes all items from the list box.
[ "Removes", "all", "items", "from", "the", "list", "box", "." ]
86feefb282b007c0a44784c09e651a50f257138e
https://github.com/GwtMaterialDesign/gwt-material/blob/86feefb282b007c0a44784c09e651a50f257138e/gwt-material/src/main/java/gwt/material/design/client/ui/MaterialListValueBox.java#L527-L540
160,588
GwtMaterialDesign/gwt-material
gwt-material/src/main/java/gwt/material/design/client/ui/MaterialListValueBox.java
MaterialListValueBox.getItemsSelected
public String[] getItemsSelected() { List<String> selected = new LinkedList<>(); for (int i = getIndexOffset(); i < listBox.getItemCount(); i++) { if (listBox.isItemSelected(i)) { selected.add(listBox.getValue(i)); } } return selected.toArray(new String[selected.size()]); }
java
public String[] getItemsSelected() { List<String> selected = new LinkedList<>(); for (int i = getIndexOffset(); i < listBox.getItemCount(); i++) { if (listBox.isItemSelected(i)) { selected.add(listBox.getValue(i)); } } return selected.toArray(new String[selected.size()]); }
[ "public", "String", "[", "]", "getItemsSelected", "(", ")", "{", "List", "<", "String", ">", "selected", "=", "new", "LinkedList", "<>", "(", ")", ";", "for", "(", "int", "i", "=", "getIndexOffset", "(", ")", ";", "i", "<", "listBox", ".", "getItemCount", "(", ")", ";", "i", "++", ")", "{", "if", "(", "listBox", ".", "isItemSelected", "(", "i", ")", ")", "{", "selected", ".", "add", "(", "listBox", ".", "getValue", "(", "i", ")", ")", ";", "}", "}", "return", "selected", ".", "toArray", "(", "new", "String", "[", "selected", ".", "size", "(", ")", "]", ")", ";", "}" ]
Returns all selected values of the list box, or empty array if none. @return the selected values of the list box
[ "Returns", "all", "selected", "values", "of", "the", "list", "box", "or", "empty", "array", "if", "none", "." ]
86feefb282b007c0a44784c09e651a50f257138e
https://github.com/GwtMaterialDesign/gwt-material/blob/86feefb282b007c0a44784c09e651a50f257138e/gwt-material/src/main/java/gwt/material/design/client/ui/MaterialListValueBox.java#L977-L985
160,589
GwtMaterialDesign/gwt-material
gwt-material/src/main/java/gwt/material/design/client/ui/MaterialListValueBox.java
MaterialListValueBox.setValueSelected
public void setValueSelected(T value, boolean selected) { int idx = getIndex(value); if (idx >= 0) { setItemSelectedInternal(idx, selected); } }
java
public void setValueSelected(T value, boolean selected) { int idx = getIndex(value); if (idx >= 0) { setItemSelectedInternal(idx, selected); } }
[ "public", "void", "setValueSelected", "(", "T", "value", ",", "boolean", "selected", ")", "{", "int", "idx", "=", "getIndex", "(", "value", ")", ";", "if", "(", "idx", ">=", "0", ")", "{", "setItemSelectedInternal", "(", "idx", ",", "selected", ")", ";", "}", "}" ]
Sets whether an individual list value is selected. @param value the value of the item to be selected or unselected @param selected <code>true</code> to select the item
[ "Sets", "whether", "an", "individual", "list", "value", "is", "selected", "." ]
86feefb282b007c0a44784c09e651a50f257138e
https://github.com/GwtMaterialDesign/gwt-material/blob/86feefb282b007c0a44784c09e651a50f257138e/gwt-material/src/main/java/gwt/material/design/client/ui/MaterialListValueBox.java#L1010-L1015
160,590
GwtMaterialDesign/gwt-material
gwt-material/src/main/java/gwt/material/design/client/ui/MaterialListValueBox.java
MaterialListValueBox.getIndex
public int getIndex(T value) { int count = getItemCount(); for (int i = 0; i < count; i++) { if (Objects.equals(getValue(i), value)) { return i; } } return -1; }
java
public int getIndex(T value) { int count = getItemCount(); for (int i = 0; i < count; i++) { if (Objects.equals(getValue(i), value)) { return i; } } return -1; }
[ "public", "int", "getIndex", "(", "T", "value", ")", "{", "int", "count", "=", "getItemCount", "(", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "count", ";", "i", "++", ")", "{", "if", "(", "Objects", ".", "equals", "(", "getValue", "(", "i", ")", ",", "value", ")", ")", "{", "return", "i", ";", "}", "}", "return", "-", "1", ";", "}" ]
Gets the index of the specified value. @param value the value of the item to be found @return the index of the value
[ "Gets", "the", "index", "of", "the", "specified", "value", "." ]
86feefb282b007c0a44784c09e651a50f257138e
https://github.com/GwtMaterialDesign/gwt-material/blob/86feefb282b007c0a44784c09e651a50f257138e/gwt-material/src/main/java/gwt/material/design/client/ui/MaterialListValueBox.java#L1023-L1031
160,591
GwtMaterialDesign/gwt-material
gwt-material/src/main/java/gwt/material/design/client/ui/MaterialSearch.java
MaterialSearch.addSearchFinishHandler
@Override public HandlerRegistration addSearchFinishHandler(final SearchFinishEvent.SearchFinishHandler handler) { return addHandler(handler, SearchFinishEvent.TYPE); }
java
@Override public HandlerRegistration addSearchFinishHandler(final SearchFinishEvent.SearchFinishHandler handler) { return addHandler(handler, SearchFinishEvent.TYPE); }
[ "@", "Override", "public", "HandlerRegistration", "addSearchFinishHandler", "(", "final", "SearchFinishEvent", ".", "SearchFinishHandler", "handler", ")", "{", "return", "addHandler", "(", "handler", ",", "SearchFinishEvent", ".", "TYPE", ")", ";", "}" ]
This handler will be triggered when search is finish
[ "This", "handler", "will", "be", "triggered", "when", "search", "is", "finish" ]
86feefb282b007c0a44784c09e651a50f257138e
https://github.com/GwtMaterialDesign/gwt-material/blob/86feefb282b007c0a44784c09e651a50f257138e/gwt-material/src/main/java/gwt/material/design/client/ui/MaterialSearch.java#L371-L374
160,592
GwtMaterialDesign/gwt-material
gwt-material/src/main/java/gwt/material/design/client/ui/MaterialSearch.java
MaterialSearch.addSearchNoResultHandler
@Override public HandlerRegistration addSearchNoResultHandler(final SearchNoResultEvent.SearchNoResultHandler handler) { return addHandler(handler, SearchNoResultEvent.TYPE); }
java
@Override public HandlerRegistration addSearchNoResultHandler(final SearchNoResultEvent.SearchNoResultHandler handler) { return addHandler(handler, SearchNoResultEvent.TYPE); }
[ "@", "Override", "public", "HandlerRegistration", "addSearchNoResultHandler", "(", "final", "SearchNoResultEvent", ".", "SearchNoResultHandler", "handler", ")", "{", "return", "addHandler", "(", "handler", ",", "SearchNoResultEvent", ".", "TYPE", ")", ";", "}" ]
This handler will be triggered when there's no search result
[ "This", "handler", "will", "be", "triggered", "when", "there", "s", "no", "search", "result" ]
86feefb282b007c0a44784c09e651a50f257138e
https://github.com/GwtMaterialDesign/gwt-material/blob/86feefb282b007c0a44784c09e651a50f257138e/gwt-material/src/main/java/gwt/material/design/client/ui/MaterialSearch.java#L379-L382
160,593
GwtMaterialDesign/gwt-material
gwt-material/src/main/java/gwt/material/design/client/base/AbstractButton.java
AbstractButton.setSize
public void setSize(ButtonSize size) { if (this.size != null) { removeStyleName(this.size.getCssName()); } this.size = size; if (size != null) { addStyleName(size.getCssName()); } }
java
public void setSize(ButtonSize size) { if (this.size != null) { removeStyleName(this.size.getCssName()); } this.size = size; if (size != null) { addStyleName(size.getCssName()); } }
[ "public", "void", "setSize", "(", "ButtonSize", "size", ")", "{", "if", "(", "this", ".", "size", "!=", "null", ")", "{", "removeStyleName", "(", "this", ".", "size", ".", "getCssName", "(", ")", ")", ";", "}", "this", ".", "size", "=", "size", ";", "if", "(", "size", "!=", "null", ")", "{", "addStyleName", "(", "size", ".", "getCssName", "(", ")", ")", ";", "}", "}" ]
Set the buttons size.
[ "Set", "the", "buttons", "size", "." ]
86feefb282b007c0a44784c09e651a50f257138e
https://github.com/GwtMaterialDesign/gwt-material/blob/86feefb282b007c0a44784c09e651a50f257138e/gwt-material/src/main/java/gwt/material/design/client/base/AbstractButton.java#L136-L145
160,594
GwtMaterialDesign/gwt-material
gwt-material/src/main/java/gwt/material/design/client/base/AbstractButton.java
AbstractButton.setText
public void setText(String text) { span.setText(text); if (!span.isAttached()) { add(span); } }
java
public void setText(String text) { span.setText(text); if (!span.isAttached()) { add(span); } }
[ "public", "void", "setText", "(", "String", "text", ")", "{", "span", ".", "setText", "(", "text", ")", ";", "if", "(", "!", "span", ".", "isAttached", "(", ")", ")", "{", "add", "(", "span", ")", ";", "}", "}" ]
Set the buttons span text.
[ "Set", "the", "buttons", "span", "text", "." ]
86feefb282b007c0a44784c09e651a50f257138e
https://github.com/GwtMaterialDesign/gwt-material/blob/86feefb282b007c0a44784c09e651a50f257138e/gwt-material/src/main/java/gwt/material/design/client/base/AbstractButton.java#L164-L170
160,595
GwtMaterialDesign/gwt-material
gwt-material/src/main/java/gwt/material/design/client/base/helper/ColorHelper.java
ColorHelper.fromStyleName
public static <E extends Enum<? extends Style.HasCssName>> E fromStyleName(final String styleName, final Class<E> enumClass, final E defaultValue) { return EnumHelper.fromStyleName(styleName, enumClass, defaultValue, true); }
java
public static <E extends Enum<? extends Style.HasCssName>> E fromStyleName(final String styleName, final Class<E> enumClass, final E defaultValue) { return EnumHelper.fromStyleName(styleName, enumClass, defaultValue, true); }
[ "public", "static", "<", "E", "extends", "Enum", "<", "?", "extends", "Style", ".", "HasCssName", ">", ">", "E", "fromStyleName", "(", "final", "String", "styleName", ",", "final", "Class", "<", "E", ">", "enumClass", ",", "final", "E", "defaultValue", ")", "{", "return", "EnumHelper", ".", "fromStyleName", "(", "styleName", ",", "enumClass", ",", "defaultValue", ",", "true", ")", ";", "}" ]
Returns first enum constant found.. @param styleName Space-separated list of styles @param enumClass Type of enum @param defaultValue Default value of no match was found @return First enum constant found or default value
[ "Returns", "first", "enum", "constant", "found", ".." ]
86feefb282b007c0a44784c09e651a50f257138e
https://github.com/GwtMaterialDesign/gwt-material/blob/86feefb282b007c0a44784c09e651a50f257138e/gwt-material/src/main/java/gwt/material/design/client/base/helper/ColorHelper.java#L40-L44
160,596
GwtMaterialDesign/gwt-material
gwt-material/src/main/java/gwt/material/design/client/ui/animate/MaterialAnimation.java
MaterialAnimation.stopAnimation
public void stopAnimation() { if(widget != null) { widget.removeStyleName("animated"); widget.removeStyleName(transition.getCssName()); widget.removeStyleName(CssName.INFINITE); } }
java
public void stopAnimation() { if(widget != null) { widget.removeStyleName("animated"); widget.removeStyleName(transition.getCssName()); widget.removeStyleName(CssName.INFINITE); } }
[ "public", "void", "stopAnimation", "(", ")", "{", "if", "(", "widget", "!=", "null", ")", "{", "widget", ".", "removeStyleName", "(", "\"animated\"", ")", ";", "widget", ".", "removeStyleName", "(", "transition", ".", "getCssName", "(", ")", ")", ";", "widget", ".", "removeStyleName", "(", "CssName", ".", "INFINITE", ")", ";", "}", "}" ]
Stop an animation.
[ "Stop", "an", "animation", "." ]
86feefb282b007c0a44784c09e651a50f257138e
https://github.com/GwtMaterialDesign/gwt-material/blob/86feefb282b007c0a44784c09e651a50f257138e/gwt-material/src/main/java/gwt/material/design/client/ui/animate/MaterialAnimation.java#L182-L188
160,597
GwtMaterialDesign/gwt-material
gwt-material/src/main/java/gwt/material/design/client/ui/MaterialValueBox.java
MaterialValueBox.clear
public void clear() { valueBoxBase.setText(""); clearStatusText(); if (getPlaceholder() == null || getPlaceholder().isEmpty()) { label.removeStyleName(CssName.ACTIVE); } }
java
public void clear() { valueBoxBase.setText(""); clearStatusText(); if (getPlaceholder() == null || getPlaceholder().isEmpty()) { label.removeStyleName(CssName.ACTIVE); } }
[ "public", "void", "clear", "(", ")", "{", "valueBoxBase", ".", "setText", "(", "\"\"", ")", ";", "clearStatusText", "(", ")", ";", "if", "(", "getPlaceholder", "(", ")", "==", "null", "||", "getPlaceholder", "(", ")", ".", "isEmpty", "(", ")", ")", "{", "label", ".", "removeStyleName", "(", "CssName", ".", "ACTIVE", ")", ";", "}", "}" ]
Resets the text box by removing its content and resetting visual state.
[ "Resets", "the", "text", "box", "by", "removing", "its", "content", "and", "resetting", "visual", "state", "." ]
86feefb282b007c0a44784c09e651a50f257138e
https://github.com/GwtMaterialDesign/gwt-material/blob/86feefb282b007c0a44784c09e651a50f257138e/gwt-material/src/main/java/gwt/material/design/client/ui/MaterialValueBox.java#L154-L161
160,598
GwtMaterialDesign/gwt-material
gwt-material/src/main/java/gwt/material/design/client/ui/MaterialValueBox.java
MaterialValueBox.updateLabelActiveStyle
protected void updateLabelActiveStyle() { if (this.valueBoxBase.getText() != null && !this.valueBoxBase.getText().isEmpty()) { label.addStyleName(CssName.ACTIVE); } else { label.removeStyleName(CssName.ACTIVE); } }
java
protected void updateLabelActiveStyle() { if (this.valueBoxBase.getText() != null && !this.valueBoxBase.getText().isEmpty()) { label.addStyleName(CssName.ACTIVE); } else { label.removeStyleName(CssName.ACTIVE); } }
[ "protected", "void", "updateLabelActiveStyle", "(", ")", "{", "if", "(", "this", ".", "valueBoxBase", ".", "getText", "(", ")", "!=", "null", "&&", "!", "this", ".", "valueBoxBase", ".", "getText", "(", ")", ".", "isEmpty", "(", ")", ")", "{", "label", ".", "addStyleName", "(", "CssName", ".", "ACTIVE", ")", ";", "}", "else", "{", "label", ".", "removeStyleName", "(", "CssName", ".", "ACTIVE", ")", ";", "}", "}" ]
Updates the style of the field label according to the field value if the field value is empty - null or "" - removes the label 'active' style else will add the 'active' style to the field label.
[ "Updates", "the", "style", "of", "the", "field", "label", "according", "to", "the", "field", "value", "if", "the", "field", "value", "is", "empty", "-", "null", "or", "-", "removes", "the", "label", "active", "style", "else", "will", "add", "the", "active", "style", "to", "the", "field", "label", "." ]
86feefb282b007c0a44784c09e651a50f257138e
https://github.com/GwtMaterialDesign/gwt-material/blob/86feefb282b007c0a44784c09e651a50f257138e/gwt-material/src/main/java/gwt/material/design/client/ui/MaterialValueBox.java#L432-L438
160,599
GwtMaterialDesign/gwt-material
gwt-material/src/main/java/gwt/material/design/client/ui/MaterialCollapsibleBody.java
MaterialCollapsibleBody.checkActiveState
protected void checkActiveState(Widget child) { // Check if this widget has a valid href String href = child.getElement().getAttribute("href"); String url = Window.Location.getHref(); int pos = url.indexOf("#"); String location = pos >= 0 ? url.substring(pos, url.length()) : ""; if (!href.isEmpty() && location.startsWith(href)) { ListItem li = findListItemParent(child); if (li != null) { makeActive(li); } } else if (child instanceof HasWidgets) { // Recursive check for (Widget w : (HasWidgets) child) { checkActiveState(w); } } }
java
protected void checkActiveState(Widget child) { // Check if this widget has a valid href String href = child.getElement().getAttribute("href"); String url = Window.Location.getHref(); int pos = url.indexOf("#"); String location = pos >= 0 ? url.substring(pos, url.length()) : ""; if (!href.isEmpty() && location.startsWith(href)) { ListItem li = findListItemParent(child); if (li != null) { makeActive(li); } } else if (child instanceof HasWidgets) { // Recursive check for (Widget w : (HasWidgets) child) { checkActiveState(w); } } }
[ "protected", "void", "checkActiveState", "(", "Widget", "child", ")", "{", "// Check if this widget has a valid href", "String", "href", "=", "child", ".", "getElement", "(", ")", ".", "getAttribute", "(", "\"href\"", ")", ";", "String", "url", "=", "Window", ".", "Location", ".", "getHref", "(", ")", ";", "int", "pos", "=", "url", ".", "indexOf", "(", "\"#\"", ")", ";", "String", "location", "=", "pos", ">=", "0", "?", "url", ".", "substring", "(", "pos", ",", "url", ".", "length", "(", ")", ")", ":", "\"\"", ";", "if", "(", "!", "href", ".", "isEmpty", "(", ")", "&&", "location", ".", "startsWith", "(", "href", ")", ")", "{", "ListItem", "li", "=", "findListItemParent", "(", "child", ")", ";", "if", "(", "li", "!=", "null", ")", "{", "makeActive", "(", "li", ")", ";", "}", "}", "else", "if", "(", "child", "instanceof", "HasWidgets", ")", "{", "// Recursive check", "for", "(", "Widget", "w", ":", "(", "HasWidgets", ")", "child", ")", "{", "checkActiveState", "(", "w", ")", ";", "}", "}", "}" ]
Checks if this child holds the current active state. If the child is or contains the active state it is applied.
[ "Checks", "if", "this", "child", "holds", "the", "current", "active", "state", ".", "If", "the", "child", "is", "or", "contains", "the", "active", "state", "it", "is", "applied", "." ]
86feefb282b007c0a44784c09e651a50f257138e
https://github.com/GwtMaterialDesign/gwt-material/blob/86feefb282b007c0a44784c09e651a50f257138e/gwt-material/src/main/java/gwt/material/design/client/ui/MaterialCollapsibleBody.java#L126-L144