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
sequence | docstring
stringlengths 3
16k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 105
339
|
---|---|---|---|---|---|---|---|---|---|---|---|
3,600 | twitter/cloudhopper-commons | ch-commons-gsm/src/main/java/com/cloudhopper/commons/gsm/DataCoding.java | DataCoding.createCharacterEncodingGroup | static public DataCoding createCharacterEncodingGroup(byte characterEncoding) throws IllegalArgumentException {
// bits 3 thru 0 of the encoding represent 16 languages
// make sure the top bits 7 thru 4 are not set
if ((characterEncoding & 0xF0) != 0) {
throw new IllegalArgumentException("Invalid characterEncoding [0x" + HexUtil.toHexString(characterEncoding) + "] value used: only 16 possible for char encoding group");
}
return new DataCoding(characterEncoding, Group.CHARACTER_ENCODING, characterEncoding, MESSAGE_CLASS_0, false);
} | java | static public DataCoding createCharacterEncodingGroup(byte characterEncoding) throws IllegalArgumentException {
// bits 3 thru 0 of the encoding represent 16 languages
// make sure the top bits 7 thru 4 are not set
if ((characterEncoding & 0xF0) != 0) {
throw new IllegalArgumentException("Invalid characterEncoding [0x" + HexUtil.toHexString(characterEncoding) + "] value used: only 16 possible for char encoding group");
}
return new DataCoding(characterEncoding, Group.CHARACTER_ENCODING, characterEncoding, MESSAGE_CLASS_0, false);
} | [
"static",
"public",
"DataCoding",
"createCharacterEncodingGroup",
"(",
"byte",
"characterEncoding",
")",
"throws",
"IllegalArgumentException",
"{",
"// bits 3 thru 0 of the encoding represent 16 languages",
"// make sure the top bits 7 thru 4 are not set",
"if",
"(",
"(",
"characterEncoding",
"&",
"0xF0",
")",
"!=",
"0",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Invalid characterEncoding [0x\"",
"+",
"HexUtil",
".",
"toHexString",
"(",
"characterEncoding",
")",
"+",
"\"] value used: only 16 possible for char encoding group\"",
")",
";",
"}",
"return",
"new",
"DataCoding",
"(",
"characterEncoding",
",",
"Group",
".",
"CHARACTER_ENCODING",
",",
"characterEncoding",
",",
"MESSAGE_CLASS_0",
",",
"false",
")",
";",
"}"
] | Creates a "Character Encoding" group data coding scheme where 16 different
languages are supported. This method validates the range and
sets the message class to 0 and compression flags to false.
@param characterEncoding The different possible character encodings
@return A new immutable DataCoding instance representing this data coding scheme
@throws IllegalArgumentException Thrown if the range is not supported. | [
"Creates",
"a",
"Character",
"Encoding",
"group",
"data",
"coding",
"scheme",
"where",
"16",
"different",
"languages",
"are",
"supported",
".",
"This",
"method",
"validates",
"the",
"range",
"and",
"sets",
"the",
"message",
"class",
"to",
"0",
"and",
"compression",
"flags",
"to",
"false",
"."
] | b5bc397dbec4537e8149e7ec0733c1d7ed477499 | https://github.com/twitter/cloudhopper-commons/blob/b5bc397dbec4537e8149e7ec0733c1d7ed477499/ch-commons-gsm/src/main/java/com/cloudhopper/commons/gsm/DataCoding.java#L202-L209 |
3,601 | twitter/cloudhopper-commons | ch-commons-gsm/src/main/java/com/cloudhopper/commons/gsm/DataCoding.java | DataCoding.parse | static public DataCoding parse(byte dcs) {
try {
// if bits 7 thru 4 are all off, this represents a simple character encoding group
if ((dcs & (byte)0xF0) == 0x00) {
// the raw dcs value is exactly our 16 possible languaged
return createCharacterEncodingGroup(dcs);
// if bits 7 thru 4 are all on, this represents a message class group
} else if ((dcs & (byte)0xF0) == (byte)0xF0) {
// bit 2 is the language encoding
byte characterEncoding = CHAR_ENC_DEFAULT;
if ((dcs & (byte)0x04) == (byte)0x04) {
characterEncoding = CHAR_ENC_8BIT;
}
// bits 1 thru 0 is the message class
byte messageClass = (byte)(dcs & (byte)0x03);
return createMessageClassGroup(characterEncoding, messageClass);
// at this point if bits 7 and 6 are off, then general data coding group
} else if ((dcs & (byte)0xC0) == (byte)0x00) {
// bit 5 represents "compression"
boolean compressed = false;
if ((dcs & (byte)0x20) == (byte)0x20) {
compressed = true;
}
// bits 1 thru 0 is the message class
byte tempMessageClass = (byte)(dcs & (byte)0x03);
Byte messageClass = null;
// bit 4 on means the message class becomes used
if ((dcs & (byte)0x10) == (byte)0x10) {
messageClass = new Byte(tempMessageClass);
}
// bits 3 and 2 represent the language encodings (nicely match default, 8-bit, or UCS2)
byte characterEncoding = (byte)(dcs & (byte)0x0C);
return createGeneralGroup(characterEncoding, messageClass, compressed);
// at this point if bits 7 and 6 are on, then bits 5 and 4 determine MWI
} else if ((dcs & (byte)0xC0) == (byte)0xC0) {
// bit 5: 0=default, 1=UCS2
byte characterEncoding = CHAR_ENC_DEFAULT;
if ((byte)(dcs & (byte)0x20) == 0x20) {
characterEncoding = CHAR_ENC_UCS2;
}
// bit 4: 0=discard, 1=store
boolean store = false;
if ((byte)(dcs & (byte)0x10) == 0x10) {
store = true;
}
// bit 3: indicator active
boolean indicatorActive = false;
if ((byte)(dcs & (byte)0x08) == 0x08) {
indicatorActive = true;
}
// bit 2: means nothing
// bit 1 thru 0 is the type of indicator
byte indicatorType = (byte)(dcs & (byte)0x03);
return createMessageWaitingIndicationGroup(characterEncoding, store, indicatorActive, indicatorType);
} else {
return createReservedGroup(dcs);
}
} catch (IllegalArgumentException e) {
return createReservedGroup(dcs);
}
} | java | static public DataCoding parse(byte dcs) {
try {
// if bits 7 thru 4 are all off, this represents a simple character encoding group
if ((dcs & (byte)0xF0) == 0x00) {
// the raw dcs value is exactly our 16 possible languaged
return createCharacterEncodingGroup(dcs);
// if bits 7 thru 4 are all on, this represents a message class group
} else if ((dcs & (byte)0xF0) == (byte)0xF0) {
// bit 2 is the language encoding
byte characterEncoding = CHAR_ENC_DEFAULT;
if ((dcs & (byte)0x04) == (byte)0x04) {
characterEncoding = CHAR_ENC_8BIT;
}
// bits 1 thru 0 is the message class
byte messageClass = (byte)(dcs & (byte)0x03);
return createMessageClassGroup(characterEncoding, messageClass);
// at this point if bits 7 and 6 are off, then general data coding group
} else if ((dcs & (byte)0xC0) == (byte)0x00) {
// bit 5 represents "compression"
boolean compressed = false;
if ((dcs & (byte)0x20) == (byte)0x20) {
compressed = true;
}
// bits 1 thru 0 is the message class
byte tempMessageClass = (byte)(dcs & (byte)0x03);
Byte messageClass = null;
// bit 4 on means the message class becomes used
if ((dcs & (byte)0x10) == (byte)0x10) {
messageClass = new Byte(tempMessageClass);
}
// bits 3 and 2 represent the language encodings (nicely match default, 8-bit, or UCS2)
byte characterEncoding = (byte)(dcs & (byte)0x0C);
return createGeneralGroup(characterEncoding, messageClass, compressed);
// at this point if bits 7 and 6 are on, then bits 5 and 4 determine MWI
} else if ((dcs & (byte)0xC0) == (byte)0xC0) {
// bit 5: 0=default, 1=UCS2
byte characterEncoding = CHAR_ENC_DEFAULT;
if ((byte)(dcs & (byte)0x20) == 0x20) {
characterEncoding = CHAR_ENC_UCS2;
}
// bit 4: 0=discard, 1=store
boolean store = false;
if ((byte)(dcs & (byte)0x10) == 0x10) {
store = true;
}
// bit 3: indicator active
boolean indicatorActive = false;
if ((byte)(dcs & (byte)0x08) == 0x08) {
indicatorActive = true;
}
// bit 2: means nothing
// bit 1 thru 0 is the type of indicator
byte indicatorType = (byte)(dcs & (byte)0x03);
return createMessageWaitingIndicationGroup(characterEncoding, store, indicatorActive, indicatorType);
} else {
return createReservedGroup(dcs);
}
} catch (IllegalArgumentException e) {
return createReservedGroup(dcs);
}
} | [
"static",
"public",
"DataCoding",
"parse",
"(",
"byte",
"dcs",
")",
"{",
"try",
"{",
"// if bits 7 thru 4 are all off, this represents a simple character encoding group",
"if",
"(",
"(",
"dcs",
"&",
"(",
"byte",
")",
"0xF0",
")",
"==",
"0x00",
")",
"{",
"// the raw dcs value is exactly our 16 possible languaged",
"return",
"createCharacterEncodingGroup",
"(",
"dcs",
")",
";",
"// if bits 7 thru 4 are all on, this represents a message class group",
"}",
"else",
"if",
"(",
"(",
"dcs",
"&",
"(",
"byte",
")",
"0xF0",
")",
"==",
"(",
"byte",
")",
"0xF0",
")",
"{",
"// bit 2 is the language encoding",
"byte",
"characterEncoding",
"=",
"CHAR_ENC_DEFAULT",
";",
"if",
"(",
"(",
"dcs",
"&",
"(",
"byte",
")",
"0x04",
")",
"==",
"(",
"byte",
")",
"0x04",
")",
"{",
"characterEncoding",
"=",
"CHAR_ENC_8BIT",
";",
"}",
"// bits 1 thru 0 is the message class",
"byte",
"messageClass",
"=",
"(",
"byte",
")",
"(",
"dcs",
"&",
"(",
"byte",
")",
"0x03",
")",
";",
"return",
"createMessageClassGroup",
"(",
"characterEncoding",
",",
"messageClass",
")",
";",
"// at this point if bits 7 and 6 are off, then general data coding group",
"}",
"else",
"if",
"(",
"(",
"dcs",
"&",
"(",
"byte",
")",
"0xC0",
")",
"==",
"(",
"byte",
")",
"0x00",
")",
"{",
"// bit 5 represents \"compression\"",
"boolean",
"compressed",
"=",
"false",
";",
"if",
"(",
"(",
"dcs",
"&",
"(",
"byte",
")",
"0x20",
")",
"==",
"(",
"byte",
")",
"0x20",
")",
"{",
"compressed",
"=",
"true",
";",
"}",
"// bits 1 thru 0 is the message class",
"byte",
"tempMessageClass",
"=",
"(",
"byte",
")",
"(",
"dcs",
"&",
"(",
"byte",
")",
"0x03",
")",
";",
"Byte",
"messageClass",
"=",
"null",
";",
"// bit 4 on means the message class becomes used",
"if",
"(",
"(",
"dcs",
"&",
"(",
"byte",
")",
"0x10",
")",
"==",
"(",
"byte",
")",
"0x10",
")",
"{",
"messageClass",
"=",
"new",
"Byte",
"(",
"tempMessageClass",
")",
";",
"}",
"// bits 3 and 2 represent the language encodings (nicely match default, 8-bit, or UCS2)",
"byte",
"characterEncoding",
"=",
"(",
"byte",
")",
"(",
"dcs",
"&",
"(",
"byte",
")",
"0x0C",
")",
";",
"return",
"createGeneralGroup",
"(",
"characterEncoding",
",",
"messageClass",
",",
"compressed",
")",
";",
"// at this point if bits 7 and 6 are on, then bits 5 and 4 determine MWI",
"}",
"else",
"if",
"(",
"(",
"dcs",
"&",
"(",
"byte",
")",
"0xC0",
")",
"==",
"(",
"byte",
")",
"0xC0",
")",
"{",
"// bit 5: 0=default, 1=UCS2",
"byte",
"characterEncoding",
"=",
"CHAR_ENC_DEFAULT",
";",
"if",
"(",
"(",
"byte",
")",
"(",
"dcs",
"&",
"(",
"byte",
")",
"0x20",
")",
"==",
"0x20",
")",
"{",
"characterEncoding",
"=",
"CHAR_ENC_UCS2",
";",
"}",
"// bit 4: 0=discard, 1=store",
"boolean",
"store",
"=",
"false",
";",
"if",
"(",
"(",
"byte",
")",
"(",
"dcs",
"&",
"(",
"byte",
")",
"0x10",
")",
"==",
"0x10",
")",
"{",
"store",
"=",
"true",
";",
"}",
"// bit 3: indicator active",
"boolean",
"indicatorActive",
"=",
"false",
";",
"if",
"(",
"(",
"byte",
")",
"(",
"dcs",
"&",
"(",
"byte",
")",
"0x08",
")",
"==",
"0x08",
")",
"{",
"indicatorActive",
"=",
"true",
";",
"}",
"// bit 2: means nothing",
"// bit 1 thru 0 is the type of indicator",
"byte",
"indicatorType",
"=",
"(",
"byte",
")",
"(",
"dcs",
"&",
"(",
"byte",
")",
"0x03",
")",
";",
"return",
"createMessageWaitingIndicationGroup",
"(",
"characterEncoding",
",",
"store",
",",
"indicatorActive",
",",
"indicatorType",
")",
";",
"}",
"else",
"{",
"return",
"createReservedGroup",
"(",
"dcs",
")",
";",
"}",
"}",
"catch",
"(",
"IllegalArgumentException",
"e",
")",
"{",
"return",
"createReservedGroup",
"(",
"dcs",
")",
";",
"}",
"}"
] | Parse the data coding scheme value into something usable and makes various
values easy to use. If a "reserved" value is used, returns a data coding
representing the same byte value, but all properties to their defaults.
@param dcs The byte value of the data coding scheme
@return A new immutable DataCoding instance representing this data coding scheme | [
"Parse",
"the",
"data",
"coding",
"scheme",
"value",
"into",
"something",
"usable",
"and",
"makes",
"various",
"values",
"easy",
"to",
"use",
".",
"If",
"a",
"reserved",
"value",
"is",
"used",
"returns",
"a",
"data",
"coding",
"representing",
"the",
"same",
"byte",
"value",
"but",
"all",
"properties",
"to",
"their",
"defaults",
"."
] | b5bc397dbec4537e8149e7ec0733c1d7ed477499 | https://github.com/twitter/cloudhopper-commons/blob/b5bc397dbec4537e8149e7ec0733c1d7ed477499/ch-commons-gsm/src/main/java/com/cloudhopper/commons/gsm/DataCoding.java#L343-L418 |
3,602 | twitter/cloudhopper-commons | ch-commons-util/src/main/java/com/cloudhopper/commons/util/ByteBuffer.java | ByteBuffer.circularByteBufferInitializer | private void circularByteBufferInitializer(int bufferCapacity, int bufferSize, int readPosition, int writePosition) {
if (bufferCapacity < 2) {
throw new IllegalArgumentException("Buffer capacity must be greater than 2 !");
}
if ((bufferSize < 0) || (bufferSize > bufferCapacity)) {
throw new IllegalArgumentException("Buffer size must be a value between 0 and "+bufferCapacity+" !");
}
if ((readPosition < 0) || (readPosition > bufferSize)) {
throw new IllegalArgumentException("Buffer read position must be a value between 0 and "+bufferSize+" !");
}
if ((writePosition < 0) || (writePosition > bufferSize)) {
throw new IllegalArgumentException("Buffer write position must be a value between 0 and "+bufferSize+" !");
}
this.buffer = new byte[bufferCapacity];
this.currentBufferSize = bufferSize;
this.currentReadPosition = readPosition;
this.currentWritePosition = writePosition;
} | java | private void circularByteBufferInitializer(int bufferCapacity, int bufferSize, int readPosition, int writePosition) {
if (bufferCapacity < 2) {
throw new IllegalArgumentException("Buffer capacity must be greater than 2 !");
}
if ((bufferSize < 0) || (bufferSize > bufferCapacity)) {
throw new IllegalArgumentException("Buffer size must be a value between 0 and "+bufferCapacity+" !");
}
if ((readPosition < 0) || (readPosition > bufferSize)) {
throw new IllegalArgumentException("Buffer read position must be a value between 0 and "+bufferSize+" !");
}
if ((writePosition < 0) || (writePosition > bufferSize)) {
throw new IllegalArgumentException("Buffer write position must be a value between 0 and "+bufferSize+" !");
}
this.buffer = new byte[bufferCapacity];
this.currentBufferSize = bufferSize;
this.currentReadPosition = readPosition;
this.currentWritePosition = writePosition;
} | [
"private",
"void",
"circularByteBufferInitializer",
"(",
"int",
"bufferCapacity",
",",
"int",
"bufferSize",
",",
"int",
"readPosition",
",",
"int",
"writePosition",
")",
"{",
"if",
"(",
"bufferCapacity",
"<",
"2",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Buffer capacity must be greater than 2 !\"",
")",
";",
"}",
"if",
"(",
"(",
"bufferSize",
"<",
"0",
")",
"||",
"(",
"bufferSize",
">",
"bufferCapacity",
")",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Buffer size must be a value between 0 and \"",
"+",
"bufferCapacity",
"+",
"\" !\"",
")",
";",
"}",
"if",
"(",
"(",
"readPosition",
"<",
"0",
")",
"||",
"(",
"readPosition",
">",
"bufferSize",
")",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Buffer read position must be a value between 0 and \"",
"+",
"bufferSize",
"+",
"\" !\"",
")",
";",
"}",
"if",
"(",
"(",
"writePosition",
"<",
"0",
")",
"||",
"(",
"writePosition",
">",
"bufferSize",
")",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Buffer write position must be a value between 0 and \"",
"+",
"bufferSize",
"+",
"\" !\"",
")",
";",
"}",
"this",
".",
"buffer",
"=",
"new",
"byte",
"[",
"bufferCapacity",
"]",
";",
"this",
".",
"currentBufferSize",
"=",
"bufferSize",
";",
"this",
".",
"currentReadPosition",
"=",
"readPosition",
";",
"this",
".",
"currentWritePosition",
"=",
"writePosition",
";",
"}"
] | Intializes the new CircularByteBuffer with all parameters that characterize a CircularByteBuffer.
@param bufferCapacity the buffer capacity. Must be >= 2.
@param bufferSize the buffer initial size. Must be in [0, bufferCapacity].
@param readPosition the buffer initial read position. Must be in [0, bufferSize]
@param writePosition the buffer initial write position. Must be in [0, bufferSize] | [
"Intializes",
"the",
"new",
"CircularByteBuffer",
"with",
"all",
"parameters",
"that",
"characterize",
"a",
"CircularByteBuffer",
"."
] | b5bc397dbec4537e8149e7ec0733c1d7ed477499 | https://github.com/twitter/cloudhopper-commons/blob/b5bc397dbec4537e8149e7ec0733c1d7ed477499/ch-commons-util/src/main/java/com/cloudhopper/commons/util/ByteBuffer.java#L243-L260 |
3,603 | twitter/cloudhopper-commons | ch-commons-util/src/main/java/com/cloudhopper/commons/util/ByteBuffer.java | ByteBuffer.modularExponentation | private int modularExponentation(int a, int b, int n) throws IllegalArgumentException {
int result = 1;
int counter;
int maxBinarySize = 32;
boolean[] b2Binary = new boolean[maxBinarySize];
for (counter = 0; b > 0; counter++) {
if (counter >= maxBinarySize){
throw new IllegalArgumentException("Exponent "+b+" is too big !");
}
b2Binary[counter] = (b % 2 != 0);
b = b / 2;
}
for (int k = counter - 1; k >= 0; k--) {
result = (result * result) % n;
if (b2Binary[k]){
result = (result * a) % n;
}
}
return result;
} | java | private int modularExponentation(int a, int b, int n) throws IllegalArgumentException {
int result = 1;
int counter;
int maxBinarySize = 32;
boolean[] b2Binary = new boolean[maxBinarySize];
for (counter = 0; b > 0; counter++) {
if (counter >= maxBinarySize){
throw new IllegalArgumentException("Exponent "+b+" is too big !");
}
b2Binary[counter] = (b % 2 != 0);
b = b / 2;
}
for (int k = counter - 1; k >= 0; k--) {
result = (result * result) % n;
if (b2Binary[k]){
result = (result * a) % n;
}
}
return result;
} | [
"private",
"int",
"modularExponentation",
"(",
"int",
"a",
",",
"int",
"b",
",",
"int",
"n",
")",
"throws",
"IllegalArgumentException",
"{",
"int",
"result",
"=",
"1",
";",
"int",
"counter",
";",
"int",
"maxBinarySize",
"=",
"32",
";",
"boolean",
"[",
"]",
"b2Binary",
"=",
"new",
"boolean",
"[",
"maxBinarySize",
"]",
";",
"for",
"(",
"counter",
"=",
"0",
";",
"b",
">",
"0",
";",
"counter",
"++",
")",
"{",
"if",
"(",
"counter",
">=",
"maxBinarySize",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Exponent \"",
"+",
"b",
"+",
"\" is too big !\"",
")",
";",
"}",
"b2Binary",
"[",
"counter",
"]",
"=",
"(",
"b",
"%",
"2",
"!=",
"0",
")",
";",
"b",
"=",
"b",
"/",
"2",
";",
"}",
"for",
"(",
"int",
"k",
"=",
"counter",
"-",
"1",
";",
"k",
">=",
"0",
";",
"k",
"--",
")",
"{",
"result",
"=",
"(",
"result",
"*",
"result",
")",
"%",
"n",
";",
"if",
"(",
"b2Binary",
"[",
"k",
"]",
")",
"{",
"result",
"=",
"(",
"result",
"*",
"a",
")",
"%",
"n",
";",
"}",
"}",
"return",
"result",
";",
"}"
] | Gets the modular exponentiation, i.e. result of a^b mod n. Use to calculate hashcode.
@param a A number.
@param b An exponent.
@param n A modulus.
@return Result of modular exponentiation, i.e. result of a^b mod n. | [
"Gets",
"the",
"modular",
"exponentiation",
"i",
".",
"e",
".",
"result",
"of",
"a^b",
"mod",
"n",
".",
"Use",
"to",
"calculate",
"hashcode",
"."
] | b5bc397dbec4537e8149e7ec0733c1d7ed477499 | https://github.com/twitter/cloudhopper-commons/blob/b5bc397dbec4537e8149e7ec0733c1d7ed477499/ch-commons-util/src/main/java/com/cloudhopper/commons/util/ByteBuffer.java#L270-L289 |
3,604 | twitter/cloudhopper-commons | ch-commons-util/src/main/java/com/cloudhopper/commons/util/ByteBuffer.java | ByteBuffer.add | public void add(byte b) throws BufferIsFullException {
if (isFull()) {
throw new BufferIsFullException("Buffer is full and has reached maximum capacity (" + capacity() + ")");
}
// buffer is not full
this.buffer[this.currentWritePosition] = b;
this.currentWritePosition = (this.currentWritePosition + 1) % this.buffer.length;
this.currentBufferSize += 1;
} | java | public void add(byte b) throws BufferIsFullException {
if (isFull()) {
throw new BufferIsFullException("Buffer is full and has reached maximum capacity (" + capacity() + ")");
}
// buffer is not full
this.buffer[this.currentWritePosition] = b;
this.currentWritePosition = (this.currentWritePosition + 1) % this.buffer.length;
this.currentBufferSize += 1;
} | [
"public",
"void",
"add",
"(",
"byte",
"b",
")",
"throws",
"BufferIsFullException",
"{",
"if",
"(",
"isFull",
"(",
")",
")",
"{",
"throw",
"new",
"BufferIsFullException",
"(",
"\"Buffer is full and has reached maximum capacity (\"",
"+",
"capacity",
"(",
")",
"+",
"\")\"",
")",
";",
"}",
"// buffer is not full",
"this",
".",
"buffer",
"[",
"this",
".",
"currentWritePosition",
"]",
"=",
"b",
";",
"this",
".",
"currentWritePosition",
"=",
"(",
"this",
".",
"currentWritePosition",
"+",
"1",
")",
"%",
"this",
".",
"buffer",
".",
"length",
";",
"this",
".",
"currentBufferSize",
"+=",
"1",
";",
"}"
] | Adds one byte to the buffer and throws an exception if the buffer is
full.
@param b Byte to add to the buffer.
@throws BufferIsFullException If the buffer is full and the byte cannot
be stored. | [
"Adds",
"one",
"byte",
"to",
"the",
"buffer",
"and",
"throws",
"an",
"exception",
"if",
"the",
"buffer",
"is",
"full",
"."
] | b5bc397dbec4537e8149e7ec0733c1d7ed477499 | https://github.com/twitter/cloudhopper-commons/blob/b5bc397dbec4537e8149e7ec0733c1d7ed477499/ch-commons-util/src/main/java/com/cloudhopper/commons/util/ByteBuffer.java#L366-L375 |
3,605 | twitter/cloudhopper-commons | ch-commons-util/src/main/java/com/cloudhopper/commons/util/ByteBuffer.java | ByteBuffer.checkOffsetLength | static protected void checkOffsetLength(int bytesLength, int offset, int length)
throws IllegalArgumentException {
// offset cannot be negative
if (offset < 0) {
throw new IllegalArgumentException("The byte[] offset parameter cannot be negative");
}
// length cannot be negative either
if (length < 0) {
throw new IllegalArgumentException("The byte[] length parameter cannot be negative");
}
// is it a valid offset? Must be < bytes.length if non-zero
// if its zero, then the check below will validate if it would cause
// a read past the length of the byte array
if (offset != 0 && offset >= bytesLength) {
throw new IllegalArgumentException("The byte[] offset (" + offset + ") must be < the length of the byte[] length (" + bytesLength + ")");
}
if (offset+length > bytesLength) {
throw new IllegalArgumentException("The offset+length (" + (offset+length) + ") would read past the end of the byte[] (length=" + bytesLength + ")");
}
} | java | static protected void checkOffsetLength(int bytesLength, int offset, int length)
throws IllegalArgumentException {
// offset cannot be negative
if (offset < 0) {
throw new IllegalArgumentException("The byte[] offset parameter cannot be negative");
}
// length cannot be negative either
if (length < 0) {
throw new IllegalArgumentException("The byte[] length parameter cannot be negative");
}
// is it a valid offset? Must be < bytes.length if non-zero
// if its zero, then the check below will validate if it would cause
// a read past the length of the byte array
if (offset != 0 && offset >= bytesLength) {
throw new IllegalArgumentException("The byte[] offset (" + offset + ") must be < the length of the byte[] length (" + bytesLength + ")");
}
if (offset+length > bytesLength) {
throw new IllegalArgumentException("The offset+length (" + (offset+length) + ") would read past the end of the byte[] (length=" + bytesLength + ")");
}
} | [
"static",
"protected",
"void",
"checkOffsetLength",
"(",
"int",
"bytesLength",
",",
"int",
"offset",
",",
"int",
"length",
")",
"throws",
"IllegalArgumentException",
"{",
"// offset cannot be negative",
"if",
"(",
"offset",
"<",
"0",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"The byte[] offset parameter cannot be negative\"",
")",
";",
"}",
"// length cannot be negative either",
"if",
"(",
"length",
"<",
"0",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"The byte[] length parameter cannot be negative\"",
")",
";",
"}",
"// is it a valid offset? Must be < bytes.length if non-zero",
"// if its zero, then the check below will validate if it would cause",
"// a read past the length of the byte array",
"if",
"(",
"offset",
"!=",
"0",
"&&",
"offset",
">=",
"bytesLength",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"The byte[] offset (\"",
"+",
"offset",
"+",
"\") must be < the length of the byte[] length (\"",
"+",
"bytesLength",
"+",
"\")\"",
")",
";",
"}",
"if",
"(",
"offset",
"+",
"length",
">",
"bytesLength",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"The offset+length (\"",
"+",
"(",
"offset",
"+",
"length",
")",
"+",
"\") would read past the end of the byte[] (length=\"",
"+",
"bytesLength",
"+",
"\")\"",
")",
";",
"}",
"}"
] | Helper method for validating if an offset and length are valid for a given
byte array. Checks if the offset or length is negative or if the offset+length
would cause a read past the end of the byte array.
@param bytesLength The length of the byte array to validate against
@param offset The offset within the byte array
@param length The length to read starting from the offset
@throws java.lang.IllegalArgumentException If any of the above conditions
are violated. | [
"Helper",
"method",
"for",
"validating",
"if",
"an",
"offset",
"and",
"length",
"are",
"valid",
"for",
"a",
"given",
"byte",
"array",
".",
"Checks",
"if",
"the",
"offset",
"or",
"length",
"is",
"negative",
"or",
"if",
"the",
"offset",
"+",
"length",
"would",
"cause",
"a",
"read",
"past",
"the",
"end",
"of",
"the",
"byte",
"array",
"."
] | b5bc397dbec4537e8149e7ec0733c1d7ed477499 | https://github.com/twitter/cloudhopper-commons/blob/b5bc397dbec4537e8149e7ec0733c1d7ed477499/ch-commons-util/src/main/java/com/cloudhopper/commons/util/ByteBuffer.java#L400-L419 |
3,606 | twitter/cloudhopper-commons | ch-commons-util/src/main/java/com/cloudhopper/commons/util/ByteBuffer.java | ByteBuffer.add | public void add(byte[] bytes, int offset, int length)
throws IllegalArgumentException, BufferSizeException {
// validate the bytes, offset, length
checkOffsetLength(bytes.length, offset, length);
// is there enough free space in this buffer to add the entire array
if (length > free()) {
throw new BufferSizeException("Buffer does not have enough free space (" + free() + " bytes) to add " + length + " bytes of data");
}
// add each byte to this array
for (int i = 0; i < length; i++) {
try {
this.add(bytes[i+offset]);
} catch (BufferIsFullException e) {
// this should be an impossible case since we checked the size() above
logger.error("Buffer is full even though this method checked its size() ahead of time", e);
throw new BufferSizeException(e.getMessage());
}
}
} | java | public void add(byte[] bytes, int offset, int length)
throws IllegalArgumentException, BufferSizeException {
// validate the bytes, offset, length
checkOffsetLength(bytes.length, offset, length);
// is there enough free space in this buffer to add the entire array
if (length > free()) {
throw new BufferSizeException("Buffer does not have enough free space (" + free() + " bytes) to add " + length + " bytes of data");
}
// add each byte to this array
for (int i = 0; i < length; i++) {
try {
this.add(bytes[i+offset]);
} catch (BufferIsFullException e) {
// this should be an impossible case since we checked the size() above
logger.error("Buffer is full even though this method checked its size() ahead of time", e);
throw new BufferSizeException(e.getMessage());
}
}
} | [
"public",
"void",
"add",
"(",
"byte",
"[",
"]",
"bytes",
",",
"int",
"offset",
",",
"int",
"length",
")",
"throws",
"IllegalArgumentException",
",",
"BufferSizeException",
"{",
"// validate the bytes, offset, length",
"checkOffsetLength",
"(",
"bytes",
".",
"length",
",",
"offset",
",",
"length",
")",
";",
"// is there enough free space in this buffer to add the entire array",
"if",
"(",
"length",
">",
"free",
"(",
")",
")",
"{",
"throw",
"new",
"BufferSizeException",
"(",
"\"Buffer does not have enough free space (\"",
"+",
"free",
"(",
")",
"+",
"\" bytes) to add \"",
"+",
"length",
"+",
"\" bytes of data\"",
")",
";",
"}",
"// add each byte to this array",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"length",
";",
"i",
"++",
")",
"{",
"try",
"{",
"this",
".",
"add",
"(",
"bytes",
"[",
"i",
"+",
"offset",
"]",
")",
";",
"}",
"catch",
"(",
"BufferIsFullException",
"e",
")",
"{",
"// this should be an impossible case since we checked the size() above",
"logger",
".",
"error",
"(",
"\"Buffer is full even though this method checked its size() ahead of time\"",
",",
"e",
")",
";",
"throw",
"new",
"BufferSizeException",
"(",
"e",
".",
"getMessage",
"(",
")",
")",
";",
"}",
"}",
"}"
] | Adds a byte array to this buffer starting from the offset up to the
length requested. If the free space remaining in the buffer
is not large enough, this method will throw a BufferSizeException.
@param bytes A byte array to add to this buffer.
@param offset The offset within the byte array to begin to add
@param length The length starting from offset to begin to add
@throws BufferSizeException If this buffer's free space is not large enough to store add the byte array | [
"Adds",
"a",
"byte",
"array",
"to",
"this",
"buffer",
"starting",
"from",
"the",
"offset",
"up",
"to",
"the",
"length",
"requested",
".",
"If",
"the",
"free",
"space",
"remaining",
"in",
"the",
"buffer",
"is",
"not",
"large",
"enough",
"this",
"method",
"will",
"throw",
"a",
"BufferSizeException",
"."
] | b5bc397dbec4537e8149e7ec0733c1d7ed477499 | https://github.com/twitter/cloudhopper-commons/blob/b5bc397dbec4537e8149e7ec0733c1d7ed477499/ch-commons-util/src/main/java/com/cloudhopper/commons/util/ByteBuffer.java#L430-L449 |
3,607 | twitter/cloudhopper-commons | ch-commons-util/src/main/java/com/cloudhopper/commons/util/ByteBuffer.java | ByteBuffer.get | public byte get(int index) throws IllegalArgumentException, BufferSizeException {
if ((index < 0) || (index >= capacity())) {
throw new IllegalArgumentException("The buffer index must be a value between 0 and " + capacity() + "!");
}
if (index >= size()) {
throw new BufferSizeException("Index " + index + " is >= buffer size of " + size());
}
return this.buffer[(this.currentReadPosition + index) % this.buffer.length];
} | java | public byte get(int index) throws IllegalArgumentException, BufferSizeException {
if ((index < 0) || (index >= capacity())) {
throw new IllegalArgumentException("The buffer index must be a value between 0 and " + capacity() + "!");
}
if (index >= size()) {
throw new BufferSizeException("Index " + index + " is >= buffer size of " + size());
}
return this.buffer[(this.currentReadPosition + index) % this.buffer.length];
} | [
"public",
"byte",
"get",
"(",
"int",
"index",
")",
"throws",
"IllegalArgumentException",
",",
"BufferSizeException",
"{",
"if",
"(",
"(",
"index",
"<",
"0",
")",
"||",
"(",
"index",
">=",
"capacity",
"(",
")",
")",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"The buffer index must be a value between 0 and \"",
"+",
"capacity",
"(",
")",
"+",
"\"!\"",
")",
";",
"}",
"if",
"(",
"index",
">=",
"size",
"(",
")",
")",
"{",
"throw",
"new",
"BufferSizeException",
"(",
"\"Index \"",
"+",
"index",
"+",
"\" is >= buffer size of \"",
"+",
"size",
"(",
")",
")",
";",
"}",
"return",
"this",
".",
"buffer",
"[",
"(",
"this",
".",
"currentReadPosition",
"+",
"index",
")",
"%",
"this",
".",
"buffer",
".",
"length",
"]",
";",
"}"
] | Gets the byte at the given index relative to the beginning the circular
buffer. The index must be a value between 0 and the buffer capacity.
@param index The index of the byte relative to the beginning the buffer
(a value between 0 and the the current size).
@return The byte at the given position relative to the beginning the buffer.
@throws BufferSizeException If the index is >= size() | [
"Gets",
"the",
"byte",
"at",
"the",
"given",
"index",
"relative",
"to",
"the",
"beginning",
"the",
"circular",
"buffer",
".",
"The",
"index",
"must",
"be",
"a",
"value",
"between",
"0",
"and",
"the",
"buffer",
"capacity",
"."
] | b5bc397dbec4537e8149e7ec0733c1d7ed477499 | https://github.com/twitter/cloudhopper-commons/blob/b5bc397dbec4537e8149e7ec0733c1d7ed477499/ch-commons-util/src/main/java/com/cloudhopper/commons/util/ByteBuffer.java#L708-L716 |
3,608 | twitter/cloudhopper-commons | ch-commons-util/src/main/java/com/cloudhopper/commons/util/ByteBuffer.java | ByteBuffer.toArray | public void toArray(int offset, int length, byte[] targetBuffer, int targetOffset) {
// validate the offset, length are ok
ByteBuffer.checkOffsetLength(size(), offset, length);
// validate the offset, length are ok
ByteBuffer.checkOffsetLength(targetBuffer.length, targetOffset, length);
// will we have a large enough byte[] allocated?
if (targetBuffer.length < length) {
throw new IllegalArgumentException("TargetBuffer size must be large enough to hold a byte[] of at least a size=" + length);
}
// are we actually copying any data?
if (length > 0) {
// create adjusted versions of read and write positions based
// on the offset and length passed into this method
int offsetReadPosition = (this.currentReadPosition + offset) % this.buffer.length;
int offsetWritePosition = (this.currentReadPosition + offset + length) % this.buffer.length;
if (offsetReadPosition >= offsetWritePosition) {
System.arraycopy(
this.buffer,
offsetReadPosition,
targetBuffer,
targetOffset,
this.buffer.length - offsetReadPosition);
System.arraycopy(
this.buffer,
0,
targetBuffer,
targetOffset + this.buffer.length - offsetReadPosition,
offsetWritePosition);
} else {
System.arraycopy(
this.buffer,
offsetReadPosition,
targetBuffer,
targetOffset,
offsetWritePosition - offsetReadPosition);
}
}
} | java | public void toArray(int offset, int length, byte[] targetBuffer, int targetOffset) {
// validate the offset, length are ok
ByteBuffer.checkOffsetLength(size(), offset, length);
// validate the offset, length are ok
ByteBuffer.checkOffsetLength(targetBuffer.length, targetOffset, length);
// will we have a large enough byte[] allocated?
if (targetBuffer.length < length) {
throw new IllegalArgumentException("TargetBuffer size must be large enough to hold a byte[] of at least a size=" + length);
}
// are we actually copying any data?
if (length > 0) {
// create adjusted versions of read and write positions based
// on the offset and length passed into this method
int offsetReadPosition = (this.currentReadPosition + offset) % this.buffer.length;
int offsetWritePosition = (this.currentReadPosition + offset + length) % this.buffer.length;
if (offsetReadPosition >= offsetWritePosition) {
System.arraycopy(
this.buffer,
offsetReadPosition,
targetBuffer,
targetOffset,
this.buffer.length - offsetReadPosition);
System.arraycopy(
this.buffer,
0,
targetBuffer,
targetOffset + this.buffer.length - offsetReadPosition,
offsetWritePosition);
} else {
System.arraycopy(
this.buffer,
offsetReadPosition,
targetBuffer,
targetOffset,
offsetWritePosition - offsetReadPosition);
}
}
} | [
"public",
"void",
"toArray",
"(",
"int",
"offset",
",",
"int",
"length",
",",
"byte",
"[",
"]",
"targetBuffer",
",",
"int",
"targetOffset",
")",
"{",
"// validate the offset, length are ok",
"ByteBuffer",
".",
"checkOffsetLength",
"(",
"size",
"(",
")",
",",
"offset",
",",
"length",
")",
";",
"// validate the offset, length are ok",
"ByteBuffer",
".",
"checkOffsetLength",
"(",
"targetBuffer",
".",
"length",
",",
"targetOffset",
",",
"length",
")",
";",
"// will we have a large enough byte[] allocated?",
"if",
"(",
"targetBuffer",
".",
"length",
"<",
"length",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"TargetBuffer size must be large enough to hold a byte[] of at least a size=\"",
"+",
"length",
")",
";",
"}",
"// are we actually copying any data?",
"if",
"(",
"length",
">",
"0",
")",
"{",
"// create adjusted versions of read and write positions based",
"// on the offset and length passed into this method",
"int",
"offsetReadPosition",
"=",
"(",
"this",
".",
"currentReadPosition",
"+",
"offset",
")",
"%",
"this",
".",
"buffer",
".",
"length",
";",
"int",
"offsetWritePosition",
"=",
"(",
"this",
".",
"currentReadPosition",
"+",
"offset",
"+",
"length",
")",
"%",
"this",
".",
"buffer",
".",
"length",
";",
"if",
"(",
"offsetReadPosition",
">=",
"offsetWritePosition",
")",
"{",
"System",
".",
"arraycopy",
"(",
"this",
".",
"buffer",
",",
"offsetReadPosition",
",",
"targetBuffer",
",",
"targetOffset",
",",
"this",
".",
"buffer",
".",
"length",
"-",
"offsetReadPosition",
")",
";",
"System",
".",
"arraycopy",
"(",
"this",
".",
"buffer",
",",
"0",
",",
"targetBuffer",
",",
"targetOffset",
"+",
"this",
".",
"buffer",
".",
"length",
"-",
"offsetReadPosition",
",",
"offsetWritePosition",
")",
";",
"}",
"else",
"{",
"System",
".",
"arraycopy",
"(",
"this",
".",
"buffer",
",",
"offsetReadPosition",
",",
"targetBuffer",
",",
"targetOffset",
",",
"offsetWritePosition",
"-",
"offsetReadPosition",
")",
";",
"}",
"}",
"}"
] | Will copy data from this ByteBuffer's buffer into the targetBuffer. This
method requires the targetBuffer to already be allocated with enough capacity
to hold this ByteBuffer's data.
@param offset The offset within the ByteBuffer to start copy from
@param length The length from the offset to copy
@param targetBuffer The target byte array we'll copy data into. Must already
be allocated with enough capacity.
@param targetOffset The offset within the target byte array to start from
@throws IllegalArgumentException If the offset and length are invalid
for this ByteBuffer, if the targetOffset and targetLength are invalid
for the targetBuffer, or if if the targetBuffer's capacity is not
large enough to hold the copied data. | [
"Will",
"copy",
"data",
"from",
"this",
"ByteBuffer",
"s",
"buffer",
"into",
"the",
"targetBuffer",
".",
"This",
"method",
"requires",
"the",
"targetBuffer",
"to",
"already",
"be",
"allocated",
"with",
"enough",
"capacity",
"to",
"hold",
"this",
"ByteBuffer",
"s",
"data",
"."
] | b5bc397dbec4537e8149e7ec0733c1d7ed477499 | https://github.com/twitter/cloudhopper-commons/blob/b5bc397dbec4537e8149e7ec0733c1d7ed477499/ch-commons-util/src/main/java/com/cloudhopper/commons/util/ByteBuffer.java#L804-L847 |
3,609 | twitter/cloudhopper-commons | ch-commons-util/src/main/java/com/cloudhopper/commons/util/ByteBuffer.java | ByteBuffer.startsWith | public boolean startsWith(byte[] prefix) {
if ((prefix.length == 0) || (prefix.length > size())) {
// no match would be possible
return false;
}
boolean match = true;
int i = 0;
int j = this.currentReadPosition;
while (match && (i < prefix.length)) {
if (this.buffer[j] != prefix[i]) {
match = false;
}
i++;
j = (j + 1) % this.buffer.length;
}
return match;
} | java | public boolean startsWith(byte[] prefix) {
if ((prefix.length == 0) || (prefix.length > size())) {
// no match would be possible
return false;
}
boolean match = true;
int i = 0;
int j = this.currentReadPosition;
while (match && (i < prefix.length)) {
if (this.buffer[j] != prefix[i]) {
match = false;
}
i++;
j = (j + 1) % this.buffer.length;
}
return match;
} | [
"public",
"boolean",
"startsWith",
"(",
"byte",
"[",
"]",
"prefix",
")",
"{",
"if",
"(",
"(",
"prefix",
".",
"length",
"==",
"0",
")",
"||",
"(",
"prefix",
".",
"length",
">",
"size",
"(",
")",
")",
")",
"{",
"// no match would be possible",
"return",
"false",
";",
"}",
"boolean",
"match",
"=",
"true",
";",
"int",
"i",
"=",
"0",
";",
"int",
"j",
"=",
"this",
".",
"currentReadPosition",
";",
"while",
"(",
"match",
"&&",
"(",
"i",
"<",
"prefix",
".",
"length",
")",
")",
"{",
"if",
"(",
"this",
".",
"buffer",
"[",
"j",
"]",
"!=",
"prefix",
"[",
"i",
"]",
")",
"{",
"match",
"=",
"false",
";",
"}",
"i",
"++",
";",
"j",
"=",
"(",
"j",
"+",
"1",
")",
"%",
"this",
".",
"buffer",
".",
"length",
";",
"}",
"return",
"match",
";",
"}"
] | Tests if the buffer starts with the byte array prefix. The byte array
prefix must have a size >= this buffer's size.
@return True if the buffer starts with the bytes array, otherwise false. | [
"Tests",
"if",
"the",
"buffer",
"starts",
"with",
"the",
"byte",
"array",
"prefix",
".",
"The",
"byte",
"array",
"prefix",
"must",
"have",
"a",
"size",
">",
"=",
"this",
"buffer",
"s",
"size",
"."
] | b5bc397dbec4537e8149e7ec0733c1d7ed477499 | https://github.com/twitter/cloudhopper-commons/blob/b5bc397dbec4537e8149e7ec0733c1d7ed477499/ch-commons-util/src/main/java/com/cloudhopper/commons/util/ByteBuffer.java#L855-L871 |
3,610 | twitter/cloudhopper-commons | ch-commons-util/src/main/java/com/cloudhopper/commons/util/ByteBuffer.java | ByteBuffer.endsWith | public boolean endsWith(byte[] prefix) {
//logger.debug("Inside endsWith()");
if ((prefix.length == 0) || (prefix.length > size())) {
//It could not match :
return false;
}
boolean match = true;
int i = prefix.length - 1;
int j = (this.currentWritePosition - 1 + this.buffer.length) % this.buffer.length;
while (match && (i >= 0)) {
//logger.debug("endsWith() this.buffer["+j+"]=" + this.buffer[j] + "='" + (char)this.buffer[j] + "', prefix["+i+"]=" + prefix[i] + "='" + (char)prefix[i] + "'");
if (this.buffer[j] != prefix[i]) {
match = false;
}
i--;
j = (j - 1 + this.buffer.length) % this.buffer.length;
}
return match;
} | java | public boolean endsWith(byte[] prefix) {
//logger.debug("Inside endsWith()");
if ((prefix.length == 0) || (prefix.length > size())) {
//It could not match :
return false;
}
boolean match = true;
int i = prefix.length - 1;
int j = (this.currentWritePosition - 1 + this.buffer.length) % this.buffer.length;
while (match && (i >= 0)) {
//logger.debug("endsWith() this.buffer["+j+"]=" + this.buffer[j] + "='" + (char)this.buffer[j] + "', prefix["+i+"]=" + prefix[i] + "='" + (char)prefix[i] + "'");
if (this.buffer[j] != prefix[i]) {
match = false;
}
i--;
j = (j - 1 + this.buffer.length) % this.buffer.length;
}
return match;
} | [
"public",
"boolean",
"endsWith",
"(",
"byte",
"[",
"]",
"prefix",
")",
"{",
"//logger.debug(\"Inside endsWith()\");",
"if",
"(",
"(",
"prefix",
".",
"length",
"==",
"0",
")",
"||",
"(",
"prefix",
".",
"length",
">",
"size",
"(",
")",
")",
")",
"{",
"//It could not match :",
"return",
"false",
";",
"}",
"boolean",
"match",
"=",
"true",
";",
"int",
"i",
"=",
"prefix",
".",
"length",
"-",
"1",
";",
"int",
"j",
"=",
"(",
"this",
".",
"currentWritePosition",
"-",
"1",
"+",
"this",
".",
"buffer",
".",
"length",
")",
"%",
"this",
".",
"buffer",
".",
"length",
";",
"while",
"(",
"match",
"&&",
"(",
"i",
">=",
"0",
")",
")",
"{",
"//logger.debug(\"endsWith() this.buffer[\"+j+\"]=\" + this.buffer[j] + \"='\" + (char)this.buffer[j] + \"', prefix[\"+i+\"]=\" + prefix[i] + \"='\" + (char)prefix[i] + \"'\");",
"if",
"(",
"this",
".",
"buffer",
"[",
"j",
"]",
"!=",
"prefix",
"[",
"i",
"]",
")",
"{",
"match",
"=",
"false",
";",
"}",
"i",
"--",
";",
"j",
"=",
"(",
"j",
"-",
"1",
"+",
"this",
".",
"buffer",
".",
"length",
")",
"%",
"this",
".",
"buffer",
".",
"length",
";",
"}",
"return",
"match",
";",
"}"
] | Tests if the buffer ends with the bytes array prefix. The byte array
prefix must have a size >= this buffer's size.
@return True if the buffer ends with the bytes array, otherwise false. | [
"Tests",
"if",
"the",
"buffer",
"ends",
"with",
"the",
"bytes",
"array",
"prefix",
".",
"The",
"byte",
"array",
"prefix",
"must",
"have",
"a",
"size",
">",
"=",
"this",
"buffer",
"s",
"size",
"."
] | b5bc397dbec4537e8149e7ec0733c1d7ed477499 | https://github.com/twitter/cloudhopper-commons/blob/b5bc397dbec4537e8149e7ec0733c1d7ed477499/ch-commons-util/src/main/java/com/cloudhopper/commons/util/ByteBuffer.java#L879-L897 |
3,611 | twitter/cloudhopper-commons | ch-commons-util/src/main/java/com/cloudhopper/commons/util/ByteBuffer.java | ByteBuffer.indexOf | public int indexOf(byte[] bytes, int offset) {
// make sure we're not checking against any byte arrays of length 0
if (bytes.length == 0 || size() == 0) {
// a match is not possible
return -1;
}
// make sure the offset won't cause us to read past the end of the byte[]
if (offset < 0 || offset >= size()) {
throw new IllegalArgumentException("Offset must be a value between 0 and " + size() + " (current buffer size)");
}
int length = size()-bytes.length;
for (int i = offset; i <= length; i++) {
int j = 0;
// continue search loop while the next bytes match
while (j < bytes.length && getUnchecked(i+j) == bytes[j]) {
j++;
}
// if we found it, then j will equal the length of the search bytes
if (j == bytes.length) {
return i;
}
}
// if we get here then we didn't find it
return -1;
} | java | public int indexOf(byte[] bytes, int offset) {
// make sure we're not checking against any byte arrays of length 0
if (bytes.length == 0 || size() == 0) {
// a match is not possible
return -1;
}
// make sure the offset won't cause us to read past the end of the byte[]
if (offset < 0 || offset >= size()) {
throw new IllegalArgumentException("Offset must be a value between 0 and " + size() + " (current buffer size)");
}
int length = size()-bytes.length;
for (int i = offset; i <= length; i++) {
int j = 0;
// continue search loop while the next bytes match
while (j < bytes.length && getUnchecked(i+j) == bytes[j]) {
j++;
}
// if we found it, then j will equal the length of the search bytes
if (j == bytes.length) {
return i;
}
}
// if we get here then we didn't find it
return -1;
} | [
"public",
"int",
"indexOf",
"(",
"byte",
"[",
"]",
"bytes",
",",
"int",
"offset",
")",
"{",
"// make sure we're not checking against any byte arrays of length 0",
"if",
"(",
"bytes",
".",
"length",
"==",
"0",
"||",
"size",
"(",
")",
"==",
"0",
")",
"{",
"// a match is not possible",
"return",
"-",
"1",
";",
"}",
"// make sure the offset won't cause us to read past the end of the byte[]",
"if",
"(",
"offset",
"<",
"0",
"||",
"offset",
">=",
"size",
"(",
")",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Offset must be a value between 0 and \"",
"+",
"size",
"(",
")",
"+",
"\" (current buffer size)\"",
")",
";",
"}",
"int",
"length",
"=",
"size",
"(",
")",
"-",
"bytes",
".",
"length",
";",
"for",
"(",
"int",
"i",
"=",
"offset",
";",
"i",
"<=",
"length",
";",
"i",
"++",
")",
"{",
"int",
"j",
"=",
"0",
";",
"// continue search loop while the next bytes match",
"while",
"(",
"j",
"<",
"bytes",
".",
"length",
"&&",
"getUnchecked",
"(",
"i",
"+",
"j",
")",
"==",
"bytes",
"[",
"j",
"]",
")",
"{",
"j",
"++",
";",
"}",
"// if we found it, then j will equal the length of the search bytes",
"if",
"(",
"j",
"==",
"bytes",
".",
"length",
")",
"{",
"return",
"i",
";",
"}",
"}",
"// if we get here then we didn't find it",
"return",
"-",
"1",
";",
"}"
] | Returns the index within this buffer of the first occurrence of the
specified bytes after the offset. The bytes to search for must have a
size lower than or equal to the current buffer size. This method will
return -1 if the bytes are not contained within this byte buffer.
@param bytes The byte array to search for
@param offset The offset within the buffer to search from
@return The index where the bytes start to match within the buffer. | [
"Returns",
"the",
"index",
"within",
"this",
"buffer",
"of",
"the",
"first",
"occurrence",
"of",
"the",
"specified",
"bytes",
"after",
"the",
"offset",
".",
"The",
"bytes",
"to",
"search",
"for",
"must",
"have",
"a",
"size",
"lower",
"than",
"or",
"equal",
"to",
"the",
"current",
"buffer",
"size",
".",
"This",
"method",
"will",
"return",
"-",
"1",
"if",
"the",
"bytes",
"are",
"not",
"contained",
"within",
"this",
"byte",
"buffer",
"."
] | b5bc397dbec4537e8149e7ec0733c1d7ed477499 | https://github.com/twitter/cloudhopper-commons/blob/b5bc397dbec4537e8149e7ec0733c1d7ed477499/ch-commons-util/src/main/java/com/cloudhopper/commons/util/ByteBuffer.java#L921-L948 |
3,612 | twitter/cloudhopper-commons | ch-commons-util/src/main/java/com/cloudhopper/commons/util/ByteBuffer.java | ByteBuffer.toHexString | public String toHexString(int offset, int length) {
// is offset, length valid for the current size() of our internal byte[]
checkOffsetLength(size(), offset, length);
// if length is 0, return an empty string
if (length == 0 || size() == 0) {
return "";
}
StringBuilder s = new StringBuilder(length * 2);
int end = offset + length;
for (int i = offset; i < end; i++) {
HexUtil.appendHexString(s, getUnchecked(i));
}
return s.toString();
} | java | public String toHexString(int offset, int length) {
// is offset, length valid for the current size() of our internal byte[]
checkOffsetLength(size(), offset, length);
// if length is 0, return an empty string
if (length == 0 || size() == 0) {
return "";
}
StringBuilder s = new StringBuilder(length * 2);
int end = offset + length;
for (int i = offset; i < end; i++) {
HexUtil.appendHexString(s, getUnchecked(i));
}
return s.toString();
} | [
"public",
"String",
"toHexString",
"(",
"int",
"offset",
",",
"int",
"length",
")",
"{",
"// is offset, length valid for the current size() of our internal byte[]",
"checkOffsetLength",
"(",
"size",
"(",
")",
",",
"offset",
",",
"length",
")",
";",
"// if length is 0, return an empty string",
"if",
"(",
"length",
"==",
"0",
"||",
"size",
"(",
")",
"==",
"0",
")",
"{",
"return",
"\"\"",
";",
"}",
"StringBuilder",
"s",
"=",
"new",
"StringBuilder",
"(",
"length",
"*",
"2",
")",
";",
"int",
"end",
"=",
"offset",
"+",
"length",
";",
"for",
"(",
"int",
"i",
"=",
"offset",
";",
"i",
"<",
"end",
";",
"i",
"++",
")",
"{",
"HexUtil",
".",
"appendHexString",
"(",
"s",
",",
"getUnchecked",
"(",
"i",
")",
")",
";",
"}",
"return",
"s",
".",
"toString",
"(",
")",
";",
"}"
] | Return a hexidecimal String representation of the current buffer with each byte
displayed in a 2 character hexidecimal format. Useful for debugging.
Convert a ByteBuffer to a String with a hexidecimal format.
@param offset
@param length
@return The string in hex representation | [
"Return",
"a",
"hexidecimal",
"String",
"representation",
"of",
"the",
"current",
"buffer",
"with",
"each",
"byte",
"displayed",
"in",
"a",
"2",
"character",
"hexidecimal",
"format",
".",
"Useful",
"for",
"debugging",
".",
"Convert",
"a",
"ByteBuffer",
"to",
"a",
"String",
"with",
"a",
"hexidecimal",
"format",
"."
] | b5bc397dbec4537e8149e7ec0733c1d7ed477499 | https://github.com/twitter/cloudhopper-commons/blob/b5bc397dbec4537e8149e7ec0733c1d7ed477499/ch-commons-util/src/main/java/com/cloudhopper/commons/util/ByteBuffer.java#L1092-L1108 |
3,613 | twitter/cloudhopper-commons | ch-sxmp/src/main/java/com/cloudhopper/sxmp/SxmpSession.java | SxmpSession.process | public Response process(InputStream is) throws IOException, SAXException, ParserConfigurationException {
// create a new XML parser
SxmpParser parser = new SxmpParser(version);
// an instance of an operation we'll be processing as a request
Operation operation = null;
try {
// parse input stream into an operation (this may
operation = parser.parse(is);
} catch (SxmpParsingException e) {
// major issue parsing the request into something valid -- this
// exception may contain a partially parsed operation -- if it does
// then we want to return valid XML back to the caller of this session
// don't dump stack trace; instead just log error message and what of the operation we parsed
if (e.getOperation() != null && e.getOperation().getType() != null) {
logger.warn("Unable to fully parse XML into a request, returning ErrorResponse; error: "+e.getMessage()+", parsed: "+e.getOperation());
// we'll actually return a generic ErrorResponse back
return new ErrorResponse(e.getOperation().getType(), e.getErrorCode().getIntValue(), e.getErrorMessage());
} else {
// otherwise, we should just return a generic error since nothing
// really was parsed in the XML document
throw new SAXException(e.getMessage(), e);
}
}
// at this point, we'll catch any SxmpErrorExceptions and make sure they
// are always converted into an ErrorResponse object, rather than
// the exception ever being thrown
try {
// can only handle requests
if (!(operation instanceof Request)) {
throw new SxmpErrorException(SxmpErrorCode.UNSUPPORTED_OPERATION, "A session can only process requests");
}
// convert to a request
Request req = (Request)operation;
// was an account included?
if (req.getAccount() == null) {
throw new SxmpErrorException(SxmpErrorCode.MISSING_REQUIRED_ELEMENT, "A request must include account credentials");
}
// authenticate the request
if (!processor.authenticate(req.getAccount())) {
throw new SxmpErrorException(SxmpErrorCode.AUTHENTICATION_FAILURE, "Authentication failure");
}
// handle request type
if (operation instanceof SubmitRequest) {
return processor.submit(req.getAccount(), (SubmitRequest)operation);
} else if (operation instanceof DeliverRequest) {
return processor.deliver(req.getAccount(), (DeliverRequest)operation);
} else if (operation instanceof DeliveryReportRequest) {
return processor.deliveryReport(req.getAccount(), (DeliveryReportRequest)operation);
} else {
// if we got here, then a request we don't support occurred
throw new SxmpErrorException(SxmpErrorCode.UNSUPPORTED_OPERATION, "Unsupported operation request type");
}
} catch (SxmpErrorException e) {
// because this is a mostly normal error in the course of processing a message
// we don't want to print the full stacktrace -- we just want to print the message
logger.warn(e.getMessage());
// we'll actually return a generic ErrorResponse back
return new ErrorResponse(operation.getType(), e.getErrorCode().getIntValue(), e.getErrorMessage());
} catch (Throwable t) {
logger.error("Major uncaught throwable while processing request, generating an ErrorResponse", t);
// we'll actually return a generic ErrorResponse back
return new ErrorResponse(operation.getType(), SxmpErrorCode.GENERIC.getIntValue(), "Generic error while processing request");
}
} | java | public Response process(InputStream is) throws IOException, SAXException, ParserConfigurationException {
// create a new XML parser
SxmpParser parser = new SxmpParser(version);
// an instance of an operation we'll be processing as a request
Operation operation = null;
try {
// parse input stream into an operation (this may
operation = parser.parse(is);
} catch (SxmpParsingException e) {
// major issue parsing the request into something valid -- this
// exception may contain a partially parsed operation -- if it does
// then we want to return valid XML back to the caller of this session
// don't dump stack trace; instead just log error message and what of the operation we parsed
if (e.getOperation() != null && e.getOperation().getType() != null) {
logger.warn("Unable to fully parse XML into a request, returning ErrorResponse; error: "+e.getMessage()+", parsed: "+e.getOperation());
// we'll actually return a generic ErrorResponse back
return new ErrorResponse(e.getOperation().getType(), e.getErrorCode().getIntValue(), e.getErrorMessage());
} else {
// otherwise, we should just return a generic error since nothing
// really was parsed in the XML document
throw new SAXException(e.getMessage(), e);
}
}
// at this point, we'll catch any SxmpErrorExceptions and make sure they
// are always converted into an ErrorResponse object, rather than
// the exception ever being thrown
try {
// can only handle requests
if (!(operation instanceof Request)) {
throw new SxmpErrorException(SxmpErrorCode.UNSUPPORTED_OPERATION, "A session can only process requests");
}
// convert to a request
Request req = (Request)operation;
// was an account included?
if (req.getAccount() == null) {
throw new SxmpErrorException(SxmpErrorCode.MISSING_REQUIRED_ELEMENT, "A request must include account credentials");
}
// authenticate the request
if (!processor.authenticate(req.getAccount())) {
throw new SxmpErrorException(SxmpErrorCode.AUTHENTICATION_FAILURE, "Authentication failure");
}
// handle request type
if (operation instanceof SubmitRequest) {
return processor.submit(req.getAccount(), (SubmitRequest)operation);
} else if (operation instanceof DeliverRequest) {
return processor.deliver(req.getAccount(), (DeliverRequest)operation);
} else if (operation instanceof DeliveryReportRequest) {
return processor.deliveryReport(req.getAccount(), (DeliveryReportRequest)operation);
} else {
// if we got here, then a request we don't support occurred
throw new SxmpErrorException(SxmpErrorCode.UNSUPPORTED_OPERATION, "Unsupported operation request type");
}
} catch (SxmpErrorException e) {
// because this is a mostly normal error in the course of processing a message
// we don't want to print the full stacktrace -- we just want to print the message
logger.warn(e.getMessage());
// we'll actually return a generic ErrorResponse back
return new ErrorResponse(operation.getType(), e.getErrorCode().getIntValue(), e.getErrorMessage());
} catch (Throwable t) {
logger.error("Major uncaught throwable while processing request, generating an ErrorResponse", t);
// we'll actually return a generic ErrorResponse back
return new ErrorResponse(operation.getType(), SxmpErrorCode.GENERIC.getIntValue(), "Generic error while processing request");
}
} | [
"public",
"Response",
"process",
"(",
"InputStream",
"is",
")",
"throws",
"IOException",
",",
"SAXException",
",",
"ParserConfigurationException",
"{",
"// create a new XML parser",
"SxmpParser",
"parser",
"=",
"new",
"SxmpParser",
"(",
"version",
")",
";",
"// an instance of an operation we'll be processing as a request",
"Operation",
"operation",
"=",
"null",
";",
"try",
"{",
"// parse input stream into an operation (this may",
"operation",
"=",
"parser",
".",
"parse",
"(",
"is",
")",
";",
"}",
"catch",
"(",
"SxmpParsingException",
"e",
")",
"{",
"// major issue parsing the request into something valid -- this",
"// exception may contain a partially parsed operation -- if it does",
"// then we want to return valid XML back to the caller of this session",
"// don't dump stack trace; instead just log error message and what of the operation we parsed",
"if",
"(",
"e",
".",
"getOperation",
"(",
")",
"!=",
"null",
"&&",
"e",
".",
"getOperation",
"(",
")",
".",
"getType",
"(",
")",
"!=",
"null",
")",
"{",
"logger",
".",
"warn",
"(",
"\"Unable to fully parse XML into a request, returning ErrorResponse; error: \"",
"+",
"e",
".",
"getMessage",
"(",
")",
"+",
"\", parsed: \"",
"+",
"e",
".",
"getOperation",
"(",
")",
")",
";",
"// we'll actually return a generic ErrorResponse back",
"return",
"new",
"ErrorResponse",
"(",
"e",
".",
"getOperation",
"(",
")",
".",
"getType",
"(",
")",
",",
"e",
".",
"getErrorCode",
"(",
")",
".",
"getIntValue",
"(",
")",
",",
"e",
".",
"getErrorMessage",
"(",
")",
")",
";",
"}",
"else",
"{",
"// otherwise, we should just return a generic error since nothing",
"// really was parsed in the XML document",
"throw",
"new",
"SAXException",
"(",
"e",
".",
"getMessage",
"(",
")",
",",
"e",
")",
";",
"}",
"}",
"// at this point, we'll catch any SxmpErrorExceptions and make sure they",
"// are always converted into an ErrorResponse object, rather than",
"// the exception ever being thrown",
"try",
"{",
"// can only handle requests",
"if",
"(",
"!",
"(",
"operation",
"instanceof",
"Request",
")",
")",
"{",
"throw",
"new",
"SxmpErrorException",
"(",
"SxmpErrorCode",
".",
"UNSUPPORTED_OPERATION",
",",
"\"A session can only process requests\"",
")",
";",
"}",
"// convert to a request",
"Request",
"req",
"=",
"(",
"Request",
")",
"operation",
";",
"// was an account included?",
"if",
"(",
"req",
".",
"getAccount",
"(",
")",
"==",
"null",
")",
"{",
"throw",
"new",
"SxmpErrorException",
"(",
"SxmpErrorCode",
".",
"MISSING_REQUIRED_ELEMENT",
",",
"\"A request must include account credentials\"",
")",
";",
"}",
"// authenticate the request",
"if",
"(",
"!",
"processor",
".",
"authenticate",
"(",
"req",
".",
"getAccount",
"(",
")",
")",
")",
"{",
"throw",
"new",
"SxmpErrorException",
"(",
"SxmpErrorCode",
".",
"AUTHENTICATION_FAILURE",
",",
"\"Authentication failure\"",
")",
";",
"}",
"// handle request type",
"if",
"(",
"operation",
"instanceof",
"SubmitRequest",
")",
"{",
"return",
"processor",
".",
"submit",
"(",
"req",
".",
"getAccount",
"(",
")",
",",
"(",
"SubmitRequest",
")",
"operation",
")",
";",
"}",
"else",
"if",
"(",
"operation",
"instanceof",
"DeliverRequest",
")",
"{",
"return",
"processor",
".",
"deliver",
"(",
"req",
".",
"getAccount",
"(",
")",
",",
"(",
"DeliverRequest",
")",
"operation",
")",
";",
"}",
"else",
"if",
"(",
"operation",
"instanceof",
"DeliveryReportRequest",
")",
"{",
"return",
"processor",
".",
"deliveryReport",
"(",
"req",
".",
"getAccount",
"(",
")",
",",
"(",
"DeliveryReportRequest",
")",
"operation",
")",
";",
"}",
"else",
"{",
"// if we got here, then a request we don't support occurred",
"throw",
"new",
"SxmpErrorException",
"(",
"SxmpErrorCode",
".",
"UNSUPPORTED_OPERATION",
",",
"\"Unsupported operation request type\"",
")",
";",
"}",
"}",
"catch",
"(",
"SxmpErrorException",
"e",
")",
"{",
"// because this is a mostly normal error in the course of processing a message",
"// we don't want to print the full stacktrace -- we just want to print the message",
"logger",
".",
"warn",
"(",
"e",
".",
"getMessage",
"(",
")",
")",
";",
"// we'll actually return a generic ErrorResponse back",
"return",
"new",
"ErrorResponse",
"(",
"operation",
".",
"getType",
"(",
")",
",",
"e",
".",
"getErrorCode",
"(",
")",
".",
"getIntValue",
"(",
")",
",",
"e",
".",
"getErrorMessage",
"(",
")",
")",
";",
"}",
"catch",
"(",
"Throwable",
"t",
")",
"{",
"logger",
".",
"error",
"(",
"\"Major uncaught throwable while processing request, generating an ErrorResponse\"",
",",
"t",
")",
";",
"// we'll actually return a generic ErrorResponse back",
"return",
"new",
"ErrorResponse",
"(",
"operation",
".",
"getType",
"(",
")",
",",
"SxmpErrorCode",
".",
"GENERIC",
".",
"getIntValue",
"(",
")",
",",
"\"Generic error while processing request\"",
")",
";",
"}",
"}"
] | Processes an InputStream that contains a request. Does its best to
only produce a Response that can be written to an OutputStream. Any
exception this method throws should be treated as fatal and no attempt
should be made to print out valid XML as a response.
@param is The InputStream to read the Request from
@return A Response that can be written to an OutputStream via an SxmpWriter
@throws IOException Thrown if there is an error while reading the InputStream
@throws SAXException Thrown if there is an error with parsing the XML document
@throws ParserConfigurationException Thrown if there is an error with loading
the XML parser. | [
"Processes",
"an",
"InputStream",
"that",
"contains",
"a",
"request",
".",
"Does",
"its",
"best",
"to",
"only",
"produce",
"a",
"Response",
"that",
"can",
"be",
"written",
"to",
"an",
"OutputStream",
".",
"Any",
"exception",
"this",
"method",
"throws",
"should",
"be",
"treated",
"as",
"fatal",
"and",
"no",
"attempt",
"should",
"be",
"made",
"to",
"print",
"out",
"valid",
"XML",
"as",
"a",
"response",
"."
] | b5bc397dbec4537e8149e7ec0733c1d7ed477499 | https://github.com/twitter/cloudhopper-commons/blob/b5bc397dbec4537e8149e7ec0733c1d7ed477499/ch-sxmp/src/main/java/com/cloudhopper/sxmp/SxmpSession.java#L64-L134 |
3,614 | twitter/cloudhopper-commons | ch-commons-xbean/src/main/java/com/cloudhopper/commons/xbean/util/PropertiesReplacementUtil.java | PropertiesReplacementUtil.loadProperties | static public Properties loadProperties(Properties base, File file) throws IOException {
FileReader reader = new FileReader(file);
Properties props = new Properties();
props.load(reader);
if (base != null) props.putAll(base);
reader.close();
return props;
} | java | static public Properties loadProperties(Properties base, File file) throws IOException {
FileReader reader = new FileReader(file);
Properties props = new Properties();
props.load(reader);
if (base != null) props.putAll(base);
reader.close();
return props;
} | [
"static",
"public",
"Properties",
"loadProperties",
"(",
"Properties",
"base",
",",
"File",
"file",
")",
"throws",
"IOException",
"{",
"FileReader",
"reader",
"=",
"new",
"FileReader",
"(",
"file",
")",
";",
"Properties",
"props",
"=",
"new",
"Properties",
"(",
")",
";",
"props",
".",
"load",
"(",
"reader",
")",
";",
"if",
"(",
"base",
"!=",
"null",
")",
"props",
".",
"putAll",
"(",
"base",
")",
";",
"reader",
".",
"close",
"(",
")",
";",
"return",
"props",
";",
"}"
] | Loads the given file into a Properties object.
@param base Properties that should override those loaded from the file
@param file The file to load
@return Properties loaded from the file | [
"Loads",
"the",
"given",
"file",
"into",
"a",
"Properties",
"object",
"."
] | b5bc397dbec4537e8149e7ec0733c1d7ed477499 | https://github.com/twitter/cloudhopper-commons/blob/b5bc397dbec4537e8149e7ec0733c1d7ed477499/ch-commons-xbean/src/main/java/com/cloudhopper/commons/xbean/util/PropertiesReplacementUtil.java#L170-L177 |
3,615 | twitter/cloudhopper-commons | ch-httpclient-util/src/main/java/com/cloudhopper/httpclient/util/HttpClientUtil.java | HttpClientUtil.shutdownQuietly | static public void shutdownQuietly(HttpClient http) {
if (http != null) {
try {
http.getConnectionManager().shutdown();
} catch (Exception ignore) {
// do nothing
}
}
} | java | static public void shutdownQuietly(HttpClient http) {
if (http != null) {
try {
http.getConnectionManager().shutdown();
} catch (Exception ignore) {
// do nothing
}
}
} | [
"static",
"public",
"void",
"shutdownQuietly",
"(",
"HttpClient",
"http",
")",
"{",
"if",
"(",
"http",
"!=",
"null",
")",
"{",
"try",
"{",
"http",
".",
"getConnectionManager",
"(",
")",
".",
"shutdown",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"ignore",
")",
"{",
"// do nothing",
"}",
"}",
"}"
] | Quitely shuts down an HttpClient instance by shutting down its connection
manager and ignoring any errors that occur.
@param http The HttpClient to shutdown | [
"Quitely",
"shuts",
"down",
"an",
"HttpClient",
"instance",
"by",
"shutting",
"down",
"its",
"connection",
"manager",
"and",
"ignoring",
"any",
"errors",
"that",
"occur",
"."
] | b5bc397dbec4537e8149e7ec0733c1d7ed477499 | https://github.com/twitter/cloudhopper-commons/blob/b5bc397dbec4537e8149e7ec0733c1d7ed477499/ch-httpclient-util/src/main/java/com/cloudhopper/httpclient/util/HttpClientUtil.java#L43-L51 |
3,616 | twitter/cloudhopper-commons | ch-commons-charset/src/main/java/com/cloudhopper/commons/charset/MobileTextUtil.java | MobileTextUtil.replaceSafeUnicodeChars | static public int replaceSafeUnicodeChars(StringBuilder buffer) {
int replaced = 0;
for (int i = 0; i < buffer.length(); i++) {
char c = buffer.charAt(i);
for (int j = 0; j < CHAR_TABLE.length; j++) {
if (c == CHAR_TABLE[j][0]) {
replaced++;
buffer.setCharAt(i, CHAR_TABLE[j][1]);
}
}
}
return replaced;
} | java | static public int replaceSafeUnicodeChars(StringBuilder buffer) {
int replaced = 0;
for (int i = 0; i < buffer.length(); i++) {
char c = buffer.charAt(i);
for (int j = 0; j < CHAR_TABLE.length; j++) {
if (c == CHAR_TABLE[j][0]) {
replaced++;
buffer.setCharAt(i, CHAR_TABLE[j][1]);
}
}
}
return replaced;
} | [
"static",
"public",
"int",
"replaceSafeUnicodeChars",
"(",
"StringBuilder",
"buffer",
")",
"{",
"int",
"replaced",
"=",
"0",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"buffer",
".",
"length",
"(",
")",
";",
"i",
"++",
")",
"{",
"char",
"c",
"=",
"buffer",
".",
"charAt",
"(",
"i",
")",
";",
"for",
"(",
"int",
"j",
"=",
"0",
";",
"j",
"<",
"CHAR_TABLE",
".",
"length",
";",
"j",
"++",
")",
"{",
"if",
"(",
"c",
"==",
"CHAR_TABLE",
"[",
"j",
"]",
"[",
"0",
"]",
")",
"{",
"replaced",
"++",
";",
"buffer",
".",
"setCharAt",
"(",
"i",
",",
"CHAR_TABLE",
"[",
"j",
"]",
"[",
"1",
"]",
")",
";",
"}",
"}",
"}",
"return",
"replaced",
";",
"}"
] | Replace unicode characters with their ascii equivalents, limiting
replacement to "safe" characters such as smart quotes to dumb quotes.
"Safe" is subjective, but generally the agreement is that these character
replacements should not change the meaning of the string in any meaninful
way.
@param buffer The buffer containing the characters to analyze and replace
if necessary.
@return The number of characters replaced | [
"Replace",
"unicode",
"characters",
"with",
"their",
"ascii",
"equivalents",
"limiting",
"replacement",
"to",
"safe",
"characters",
"such",
"as",
"smart",
"quotes",
"to",
"dumb",
"quotes",
".",
"Safe",
"is",
"subjective",
"but",
"generally",
"the",
"agreement",
"is",
"that",
"these",
"character",
"replacements",
"should",
"not",
"change",
"the",
"meaning",
"of",
"the",
"string",
"in",
"any",
"meaninful",
"way",
"."
] | b5bc397dbec4537e8149e7ec0733c1d7ed477499 | https://github.com/twitter/cloudhopper-commons/blob/b5bc397dbec4537e8149e7ec0733c1d7ed477499/ch-commons-charset/src/main/java/com/cloudhopper/commons/charset/MobileTextUtil.java#L69-L81 |
3,617 | twitter/cloudhopper-commons | ch-commons-util/src/main/java/com/cloudhopper/commons/util/codec/Base64Codec.java | Base64Codec.encode | public static String encode(byte[] rawData) {
StringBuilder buffer = new StringBuilder(4 * rawData.length / 3);
int pos = 0;
int iterations = rawData.length / 3;
for (int i = 0; i < iterations; i++) {
int value = ((rawData[pos++] & 0xFF) << 16) |
((rawData[pos++] & 0xFF) << 8) | (rawData[pos++] & 0xFF);
buffer.append(BASE64_ALPHABET[(value >>> 18) & 0x3F]);
buffer.append(BASE64_ALPHABET[(value >>> 12) & 0x3F]);
buffer.append(BASE64_ALPHABET[(value >>> 6) & 0x3F]);
buffer.append(BASE64_ALPHABET[value & 0x3F]);
}
switch (rawData.length % 3) {
case 1:
buffer.append(BASE64_ALPHABET[(rawData[pos] >>> 2) & 0x3F]);
buffer.append(BASE64_ALPHABET[(rawData[pos] << 4) & 0x3F]);
buffer.append("==");
break;
case 2:
int value = ((rawData[pos++] & 0xFF) << 8) | (rawData[pos] & 0xFF);
buffer.append(BASE64_ALPHABET[(value >>> 10) & 0x3F]);
buffer.append(BASE64_ALPHABET[(value >>> 4) & 0x3F]);
buffer.append(BASE64_ALPHABET[(value << 2) & 0x3F]);
buffer.append("=");
break;
}
return buffer.toString();
} | java | public static String encode(byte[] rawData) {
StringBuilder buffer = new StringBuilder(4 * rawData.length / 3);
int pos = 0;
int iterations = rawData.length / 3;
for (int i = 0; i < iterations; i++) {
int value = ((rawData[pos++] & 0xFF) << 16) |
((rawData[pos++] & 0xFF) << 8) | (rawData[pos++] & 0xFF);
buffer.append(BASE64_ALPHABET[(value >>> 18) & 0x3F]);
buffer.append(BASE64_ALPHABET[(value >>> 12) & 0x3F]);
buffer.append(BASE64_ALPHABET[(value >>> 6) & 0x3F]);
buffer.append(BASE64_ALPHABET[value & 0x3F]);
}
switch (rawData.length % 3) {
case 1:
buffer.append(BASE64_ALPHABET[(rawData[pos] >>> 2) & 0x3F]);
buffer.append(BASE64_ALPHABET[(rawData[pos] << 4) & 0x3F]);
buffer.append("==");
break;
case 2:
int value = ((rawData[pos++] & 0xFF) << 8) | (rawData[pos] & 0xFF);
buffer.append(BASE64_ALPHABET[(value >>> 10) & 0x3F]);
buffer.append(BASE64_ALPHABET[(value >>> 4) & 0x3F]);
buffer.append(BASE64_ALPHABET[(value << 2) & 0x3F]);
buffer.append("=");
break;
}
return buffer.toString();
} | [
"public",
"static",
"String",
"encode",
"(",
"byte",
"[",
"]",
"rawData",
")",
"{",
"StringBuilder",
"buffer",
"=",
"new",
"StringBuilder",
"(",
"4",
"*",
"rawData",
".",
"length",
"/",
"3",
")",
";",
"int",
"pos",
"=",
"0",
";",
"int",
"iterations",
"=",
"rawData",
".",
"length",
"/",
"3",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"iterations",
";",
"i",
"++",
")",
"{",
"int",
"value",
"=",
"(",
"(",
"rawData",
"[",
"pos",
"++",
"]",
"&",
"0xFF",
")",
"<<",
"16",
")",
"|",
"(",
"(",
"rawData",
"[",
"pos",
"++",
"]",
"&",
"0xFF",
")",
"<<",
"8",
")",
"|",
"(",
"rawData",
"[",
"pos",
"++",
"]",
"&",
"0xFF",
")",
";",
"buffer",
".",
"append",
"(",
"BASE64_ALPHABET",
"[",
"(",
"value",
">>>",
"18",
")",
"&",
"0x3F",
"]",
")",
";",
"buffer",
".",
"append",
"(",
"BASE64_ALPHABET",
"[",
"(",
"value",
">>>",
"12",
")",
"&",
"0x3F",
"]",
")",
";",
"buffer",
".",
"append",
"(",
"BASE64_ALPHABET",
"[",
"(",
"value",
">>>",
"6",
")",
"&",
"0x3F",
"]",
")",
";",
"buffer",
".",
"append",
"(",
"BASE64_ALPHABET",
"[",
"value",
"&",
"0x3F",
"]",
")",
";",
"}",
"switch",
"(",
"rawData",
".",
"length",
"%",
"3",
")",
"{",
"case",
"1",
":",
"buffer",
".",
"append",
"(",
"BASE64_ALPHABET",
"[",
"(",
"rawData",
"[",
"pos",
"]",
">>>",
"2",
")",
"&",
"0x3F",
"]",
")",
";",
"buffer",
".",
"append",
"(",
"BASE64_ALPHABET",
"[",
"(",
"rawData",
"[",
"pos",
"]",
"<<",
"4",
")",
"&",
"0x3F",
"]",
")",
";",
"buffer",
".",
"append",
"(",
"\"==\"",
")",
";",
"break",
";",
"case",
"2",
":",
"int",
"value",
"=",
"(",
"(",
"rawData",
"[",
"pos",
"++",
"]",
"&",
"0xFF",
")",
"<<",
"8",
")",
"|",
"(",
"rawData",
"[",
"pos",
"]",
"&",
"0xFF",
")",
";",
"buffer",
".",
"append",
"(",
"BASE64_ALPHABET",
"[",
"(",
"value",
">>>",
"10",
")",
"&",
"0x3F",
"]",
")",
";",
"buffer",
".",
"append",
"(",
"BASE64_ALPHABET",
"[",
"(",
"value",
">>>",
"4",
")",
"&",
"0x3F",
"]",
")",
";",
"buffer",
".",
"append",
"(",
"BASE64_ALPHABET",
"[",
"(",
"value",
"<<",
"2",
")",
"&",
"0x3F",
"]",
")",
";",
"buffer",
".",
"append",
"(",
"\"=\"",
")",
";",
"break",
";",
"}",
"return",
"buffer",
".",
"toString",
"(",
")",
";",
"}"
] | Encodes the provided raw data using base64.
@param rawData The raw data to encode. It must not be <CODE>null</CODE>.
@return The base64-encoded representation of the provided raw data. | [
"Encodes",
"the",
"provided",
"raw",
"data",
"using",
"base64",
"."
] | b5bc397dbec4537e8149e7ec0733c1d7ed477499 | https://github.com/twitter/cloudhopper-commons/blob/b5bc397dbec4537e8149e7ec0733c1d7ed477499/ch-commons-util/src/main/java/com/cloudhopper/commons/util/codec/Base64Codec.java#L64-L95 |
3,618 | twitter/cloudhopper-commons | ch-commons-util/src/main/java/com/cloudhopper/commons/util/filefilter/FileNameStartsWithFilter.java | FileNameStartsWithFilter.accept | public boolean accept(File file) {
if (caseSensitive) {
return file.getName().startsWith(string0);
} else {
return file.getName().toLowerCase().startsWith(string0.toLowerCase());
}
} | java | public boolean accept(File file) {
if (caseSensitive) {
return file.getName().startsWith(string0);
} else {
return file.getName().toLowerCase().startsWith(string0.toLowerCase());
}
} | [
"public",
"boolean",
"accept",
"(",
"File",
"file",
")",
"{",
"if",
"(",
"caseSensitive",
")",
"{",
"return",
"file",
".",
"getName",
"(",
")",
".",
"startsWith",
"(",
"string0",
")",
";",
"}",
"else",
"{",
"return",
"file",
".",
"getName",
"(",
")",
".",
"toLowerCase",
"(",
")",
".",
"startsWith",
"(",
"string0",
".",
"toLowerCase",
"(",
")",
")",
";",
"}",
"}"
] | Accepts a File if its filename startsWith a specific string.
@param file The file to match
@return True if the File startsWith the specific string, otherwise false | [
"Accepts",
"a",
"File",
"if",
"its",
"filename",
"startsWith",
"a",
"specific",
"string",
"."
] | b5bc397dbec4537e8149e7ec0733c1d7ed477499 | https://github.com/twitter/cloudhopper-commons/blob/b5bc397dbec4537e8149e7ec0733c1d7ed477499/ch-commons-util/src/main/java/com/cloudhopper/commons/util/filefilter/FileNameStartsWithFilter.java#L53-L59 |
3,619 | twitter/cloudhopper-commons | ch-commons-charset/src/main/java/com/cloudhopper/commons/charset/GSMCharset.java | GSMCharset.decode | @Override
public void decode(byte[] bytes, StringBuilder buffer) {
if (bytes == null) {
// append nothing
return;
}
char[] table = CHAR_TABLE;
for (int i = 0; i < bytes.length; i++) {
int code = (int)bytes[i] & 0x000000ff;
if (code == EXTENDED_ESCAPE) {
// take next char from extension table
table = EXT_CHAR_TABLE;
} else {
buffer.append((code >= table.length) ? '?' : table[code]);
// go back to the default table
table = CHAR_TABLE;
}
}
} | java | @Override
public void decode(byte[] bytes, StringBuilder buffer) {
if (bytes == null) {
// append nothing
return;
}
char[] table = CHAR_TABLE;
for (int i = 0; i < bytes.length; i++) {
int code = (int)bytes[i] & 0x000000ff;
if (code == EXTENDED_ESCAPE) {
// take next char from extension table
table = EXT_CHAR_TABLE;
} else {
buffer.append((code >= table.length) ? '?' : table[code]);
// go back to the default table
table = CHAR_TABLE;
}
}
} | [
"@",
"Override",
"public",
"void",
"decode",
"(",
"byte",
"[",
"]",
"bytes",
",",
"StringBuilder",
"buffer",
")",
"{",
"if",
"(",
"bytes",
"==",
"null",
")",
"{",
"// append nothing",
"return",
";",
"}",
"char",
"[",
"]",
"table",
"=",
"CHAR_TABLE",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"bytes",
".",
"length",
";",
"i",
"++",
")",
"{",
"int",
"code",
"=",
"(",
"int",
")",
"bytes",
"[",
"i",
"]",
"&",
"0x000000ff",
";",
"if",
"(",
"code",
"==",
"EXTENDED_ESCAPE",
")",
"{",
"// take next char from extension table",
"table",
"=",
"EXT_CHAR_TABLE",
";",
"}",
"else",
"{",
"buffer",
".",
"append",
"(",
"(",
"code",
">=",
"table",
".",
"length",
")",
"?",
"'",
"'",
":",
"table",
"[",
"code",
"]",
")",
";",
"// go back to the default table",
"table",
"=",
"CHAR_TABLE",
";",
"}",
"}",
"}"
] | Decode an SMS default alphabet-encoded octet string into a Java String. | [
"Decode",
"an",
"SMS",
"default",
"alphabet",
"-",
"encoded",
"octet",
"string",
"into",
"a",
"Java",
"String",
"."
] | b5bc397dbec4537e8149e7ec0733c1d7ed477499 | https://github.com/twitter/cloudhopper-commons/blob/b5bc397dbec4537e8149e7ec0733c1d7ed477499/ch-commons-charset/src/main/java/com/cloudhopper/commons/charset/GSMCharset.java#L229-L248 |
3,620 | twitter/cloudhopper-commons | ch-commons-util/src/main/java/com/cloudhopper/commons/util/windowing/Window.java | Window.get | public WindowFuture<K,R,P> get(K key) {
return this.futures.get(key);
} | java | public WindowFuture<K,R,P> get(K key) {
return this.futures.get(key);
} | [
"public",
"WindowFuture",
"<",
"K",
",",
"R",
",",
"P",
">",
"get",
"(",
"K",
"key",
")",
"{",
"return",
"this",
".",
"futures",
".",
"get",
"(",
"key",
")",
";",
"}"
] | Gets the a future by its key.
@param key The key for the request
@return The future or null if it doesn't exist. | [
"Gets",
"the",
"a",
"future",
"by",
"its",
"key",
"."
] | b5bc397dbec4537e8149e7ec0733c1d7ed477499 | https://github.com/twitter/cloudhopper-commons/blob/b5bc397dbec4537e8149e7ec0733c1d7ed477499/ch-commons-util/src/main/java/com/cloudhopper/commons/util/windowing/Window.java#L198-L200 |
3,621 | twitter/cloudhopper-commons | ch-commons-util/src/main/java/com/cloudhopper/commons/util/windowing/Window.java | Window.addListener | public void addListener(WindowListener<K,R,P> listener) {
this.listeners.addIfAbsent(new UnwrappedWeakReference<WindowListener<K,R,P>>(listener));
} | java | public void addListener(WindowListener<K,R,P> listener) {
this.listeners.addIfAbsent(new UnwrappedWeakReference<WindowListener<K,R,P>>(listener));
} | [
"public",
"void",
"addListener",
"(",
"WindowListener",
"<",
"K",
",",
"R",
",",
"P",
">",
"listener",
")",
"{",
"this",
".",
"listeners",
".",
"addIfAbsent",
"(",
"new",
"UnwrappedWeakReference",
"<",
"WindowListener",
"<",
"K",
",",
"R",
",",
"P",
">",
">",
"(",
"listener",
")",
")",
";",
"}"
] | Adds a new WindowListener if and only if it isn't already present.
@param listener The listener to add | [
"Adds",
"a",
"new",
"WindowListener",
"if",
"and",
"only",
"if",
"it",
"isn",
"t",
"already",
"present",
"."
] | b5bc397dbec4537e8149e7ec0733c1d7ed477499 | https://github.com/twitter/cloudhopper-commons/blob/b5bc397dbec4537e8149e7ec0733c1d7ed477499/ch-commons-util/src/main/java/com/cloudhopper/commons/util/windowing/Window.java#L206-L208 |
3,622 | twitter/cloudhopper-commons | ch-commons-util/src/main/java/com/cloudhopper/commons/util/windowing/Window.java | Window.removeListener | public void removeListener(WindowListener<K,R,P> listener) {
this.listeners.remove(new UnwrappedWeakReference<WindowListener<K,R,P>>(listener));
} | java | public void removeListener(WindowListener<K,R,P> listener) {
this.listeners.remove(new UnwrappedWeakReference<WindowListener<K,R,P>>(listener));
} | [
"public",
"void",
"removeListener",
"(",
"WindowListener",
"<",
"K",
",",
"R",
",",
"P",
">",
"listener",
")",
"{",
"this",
".",
"listeners",
".",
"remove",
"(",
"new",
"UnwrappedWeakReference",
"<",
"WindowListener",
"<",
"K",
",",
"R",
",",
"P",
">",
">",
"(",
"listener",
")",
")",
";",
"}"
] | Removes a WindowListener if it is present.
@param listener The listener to remove | [
"Removes",
"a",
"WindowListener",
"if",
"it",
"is",
"present",
"."
] | b5bc397dbec4537e8149e7ec0733c1d7ed477499 | https://github.com/twitter/cloudhopper-commons/blob/b5bc397dbec4537e8149e7ec0733c1d7ed477499/ch-commons-util/src/main/java/com/cloudhopper/commons/util/windowing/Window.java#L214-L216 |
3,623 | twitter/cloudhopper-commons | ch-commons-util/src/main/java/com/cloudhopper/commons/util/windowing/Window.java | Window.startMonitor | public synchronized boolean startMonitor() {
if (this.executor != null) {
if (this.monitorHandle == null) {
this.monitorHandle = this.executor.scheduleWithFixedDelay(this.monitor, this.monitorInterval, this.monitorInterval, TimeUnit.MILLISECONDS);
}
return true;
}
return false;
} | java | public synchronized boolean startMonitor() {
if (this.executor != null) {
if (this.monitorHandle == null) {
this.monitorHandle = this.executor.scheduleWithFixedDelay(this.monitor, this.monitorInterval, this.monitorInterval, TimeUnit.MILLISECONDS);
}
return true;
}
return false;
} | [
"public",
"synchronized",
"boolean",
"startMonitor",
"(",
")",
"{",
"if",
"(",
"this",
".",
"executor",
"!=",
"null",
")",
"{",
"if",
"(",
"this",
".",
"monitorHandle",
"==",
"null",
")",
"{",
"this",
".",
"monitorHandle",
"=",
"this",
".",
"executor",
".",
"scheduleWithFixedDelay",
"(",
"this",
".",
"monitor",
",",
"this",
".",
"monitorInterval",
",",
"this",
".",
"monitorInterval",
",",
"TimeUnit",
".",
"MILLISECONDS",
")",
";",
"}",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Starts the monitor if this Window has an executor. Safe to call multiple
times.
@return True if the monitor was started (true will be returned if it
was already previously started). | [
"Starts",
"the",
"monitor",
"if",
"this",
"Window",
"has",
"an",
"executor",
".",
"Safe",
"to",
"call",
"multiple",
"times",
"."
] | b5bc397dbec4537e8149e7ec0733c1d7ed477499 | https://github.com/twitter/cloudhopper-commons/blob/b5bc397dbec4537e8149e7ec0733c1d7ed477499/ch-commons-util/src/main/java/com/cloudhopper/commons/util/windowing/Window.java#L246-L254 |
3,624 | twitter/cloudhopper-commons | ch-commons-util/src/main/java/com/cloudhopper/commons/util/windowing/Window.java | Window.createSortedSnapshot | public Map<K,WindowFuture<K,R,P>> createSortedSnapshot() {
Map<K,WindowFuture<K,R,P>> sortedRequests = new TreeMap<K,WindowFuture<K,R,P>>();
sortedRequests.putAll(this.futures);
return sortedRequests;
} | java | public Map<K,WindowFuture<K,R,P>> createSortedSnapshot() {
Map<K,WindowFuture<K,R,P>> sortedRequests = new TreeMap<K,WindowFuture<K,R,P>>();
sortedRequests.putAll(this.futures);
return sortedRequests;
} | [
"public",
"Map",
"<",
"K",
",",
"WindowFuture",
"<",
"K",
",",
"R",
",",
"P",
">",
">",
"createSortedSnapshot",
"(",
")",
"{",
"Map",
"<",
"K",
",",
"WindowFuture",
"<",
"K",
",",
"R",
",",
"P",
">",
">",
"sortedRequests",
"=",
"new",
"TreeMap",
"<",
"K",
",",
"WindowFuture",
"<",
"K",
",",
"R",
",",
"P",
">",
">",
"(",
")",
";",
"sortedRequests",
".",
"putAll",
"(",
"this",
".",
"futures",
")",
";",
"return",
"sortedRequests",
";",
"}"
] | Creates an ordered snapshot of the requests in this window. The entries
will be sorted by the natural ascending order of the key. A new map
is allocated when calling this method, so be careful about calling it
once.
@return A new map instance representing all requests sorted by
the natural ascending order of its key. | [
"Creates",
"an",
"ordered",
"snapshot",
"of",
"the",
"requests",
"in",
"this",
"window",
".",
"The",
"entries",
"will",
"be",
"sorted",
"by",
"the",
"natural",
"ascending",
"order",
"of",
"the",
"key",
".",
"A",
"new",
"map",
"is",
"allocated",
"when",
"calling",
"this",
"method",
"so",
"be",
"careful",
"about",
"calling",
"it",
"once",
"."
] | b5bc397dbec4537e8149e7ec0733c1d7ed477499 | https://github.com/twitter/cloudhopper-commons/blob/b5bc397dbec4537e8149e7ec0733c1d7ed477499/ch-commons-util/src/main/java/com/cloudhopper/commons/util/windowing/Window.java#L274-L278 |
3,625 | twitter/cloudhopper-commons | ch-commons-util/src/main/java/com/cloudhopper/commons/util/windowing/Window.java | Window.offer | public WindowFuture offer(K key, R request, long offerTimeoutMillis, long expireTimeoutMillis, boolean callerWaitingHint) throws DuplicateKeyException, OfferTimeoutException, PendingOfferAbortedException, InterruptedException {
if (offerTimeoutMillis < 0) {
throw new IllegalArgumentException("offerTimeoutMillis must be >= 0 [actual=" + offerTimeoutMillis + "]");
}
// does this key already exist?
if (this.futures.containsKey(key)) {
throw new DuplicateKeyException("The key [" + key + "] already exists in the window");
}
long offerTimestamp = System.currentTimeMillis();
this.lock.lockInterruptibly();
try {
// does enough room exist in the "window" for another pending request?
// NOTE: wait for room up to the offerTimeoutMillis
// NOTE: multiple signals may be received that will need to be ignored
while (getFreeSize() <= 0) {
// check if there time remaining to wait
long currentOfferTime = System.currentTimeMillis() - offerTimestamp;
if (currentOfferTime >= offerTimeoutMillis) {
throw new OfferTimeoutException("Unable to accept offer within [" + offerTimeoutMillis + " ms] (window full)");
}
// check if slow waiting was canceled (terminate early)
if (this.pendingOffersAborted.get()) {
throw new PendingOfferAbortedException("Pending offer aborted (by an explicit call to abortPendingOffers())");
}
// calculate the amount of timeout remaining
long remainingOfferTime = offerTimeoutMillis - currentOfferTime;
try {
// await for a new signal for this max amount of time
this.beginPendingOffer();
this.completedCondition.await(remainingOfferTime, TimeUnit.MILLISECONDS);
} finally {
boolean abortPendingOffer = this.endPendingOffer();
if (abortPendingOffer) {
throw new PendingOfferAbortedException("Pending offer aborted (by an explicit call to abortPendingOffers())");
}
}
}
long acceptTimestamp = System.currentTimeMillis();
long expireTimestamp = (expireTimeoutMillis > 0 ? (acceptTimestamp + expireTimeoutMillis) : -1);
int callerStateHint = (callerWaitingHint ? WindowFuture.CALLER_WAITING : WindowFuture.CALLER_NOT_WAITING);
DefaultWindowFuture<K,R,P> future = new DefaultWindowFuture<K,R,P>(this, lock, completedCondition, key, request, callerStateHint, offerTimeoutMillis, (futures.size() + 1), offerTimestamp, acceptTimestamp, expireTimestamp);
this.futures.put(key, future);
return future;
} finally {
this.lock.unlock();
}
} | java | public WindowFuture offer(K key, R request, long offerTimeoutMillis, long expireTimeoutMillis, boolean callerWaitingHint) throws DuplicateKeyException, OfferTimeoutException, PendingOfferAbortedException, InterruptedException {
if (offerTimeoutMillis < 0) {
throw new IllegalArgumentException("offerTimeoutMillis must be >= 0 [actual=" + offerTimeoutMillis + "]");
}
// does this key already exist?
if (this.futures.containsKey(key)) {
throw new DuplicateKeyException("The key [" + key + "] already exists in the window");
}
long offerTimestamp = System.currentTimeMillis();
this.lock.lockInterruptibly();
try {
// does enough room exist in the "window" for another pending request?
// NOTE: wait for room up to the offerTimeoutMillis
// NOTE: multiple signals may be received that will need to be ignored
while (getFreeSize() <= 0) {
// check if there time remaining to wait
long currentOfferTime = System.currentTimeMillis() - offerTimestamp;
if (currentOfferTime >= offerTimeoutMillis) {
throw new OfferTimeoutException("Unable to accept offer within [" + offerTimeoutMillis + " ms] (window full)");
}
// check if slow waiting was canceled (terminate early)
if (this.pendingOffersAborted.get()) {
throw new PendingOfferAbortedException("Pending offer aborted (by an explicit call to abortPendingOffers())");
}
// calculate the amount of timeout remaining
long remainingOfferTime = offerTimeoutMillis - currentOfferTime;
try {
// await for a new signal for this max amount of time
this.beginPendingOffer();
this.completedCondition.await(remainingOfferTime, TimeUnit.MILLISECONDS);
} finally {
boolean abortPendingOffer = this.endPendingOffer();
if (abortPendingOffer) {
throw new PendingOfferAbortedException("Pending offer aborted (by an explicit call to abortPendingOffers())");
}
}
}
long acceptTimestamp = System.currentTimeMillis();
long expireTimestamp = (expireTimeoutMillis > 0 ? (acceptTimestamp + expireTimeoutMillis) : -1);
int callerStateHint = (callerWaitingHint ? WindowFuture.CALLER_WAITING : WindowFuture.CALLER_NOT_WAITING);
DefaultWindowFuture<K,R,P> future = new DefaultWindowFuture<K,R,P>(this, lock, completedCondition, key, request, callerStateHint, offerTimeoutMillis, (futures.size() + 1), offerTimestamp, acceptTimestamp, expireTimestamp);
this.futures.put(key, future);
return future;
} finally {
this.lock.unlock();
}
} | [
"public",
"WindowFuture",
"offer",
"(",
"K",
"key",
",",
"R",
"request",
",",
"long",
"offerTimeoutMillis",
",",
"long",
"expireTimeoutMillis",
",",
"boolean",
"callerWaitingHint",
")",
"throws",
"DuplicateKeyException",
",",
"OfferTimeoutException",
",",
"PendingOfferAbortedException",
",",
"InterruptedException",
"{",
"if",
"(",
"offerTimeoutMillis",
"<",
"0",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"offerTimeoutMillis must be >= 0 [actual=\"",
"+",
"offerTimeoutMillis",
"+",
"\"]\"",
")",
";",
"}",
"// does this key already exist?",
"if",
"(",
"this",
".",
"futures",
".",
"containsKey",
"(",
"key",
")",
")",
"{",
"throw",
"new",
"DuplicateKeyException",
"(",
"\"The key [\"",
"+",
"key",
"+",
"\"] already exists in the window\"",
")",
";",
"}",
"long",
"offerTimestamp",
"=",
"System",
".",
"currentTimeMillis",
"(",
")",
";",
"this",
".",
"lock",
".",
"lockInterruptibly",
"(",
")",
";",
"try",
"{",
"// does enough room exist in the \"window\" for another pending request?",
"// NOTE: wait for room up to the offerTimeoutMillis",
"// NOTE: multiple signals may be received that will need to be ignored",
"while",
"(",
"getFreeSize",
"(",
")",
"<=",
"0",
")",
"{",
"// check if there time remaining to wait",
"long",
"currentOfferTime",
"=",
"System",
".",
"currentTimeMillis",
"(",
")",
"-",
"offerTimestamp",
";",
"if",
"(",
"currentOfferTime",
">=",
"offerTimeoutMillis",
")",
"{",
"throw",
"new",
"OfferTimeoutException",
"(",
"\"Unable to accept offer within [\"",
"+",
"offerTimeoutMillis",
"+",
"\" ms] (window full)\"",
")",
";",
"}",
"// check if slow waiting was canceled (terminate early)",
"if",
"(",
"this",
".",
"pendingOffersAborted",
".",
"get",
"(",
")",
")",
"{",
"throw",
"new",
"PendingOfferAbortedException",
"(",
"\"Pending offer aborted (by an explicit call to abortPendingOffers())\"",
")",
";",
"}",
"// calculate the amount of timeout remaining",
"long",
"remainingOfferTime",
"=",
"offerTimeoutMillis",
"-",
"currentOfferTime",
";",
"try",
"{",
"// await for a new signal for this max amount of time",
"this",
".",
"beginPendingOffer",
"(",
")",
";",
"this",
".",
"completedCondition",
".",
"await",
"(",
"remainingOfferTime",
",",
"TimeUnit",
".",
"MILLISECONDS",
")",
";",
"}",
"finally",
"{",
"boolean",
"abortPendingOffer",
"=",
"this",
".",
"endPendingOffer",
"(",
")",
";",
"if",
"(",
"abortPendingOffer",
")",
"{",
"throw",
"new",
"PendingOfferAbortedException",
"(",
"\"Pending offer aborted (by an explicit call to abortPendingOffers())\"",
")",
";",
"}",
"}",
"}",
"long",
"acceptTimestamp",
"=",
"System",
".",
"currentTimeMillis",
"(",
")",
";",
"long",
"expireTimestamp",
"=",
"(",
"expireTimeoutMillis",
">",
"0",
"?",
"(",
"acceptTimestamp",
"+",
"expireTimeoutMillis",
")",
":",
"-",
"1",
")",
";",
"int",
"callerStateHint",
"=",
"(",
"callerWaitingHint",
"?",
"WindowFuture",
".",
"CALLER_WAITING",
":",
"WindowFuture",
".",
"CALLER_NOT_WAITING",
")",
";",
"DefaultWindowFuture",
"<",
"K",
",",
"R",
",",
"P",
">",
"future",
"=",
"new",
"DefaultWindowFuture",
"<",
"K",
",",
"R",
",",
"P",
">",
"(",
"this",
",",
"lock",
",",
"completedCondition",
",",
"key",
",",
"request",
",",
"callerStateHint",
",",
"offerTimeoutMillis",
",",
"(",
"futures",
".",
"size",
"(",
")",
"+",
"1",
")",
",",
"offerTimestamp",
",",
"acceptTimestamp",
",",
"expireTimestamp",
")",
";",
"this",
".",
"futures",
".",
"put",
"(",
"key",
",",
"future",
")",
";",
"return",
"future",
";",
"}",
"finally",
"{",
"this",
".",
"lock",
".",
"unlock",
"(",
")",
";",
"}",
"}"
] | Offers a request for acceptance, waiting for the specified amount of time
in case it could not immediately accepted.
@param key The key for the request. A protocol's sequence number is a
good choice.
@param request The request to offer
@param offerTimeoutMillis The amount of time (in milliseconds) to wait
for the offer to be accepted.
@param expireTimeoutMillis The amount of time (in milliseconds) that a
request will be set to expire after acceptance. A value < 1 is
assumed to be an infinite expiration (request never expires).
Requests are not automatically expired unless monitoring was enabled
during construction of this window.
@param callerWaitingHint If true the "caller state hint" of the
future will be set to "WAITING" during construction. This generally
does not affect any internal processing by this window, but allows
callers to hint they plan on calling "await()" on the future.
@return A future representing pending completion of the request
@throws DuplicateKeyException Thrown if the key already exists
@throws PendingOfferAbortedException Thrown if the offer could not be
immediately accepted and the caller/thread was waiting, but
the abortPendingOffers() method was called in the meantime.
@throws OfferTimeoutException Thrown if the offer could not be accepted
within the specified amount of time.
@throws InterruptedException Thrown if the calling thread is interrupted
while waiting to acquire the internal lock. | [
"Offers",
"a",
"request",
"for",
"acceptance",
"waiting",
"for",
"the",
"specified",
"amount",
"of",
"time",
"in",
"case",
"it",
"could",
"not",
"immediately",
"accepted",
"."
] | b5bc397dbec4537e8149e7ec0733c1d7ed477499 | https://github.com/twitter/cloudhopper-commons/blob/b5bc397dbec4537e8149e7ec0733c1d7ed477499/ch-commons-util/src/main/java/com/cloudhopper/commons/util/windowing/Window.java#L359-L411 |
3,626 | twitter/cloudhopper-commons | ch-commons-util/src/main/java/com/cloudhopper/commons/util/windowing/Window.java | Window.endPendingOffer | private boolean endPendingOffer() {
int newValue = this.pendingOffers.decrementAndGet();
// if newValue reaches zero, make sure to always reset "offeringAborted"
if (newValue == 0) {
// if slotWaitingCanceled was true, then reset it back to false, and
// return true to make sure the caller knows to cancel waiting
return this.pendingOffersAborted.compareAndSet(true, false);
} else {
// if slotWaitingCanceled is true, then return true
return this.pendingOffersAborted.get();
}
} | java | private boolean endPendingOffer() {
int newValue = this.pendingOffers.decrementAndGet();
// if newValue reaches zero, make sure to always reset "offeringAborted"
if (newValue == 0) {
// if slotWaitingCanceled was true, then reset it back to false, and
// return true to make sure the caller knows to cancel waiting
return this.pendingOffersAborted.compareAndSet(true, false);
} else {
// if slotWaitingCanceled is true, then return true
return this.pendingOffersAborted.get();
}
} | [
"private",
"boolean",
"endPendingOffer",
"(",
")",
"{",
"int",
"newValue",
"=",
"this",
".",
"pendingOffers",
".",
"decrementAndGet",
"(",
")",
";",
"// if newValue reaches zero, make sure to always reset \"offeringAborted\"",
"if",
"(",
"newValue",
"==",
"0",
")",
"{",
"// if slotWaitingCanceled was true, then reset it back to false, and",
"// return true to make sure the caller knows to cancel waiting",
"return",
"this",
".",
"pendingOffersAborted",
".",
"compareAndSet",
"(",
"true",
",",
"false",
")",
";",
"}",
"else",
"{",
"// if slotWaitingCanceled is true, then return true",
"return",
"this",
".",
"pendingOffersAborted",
".",
"get",
"(",
")",
";",
"}",
"}"
] | End waiting for a pending offer to be accepted. Decrements pendingOffers by 1.
If "pendingOffersAborted" is true and pendingOffers reaches 0 then
pendingOffersAborted will be reset to false.
@return True if a pending offer should be aborted. False if a pending
offer can continue waiting if needed. | [
"End",
"waiting",
"for",
"a",
"pending",
"offer",
"to",
"be",
"accepted",
".",
"Decrements",
"pendingOffers",
"by",
"1",
".",
"If",
"pendingOffersAborted",
"is",
"true",
"and",
"pendingOffers",
"reaches",
"0",
"then",
"pendingOffersAborted",
"will",
"be",
"reset",
"to",
"false",
"."
] | b5bc397dbec4537e8149e7ec0733c1d7ed477499 | https://github.com/twitter/cloudhopper-commons/blob/b5bc397dbec4537e8149e7ec0733c1d7ed477499/ch-commons-util/src/main/java/com/cloudhopper/commons/util/windowing/Window.java#L435-L446 |
3,627 | twitter/cloudhopper-commons | ch-commons-util/src/main/java/com/cloudhopper/commons/util/filefilter/FileNameEndsWithFilter.java | FileNameEndsWithFilter.accept | public boolean accept(File file) {
if (caseSensitive) {
return file.getName().endsWith(string0);
} else {
return file.getName().toLowerCase().endsWith(string0.toLowerCase());
}
} | java | public boolean accept(File file) {
if (caseSensitive) {
return file.getName().endsWith(string0);
} else {
return file.getName().toLowerCase().endsWith(string0.toLowerCase());
}
} | [
"public",
"boolean",
"accept",
"(",
"File",
"file",
")",
"{",
"if",
"(",
"caseSensitive",
")",
"{",
"return",
"file",
".",
"getName",
"(",
")",
".",
"endsWith",
"(",
"string0",
")",
";",
"}",
"else",
"{",
"return",
"file",
".",
"getName",
"(",
")",
".",
"toLowerCase",
"(",
")",
".",
"endsWith",
"(",
"string0",
".",
"toLowerCase",
"(",
")",
")",
";",
"}",
"}"
] | Accepts a File if its filename endsWith a specific string.
@param file The file to match
@return True if the File endsWith the specific string, otherwise false | [
"Accepts",
"a",
"File",
"if",
"its",
"filename",
"endsWith",
"a",
"specific",
"string",
"."
] | b5bc397dbec4537e8149e7ec0733c1d7ed477499 | https://github.com/twitter/cloudhopper-commons/blob/b5bc397dbec4537e8149e7ec0733c1d7ed477499/ch-commons-util/src/main/java/com/cloudhopper/commons/util/filefilter/FileNameEndsWithFilter.java#L53-L59 |
3,628 | twitter/cloudhopper-commons | ch-sxmp/src/main/java/com/cloudhopper/sxmp/util/MobileAddressUtil.java | MobileAddressUtil.parseType | static public MobileAddress.Type parseType(String type) {
if (type.equalsIgnoreCase("network")) {
return MobileAddress.Type.NETWORK;
} else if (type.equalsIgnoreCase("national")) {
return MobileAddress.Type.NATIONAL;
} else if (type.equalsIgnoreCase("alphanumeric")) {
return MobileAddress.Type.ALPHANUMERIC;
} else if (type.equalsIgnoreCase("international")) {
return MobileAddress.Type.INTERNATIONAL;
} else if (type.equalsIgnoreCase("push_destination")) {
return MobileAddress.Type.PUSH_DESTINATION;
} else {
return null;
}
} | java | static public MobileAddress.Type parseType(String type) {
if (type.equalsIgnoreCase("network")) {
return MobileAddress.Type.NETWORK;
} else if (type.equalsIgnoreCase("national")) {
return MobileAddress.Type.NATIONAL;
} else if (type.equalsIgnoreCase("alphanumeric")) {
return MobileAddress.Type.ALPHANUMERIC;
} else if (type.equalsIgnoreCase("international")) {
return MobileAddress.Type.INTERNATIONAL;
} else if (type.equalsIgnoreCase("push_destination")) {
return MobileAddress.Type.PUSH_DESTINATION;
} else {
return null;
}
} | [
"static",
"public",
"MobileAddress",
".",
"Type",
"parseType",
"(",
"String",
"type",
")",
"{",
"if",
"(",
"type",
".",
"equalsIgnoreCase",
"(",
"\"network\"",
")",
")",
"{",
"return",
"MobileAddress",
".",
"Type",
".",
"NETWORK",
";",
"}",
"else",
"if",
"(",
"type",
".",
"equalsIgnoreCase",
"(",
"\"national\"",
")",
")",
"{",
"return",
"MobileAddress",
".",
"Type",
".",
"NATIONAL",
";",
"}",
"else",
"if",
"(",
"type",
".",
"equalsIgnoreCase",
"(",
"\"alphanumeric\"",
")",
")",
"{",
"return",
"MobileAddress",
".",
"Type",
".",
"ALPHANUMERIC",
";",
"}",
"else",
"if",
"(",
"type",
".",
"equalsIgnoreCase",
"(",
"\"international\"",
")",
")",
"{",
"return",
"MobileAddress",
".",
"Type",
".",
"INTERNATIONAL",
";",
"}",
"else",
"if",
"(",
"type",
".",
"equalsIgnoreCase",
"(",
"\"push_destination\"",
")",
")",
"{",
"return",
"MobileAddress",
".",
"Type",
".",
"PUSH_DESTINATION",
";",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"}"
] | Parses string into a MobileAddress type. Case insensitive. Returns null
if no match was found. | [
"Parses",
"string",
"into",
"a",
"MobileAddress",
"type",
".",
"Case",
"insensitive",
".",
"Returns",
"null",
"if",
"no",
"match",
"was",
"found",
"."
] | b5bc397dbec4537e8149e7ec0733c1d7ed477499 | https://github.com/twitter/cloudhopper-commons/blob/b5bc397dbec4537e8149e7ec0733c1d7ed477499/ch-sxmp/src/main/java/com/cloudhopper/sxmp/util/MobileAddressUtil.java#L37-L51 |
3,629 | twitter/cloudhopper-commons | ch-commons-util/src/main/java/com/cloudhopper/commons/util/ClassUtil.java | ClassUtil.getClassHierarchy | public static Class<?>[] getClassHierarchy(Class<?> type) {
ArrayDeque<Class<?>> classes = new ArrayDeque<Class<?>>();
// class to start our search from, we'll loop thru the entire class hierarchy
Class<?> classType = type;
// keep searching up until we reach an Object class type
while (classType != null && !classType.equals(Object.class)) {
// keep adding onto front
classes.addFirst(classType);
classType = classType.getSuperclass();
}
return classes.toArray(new Class[0]);
} | java | public static Class<?>[] getClassHierarchy(Class<?> type) {
ArrayDeque<Class<?>> classes = new ArrayDeque<Class<?>>();
// class to start our search from, we'll loop thru the entire class hierarchy
Class<?> classType = type;
// keep searching up until we reach an Object class type
while (classType != null && !classType.equals(Object.class)) {
// keep adding onto front
classes.addFirst(classType);
classType = classType.getSuperclass();
}
return classes.toArray(new Class[0]);
} | [
"public",
"static",
"Class",
"<",
"?",
">",
"[",
"]",
"getClassHierarchy",
"(",
"Class",
"<",
"?",
">",
"type",
")",
"{",
"ArrayDeque",
"<",
"Class",
"<",
"?",
">",
">",
"classes",
"=",
"new",
"ArrayDeque",
"<",
"Class",
"<",
"?",
">",
">",
"(",
")",
";",
"// class to start our search from, we'll loop thru the entire class hierarchy",
"Class",
"<",
"?",
">",
"classType",
"=",
"type",
";",
"// keep searching up until we reach an Object class type",
"while",
"(",
"classType",
"!=",
"null",
"&&",
"!",
"classType",
".",
"equals",
"(",
"Object",
".",
"class",
")",
")",
"{",
"// keep adding onto front",
"classes",
".",
"addFirst",
"(",
"classType",
")",
";",
"classType",
"=",
"classType",
".",
"getSuperclass",
"(",
")",
";",
"}",
"return",
"classes",
".",
"toArray",
"(",
"new",
"Class",
"[",
"0",
"]",
")",
";",
"}"
] | Returns an array of class objects representing the entire class hierarchy
with the most-super class as the first element followed by all subclasses
in the order they are declared. This method does not include the generic
Object type in its list. If this class represents the Object type, this
method will return a zero-size array. | [
"Returns",
"an",
"array",
"of",
"class",
"objects",
"representing",
"the",
"entire",
"class",
"hierarchy",
"with",
"the",
"most",
"-",
"super",
"class",
"as",
"the",
"first",
"element",
"followed",
"by",
"all",
"subclasses",
"in",
"the",
"order",
"they",
"are",
"declared",
".",
"This",
"method",
"does",
"not",
"include",
"the",
"generic",
"Object",
"type",
"in",
"its",
"list",
".",
"If",
"this",
"class",
"represents",
"the",
"Object",
"type",
"this",
"method",
"will",
"return",
"a",
"zero",
"-",
"size",
"array",
"."
] | b5bc397dbec4537e8149e7ec0733c1d7ed477499 | https://github.com/twitter/cloudhopper-commons/blob/b5bc397dbec4537e8149e7ec0733c1d7ed477499/ch-commons-util/src/main/java/com/cloudhopper/commons/util/ClassUtil.java#L74-L85 |
3,630 | twitter/cloudhopper-commons | ch-commons-util/src/main/java/com/cloudhopper/commons/util/ClassUtil.java | ClassUtil.getMethod | public static Method getMethod(Class<?> type, String name, Class<?> returnType, Class<?> paramType, boolean caseSensitive)
throws IllegalAccessException, NoSuchMethodException {
// flag to help modify the exception to make it a little easier for debugging
boolean methodNameFound = false;
// start our search
Class<?> classType = type;
while (classType != null && !classType.equals(Object.class)) {
for (Method m : classType.getDeclaredMethods()) {
if ((!caseSensitive && m.getName().equalsIgnoreCase(name)) || (caseSensitive && m.getName().equals(name))) {
// we found the method name, but its possible the signature won't
// match below, we'll set this flag to help construct a better exception
// below
methodNameFound = true;
// should we validate the return type?
if (returnType != null) {
// if the return types don't match, then this must be invalid
// since the JVM doesn't allow the same return type
if (!m.getReturnType().equals(returnType)) {
throw new NoSuchMethodException("Method '" + name + "' was found in " + type.getSimpleName() + ".class"
+ ", but the returnType " + m.getReturnType().getSimpleName() + ".class did not match expected " + returnType.getSimpleName() + ".class");
}
// make sure the return type is VOID
} else {
if (!m.getReturnType().equals(void.class)) {
throw new NoSuchMethodException("Method '" + name + "' was found in " + type.getSimpleName() + ".class"
+ ", but the returnType " + m.getReturnType().getSimpleName() + ".class was expected to be void");
}
}
// return type was okay, check the parameters
Class<?>[] paramTypes = m.getParameterTypes();
// should we check the parameter type?
if (paramType != null) {
// must have exactly 1 parameter
if (paramTypes.length != 1) {
// this might not be the method we want, keep searching
continue;
} else {
// if the parameters don't match, keep searching
if (!paramTypes[0].equals(paramType)) {
continue;
}
}
// if paramType was null, then make sure no parameters are expected
} else {
if (paramTypes.length != 0) {
continue;
}
}
// if we got here, then everything matches so far
// now its time to check if the method is accessible
if (!Modifier.isPublic(m.getModifiers())) {
throw new IllegalAccessException("Method '" + name + "' was found in " + type.getSimpleName() + ".class "+
", but its not accessible since its " + Modifier.toString(m.getModifiers()));
}
// everything was okay
return m;
}
}
// move onto the superclass
classType = classType.getSuperclass();
}
String signature = "public " + (returnType == null ? "void" : returnType.getName()) + " " + name + "(" + (paramType == null ? "" : paramType.getName()) + ")";
if (methodNameFound) {
throw new NoSuchMethodException("Method '" + signature + "' was found in " + type.getSimpleName() + ".class, but signature match failed");
} else {
throw new NoSuchMethodException("Method '" + signature + "' was not found in " + type.getSimpleName() + ".class");
}
} | java | public static Method getMethod(Class<?> type, String name, Class<?> returnType, Class<?> paramType, boolean caseSensitive)
throws IllegalAccessException, NoSuchMethodException {
// flag to help modify the exception to make it a little easier for debugging
boolean methodNameFound = false;
// start our search
Class<?> classType = type;
while (classType != null && !classType.equals(Object.class)) {
for (Method m : classType.getDeclaredMethods()) {
if ((!caseSensitive && m.getName().equalsIgnoreCase(name)) || (caseSensitive && m.getName().equals(name))) {
// we found the method name, but its possible the signature won't
// match below, we'll set this flag to help construct a better exception
// below
methodNameFound = true;
// should we validate the return type?
if (returnType != null) {
// if the return types don't match, then this must be invalid
// since the JVM doesn't allow the same return type
if (!m.getReturnType().equals(returnType)) {
throw new NoSuchMethodException("Method '" + name + "' was found in " + type.getSimpleName() + ".class"
+ ", but the returnType " + m.getReturnType().getSimpleName() + ".class did not match expected " + returnType.getSimpleName() + ".class");
}
// make sure the return type is VOID
} else {
if (!m.getReturnType().equals(void.class)) {
throw new NoSuchMethodException("Method '" + name + "' was found in " + type.getSimpleName() + ".class"
+ ", but the returnType " + m.getReturnType().getSimpleName() + ".class was expected to be void");
}
}
// return type was okay, check the parameters
Class<?>[] paramTypes = m.getParameterTypes();
// should we check the parameter type?
if (paramType != null) {
// must have exactly 1 parameter
if (paramTypes.length != 1) {
// this might not be the method we want, keep searching
continue;
} else {
// if the parameters don't match, keep searching
if (!paramTypes[0].equals(paramType)) {
continue;
}
}
// if paramType was null, then make sure no parameters are expected
} else {
if (paramTypes.length != 0) {
continue;
}
}
// if we got here, then everything matches so far
// now its time to check if the method is accessible
if (!Modifier.isPublic(m.getModifiers())) {
throw new IllegalAccessException("Method '" + name + "' was found in " + type.getSimpleName() + ".class "+
", but its not accessible since its " + Modifier.toString(m.getModifiers()));
}
// everything was okay
return m;
}
}
// move onto the superclass
classType = classType.getSuperclass();
}
String signature = "public " + (returnType == null ? "void" : returnType.getName()) + " " + name + "(" + (paramType == null ? "" : paramType.getName()) + ")";
if (methodNameFound) {
throw new NoSuchMethodException("Method '" + signature + "' was found in " + type.getSimpleName() + ".class, but signature match failed");
} else {
throw new NoSuchMethodException("Method '" + signature + "' was not found in " + type.getSimpleName() + ".class");
}
} | [
"public",
"static",
"Method",
"getMethod",
"(",
"Class",
"<",
"?",
">",
"type",
",",
"String",
"name",
",",
"Class",
"<",
"?",
">",
"returnType",
",",
"Class",
"<",
"?",
">",
"paramType",
",",
"boolean",
"caseSensitive",
")",
"throws",
"IllegalAccessException",
",",
"NoSuchMethodException",
"{",
"// flag to help modify the exception to make it a little easier for debugging",
"boolean",
"methodNameFound",
"=",
"false",
";",
"// start our search",
"Class",
"<",
"?",
">",
"classType",
"=",
"type",
";",
"while",
"(",
"classType",
"!=",
"null",
"&&",
"!",
"classType",
".",
"equals",
"(",
"Object",
".",
"class",
")",
")",
"{",
"for",
"(",
"Method",
"m",
":",
"classType",
".",
"getDeclaredMethods",
"(",
")",
")",
"{",
"if",
"(",
"(",
"!",
"caseSensitive",
"&&",
"m",
".",
"getName",
"(",
")",
".",
"equalsIgnoreCase",
"(",
"name",
")",
")",
"||",
"(",
"caseSensitive",
"&&",
"m",
".",
"getName",
"(",
")",
".",
"equals",
"(",
"name",
")",
")",
")",
"{",
"// we found the method name, but its possible the signature won't",
"// match below, we'll set this flag to help construct a better exception",
"// below",
"methodNameFound",
"=",
"true",
";",
"// should we validate the return type?",
"if",
"(",
"returnType",
"!=",
"null",
")",
"{",
"// if the return types don't match, then this must be invalid",
"// since the JVM doesn't allow the same return type",
"if",
"(",
"!",
"m",
".",
"getReturnType",
"(",
")",
".",
"equals",
"(",
"returnType",
")",
")",
"{",
"throw",
"new",
"NoSuchMethodException",
"(",
"\"Method '\"",
"+",
"name",
"+",
"\"' was found in \"",
"+",
"type",
".",
"getSimpleName",
"(",
")",
"+",
"\".class\"",
"+",
"\", but the returnType \"",
"+",
"m",
".",
"getReturnType",
"(",
")",
".",
"getSimpleName",
"(",
")",
"+",
"\".class did not match expected \"",
"+",
"returnType",
".",
"getSimpleName",
"(",
")",
"+",
"\".class\"",
")",
";",
"}",
"// make sure the return type is VOID",
"}",
"else",
"{",
"if",
"(",
"!",
"m",
".",
"getReturnType",
"(",
")",
".",
"equals",
"(",
"void",
".",
"class",
")",
")",
"{",
"throw",
"new",
"NoSuchMethodException",
"(",
"\"Method '\"",
"+",
"name",
"+",
"\"' was found in \"",
"+",
"type",
".",
"getSimpleName",
"(",
")",
"+",
"\".class\"",
"+",
"\", but the returnType \"",
"+",
"m",
".",
"getReturnType",
"(",
")",
".",
"getSimpleName",
"(",
")",
"+",
"\".class was expected to be void\"",
")",
";",
"}",
"}",
"// return type was okay, check the parameters",
"Class",
"<",
"?",
">",
"[",
"]",
"paramTypes",
"=",
"m",
".",
"getParameterTypes",
"(",
")",
";",
"// should we check the parameter type?",
"if",
"(",
"paramType",
"!=",
"null",
")",
"{",
"// must have exactly 1 parameter",
"if",
"(",
"paramTypes",
".",
"length",
"!=",
"1",
")",
"{",
"// this might not be the method we want, keep searching",
"continue",
";",
"}",
"else",
"{",
"// if the parameters don't match, keep searching",
"if",
"(",
"!",
"paramTypes",
"[",
"0",
"]",
".",
"equals",
"(",
"paramType",
")",
")",
"{",
"continue",
";",
"}",
"}",
"// if paramType was null, then make sure no parameters are expected",
"}",
"else",
"{",
"if",
"(",
"paramTypes",
".",
"length",
"!=",
"0",
")",
"{",
"continue",
";",
"}",
"}",
"// if we got here, then everything matches so far",
"// now its time to check if the method is accessible",
"if",
"(",
"!",
"Modifier",
".",
"isPublic",
"(",
"m",
".",
"getModifiers",
"(",
")",
")",
")",
"{",
"throw",
"new",
"IllegalAccessException",
"(",
"\"Method '\"",
"+",
"name",
"+",
"\"' was found in \"",
"+",
"type",
".",
"getSimpleName",
"(",
")",
"+",
"\".class \"",
"+",
"\", but its not accessible since its \"",
"+",
"Modifier",
".",
"toString",
"(",
"m",
".",
"getModifiers",
"(",
")",
")",
")",
";",
"}",
"// everything was okay",
"return",
"m",
";",
"}",
"}",
"// move onto the superclass",
"classType",
"=",
"classType",
".",
"getSuperclass",
"(",
")",
";",
"}",
"String",
"signature",
"=",
"\"public \"",
"+",
"(",
"returnType",
"==",
"null",
"?",
"\"void\"",
":",
"returnType",
".",
"getName",
"(",
")",
")",
"+",
"\" \"",
"+",
"name",
"+",
"\"(\"",
"+",
"(",
"paramType",
"==",
"null",
"?",
"\"\"",
":",
"paramType",
".",
"getName",
"(",
")",
")",
"+",
"\")\"",
";",
"if",
"(",
"methodNameFound",
")",
"{",
"throw",
"new",
"NoSuchMethodException",
"(",
"\"Method '\"",
"+",
"signature",
"+",
"\"' was found in \"",
"+",
"type",
".",
"getSimpleName",
"(",
")",
"+",
"\".class, but signature match failed\"",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"NoSuchMethodException",
"(",
"\"Method '\"",
"+",
"signature",
"+",
"\"' was not found in \"",
"+",
"type",
".",
"getSimpleName",
"(",
")",
"+",
"\".class\"",
")",
";",
"}",
"}"
] | Gets the public method within the type that matches the method name, return type,
and single parameter type. Optionally is a case sensitive search. Useful
for searching for "bean" methods on classes.
@param type The class to search for the method
@param name The name of the method to search for
@param returnType The expected return type or null if its expected to be a void method
@param paramType The expected parameter type or null if no parameters are expected
@param caseSensitive True if its a case sensitive search, otherwise false
@return The method matching the search criteria
@throws java.lang.IllegalAccessException If the method was found, but is not public.
@throws java.lang.NoSuchMethodException If the method was not found | [
"Gets",
"the",
"public",
"method",
"within",
"the",
"type",
"that",
"matches",
"the",
"method",
"name",
"return",
"type",
"and",
"single",
"parameter",
"type",
".",
"Optionally",
"is",
"a",
"case",
"sensitive",
"search",
".",
"Useful",
"for",
"searching",
"for",
"bean",
"methods",
"on",
"classes",
"."
] | b5bc397dbec4537e8149e7ec0733c1d7ed477499 | https://github.com/twitter/cloudhopper-commons/blob/b5bc397dbec4537e8149e7ec0733c1d7ed477499/ch-commons-util/src/main/java/com/cloudhopper/commons/util/ClassUtil.java#L157-L238 |
3,631 | twitter/cloudhopper-commons | ch-commons-util/src/main/java/com/cloudhopper/commons/util/LoadBalancedLists.java | LoadBalancedLists.synchronizedList | static public <E> LoadBalancedList<E> synchronizedList(LoadBalancedList<E> list) {
return new ConcurrentLoadBalancedList<E>(list);
} | java | static public <E> LoadBalancedList<E> synchronizedList(LoadBalancedList<E> list) {
return new ConcurrentLoadBalancedList<E>(list);
} | [
"static",
"public",
"<",
"E",
">",
"LoadBalancedList",
"<",
"E",
">",
"synchronizedList",
"(",
"LoadBalancedList",
"<",
"E",
">",
"list",
")",
"{",
"return",
"new",
"ConcurrentLoadBalancedList",
"<",
"E",
">",
"(",
"list",
")",
";",
"}"
] | Creates a synchronized version of a LoadBalancedList by putting a lock
around any method that reads or writes to the internal data structure.
@param list The list to synchronize
@return A wrapper around the original list that provides synchronized access. | [
"Creates",
"a",
"synchronized",
"version",
"of",
"a",
"LoadBalancedList",
"by",
"putting",
"a",
"lock",
"around",
"any",
"method",
"that",
"reads",
"or",
"writes",
"to",
"the",
"internal",
"data",
"structure",
"."
] | b5bc397dbec4537e8149e7ec0733c1d7ed477499 | https://github.com/twitter/cloudhopper-commons/blob/b5bc397dbec4537e8149e7ec0733c1d7ed477499/ch-commons-util/src/main/java/com/cloudhopper/commons/util/LoadBalancedLists.java#L40-L42 |
3,632 | twitter/cloudhopper-commons | ch-commons-util/src/main/java/com/cloudhopper/commons/util/HexUtil.java | HexUtil.toHexString | static public String toHexString(byte value) {
StringBuilder buffer = new StringBuilder(2);
appendHexString(buffer, value);
return buffer.toString();
} | java | static public String toHexString(byte value) {
StringBuilder buffer = new StringBuilder(2);
appendHexString(buffer, value);
return buffer.toString();
} | [
"static",
"public",
"String",
"toHexString",
"(",
"byte",
"value",
")",
"{",
"StringBuilder",
"buffer",
"=",
"new",
"StringBuilder",
"(",
"2",
")",
";",
"appendHexString",
"(",
"buffer",
",",
"value",
")",
";",
"return",
"buffer",
".",
"toString",
"(",
")",
";",
"}"
] | Creates a 2 character hex String from a byte with the byte in a "Big Endian"
hexidecimal format. For example, a byte 0x34 will be returned as a
String in format "34". A byte of value 0 will be returned as "00".
@param value The byte value that will be converted to a hexidecimal String. | [
"Creates",
"a",
"2",
"character",
"hex",
"String",
"from",
"a",
"byte",
"with",
"the",
"byte",
"in",
"a",
"Big",
"Endian",
"hexidecimal",
"format",
".",
"For",
"example",
"a",
"byte",
"0x34",
"will",
"be",
"returned",
"as",
"a",
"String",
"in",
"format",
"34",
".",
"A",
"byte",
"of",
"value",
"0",
"will",
"be",
"returned",
"as",
"00",
"."
] | b5bc397dbec4537e8149e7ec0733c1d7ed477499 | https://github.com/twitter/cloudhopper-commons/blob/b5bc397dbec4537e8149e7ec0733c1d7ed477499/ch-commons-util/src/main/java/com/cloudhopper/commons/util/HexUtil.java#L129-L133 |
3,633 | twitter/cloudhopper-commons | ch-commons-util/src/main/java/com/cloudhopper/commons/util/HexUtil.java | HexUtil.appendHexString | static public void appendHexString(StringBuilder buffer, byte value) {
assertNotNull(buffer);
int nibble = (value & 0xF0) >>> 4;
buffer.append(HEX_TABLE[nibble]);
nibble = (value & 0x0F);
buffer.append(HEX_TABLE[nibble]);
} | java | static public void appendHexString(StringBuilder buffer, byte value) {
assertNotNull(buffer);
int nibble = (value & 0xF0) >>> 4;
buffer.append(HEX_TABLE[nibble]);
nibble = (value & 0x0F);
buffer.append(HEX_TABLE[nibble]);
} | [
"static",
"public",
"void",
"appendHexString",
"(",
"StringBuilder",
"buffer",
",",
"byte",
"value",
")",
"{",
"assertNotNull",
"(",
"buffer",
")",
";",
"int",
"nibble",
"=",
"(",
"value",
"&",
"0xF0",
")",
">>>",
"4",
";",
"buffer",
".",
"append",
"(",
"HEX_TABLE",
"[",
"nibble",
"]",
")",
";",
"nibble",
"=",
"(",
"value",
"&",
"0x0F",
")",
";",
"buffer",
".",
"append",
"(",
"HEX_TABLE",
"[",
"nibble",
"]",
")",
";",
"}"
] | Appends 2 characters to a StringBuilder with the byte in a "Big Endian"
hexidecimal format. For example, a byte 0x34 will be appended as a
String in format "34". A byte of value 0 will be appended as "00".
@param buffer The StringBuilder the byte value in hexidecimal format
will be appended to. If the buffer is null, this method will throw
a NullPointerException.
@param value The byte value that will be converted to a hexidecimal String. | [
"Appends",
"2",
"characters",
"to",
"a",
"StringBuilder",
"with",
"the",
"byte",
"in",
"a",
"Big",
"Endian",
"hexidecimal",
"format",
".",
"For",
"example",
"a",
"byte",
"0x34",
"will",
"be",
"appended",
"as",
"a",
"String",
"in",
"format",
"34",
".",
"A",
"byte",
"of",
"value",
"0",
"will",
"be",
"appended",
"as",
"00",
"."
] | b5bc397dbec4537e8149e7ec0733c1d7ed477499 | https://github.com/twitter/cloudhopper-commons/blob/b5bc397dbec4537e8149e7ec0733c1d7ed477499/ch-commons-util/src/main/java/com/cloudhopper/commons/util/HexUtil.java#L144-L150 |
3,634 | twitter/cloudhopper-commons | ch-commons-util/src/main/java/com/cloudhopper/commons/util/HexUtil.java | HexUtil.appendHexString | static public void appendHexString(StringBuilder buffer, short value) {
assertNotNull(buffer);
int nibble = (value & 0xF000) >>> 12;
buffer.append(HEX_TABLE[nibble]);
nibble = (value & 0x0F00) >>> 8;
buffer.append(HEX_TABLE[nibble]);
nibble = (value & 0x00F0) >>> 4;
buffer.append(HEX_TABLE[nibble]);
nibble = (value & 0x000F);
buffer.append(HEX_TABLE[nibble]);
} | java | static public void appendHexString(StringBuilder buffer, short value) {
assertNotNull(buffer);
int nibble = (value & 0xF000) >>> 12;
buffer.append(HEX_TABLE[nibble]);
nibble = (value & 0x0F00) >>> 8;
buffer.append(HEX_TABLE[nibble]);
nibble = (value & 0x00F0) >>> 4;
buffer.append(HEX_TABLE[nibble]);
nibble = (value & 0x000F);
buffer.append(HEX_TABLE[nibble]);
} | [
"static",
"public",
"void",
"appendHexString",
"(",
"StringBuilder",
"buffer",
",",
"short",
"value",
")",
"{",
"assertNotNull",
"(",
"buffer",
")",
";",
"int",
"nibble",
"=",
"(",
"value",
"&",
"0xF000",
")",
">>>",
"12",
";",
"buffer",
".",
"append",
"(",
"HEX_TABLE",
"[",
"nibble",
"]",
")",
";",
"nibble",
"=",
"(",
"value",
"&",
"0x0F00",
")",
">>>",
"8",
";",
"buffer",
".",
"append",
"(",
"HEX_TABLE",
"[",
"nibble",
"]",
")",
";",
"nibble",
"=",
"(",
"value",
"&",
"0x00F0",
")",
">>>",
"4",
";",
"buffer",
".",
"append",
"(",
"HEX_TABLE",
"[",
"nibble",
"]",
")",
";",
"nibble",
"=",
"(",
"value",
"&",
"0x000F",
")",
";",
"buffer",
".",
"append",
"(",
"HEX_TABLE",
"[",
"nibble",
"]",
")",
";",
"}"
] | Appends 4 characters to a StringBuilder with the short in a "Big Endian"
hexidecimal format. For example, a short 0x1234 will be appended as a
String in format "1234". A short of value 0 will be appended as "0000".
@param buffer The StringBuilder the short value in hexidecimal format
will be appended to. If the buffer is null, this method will throw
a NullPointerException.
@param value The short value that will be converted to a hexidecimal String. | [
"Appends",
"4",
"characters",
"to",
"a",
"StringBuilder",
"with",
"the",
"short",
"in",
"a",
"Big",
"Endian",
"hexidecimal",
"format",
".",
"For",
"example",
"a",
"short",
"0x1234",
"will",
"be",
"appended",
"as",
"a",
"String",
"in",
"format",
"1234",
".",
"A",
"short",
"of",
"value",
"0",
"will",
"be",
"appended",
"as",
"0000",
"."
] | b5bc397dbec4537e8149e7ec0733c1d7ed477499 | https://github.com/twitter/cloudhopper-commons/blob/b5bc397dbec4537e8149e7ec0733c1d7ed477499/ch-commons-util/src/main/java/com/cloudhopper/commons/util/HexUtil.java#L173-L183 |
3,635 | twitter/cloudhopper-commons | ch-commons-util/src/main/java/com/cloudhopper/commons/util/HexUtil.java | HexUtil.appendHexString | static public void appendHexString(StringBuilder buffer, int value) {
assertNotNull(buffer);
int nibble = (value & 0xF0000000) >>> 28;
buffer.append(HEX_TABLE[nibble]);
nibble = (value & 0x0F000000) >>> 24;
buffer.append(HEX_TABLE[nibble]);
nibble = (value & 0x00F00000) >>> 20;
buffer.append(HEX_TABLE[nibble]);
nibble = (value & 0x000F0000) >>> 16;
buffer.append(HEX_TABLE[nibble]);
nibble = (value & 0x0000F000) >>> 12;
buffer.append(HEX_TABLE[nibble]);
nibble = (value & 0x00000F00) >>> 8;
buffer.append(HEX_TABLE[nibble]);
nibble = (value & 0x000000F0) >>> 4;
buffer.append(HEX_TABLE[nibble]);
nibble = (value & 0x0000000F);
buffer.append(HEX_TABLE[nibble]);
} | java | static public void appendHexString(StringBuilder buffer, int value) {
assertNotNull(buffer);
int nibble = (value & 0xF0000000) >>> 28;
buffer.append(HEX_TABLE[nibble]);
nibble = (value & 0x0F000000) >>> 24;
buffer.append(HEX_TABLE[nibble]);
nibble = (value & 0x00F00000) >>> 20;
buffer.append(HEX_TABLE[nibble]);
nibble = (value & 0x000F0000) >>> 16;
buffer.append(HEX_TABLE[nibble]);
nibble = (value & 0x0000F000) >>> 12;
buffer.append(HEX_TABLE[nibble]);
nibble = (value & 0x00000F00) >>> 8;
buffer.append(HEX_TABLE[nibble]);
nibble = (value & 0x000000F0) >>> 4;
buffer.append(HEX_TABLE[nibble]);
nibble = (value & 0x0000000F);
buffer.append(HEX_TABLE[nibble]);
} | [
"static",
"public",
"void",
"appendHexString",
"(",
"StringBuilder",
"buffer",
",",
"int",
"value",
")",
"{",
"assertNotNull",
"(",
"buffer",
")",
";",
"int",
"nibble",
"=",
"(",
"value",
"&",
"0xF0000000",
")",
">>>",
"28",
";",
"buffer",
".",
"append",
"(",
"HEX_TABLE",
"[",
"nibble",
"]",
")",
";",
"nibble",
"=",
"(",
"value",
"&",
"0x0F000000",
")",
">>>",
"24",
";",
"buffer",
".",
"append",
"(",
"HEX_TABLE",
"[",
"nibble",
"]",
")",
";",
"nibble",
"=",
"(",
"value",
"&",
"0x00F00000",
")",
">>>",
"20",
";",
"buffer",
".",
"append",
"(",
"HEX_TABLE",
"[",
"nibble",
"]",
")",
";",
"nibble",
"=",
"(",
"value",
"&",
"0x000F0000",
")",
">>>",
"16",
";",
"buffer",
".",
"append",
"(",
"HEX_TABLE",
"[",
"nibble",
"]",
")",
";",
"nibble",
"=",
"(",
"value",
"&",
"0x0000F000",
")",
">>>",
"12",
";",
"buffer",
".",
"append",
"(",
"HEX_TABLE",
"[",
"nibble",
"]",
")",
";",
"nibble",
"=",
"(",
"value",
"&",
"0x00000F00",
")",
">>>",
"8",
";",
"buffer",
".",
"append",
"(",
"HEX_TABLE",
"[",
"nibble",
"]",
")",
";",
"nibble",
"=",
"(",
"value",
"&",
"0x000000F0",
")",
">>>",
"4",
";",
"buffer",
".",
"append",
"(",
"HEX_TABLE",
"[",
"nibble",
"]",
")",
";",
"nibble",
"=",
"(",
"value",
"&",
"0x0000000F",
")",
";",
"buffer",
".",
"append",
"(",
"HEX_TABLE",
"[",
"nibble",
"]",
")",
";",
"}"
] | Appends 8 characters to a StringBuilder with the int in a "Big Endian"
hexidecimal format. For example, a int 0xFFAA1234 will be appended as a
String in format "FFAA1234". A int of value 0 will be appended as "00000000".
@param buffer The StringBuilder the int value in hexidecimal format
will be appended to. If the buffer is null, this method will throw
a NullPointerException.
@param value The int value that will be converted to a hexidecimal String. | [
"Appends",
"8",
"characters",
"to",
"a",
"StringBuilder",
"with",
"the",
"int",
"in",
"a",
"Big",
"Endian",
"hexidecimal",
"format",
".",
"For",
"example",
"a",
"int",
"0xFFAA1234",
"will",
"be",
"appended",
"as",
"a",
"String",
"in",
"format",
"FFAA1234",
".",
"A",
"int",
"of",
"value",
"0",
"will",
"be",
"appended",
"as",
"00000000",
"."
] | b5bc397dbec4537e8149e7ec0733c1d7ed477499 | https://github.com/twitter/cloudhopper-commons/blob/b5bc397dbec4537e8149e7ec0733c1d7ed477499/ch-commons-util/src/main/java/com/cloudhopper/commons/util/HexUtil.java#L206-L224 |
3,636 | twitter/cloudhopper-commons | ch-commons-util/src/main/java/com/cloudhopper/commons/util/HexUtil.java | HexUtil.appendHexString | static public void appendHexString(StringBuilder buffer, long value) {
appendHexString(buffer, (int)((value & 0xFFFFFFFF00000000L) >>> 32));
appendHexString(buffer, (int)(value & 0x00000000FFFFFFFFL));
} | java | static public void appendHexString(StringBuilder buffer, long value) {
appendHexString(buffer, (int)((value & 0xFFFFFFFF00000000L) >>> 32));
appendHexString(buffer, (int)(value & 0x00000000FFFFFFFFL));
} | [
"static",
"public",
"void",
"appendHexString",
"(",
"StringBuilder",
"buffer",
",",
"long",
"value",
")",
"{",
"appendHexString",
"(",
"buffer",
",",
"(",
"int",
")",
"(",
"(",
"value",
"&",
"0xFFFFFFFF00000000",
"L",
")",
">>>",
"32",
")",
")",
";",
"appendHexString",
"(",
"buffer",
",",
"(",
"int",
")",
"(",
"value",
"&",
"0x00000000FFFFFFFF",
"L",
")",
")",
";",
"}"
] | Appends 16 characters to a StringBuilder with the long in a "Big Endian"
hexidecimal format. For example, a long 0xAABBCCDDEE123456 will be appended as a
String in format "AABBCCDDEE123456". A long of value 0 will be appended as "0000000000000000".
@param buffer The StringBuilder the long value in hexidecimal format
will be appended to. If the buffer is null, this method will throw
a NullPointerException.
@param value The long value that will be converted to a hexidecimal String. | [
"Appends",
"16",
"characters",
"to",
"a",
"StringBuilder",
"with",
"the",
"long",
"in",
"a",
"Big",
"Endian",
"hexidecimal",
"format",
".",
"For",
"example",
"a",
"long",
"0xAABBCCDDEE123456",
"will",
"be",
"appended",
"as",
"a",
"String",
"in",
"format",
"AABBCCDDEE123456",
".",
"A",
"long",
"of",
"value",
"0",
"will",
"be",
"appended",
"as",
"0000000000000000",
"."
] | b5bc397dbec4537e8149e7ec0733c1d7ed477499 | https://github.com/twitter/cloudhopper-commons/blob/b5bc397dbec4537e8149e7ec0733c1d7ed477499/ch-commons-util/src/main/java/com/cloudhopper/commons/util/HexUtil.java#L247-L250 |
3,637 | twitter/cloudhopper-commons | ch-commons-util/src/main/java/com/cloudhopper/commons/util/HexUtil.java | HexUtil.hexCharToIntValue | static public int hexCharToIntValue(char c) {
if (c == '0') {
return 0;
} else if (c == '1') {
return 1;
} else if (c == '2') {
return 2;
} else if (c == '3') {
return 3;
} else if (c == '4') {
return 4;
} else if (c == '5') {
return 5;
} else if (c == '6') {
return 6;
} else if (c == '7') {
return 7;
} else if (c == '8') {
return 8;
} else if (c == '9') {
return 9;
} else if (c == 'A' || c == 'a') {
return 10;
} else if (c == 'B' || c == 'b') {
return 11;
} else if (c == 'C' || c == 'c') {
return 12;
} else if (c == 'D' || c == 'd') {
return 13;
} else if (c == 'E' || c == 'e') {
return 14;
} else if (c == 'F' || c == 'f') {
return 15;
} else {
throw new IllegalArgumentException("The character [" + c + "] does not represent a valid hex digit");
}
} | java | static public int hexCharToIntValue(char c) {
if (c == '0') {
return 0;
} else if (c == '1') {
return 1;
} else if (c == '2') {
return 2;
} else if (c == '3') {
return 3;
} else if (c == '4') {
return 4;
} else if (c == '5') {
return 5;
} else if (c == '6') {
return 6;
} else if (c == '7') {
return 7;
} else if (c == '8') {
return 8;
} else if (c == '9') {
return 9;
} else if (c == 'A' || c == 'a') {
return 10;
} else if (c == 'B' || c == 'b') {
return 11;
} else if (c == 'C' || c == 'c') {
return 12;
} else if (c == 'D' || c == 'd') {
return 13;
} else if (c == 'E' || c == 'e') {
return 14;
} else if (c == 'F' || c == 'f') {
return 15;
} else {
throw new IllegalArgumentException("The character [" + c + "] does not represent a valid hex digit");
}
} | [
"static",
"public",
"int",
"hexCharToIntValue",
"(",
"char",
"c",
")",
"{",
"if",
"(",
"c",
"==",
"'",
"'",
")",
"{",
"return",
"0",
";",
"}",
"else",
"if",
"(",
"c",
"==",
"'",
"'",
")",
"{",
"return",
"1",
";",
"}",
"else",
"if",
"(",
"c",
"==",
"'",
"'",
")",
"{",
"return",
"2",
";",
"}",
"else",
"if",
"(",
"c",
"==",
"'",
"'",
")",
"{",
"return",
"3",
";",
"}",
"else",
"if",
"(",
"c",
"==",
"'",
"'",
")",
"{",
"return",
"4",
";",
"}",
"else",
"if",
"(",
"c",
"==",
"'",
"'",
")",
"{",
"return",
"5",
";",
"}",
"else",
"if",
"(",
"c",
"==",
"'",
"'",
")",
"{",
"return",
"6",
";",
"}",
"else",
"if",
"(",
"c",
"==",
"'",
"'",
")",
"{",
"return",
"7",
";",
"}",
"else",
"if",
"(",
"c",
"==",
"'",
"'",
")",
"{",
"return",
"8",
";",
"}",
"else",
"if",
"(",
"c",
"==",
"'",
"'",
")",
"{",
"return",
"9",
";",
"}",
"else",
"if",
"(",
"c",
"==",
"'",
"'",
"||",
"c",
"==",
"'",
"'",
")",
"{",
"return",
"10",
";",
"}",
"else",
"if",
"(",
"c",
"==",
"'",
"'",
"||",
"c",
"==",
"'",
"'",
")",
"{",
"return",
"11",
";",
"}",
"else",
"if",
"(",
"c",
"==",
"'",
"'",
"||",
"c",
"==",
"'",
"'",
")",
"{",
"return",
"12",
";",
"}",
"else",
"if",
"(",
"c",
"==",
"'",
"'",
"||",
"c",
"==",
"'",
"'",
")",
"{",
"return",
"13",
";",
"}",
"else",
"if",
"(",
"c",
"==",
"'",
"'",
"||",
"c",
"==",
"'",
"'",
")",
"{",
"return",
"14",
";",
"}",
"else",
"if",
"(",
"c",
"==",
"'",
"'",
"||",
"c",
"==",
"'",
"'",
")",
"{",
"return",
"15",
";",
"}",
"else",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"The character [\"",
"+",
"c",
"+",
"\"] does not represent a valid hex digit\"",
")",
";",
"}",
"}"
] | Converts a hexidecimal character such as '0' or 'A' or 'a' to its integer
value such as 0 or 10. Used to decode hexidecimal Strings to integer values.
@param c The hexidecimal character
@return The integer value the character represents
@throws IllegalArgumentException Thrown if a character that does not
represent a hexidecimal character is used. | [
"Converts",
"a",
"hexidecimal",
"character",
"such",
"as",
"0",
"or",
"A",
"or",
"a",
"to",
"its",
"integer",
"value",
"such",
"as",
"0",
"or",
"10",
".",
"Used",
"to",
"decode",
"hexidecimal",
"Strings",
"to",
"integer",
"values",
"."
] | b5bc397dbec4537e8149e7ec0733c1d7ed477499 | https://github.com/twitter/cloudhopper-commons/blob/b5bc397dbec4537e8149e7ec0733c1d7ed477499/ch-commons-util/src/main/java/com/cloudhopper/commons/util/HexUtil.java#L278-L314 |
3,638 | twitter/cloudhopper-commons | ch-commons-util/src/main/java/com/cloudhopper/commons/util/ManagementUtil.java | ManagementUtil.getMBeanServerId | public static String getMBeanServerId(final MBeanServer aMBeanServer) {
String serverId = null;
final String SERVER_DELEGATE = "JMImplementation:type=MBeanServerDelegate";
final String MBEAN_SERVER_ID_KEY = "MBeanServerId";
try {
ObjectName delegateObjName = new ObjectName(SERVER_DELEGATE);
serverId = (String) aMBeanServer.getAttribute(delegateObjName,
MBEAN_SERVER_ID_KEY);
} catch (MalformedObjectNameException malformedObjectNameException) {
//System.err.println("Problems constructing MBean ObjectName: " + malformedObjectNameException.getMessage());
} catch (AttributeNotFoundException noMatchingAttrException) {
//System.err.println("Unable to find attribute " + MBEAN_SERVER_ID_KEY + " in MBean " + SERVER_DELEGATE + ": " + noMatchingAttrException);
} catch (MBeanException mBeanException) {
//System.err.println("Exception thrown by MBean's (" + SERVER_DELEGATE + "'s " + MBEAN_SERVER_ID_KEY + ") getter: " + mBeanException.getMessage());
} catch (ReflectionException reflectionException) {
//System.err.println("Exception thrown by MBean's (" + SERVER_DELEGATE + "'s " + MBEAN_SERVER_ID_KEY + ") setter: " + reflectionException.getMessage());
} catch (InstanceNotFoundException noMBeanInstance) {
//System.err.println("No instance of MBean " + SERVER_DELEGATE + " found in MBeanServer: " + noMBeanInstance.getMessage());
}
return serverId;
} | java | public static String getMBeanServerId(final MBeanServer aMBeanServer) {
String serverId = null;
final String SERVER_DELEGATE = "JMImplementation:type=MBeanServerDelegate";
final String MBEAN_SERVER_ID_KEY = "MBeanServerId";
try {
ObjectName delegateObjName = new ObjectName(SERVER_DELEGATE);
serverId = (String) aMBeanServer.getAttribute(delegateObjName,
MBEAN_SERVER_ID_KEY);
} catch (MalformedObjectNameException malformedObjectNameException) {
//System.err.println("Problems constructing MBean ObjectName: " + malformedObjectNameException.getMessage());
} catch (AttributeNotFoundException noMatchingAttrException) {
//System.err.println("Unable to find attribute " + MBEAN_SERVER_ID_KEY + " in MBean " + SERVER_DELEGATE + ": " + noMatchingAttrException);
} catch (MBeanException mBeanException) {
//System.err.println("Exception thrown by MBean's (" + SERVER_DELEGATE + "'s " + MBEAN_SERVER_ID_KEY + ") getter: " + mBeanException.getMessage());
} catch (ReflectionException reflectionException) {
//System.err.println("Exception thrown by MBean's (" + SERVER_DELEGATE + "'s " + MBEAN_SERVER_ID_KEY + ") setter: " + reflectionException.getMessage());
} catch (InstanceNotFoundException noMBeanInstance) {
//System.err.println("No instance of MBean " + SERVER_DELEGATE + " found in MBeanServer: " + noMBeanInstance.getMessage());
}
return serverId;
} | [
"public",
"static",
"String",
"getMBeanServerId",
"(",
"final",
"MBeanServer",
"aMBeanServer",
")",
"{",
"String",
"serverId",
"=",
"null",
";",
"final",
"String",
"SERVER_DELEGATE",
"=",
"\"JMImplementation:type=MBeanServerDelegate\"",
";",
"final",
"String",
"MBEAN_SERVER_ID_KEY",
"=",
"\"MBeanServerId\"",
";",
"try",
"{",
"ObjectName",
"delegateObjName",
"=",
"new",
"ObjectName",
"(",
"SERVER_DELEGATE",
")",
";",
"serverId",
"=",
"(",
"String",
")",
"aMBeanServer",
".",
"getAttribute",
"(",
"delegateObjName",
",",
"MBEAN_SERVER_ID_KEY",
")",
";",
"}",
"catch",
"(",
"MalformedObjectNameException",
"malformedObjectNameException",
")",
"{",
"//System.err.println(\"Problems constructing MBean ObjectName: \" + malformedObjectNameException.getMessage());",
"}",
"catch",
"(",
"AttributeNotFoundException",
"noMatchingAttrException",
")",
"{",
"//System.err.println(\"Unable to find attribute \" + MBEAN_SERVER_ID_KEY + \" in MBean \" + SERVER_DELEGATE + \": \" + noMatchingAttrException);",
"}",
"catch",
"(",
"MBeanException",
"mBeanException",
")",
"{",
"//System.err.println(\"Exception thrown by MBean's (\" + SERVER_DELEGATE + \"'s \" + MBEAN_SERVER_ID_KEY + \") getter: \" + mBeanException.getMessage());",
"}",
"catch",
"(",
"ReflectionException",
"reflectionException",
")",
"{",
"//System.err.println(\"Exception thrown by MBean's (\" + SERVER_DELEGATE + \"'s \" + MBEAN_SERVER_ID_KEY + \") setter: \" + reflectionException.getMessage());",
"}",
"catch",
"(",
"InstanceNotFoundException",
"noMBeanInstance",
")",
"{",
"//System.err.println(\"No instance of MBean \" + SERVER_DELEGATE + \" found in MBeanServer: \" + noMBeanInstance.getMessage());",
"}",
"return",
"serverId",
";",
"}"
] | Get the MBeanServerId of Agent ID for the provided MBeanServer.
@param aMBeanServer MBeanServer whose Server ID/Agent ID is desired.
@return MBeanServerId/Agent ID of provided MBeanServer. | [
"Get",
"the",
"MBeanServerId",
"of",
"Agent",
"ID",
"for",
"the",
"provided",
"MBeanServer",
"."
] | b5bc397dbec4537e8149e7ec0733c1d7ed477499 | https://github.com/twitter/cloudhopper-commons/blob/b5bc397dbec4537e8149e7ec0733c1d7ed477499/ch-commons-util/src/main/java/com/cloudhopper/commons/util/ManagementUtil.java#L37-L57 |
3,639 | twitter/cloudhopper-commons | ch-commons-util/src/main/java/com/cloudhopper/commons/util/FastByteArrayOutputStream.java | FastByteArrayOutputStream.addBuffer | protected void addBuffer() {
if (buffers == null) {
buffers = new LinkedList<byte[]>();
}
buffers.addLast(buffer);
buffer = new byte[blockSize];
size += index;
index = 0;
} | java | protected void addBuffer() {
if (buffers == null) {
buffers = new LinkedList<byte[]>();
}
buffers.addLast(buffer);
buffer = new byte[blockSize];
size += index;
index = 0;
} | [
"protected",
"void",
"addBuffer",
"(",
")",
"{",
"if",
"(",
"buffers",
"==",
"null",
")",
"{",
"buffers",
"=",
"new",
"LinkedList",
"<",
"byte",
"[",
"]",
">",
"(",
")",
";",
"}",
"buffers",
".",
"addLast",
"(",
"buffer",
")",
";",
"buffer",
"=",
"new",
"byte",
"[",
"blockSize",
"]",
";",
"size",
"+=",
"index",
";",
"index",
"=",
"0",
";",
"}"
] | Create a new buffer and store the
current one in linked list | [
"Create",
"a",
"new",
"buffer",
"and",
"store",
"the",
"current",
"one",
"in",
"linked",
"list"
] | b5bc397dbec4537e8149e7ec0733c1d7ed477499 | https://github.com/twitter/cloudhopper-commons/blob/b5bc397dbec4537e8149e7ec0733c1d7ed477499/ch-commons-util/src/main/java/com/cloudhopper/commons/util/FastByteArrayOutputStream.java#L264-L274 |
3,640 | twitter/cloudhopper-commons | ch-commons-xbean/src/main/java/com/cloudhopper/commons/xml/XmlParser.java | XmlParser.parse | public synchronized Node parse(String xml) throws IOException, SAXException {
ByteArrayInputStream is = new ByteArrayInputStream(xml.getBytes());
return parse(is);
} | java | public synchronized Node parse(String xml) throws IOException, SAXException {
ByteArrayInputStream is = new ByteArrayInputStream(xml.getBytes());
return parse(is);
} | [
"public",
"synchronized",
"Node",
"parse",
"(",
"String",
"xml",
")",
"throws",
"IOException",
",",
"SAXException",
"{",
"ByteArrayInputStream",
"is",
"=",
"new",
"ByteArrayInputStream",
"(",
"xml",
".",
"getBytes",
"(",
")",
")",
";",
"return",
"parse",
"(",
"is",
")",
";",
"}"
] | Parse XML from a String. | [
"Parse",
"XML",
"from",
"a",
"String",
"."
] | b5bc397dbec4537e8149e7ec0733c1d7ed477499 | https://github.com/twitter/cloudhopper-commons/blob/b5bc397dbec4537e8149e7ec0733c1d7ed477499/ch-commons-xbean/src/main/java/com/cloudhopper/commons/xml/XmlParser.java#L221-L224 |
3,641 | twitter/cloudhopper-commons | ch-commons-xbean/src/main/java/com/cloudhopper/commons/xml/XmlParser.java | XmlParser.parse | public synchronized Node parse(File file) throws IOException, SAXException {
return parse(new InputSource(file.toURI().toURL().toString()));
} | java | public synchronized Node parse(File file) throws IOException, SAXException {
return parse(new InputSource(file.toURI().toURL().toString()));
} | [
"public",
"synchronized",
"Node",
"parse",
"(",
"File",
"file",
")",
"throws",
"IOException",
",",
"SAXException",
"{",
"return",
"parse",
"(",
"new",
"InputSource",
"(",
"file",
".",
"toURI",
"(",
")",
".",
"toURL",
"(",
")",
".",
"toString",
"(",
")",
")",
")",
";",
"}"
] | Parse XML from File. | [
"Parse",
"XML",
"from",
"File",
"."
] | b5bc397dbec4537e8149e7ec0733c1d7ed477499 | https://github.com/twitter/cloudhopper-commons/blob/b5bc397dbec4537e8149e7ec0733c1d7ed477499/ch-commons-xbean/src/main/java/com/cloudhopper/commons/xml/XmlParser.java#L229-L231 |
3,642 | twitter/cloudhopper-commons | ch-commons-xbean/src/main/java/com/cloudhopper/commons/xml/XmlParser.java | XmlParser.parse | public synchronized Node parse(InputStream in) throws IOException, SAXException {
//_dtd=null;
Handler handler = new Handler();
XMLReader reader = _parser.getXMLReader();
reader.setContentHandler(handler);
reader.setErrorHandler(handler);
reader.setEntityResolver(handler);
_parser.parse(new InputSource(in), handler);
if (handler.error != null)
throw handler.error;
Node root = (Node)handler.root;
handler.reset();
return root;
} | java | public synchronized Node parse(InputStream in) throws IOException, SAXException {
//_dtd=null;
Handler handler = new Handler();
XMLReader reader = _parser.getXMLReader();
reader.setContentHandler(handler);
reader.setErrorHandler(handler);
reader.setEntityResolver(handler);
_parser.parse(new InputSource(in), handler);
if (handler.error != null)
throw handler.error;
Node root = (Node)handler.root;
handler.reset();
return root;
} | [
"public",
"synchronized",
"Node",
"parse",
"(",
"InputStream",
"in",
")",
"throws",
"IOException",
",",
"SAXException",
"{",
"//_dtd=null;",
"Handler",
"handler",
"=",
"new",
"Handler",
"(",
")",
";",
"XMLReader",
"reader",
"=",
"_parser",
".",
"getXMLReader",
"(",
")",
";",
"reader",
".",
"setContentHandler",
"(",
"handler",
")",
";",
"reader",
".",
"setErrorHandler",
"(",
"handler",
")",
";",
"reader",
".",
"setEntityResolver",
"(",
"handler",
")",
";",
"_parser",
".",
"parse",
"(",
"new",
"InputSource",
"(",
"in",
")",
",",
"handler",
")",
";",
"if",
"(",
"handler",
".",
"error",
"!=",
"null",
")",
"throw",
"handler",
".",
"error",
";",
"Node",
"root",
"=",
"(",
"Node",
")",
"handler",
".",
"root",
";",
"handler",
".",
"reset",
"(",
")",
";",
"return",
"root",
";",
"}"
] | Parse XML from InputStream. | [
"Parse",
"XML",
"from",
"InputStream",
"."
] | b5bc397dbec4537e8149e7ec0733c1d7ed477499 | https://github.com/twitter/cloudhopper-commons/blob/b5bc397dbec4537e8149e7ec0733c1d7ed477499/ch-commons-xbean/src/main/java/com/cloudhopper/commons/xml/XmlParser.java#L236-L249 |
3,643 | twitter/cloudhopper-commons | ch-jetty/src/main/java/com/cloudhopper/jetty/JettyHttpServer.java | JettyHttpServer.start | public void start() throws Exception {
// verify server is NOT null
if (server == null) {
throw new NullPointerException("Internal server instance was null, server not configured perhaps?");
}
logger.info("HttpServer [{}] version [{}] using Jetty [{}]", configuration.safeGetName(), com.cloudhopper.jetty.Version.getLongVersion(),
server.getVersion());
logger.info("HttpServer [{}] on [{}] starting...", configuration.safeGetName(), configuration.getPortString());
// try to start jetty server -- if it fails, it'll actually keep running
// so if an exception occurs, we'll make to stop it afterwards and rethrow the exception
try {
server.start();
} catch (Exception e) {
// make sure we stop the server
try { this.stop(); } catch (Exception ex) { }
throw e;
}
logger.info("HttpServer [{}] on [{}] started", configuration.safeGetName(), configuration.getPortString());
} | java | public void start() throws Exception {
// verify server is NOT null
if (server == null) {
throw new NullPointerException("Internal server instance was null, server not configured perhaps?");
}
logger.info("HttpServer [{}] version [{}] using Jetty [{}]", configuration.safeGetName(), com.cloudhopper.jetty.Version.getLongVersion(),
server.getVersion());
logger.info("HttpServer [{}] on [{}] starting...", configuration.safeGetName(), configuration.getPortString());
// try to start jetty server -- if it fails, it'll actually keep running
// so if an exception occurs, we'll make to stop it afterwards and rethrow the exception
try {
server.start();
} catch (Exception e) {
// make sure we stop the server
try { this.stop(); } catch (Exception ex) { }
throw e;
}
logger.info("HttpServer [{}] on [{}] started", configuration.safeGetName(), configuration.getPortString());
} | [
"public",
"void",
"start",
"(",
")",
"throws",
"Exception",
"{",
"// verify server is NOT null",
"if",
"(",
"server",
"==",
"null",
")",
"{",
"throw",
"new",
"NullPointerException",
"(",
"\"Internal server instance was null, server not configured perhaps?\"",
")",
";",
"}",
"logger",
".",
"info",
"(",
"\"HttpServer [{}] version [{}] using Jetty [{}]\"",
",",
"configuration",
".",
"safeGetName",
"(",
")",
",",
"com",
".",
"cloudhopper",
".",
"jetty",
".",
"Version",
".",
"getLongVersion",
"(",
")",
",",
"server",
".",
"getVersion",
"(",
")",
")",
";",
"logger",
".",
"info",
"(",
"\"HttpServer [{}] on [{}] starting...\"",
",",
"configuration",
".",
"safeGetName",
"(",
")",
",",
"configuration",
".",
"getPortString",
"(",
")",
")",
";",
"// try to start jetty server -- if it fails, it'll actually keep running",
"// so if an exception occurs, we'll make to stop it afterwards and rethrow the exception",
"try",
"{",
"server",
".",
"start",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"// make sure we stop the server",
"try",
"{",
"this",
".",
"stop",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"ex",
")",
"{",
"}",
"throw",
"e",
";",
"}",
"logger",
".",
"info",
"(",
"\"HttpServer [{}] on [{}] started\"",
",",
"configuration",
".",
"safeGetName",
"(",
")",
",",
"configuration",
".",
"getPortString",
"(",
")",
")",
";",
"}"
] | Starts the HTTP server. If an exception is thrown during startup, Jetty
usually still runs, but this method will catch that and make sure it's
shutdown before re-throwing the exception.
@throws Exception Thrown if there is an error during start | [
"Starts",
"the",
"HTTP",
"server",
".",
"If",
"an",
"exception",
"is",
"thrown",
"during",
"startup",
"Jetty",
"usually",
"still",
"runs",
"but",
"this",
"method",
"will",
"catch",
"that",
"and",
"make",
"sure",
"it",
"s",
"shutdown",
"before",
"re",
"-",
"throwing",
"the",
"exception",
"."
] | b5bc397dbec4537e8149e7ec0733c1d7ed477499 | https://github.com/twitter/cloudhopper-commons/blob/b5bc397dbec4537e8149e7ec0733c1d7ed477499/ch-jetty/src/main/java/com/cloudhopper/jetty/JettyHttpServer.java#L73-L94 |
3,644 | twitter/cloudhopper-commons | ch-jetty/src/main/java/com/cloudhopper/jetty/JettyHttpServer.java | JettyHttpServer.stop | public void stop() throws Exception {
// verify server isn't null
if (server == null) {
throw new NullPointerException("Internal server instance was null, server already stopped perhaps?");
}
logger.info("HttpServer [{}] on [{}] stopping...", configuration.safeGetName(), configuration.getPortString());
server.stop();
logger.info("HttpServer [{}] on [{}] stopped", configuration.safeGetName(), configuration.getPortString());
} | java | public void stop() throws Exception {
// verify server isn't null
if (server == null) {
throw new NullPointerException("Internal server instance was null, server already stopped perhaps?");
}
logger.info("HttpServer [{}] on [{}] stopping...", configuration.safeGetName(), configuration.getPortString());
server.stop();
logger.info("HttpServer [{}] on [{}] stopped", configuration.safeGetName(), configuration.getPortString());
} | [
"public",
"void",
"stop",
"(",
")",
"throws",
"Exception",
"{",
"// verify server isn't null",
"if",
"(",
"server",
"==",
"null",
")",
"{",
"throw",
"new",
"NullPointerException",
"(",
"\"Internal server instance was null, server already stopped perhaps?\"",
")",
";",
"}",
"logger",
".",
"info",
"(",
"\"HttpServer [{}] on [{}] stopping...\"",
",",
"configuration",
".",
"safeGetName",
"(",
")",
",",
"configuration",
".",
"getPortString",
"(",
")",
")",
";",
"server",
".",
"stop",
"(",
")",
";",
"logger",
".",
"info",
"(",
"\"HttpServer [{}] on [{}] stopped\"",
",",
"configuration",
".",
"safeGetName",
"(",
")",
",",
"configuration",
".",
"getPortString",
"(",
")",
")",
";",
"}"
] | Stops the HTTP server.
@throws Exception Thrown if there is an error during stop | [
"Stops",
"the",
"HTTP",
"server",
"."
] | b5bc397dbec4537e8149e7ec0733c1d7ed477499 | https://github.com/twitter/cloudhopper-commons/blob/b5bc397dbec4537e8149e7ec0733c1d7ed477499/ch-jetty/src/main/java/com/cloudhopper/jetty/JettyHttpServer.java#L100-L111 |
3,645 | twitter/cloudhopper-commons | ch-jetty/src/main/java/com/cloudhopper/jetty/JettyHttpServer.java | JettyHttpServer.addServlet | public void addServlet(Servlet servlet, String uri) {
// create a holder and then add it to the mapping
ServletHolder servletHolder = new ServletHolder(servlet);
rootServletContext.addServlet(servletHolder, uri);
} | java | public void addServlet(Servlet servlet, String uri) {
// create a holder and then add it to the mapping
ServletHolder servletHolder = new ServletHolder(servlet);
rootServletContext.addServlet(servletHolder, uri);
} | [
"public",
"void",
"addServlet",
"(",
"Servlet",
"servlet",
",",
"String",
"uri",
")",
"{",
"// create a holder and then add it to the mapping",
"ServletHolder",
"servletHolder",
"=",
"new",
"ServletHolder",
"(",
"servlet",
")",
";",
"rootServletContext",
".",
"addServlet",
"(",
"servletHolder",
",",
"uri",
")",
";",
"}"
] | Adds a servlet to this server.
@param servlet The servlet to add
@param uri The uri mapping (relative to root context /) to trigger this
servlet to be executed. Wildcards are permitted. | [
"Adds",
"a",
"servlet",
"to",
"this",
"server",
"."
] | b5bc397dbec4537e8149e7ec0733c1d7ed477499 | https://github.com/twitter/cloudhopper-commons/blob/b5bc397dbec4537e8149e7ec0733c1d7ed477499/ch-jetty/src/main/java/com/cloudhopper/jetty/JettyHttpServer.java#L134-L138 |
3,646 | twitter/cloudhopper-commons | ch-jetty/src/main/java/com/cloudhopper/jetty/JettyHttpServer.java | JettyHttpServer.getMaxQueuedConnections | public int getMaxQueuedConnections() {
return getThreadPool() == null ? -1 :
((getThreadPool().getQueue() instanceof ArrayBlockingQueue) ?
((ArrayBlockingQueue)getThreadPool().getQueue()).size() +
((ArrayBlockingQueue)getThreadPool().getQueue()).remainingCapacity() : -1);
} | java | public int getMaxQueuedConnections() {
return getThreadPool() == null ? -1 :
((getThreadPool().getQueue() instanceof ArrayBlockingQueue) ?
((ArrayBlockingQueue)getThreadPool().getQueue()).size() +
((ArrayBlockingQueue)getThreadPool().getQueue()).remainingCapacity() : -1);
} | [
"public",
"int",
"getMaxQueuedConnections",
"(",
")",
"{",
"return",
"getThreadPool",
"(",
")",
"==",
"null",
"?",
"-",
"1",
":",
"(",
"(",
"getThreadPool",
"(",
")",
".",
"getQueue",
"(",
")",
"instanceof",
"ArrayBlockingQueue",
")",
"?",
"(",
"(",
"ArrayBlockingQueue",
")",
"getThreadPool",
"(",
")",
".",
"getQueue",
"(",
")",
")",
".",
"size",
"(",
")",
"+",
"(",
"(",
"ArrayBlockingQueue",
")",
"getThreadPool",
"(",
")",
".",
"getQueue",
"(",
")",
")",
".",
"remainingCapacity",
"(",
")",
":",
"-",
"1",
")",
";",
"}"
] | this should only be used as an estimate | [
"this",
"should",
"only",
"be",
"used",
"as",
"an",
"estimate"
] | b5bc397dbec4537e8149e7ec0733c1d7ed477499 | https://github.com/twitter/cloudhopper-commons/blob/b5bc397dbec4537e8149e7ec0733c1d7ed477499/ch-jetty/src/main/java/com/cloudhopper/jetty/JettyHttpServer.java#L198-L203 |
3,647 | twitter/cloudhopper-commons | ch-commons-util/src/main/java/com/cloudhopper/commons/util/CompressionUtil.java | CompressionUtil.compress | public static File compress(File sourceFile, String algorithm, boolean deleteSourceFileAfterCompressed) throws FileAlreadyExistsException, IOException {
return compress(sourceFile, sourceFile.getParentFile(), algorithm, deleteSourceFileAfterCompressed);
} | java | public static File compress(File sourceFile, String algorithm, boolean deleteSourceFileAfterCompressed) throws FileAlreadyExistsException, IOException {
return compress(sourceFile, sourceFile.getParentFile(), algorithm, deleteSourceFileAfterCompressed);
} | [
"public",
"static",
"File",
"compress",
"(",
"File",
"sourceFile",
",",
"String",
"algorithm",
",",
"boolean",
"deleteSourceFileAfterCompressed",
")",
"throws",
"FileAlreadyExistsException",
",",
"IOException",
"{",
"return",
"compress",
"(",
"sourceFile",
",",
"sourceFile",
".",
"getParentFile",
"(",
")",
",",
"algorithm",
",",
"deleteSourceFileAfterCompressed",
")",
";",
"}"
] | Compresses the source file using a variety of supported compression
algorithms. This method will create a target file in the same
directory as the source file and will append a file extension matching
the compression algorithm used. For example, using "gzip" will mean a
source file of "app.log" would be compressed to "app.log.gz".
@param sourceFile The uncompressed file
@param algorithm The compression algorithm to use
@param deleteSourceFileAfterCompressed Delete the original source file
only if the compression was successful.
@return The compressed file
@throws FileAlreadyExistsException Thrown if the target file already
exists and an overwrite is not permitted. This exception is a
subclass of IOException, so its safe to only catch an IOException
if no specific action is required for this case.
@throws IOException Thrown if an error occurs while attempting to
compress the source file. | [
"Compresses",
"the",
"source",
"file",
"using",
"a",
"variety",
"of",
"supported",
"compression",
"algorithms",
".",
"This",
"method",
"will",
"create",
"a",
"target",
"file",
"in",
"the",
"same",
"directory",
"as",
"the",
"source",
"file",
"and",
"will",
"append",
"a",
"file",
"extension",
"matching",
"the",
"compression",
"algorithm",
"used",
".",
"For",
"example",
"using",
"gzip",
"will",
"mean",
"a",
"source",
"file",
"of",
"app",
".",
"log",
"would",
"be",
"compressed",
"to",
"app",
".",
"log",
".",
"gz",
"."
] | b5bc397dbec4537e8149e7ec0733c1d7ed477499 | https://github.com/twitter/cloudhopper-commons/blob/b5bc397dbec4537e8149e7ec0733c1d7ed477499/ch-commons-util/src/main/java/com/cloudhopper/commons/util/CompressionUtil.java#L162-L164 |
3,648 | twitter/cloudhopper-commons | ch-commons-util/src/main/java/com/cloudhopper/commons/util/CompressionUtil.java | CompressionUtil.compress | public static File compress(File sourceFile, File targetDir, String algorithm, boolean deleteSourceFileAfterCompressed) throws FileAlreadyExistsException, IOException {
// make sure the destination directory is a directory
if (!targetDir.isDirectory()) {
throw new IOException("Cannot compress file since target directory " + targetDir + " neither exists or is a directory");
}
// try to find compression algorithm
Algorithm a = Algorithm.findByName(algorithm);
// was it found?
if (a == null) {
throw new IOException("Compression algorithm '" + algorithm + "' is not supported");
}
// create a target file with the default file extension for this algorithm
File targetFile = new File(targetDir, sourceFile.getName() + "." + a.getFileExtension());
compress(a, sourceFile, targetFile, deleteSourceFileAfterCompressed);
return targetFile;
} | java | public static File compress(File sourceFile, File targetDir, String algorithm, boolean deleteSourceFileAfterCompressed) throws FileAlreadyExistsException, IOException {
// make sure the destination directory is a directory
if (!targetDir.isDirectory()) {
throw new IOException("Cannot compress file since target directory " + targetDir + " neither exists or is a directory");
}
// try to find compression algorithm
Algorithm a = Algorithm.findByName(algorithm);
// was it found?
if (a == null) {
throw new IOException("Compression algorithm '" + algorithm + "' is not supported");
}
// create a target file with the default file extension for this algorithm
File targetFile = new File(targetDir, sourceFile.getName() + "." + a.getFileExtension());
compress(a, sourceFile, targetFile, deleteSourceFileAfterCompressed);
return targetFile;
} | [
"public",
"static",
"File",
"compress",
"(",
"File",
"sourceFile",
",",
"File",
"targetDir",
",",
"String",
"algorithm",
",",
"boolean",
"deleteSourceFileAfterCompressed",
")",
"throws",
"FileAlreadyExistsException",
",",
"IOException",
"{",
"// make sure the destination directory is a directory",
"if",
"(",
"!",
"targetDir",
".",
"isDirectory",
"(",
")",
")",
"{",
"throw",
"new",
"IOException",
"(",
"\"Cannot compress file since target directory \"",
"+",
"targetDir",
"+",
"\" neither exists or is a directory\"",
")",
";",
"}",
"// try to find compression algorithm",
"Algorithm",
"a",
"=",
"Algorithm",
".",
"findByName",
"(",
"algorithm",
")",
";",
"// was it found?",
"if",
"(",
"a",
"==",
"null",
")",
"{",
"throw",
"new",
"IOException",
"(",
"\"Compression algorithm '\"",
"+",
"algorithm",
"+",
"\"' is not supported\"",
")",
";",
"}",
"// create a target file with the default file extension for this algorithm",
"File",
"targetFile",
"=",
"new",
"File",
"(",
"targetDir",
",",
"sourceFile",
".",
"getName",
"(",
")",
"+",
"\".\"",
"+",
"a",
".",
"getFileExtension",
"(",
")",
")",
";",
"compress",
"(",
"a",
",",
"sourceFile",
",",
"targetFile",
",",
"deleteSourceFileAfterCompressed",
")",
";",
"return",
"targetFile",
";",
"}"
] | Compresses the source file using a variety of supported compression
algorithms. This method will create a destination file in the destination
directory and will append a file extension matching the compression
algorithm used. For example, using "gzip" will mean a source file of
"app.log" would be compressed to "app.log.gz" and placed in the destination
directory.
@param sourceFile The uncompressed file
@param targetDir The target directory or null if same directory as sourceFile
@param algorithm The compression algorithm to use
@param deleteSourceFileAfterCompressed Delete the original source file
only if the compression was successful.
@return The compressed file
@throws FileAlreadyExistsException Thrown if the target file already
exists and an overwrite is not permitted. This exception is a
subclass of IOException, so its safe to only catch an IOException
if no specific action is required for this case.
@throws IOException Thrown if an error occurs while attempting to
compress the source file. | [
"Compresses",
"the",
"source",
"file",
"using",
"a",
"variety",
"of",
"supported",
"compression",
"algorithms",
".",
"This",
"method",
"will",
"create",
"a",
"destination",
"file",
"in",
"the",
"destination",
"directory",
"and",
"will",
"append",
"a",
"file",
"extension",
"matching",
"the",
"compression",
"algorithm",
"used",
".",
"For",
"example",
"using",
"gzip",
"will",
"mean",
"a",
"source",
"file",
"of",
"app",
".",
"log",
"would",
"be",
"compressed",
"to",
"app",
".",
"log",
".",
"gz",
"and",
"placed",
"in",
"the",
"destination",
"directory",
"."
] | b5bc397dbec4537e8149e7ec0733c1d7ed477499 | https://github.com/twitter/cloudhopper-commons/blob/b5bc397dbec4537e8149e7ec0733c1d7ed477499/ch-commons-util/src/main/java/com/cloudhopper/commons/util/CompressionUtil.java#L187-L207 |
3,649 | twitter/cloudhopper-commons | ch-commons-util/src/main/java/com/cloudhopper/commons/util/CompressionUtil.java | CompressionUtil.uncompress | public static File uncompress(File sourceFile, boolean deleteSourceFileAfterUncompressed) throws FileAlreadyExistsException, IOException {
return uncompress(sourceFile, sourceFile.getParentFile(), deleteSourceFileAfterUncompressed);
} | java | public static File uncompress(File sourceFile, boolean deleteSourceFileAfterUncompressed) throws FileAlreadyExistsException, IOException {
return uncompress(sourceFile, sourceFile.getParentFile(), deleteSourceFileAfterUncompressed);
} | [
"public",
"static",
"File",
"uncompress",
"(",
"File",
"sourceFile",
",",
"boolean",
"deleteSourceFileAfterUncompressed",
")",
"throws",
"FileAlreadyExistsException",
",",
"IOException",
"{",
"return",
"uncompress",
"(",
"sourceFile",
",",
"sourceFile",
".",
"getParentFile",
"(",
")",
",",
"deleteSourceFileAfterUncompressed",
")",
";",
"}"
] | Uncompresses the source file using a variety of supported compression
algorithms. This method will create a file in the same directory as
the source file by stripping the compression algorithm's file extension from
the source filename. For example, using "gzip" will mean a source file of
"app.log.gz" would be uncompressed to "app.log".
@param sourceFile The compressed file
@param deleteSourceFileAfterUncompressed Delete the original source file
only if the uncompression was successful.
@return The uncompressed file
@throws FileAlreadyExistsException Thrown if the target file already
exists and an overwrite is not permitted. This exception is a
subclass of IOException, so its safe to only catch an IOException
if no specific action is required for this case.
@throws IOException Thrown if an error occurs while attempting to
uncompress the source file. | [
"Uncompresses",
"the",
"source",
"file",
"using",
"a",
"variety",
"of",
"supported",
"compression",
"algorithms",
".",
"This",
"method",
"will",
"create",
"a",
"file",
"in",
"the",
"same",
"directory",
"as",
"the",
"source",
"file",
"by",
"stripping",
"the",
"compression",
"algorithm",
"s",
"file",
"extension",
"from",
"the",
"source",
"filename",
".",
"For",
"example",
"using",
"gzip",
"will",
"mean",
"a",
"source",
"file",
"of",
"app",
".",
"log",
".",
"gz",
"would",
"be",
"uncompressed",
"to",
"app",
".",
"log",
"."
] | b5bc397dbec4537e8149e7ec0733c1d7ed477499 | https://github.com/twitter/cloudhopper-commons/blob/b5bc397dbec4537e8149e7ec0733c1d7ed477499/ch-commons-util/src/main/java/com/cloudhopper/commons/util/CompressionUtil.java#L227-L229 |
3,650 | twitter/cloudhopper-commons | ch-commons-util/src/main/java/com/cloudhopper/commons/util/CompressionUtil.java | CompressionUtil.uncompress | public static File uncompress(File sourceFile, File targetDir, boolean deleteSourceFileAfterUncompressed) throws FileAlreadyExistsException, IOException {
//
// figure out compression algorithm used by its extension
//
String fileExt = FileUtil.parseFileExtension(sourceFile.getName());
// was a file extension parsed
if (fileExt == null) {
throw new IOException("File '" + sourceFile + "' must contain a file extension in order to lookup the compression algorithm");
}
// try to find compression algorithm
Algorithm a = Algorithm.findByFileExtension(fileExt);
// was it not found?
if (a == null) {
throw new IOException("Unrecognized or unsupported compression algorithm for file extension '" + fileExt + "'");
}
// make sure the destination directory is a directory
if (!targetDir.isDirectory()) {
throw new IOException("Cannot uncompress file since target directory " + targetDir + " neither exists or is a directory");
}
//
// create a target file by stripping the file extension from the original file
//
String filename = sourceFile.getName();
filename = filename.substring(0, filename.length()-(fileExt.length()+1));
File targetFile = new File(targetDir, filename);
uncompress(a, sourceFile, targetFile, deleteSourceFileAfterUncompressed);
return targetFile;
} | java | public static File uncompress(File sourceFile, File targetDir, boolean deleteSourceFileAfterUncompressed) throws FileAlreadyExistsException, IOException {
//
// figure out compression algorithm used by its extension
//
String fileExt = FileUtil.parseFileExtension(sourceFile.getName());
// was a file extension parsed
if (fileExt == null) {
throw new IOException("File '" + sourceFile + "' must contain a file extension in order to lookup the compression algorithm");
}
// try to find compression algorithm
Algorithm a = Algorithm.findByFileExtension(fileExt);
// was it not found?
if (a == null) {
throw new IOException("Unrecognized or unsupported compression algorithm for file extension '" + fileExt + "'");
}
// make sure the destination directory is a directory
if (!targetDir.isDirectory()) {
throw new IOException("Cannot uncompress file since target directory " + targetDir + " neither exists or is a directory");
}
//
// create a target file by stripping the file extension from the original file
//
String filename = sourceFile.getName();
filename = filename.substring(0, filename.length()-(fileExt.length()+1));
File targetFile = new File(targetDir, filename);
uncompress(a, sourceFile, targetFile, deleteSourceFileAfterUncompressed);
return targetFile;
} | [
"public",
"static",
"File",
"uncompress",
"(",
"File",
"sourceFile",
",",
"File",
"targetDir",
",",
"boolean",
"deleteSourceFileAfterUncompressed",
")",
"throws",
"FileAlreadyExistsException",
",",
"IOException",
"{",
"//",
"// figure out compression algorithm used by its extension",
"//",
"String",
"fileExt",
"=",
"FileUtil",
".",
"parseFileExtension",
"(",
"sourceFile",
".",
"getName",
"(",
")",
")",
";",
"// was a file extension parsed",
"if",
"(",
"fileExt",
"==",
"null",
")",
"{",
"throw",
"new",
"IOException",
"(",
"\"File '\"",
"+",
"sourceFile",
"+",
"\"' must contain a file extension in order to lookup the compression algorithm\"",
")",
";",
"}",
"// try to find compression algorithm",
"Algorithm",
"a",
"=",
"Algorithm",
".",
"findByFileExtension",
"(",
"fileExt",
")",
";",
"// was it not found?",
"if",
"(",
"a",
"==",
"null",
")",
"{",
"throw",
"new",
"IOException",
"(",
"\"Unrecognized or unsupported compression algorithm for file extension '\"",
"+",
"fileExt",
"+",
"\"'\"",
")",
";",
"}",
"// make sure the destination directory is a directory",
"if",
"(",
"!",
"targetDir",
".",
"isDirectory",
"(",
")",
")",
"{",
"throw",
"new",
"IOException",
"(",
"\"Cannot uncompress file since target directory \"",
"+",
"targetDir",
"+",
"\" neither exists or is a directory\"",
")",
";",
"}",
"//",
"// create a target file by stripping the file extension from the original file",
"//",
"String",
"filename",
"=",
"sourceFile",
".",
"getName",
"(",
")",
";",
"filename",
"=",
"filename",
".",
"substring",
"(",
"0",
",",
"filename",
".",
"length",
"(",
")",
"-",
"(",
"fileExt",
".",
"length",
"(",
")",
"+",
"1",
")",
")",
";",
"File",
"targetFile",
"=",
"new",
"File",
"(",
"targetDir",
",",
"filename",
")",
";",
"uncompress",
"(",
"a",
",",
"sourceFile",
",",
"targetFile",
",",
"deleteSourceFileAfterUncompressed",
")",
";",
"return",
"targetFile",
";",
"}"
] | Uncompresses the source file using a variety of supported compression
algorithms. This method will create a file in the target
directory by stripping the compression algorithm's file extension from
the source filename. For example, using "gzip" will mean a source file of
"app.log.gz" would be uncompressed to "app.log" and placed in the target
directory.
@param sourceFile The compressed file
@param targetDir The target directory or null to uncompress in same directory as source file
@param deleteSourceFileAfterUncompressed Delete the original source file
only if the uncompression was successful.
@return The uncompressed file
@throws FileAlreadyExistsException Thrown if the target file already
exists and an overwrite is not permitted. This exception is a
subclass of IOException, so its safe to only catch an IOException
if no specific action is required for this case.
@throws IOException Thrown if an error occurs while attempting to
uncompress the source file. | [
"Uncompresses",
"the",
"source",
"file",
"using",
"a",
"variety",
"of",
"supported",
"compression",
"algorithms",
".",
"This",
"method",
"will",
"create",
"a",
"file",
"in",
"the",
"target",
"directory",
"by",
"stripping",
"the",
"compression",
"algorithm",
"s",
"file",
"extension",
"from",
"the",
"source",
"filename",
".",
"For",
"example",
"using",
"gzip",
"will",
"mean",
"a",
"source",
"file",
"of",
"app",
".",
"log",
".",
"gz",
"would",
"be",
"uncompressed",
"to",
"app",
".",
"log",
"and",
"placed",
"in",
"the",
"target",
"directory",
"."
] | b5bc397dbec4537e8149e7ec0733c1d7ed477499 | https://github.com/twitter/cloudhopper-commons/blob/b5bc397dbec4537e8149e7ec0733c1d7ed477499/ch-commons-util/src/main/java/com/cloudhopper/commons/util/CompressionUtil.java#L251-L286 |
3,651 | twitter/cloudhopper-commons | ch-commons-gsm/src/main/java/com/cloudhopper/commons/gsm/TypeOfAddress.java | TypeOfAddress.toByte | public static byte toByte(TypeOfAddress toa) {
byte b = 0;
if (toa.getTon() != null) {
b |= ( toa.getTon().toInt() << 0 );
}
if (toa.getNpi() != null) {
b |= ( toa.getNpi().toInt() << 4 );
}
b |= ( 1 << 7 );
return b;
} | java | public static byte toByte(TypeOfAddress toa) {
byte b = 0;
if (toa.getTon() != null) {
b |= ( toa.getTon().toInt() << 0 );
}
if (toa.getNpi() != null) {
b |= ( toa.getNpi().toInt() << 4 );
}
b |= ( 1 << 7 );
return b;
} | [
"public",
"static",
"byte",
"toByte",
"(",
"TypeOfAddress",
"toa",
")",
"{",
"byte",
"b",
"=",
"0",
";",
"if",
"(",
"toa",
".",
"getTon",
"(",
")",
"!=",
"null",
")",
"{",
"b",
"|=",
"(",
"toa",
".",
"getTon",
"(",
")",
".",
"toInt",
"(",
")",
"<<",
"0",
")",
";",
"}",
"if",
"(",
"toa",
".",
"getNpi",
"(",
")",
"!=",
"null",
")",
"{",
"b",
"|=",
"(",
"toa",
".",
"getNpi",
"(",
")",
".",
"toInt",
"(",
")",
"<<",
"4",
")",
";",
"}",
"b",
"|=",
"(",
"1",
"<<",
"7",
")",
";",
"return",
"b",
";",
"}"
] | To a GSM-encoded type of address byte.
@return The byte representing a type of address | [
"To",
"a",
"GSM",
"-",
"encoded",
"type",
"of",
"address",
"byte",
"."
] | b5bc397dbec4537e8149e7ec0733c1d7ed477499 | https://github.com/twitter/cloudhopper-commons/blob/b5bc397dbec4537e8149e7ec0733c1d7ed477499/ch-commons-gsm/src/main/java/com/cloudhopper/commons/gsm/TypeOfAddress.java#L67-L77 |
3,652 | twitter/cloudhopper-commons | ch-commons-gsm/src/main/java/com/cloudhopper/commons/gsm/TypeOfAddress.java | TypeOfAddress.valueOf | public static TypeOfAddress valueOf(byte b) {
// bits 0-3 are the ton (shift over 0, then only the first 4 bits)
int ton = (b & 0x0F);
// bits 4-7 are the npi (shift over 4, then only the first 3 bits)
int npi = ((b >> 4) & 0x07);
// create our type of address now
return new TypeOfAddress(Ton.fromInt(ton), Npi.fromInt(npi));
} | java | public static TypeOfAddress valueOf(byte b) {
// bits 0-3 are the ton (shift over 0, then only the first 4 bits)
int ton = (b & 0x0F);
// bits 4-7 are the npi (shift over 4, then only the first 3 bits)
int npi = ((b >> 4) & 0x07);
// create our type of address now
return new TypeOfAddress(Ton.fromInt(ton), Npi.fromInt(npi));
} | [
"public",
"static",
"TypeOfAddress",
"valueOf",
"(",
"byte",
"b",
")",
"{",
"// bits 0-3 are the ton (shift over 0, then only the first 4 bits)",
"int",
"ton",
"=",
"(",
"b",
"&",
"0x0F",
")",
";",
"// bits 4-7 are the npi (shift over 4, then only the first 3 bits)",
"int",
"npi",
"=",
"(",
"(",
"b",
">>",
"4",
")",
"&",
"0x07",
")",
";",
"// create our type of address now",
"return",
"new",
"TypeOfAddress",
"(",
"Ton",
".",
"fromInt",
"(",
"ton",
")",
",",
"Npi",
".",
"fromInt",
"(",
"npi",
")",
")",
";",
"}"
] | Creates a TypeOfAddress from a GSM-encoded type of address byte.
@return | [
"Creates",
"a",
"TypeOfAddress",
"from",
"a",
"GSM",
"-",
"encoded",
"type",
"of",
"address",
"byte",
"."
] | b5bc397dbec4537e8149e7ec0733c1d7ed477499 | https://github.com/twitter/cloudhopper-commons/blob/b5bc397dbec4537e8149e7ec0733c1d7ed477499/ch-commons-gsm/src/main/java/com/cloudhopper/commons/gsm/TypeOfAddress.java#L83-L90 |
3,653 | mojohaus/webstart | webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/sign/DefaultSignTool.java | DefaultSignTool.infoOrDebug | private void infoOrDebug( boolean info, String msg )
{
if ( info )
{
getLogger().info( msg );
}
else
{
getLogger().debug( msg );
}
} | java | private void infoOrDebug( boolean info, String msg )
{
if ( info )
{
getLogger().info( msg );
}
else
{
getLogger().debug( msg );
}
} | [
"private",
"void",
"infoOrDebug",
"(",
"boolean",
"info",
",",
"String",
"msg",
")",
"{",
"if",
"(",
"info",
")",
"{",
"getLogger",
"(",
")",
".",
"info",
"(",
"msg",
")",
";",
"}",
"else",
"{",
"getLogger",
"(",
")",
".",
"debug",
"(",
"msg",
")",
";",
"}",
"}"
] | Log a message as info or debug.
@param info if set to true, log as info(), otherwise as debug()
@param msg message to log | [
"Log",
"a",
"message",
"as",
"info",
"or",
"debug",
"."
] | 38fdd1d21f063f21716cfcd61ebeabd963487576 | https://github.com/mojohaus/webstart/blob/38fdd1d21f063f21716cfcd61ebeabd963487576/webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/sign/DefaultSignTool.java#L288-L298 |
3,654 | mojohaus/webstart | webstart-jnlp-servlet/src/main/java/jnlp/sample/servlet/DownloadRequest.java | DownloadRequest.getStringList | static private String[] getStringList( String str )
{
if ( str == null )
{
return null;
}
List<String> list = new ArrayList<>();
int i = 0;
int length = str.length();
StringBuffer sb = null;
while ( i < length )
{
char ch = str.charAt( i );
if ( ch == ' ' )
{
// A space was hit. Add string to list
if ( sb != null )
{
list.add( sb.toString() );
sb = null;
}
}
else if ( ch == '\\' )
{
// It is a delimiter. Add next character
if ( i + 1 < length )
{
ch = str.charAt( ++i );
if ( sb == null )
{
sb = new StringBuffer();
}
sb.append( ch );
}
}
else
{
if ( sb == null )
{
sb = new StringBuffer();
}
sb.append( ch );
}
i++; // Next character
}
// Make sure to add the last part to the list too
if ( sb != null )
{
list.add( sb.toString() );
}
if ( list.size() == 0 )
{
return null;
}
String[] results = new String[list.size()];
return list.toArray( results );
} | java | static private String[] getStringList( String str )
{
if ( str == null )
{
return null;
}
List<String> list = new ArrayList<>();
int i = 0;
int length = str.length();
StringBuffer sb = null;
while ( i < length )
{
char ch = str.charAt( i );
if ( ch == ' ' )
{
// A space was hit. Add string to list
if ( sb != null )
{
list.add( sb.toString() );
sb = null;
}
}
else if ( ch == '\\' )
{
// It is a delimiter. Add next character
if ( i + 1 < length )
{
ch = str.charAt( ++i );
if ( sb == null )
{
sb = new StringBuffer();
}
sb.append( ch );
}
}
else
{
if ( sb == null )
{
sb = new StringBuffer();
}
sb.append( ch );
}
i++; // Next character
}
// Make sure to add the last part to the list too
if ( sb != null )
{
list.add( sb.toString() );
}
if ( list.size() == 0 )
{
return null;
}
String[] results = new String[list.size()];
return list.toArray( results );
} | [
"static",
"private",
"String",
"[",
"]",
"getStringList",
"(",
"String",
"str",
")",
"{",
"if",
"(",
"str",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"List",
"<",
"String",
">",
"list",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"int",
"i",
"=",
"0",
";",
"int",
"length",
"=",
"str",
".",
"length",
"(",
")",
";",
"StringBuffer",
"sb",
"=",
"null",
";",
"while",
"(",
"i",
"<",
"length",
")",
"{",
"char",
"ch",
"=",
"str",
".",
"charAt",
"(",
"i",
")",
";",
"if",
"(",
"ch",
"==",
"'",
"'",
")",
"{",
"// A space was hit. Add string to list",
"if",
"(",
"sb",
"!=",
"null",
")",
"{",
"list",
".",
"add",
"(",
"sb",
".",
"toString",
"(",
")",
")",
";",
"sb",
"=",
"null",
";",
"}",
"}",
"else",
"if",
"(",
"ch",
"==",
"'",
"'",
")",
"{",
"// It is a delimiter. Add next character",
"if",
"(",
"i",
"+",
"1",
"<",
"length",
")",
"{",
"ch",
"=",
"str",
".",
"charAt",
"(",
"++",
"i",
")",
";",
"if",
"(",
"sb",
"==",
"null",
")",
"{",
"sb",
"=",
"new",
"StringBuffer",
"(",
")",
";",
"}",
"sb",
".",
"append",
"(",
"ch",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"sb",
"==",
"null",
")",
"{",
"sb",
"=",
"new",
"StringBuffer",
"(",
")",
";",
"}",
"sb",
".",
"append",
"(",
"ch",
")",
";",
"}",
"i",
"++",
";",
"// Next character",
"}",
"// Make sure to add the last part to the list too",
"if",
"(",
"sb",
"!=",
"null",
")",
"{",
"list",
".",
"add",
"(",
"sb",
".",
"toString",
"(",
")",
")",
";",
"}",
"if",
"(",
"list",
".",
"size",
"(",
")",
"==",
"0",
")",
"{",
"return",
"null",
";",
"}",
"String",
"[",
"]",
"results",
"=",
"new",
"String",
"[",
"list",
".",
"size",
"(",
")",
"]",
";",
"return",
"list",
".",
"toArray",
"(",
"results",
")",
";",
"}"
] | Converts a space delimitered string to a list of strings | [
"Converts",
"a",
"space",
"delimitered",
"string",
"to",
"a",
"list",
"of",
"strings"
] | 38fdd1d21f063f21716cfcd61ebeabd963487576 | https://github.com/mojohaus/webstart/blob/38fdd1d21f063f21716cfcd61ebeabd963487576/webstart-jnlp-servlet/src/main/java/jnlp/sample/servlet/DownloadRequest.java#L188-L244 |
3,655 | mojohaus/webstart | webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/ResolvedJarResource.java | ResolvedJarResource.getHrefValue | public String getHrefValue()
{
String result;
if ( hrefValue == null && getArtifact() != null )
{
// use default value
result = getArtifact().getFile().getName();
}
else
{
// use customized value
result = hrefValue;
}
return result;
} | java | public String getHrefValue()
{
String result;
if ( hrefValue == null && getArtifact() != null )
{
// use default value
result = getArtifact().getFile().getName();
}
else
{
// use customized value
result = hrefValue;
}
return result;
} | [
"public",
"String",
"getHrefValue",
"(",
")",
"{",
"String",
"result",
";",
"if",
"(",
"hrefValue",
"==",
"null",
"&&",
"getArtifact",
"(",
")",
"!=",
"null",
")",
"{",
"// use default value",
"result",
"=",
"getArtifact",
"(",
")",
".",
"getFile",
"(",
")",
".",
"getName",
"(",
")",
";",
"}",
"else",
"{",
"// use customized value",
"result",
"=",
"hrefValue",
";",
"}",
"return",
"result",
";",
"}"
] | Returns the value that should be output for this jar in the href attribute of the
jar resource element in the generated JNLP file. If not set explicitly, this defaults
to the file name of the underlying artifact.
@return The href attribute to be output for this jar resource in the generated JNLP file. | [
"Returns",
"the",
"value",
"that",
"should",
"be",
"output",
"for",
"this",
"jar",
"in",
"the",
"href",
"attribute",
"of",
"the",
"jar",
"resource",
"element",
"in",
"the",
"generated",
"JNLP",
"file",
".",
"If",
"not",
"set",
"explicitly",
"this",
"defaults",
"to",
"the",
"file",
"name",
"of",
"the",
"underlying",
"artifact",
"."
] | 38fdd1d21f063f21716cfcd61ebeabd963487576 | https://github.com/mojohaus/webstart/blob/38fdd1d21f063f21716cfcd61ebeabd963487576/webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/ResolvedJarResource.java#L126-L140 |
3,656 | mojohaus/webstart | webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/generator/AbstractGenerator.java | AbstractGenerator.generate | public final void generate()
throws Exception
{
VelocityContext context = createAndPopulateContext();
Writer writer = WriterFactory.newWriter( config.getOutputFile(), config.getEncoding() );
try
{
velocityTemplate.merge( context, writer );
writer.flush();
}
catch ( Exception e )
{
throw new Exception(
"Could not generate the template " + velocityTemplate.getName() + ": " + e.getMessage(), e );
}
finally
{
writer.close();
}
} | java | public final void generate()
throws Exception
{
VelocityContext context = createAndPopulateContext();
Writer writer = WriterFactory.newWriter( config.getOutputFile(), config.getEncoding() );
try
{
velocityTemplate.merge( context, writer );
writer.flush();
}
catch ( Exception e )
{
throw new Exception(
"Could not generate the template " + velocityTemplate.getName() + ": " + e.getMessage(), e );
}
finally
{
writer.close();
}
} | [
"public",
"final",
"void",
"generate",
"(",
")",
"throws",
"Exception",
"{",
"VelocityContext",
"context",
"=",
"createAndPopulateContext",
"(",
")",
";",
"Writer",
"writer",
"=",
"WriterFactory",
".",
"newWriter",
"(",
"config",
".",
"getOutputFile",
"(",
")",
",",
"config",
".",
"getEncoding",
"(",
")",
")",
";",
"try",
"{",
"velocityTemplate",
".",
"merge",
"(",
"context",
",",
"writer",
")",
";",
"writer",
".",
"flush",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Could not generate the template \"",
"+",
"velocityTemplate",
".",
"getName",
"(",
")",
"+",
"\": \"",
"+",
"e",
".",
"getMessage",
"(",
")",
",",
"e",
")",
";",
"}",
"finally",
"{",
"writer",
".",
"close",
"(",
")",
";",
"}",
"}"
] | Generate the JNLP file.
@throws Exception TODO | [
"Generate",
"the",
"JNLP",
"file",
"."
] | 38fdd1d21f063f21716cfcd61ebeabd963487576 | https://github.com/mojohaus/webstart/blob/38fdd1d21f063f21716cfcd61ebeabd963487576/webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/generator/AbstractGenerator.java#L152-L174 |
3,657 | mojohaus/webstart | webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/generator/AbstractGenerator.java | AbstractGenerator.createAndPopulateContext | protected VelocityContext createAndPopulateContext()
{
VelocityContext context = new VelocityContext();
context.put( "dependencies", getDependenciesText() );
context.put( "arguments", getArgumentsText() );
// Note: properties that contain dots will not be properly parsed by Velocity.
// Should we replace dots with underscores ?
addPropertiesToContext( System.getProperties(), context );
MavenProject mavenProject = config.getMavenProject();
String encoding = config.getEncoding();
addPropertiesToContext( mavenProject.getProperties(), context );
addPropertiesToContext( extraConfig.getProperties(), context );
context.put( "project", mavenProject.getModel() );
context.put( "jnlpCodebase", extraConfig.getJnlpCodeBase() );
// aliases named after the JNLP file structure
context.put( "informationTitle", mavenProject.getModel().getName() );
context.put( "informationDescription", mavenProject.getModel().getDescription() );
if ( mavenProject.getModel().getOrganization() != null )
{
context.put( "informationVendor", mavenProject.getModel().getOrganization().getName() );
context.put( "informationHomepage", mavenProject.getModel().getOrganization().getUrl() );
}
// explicit timestamps in local and and UTC time zones
Date timestamp = new Date();
context.put( "explicitTimestamp", dateToExplicitTimestamp( timestamp ) );
context.put( "explicitTimestampUTC", dateToExplicitTimestampUTC( timestamp ) );
context.put( "outputFile", config.getOutputFile().getName() );
context.put( "mainClass", config.getMainClass() );
context.put( "encoding", encoding );
context.put( "input.encoding", encoding );
context.put( "output.encoding", encoding );
// TODO make this more extensible
context.put( "allPermissions", BooleanUtils.toBoolean( extraConfig.getAllPermissions() ) );
context.put( "offlineAllowed", BooleanUtils.toBoolean( extraConfig.getOfflineAllowed() ) );
context.put( "jnlpspec", extraConfig.getJnlpSpec() );
context.put( "j2seVersion", extraConfig.getJ2seVersion() );
context.put( "iconHref", extraConfig.getIconHref() );
// FIXME: 7/18/2017 Where is extraConfig's implementation so getIconHref can be added to it?
return context;
} | java | protected VelocityContext createAndPopulateContext()
{
VelocityContext context = new VelocityContext();
context.put( "dependencies", getDependenciesText() );
context.put( "arguments", getArgumentsText() );
// Note: properties that contain dots will not be properly parsed by Velocity.
// Should we replace dots with underscores ?
addPropertiesToContext( System.getProperties(), context );
MavenProject mavenProject = config.getMavenProject();
String encoding = config.getEncoding();
addPropertiesToContext( mavenProject.getProperties(), context );
addPropertiesToContext( extraConfig.getProperties(), context );
context.put( "project", mavenProject.getModel() );
context.put( "jnlpCodebase", extraConfig.getJnlpCodeBase() );
// aliases named after the JNLP file structure
context.put( "informationTitle", mavenProject.getModel().getName() );
context.put( "informationDescription", mavenProject.getModel().getDescription() );
if ( mavenProject.getModel().getOrganization() != null )
{
context.put( "informationVendor", mavenProject.getModel().getOrganization().getName() );
context.put( "informationHomepage", mavenProject.getModel().getOrganization().getUrl() );
}
// explicit timestamps in local and and UTC time zones
Date timestamp = new Date();
context.put( "explicitTimestamp", dateToExplicitTimestamp( timestamp ) );
context.put( "explicitTimestampUTC", dateToExplicitTimestampUTC( timestamp ) );
context.put( "outputFile", config.getOutputFile().getName() );
context.put( "mainClass", config.getMainClass() );
context.put( "encoding", encoding );
context.put( "input.encoding", encoding );
context.put( "output.encoding", encoding );
// TODO make this more extensible
context.put( "allPermissions", BooleanUtils.toBoolean( extraConfig.getAllPermissions() ) );
context.put( "offlineAllowed", BooleanUtils.toBoolean( extraConfig.getOfflineAllowed() ) );
context.put( "jnlpspec", extraConfig.getJnlpSpec() );
context.put( "j2seVersion", extraConfig.getJ2seVersion() );
context.put( "iconHref", extraConfig.getIconHref() );
// FIXME: 7/18/2017 Where is extraConfig's implementation so getIconHref can be added to it?
return context;
} | [
"protected",
"VelocityContext",
"createAndPopulateContext",
"(",
")",
"{",
"VelocityContext",
"context",
"=",
"new",
"VelocityContext",
"(",
")",
";",
"context",
".",
"put",
"(",
"\"dependencies\"",
",",
"getDependenciesText",
"(",
")",
")",
";",
"context",
".",
"put",
"(",
"\"arguments\"",
",",
"getArgumentsText",
"(",
")",
")",
";",
"// Note: properties that contain dots will not be properly parsed by Velocity. ",
"// Should we replace dots with underscores ? ",
"addPropertiesToContext",
"(",
"System",
".",
"getProperties",
"(",
")",
",",
"context",
")",
";",
"MavenProject",
"mavenProject",
"=",
"config",
".",
"getMavenProject",
"(",
")",
";",
"String",
"encoding",
"=",
"config",
".",
"getEncoding",
"(",
")",
";",
"addPropertiesToContext",
"(",
"mavenProject",
".",
"getProperties",
"(",
")",
",",
"context",
")",
";",
"addPropertiesToContext",
"(",
"extraConfig",
".",
"getProperties",
"(",
")",
",",
"context",
")",
";",
"context",
".",
"put",
"(",
"\"project\"",
",",
"mavenProject",
".",
"getModel",
"(",
")",
")",
";",
"context",
".",
"put",
"(",
"\"jnlpCodebase\"",
",",
"extraConfig",
".",
"getJnlpCodeBase",
"(",
")",
")",
";",
"// aliases named after the JNLP file structure",
"context",
".",
"put",
"(",
"\"informationTitle\"",
",",
"mavenProject",
".",
"getModel",
"(",
")",
".",
"getName",
"(",
")",
")",
";",
"context",
".",
"put",
"(",
"\"informationDescription\"",
",",
"mavenProject",
".",
"getModel",
"(",
")",
".",
"getDescription",
"(",
")",
")",
";",
"if",
"(",
"mavenProject",
".",
"getModel",
"(",
")",
".",
"getOrganization",
"(",
")",
"!=",
"null",
")",
"{",
"context",
".",
"put",
"(",
"\"informationVendor\"",
",",
"mavenProject",
".",
"getModel",
"(",
")",
".",
"getOrganization",
"(",
")",
".",
"getName",
"(",
")",
")",
";",
"context",
".",
"put",
"(",
"\"informationHomepage\"",
",",
"mavenProject",
".",
"getModel",
"(",
")",
".",
"getOrganization",
"(",
")",
".",
"getUrl",
"(",
")",
")",
";",
"}",
"// explicit timestamps in local and and UTC time zones",
"Date",
"timestamp",
"=",
"new",
"Date",
"(",
")",
";",
"context",
".",
"put",
"(",
"\"explicitTimestamp\"",
",",
"dateToExplicitTimestamp",
"(",
"timestamp",
")",
")",
";",
"context",
".",
"put",
"(",
"\"explicitTimestampUTC\"",
",",
"dateToExplicitTimestampUTC",
"(",
"timestamp",
")",
")",
";",
"context",
".",
"put",
"(",
"\"outputFile\"",
",",
"config",
".",
"getOutputFile",
"(",
")",
".",
"getName",
"(",
")",
")",
";",
"context",
".",
"put",
"(",
"\"mainClass\"",
",",
"config",
".",
"getMainClass",
"(",
")",
")",
";",
"context",
".",
"put",
"(",
"\"encoding\"",
",",
"encoding",
")",
";",
"context",
".",
"put",
"(",
"\"input.encoding\"",
",",
"encoding",
")",
";",
"context",
".",
"put",
"(",
"\"output.encoding\"",
",",
"encoding",
")",
";",
"// TODO make this more extensible",
"context",
".",
"put",
"(",
"\"allPermissions\"",
",",
"BooleanUtils",
".",
"toBoolean",
"(",
"extraConfig",
".",
"getAllPermissions",
"(",
")",
")",
")",
";",
"context",
".",
"put",
"(",
"\"offlineAllowed\"",
",",
"BooleanUtils",
".",
"toBoolean",
"(",
"extraConfig",
".",
"getOfflineAllowed",
"(",
")",
")",
")",
";",
"context",
".",
"put",
"(",
"\"jnlpspec\"",
",",
"extraConfig",
".",
"getJnlpSpec",
"(",
")",
")",
";",
"context",
".",
"put",
"(",
"\"j2seVersion\"",
",",
"extraConfig",
".",
"getJ2seVersion",
"(",
")",
")",
";",
"context",
".",
"put",
"(",
"\"iconHref\"",
",",
"extraConfig",
".",
"getIconHref",
"(",
")",
")",
";",
"// FIXME: 7/18/2017 Where is extraConfig's implementation so getIconHref can be added to it?",
"return",
"context",
";",
"}"
] | Creates a Velocity context and populates it with replacement values
for our pre-defined placeholders.
@return Returns a velocity context with system and maven properties added | [
"Creates",
"a",
"Velocity",
"context",
"and",
"populates",
"it",
"with",
"replacement",
"values",
"for",
"our",
"pre",
"-",
"defined",
"placeholders",
"."
] | 38fdd1d21f063f21716cfcd61ebeabd963487576 | https://github.com/mojohaus/webstart/blob/38fdd1d21f063f21716cfcd61ebeabd963487576/webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/generator/AbstractGenerator.java#L190-L241 |
3,658 | mojohaus/webstart | webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/generator/AbstractGenerator.java | AbstractGenerator.dateToExplicitTimestamp | private String dateToExplicitTimestamp( Date date )
{
DateFormat df = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ssZ" );
return "TS: " + df.format( date );
} | java | private String dateToExplicitTimestamp( Date date )
{
DateFormat df = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ssZ" );
return "TS: " + df.format( date );
} | [
"private",
"String",
"dateToExplicitTimestamp",
"(",
"Date",
"date",
")",
"{",
"DateFormat",
"df",
"=",
"new",
"SimpleDateFormat",
"(",
"\"yyyy-MM-dd HH:mm:ssZ\"",
")",
";",
"return",
"\"TS: \"",
"+",
"df",
".",
"format",
"(",
"date",
")",
";",
"}"
] | Converts a given date to an explicit timestamp string in local time zone.
@param date a timestamp to convert.
@return a string representing a timestamp. | [
"Converts",
"a",
"given",
"date",
"to",
"an",
"explicit",
"timestamp",
"string",
"in",
"local",
"time",
"zone",
"."
] | 38fdd1d21f063f21716cfcd61ebeabd963487576 | https://github.com/mojohaus/webstart/blob/38fdd1d21f063f21716cfcd61ebeabd963487576/webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/generator/AbstractGenerator.java#L264-L268 |
3,659 | mojohaus/webstart | webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/generator/AbstractGenerator.java | AbstractGenerator.dateToExplicitTimestampUTC | private String dateToExplicitTimestampUTC( Date date )
{
DateFormat df = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" );
df.setTimeZone( TimeZone.getTimeZone( "UTC" ) );
return "TS: " + df.format( date ) + "Z";
} | java | private String dateToExplicitTimestampUTC( Date date )
{
DateFormat df = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" );
df.setTimeZone( TimeZone.getTimeZone( "UTC" ) );
return "TS: " + df.format( date ) + "Z";
} | [
"private",
"String",
"dateToExplicitTimestampUTC",
"(",
"Date",
"date",
")",
"{",
"DateFormat",
"df",
"=",
"new",
"SimpleDateFormat",
"(",
"\"yyyy-MM-dd HH:mm:ss\"",
")",
";",
"df",
".",
"setTimeZone",
"(",
"TimeZone",
".",
"getTimeZone",
"(",
"\"UTC\"",
")",
")",
";",
"return",
"\"TS: \"",
"+",
"df",
".",
"format",
"(",
"date",
")",
"+",
"\"Z\"",
";",
"}"
] | Converts a given date to an explicit timestamp string in UTC time zone.
@param date a timestamp to convert.
@return a string representing a timestamp. | [
"Converts",
"a",
"given",
"date",
"to",
"an",
"explicit",
"timestamp",
"string",
"in",
"UTC",
"time",
"zone",
"."
] | 38fdd1d21f063f21716cfcd61ebeabd963487576 | https://github.com/mojohaus/webstart/blob/38fdd1d21f063f21716cfcd61ebeabd963487576/webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/generator/AbstractGenerator.java#L276-L281 |
3,660 | mojohaus/webstart | webstart-jnlp-servlet/src/main/java/jnlp/sample/servlet/JarDiffHandler.java | JarDiffHandler.getJarDiffEntry | public synchronized DownloadResponse getJarDiffEntry( ResourceCatalog catalog, DownloadRequest dreq,
JnlpResource res )
{
if ( dreq.getCurrentVersionId() == null )
{
return null;
}
// check whether the request is from javaws 1.0/1.0.1
// do not generate minimal jardiff if it is from 1.0/1.0.1
boolean doJarDiffWorkAround = isJavawsVersion( dreq, "1.0*" );
// First do a lookup to find a match
JarDiffKey key =
new JarDiffKey( res.getName(), dreq.getCurrentVersionId(), res.getReturnVersionId(), !doJarDiffWorkAround );
JarDiffEntry entry = (JarDiffEntry) _jarDiffEntries.get( key );
// If entry is not found, then the querty has not been made.
if ( entry == null )
{
if ( _log.isInformationalLevel() )
{
_log.addInformational( "servlet.log.info.jardiff.gen", res.getName(), dreq.getCurrentVersionId(),
res.getReturnVersionId() );
}
File f = generateJarDiff( catalog, dreq, res, doJarDiffWorkAround );
if ( f == null )
{
_log.addWarning( "servlet.log.warning.jardiff.failed", res.getName(), dreq.getCurrentVersionId(),
res.getReturnVersionId() );
}
// Store entry in table
entry = new JarDiffEntry( f );
_jarDiffEntries.put( key, entry );
}
// Check for no JarDiff to return
if ( entry.getJarDiffFile() == null )
{
return null;
}
else
{
return DownloadResponse.getFileDownloadResponse( entry.getJarDiffFile(), _jarDiffMimeType,
entry.getJarDiffFile().lastModified(),
res.getReturnVersionId() );
}
} | java | public synchronized DownloadResponse getJarDiffEntry( ResourceCatalog catalog, DownloadRequest dreq,
JnlpResource res )
{
if ( dreq.getCurrentVersionId() == null )
{
return null;
}
// check whether the request is from javaws 1.0/1.0.1
// do not generate minimal jardiff if it is from 1.0/1.0.1
boolean doJarDiffWorkAround = isJavawsVersion( dreq, "1.0*" );
// First do a lookup to find a match
JarDiffKey key =
new JarDiffKey( res.getName(), dreq.getCurrentVersionId(), res.getReturnVersionId(), !doJarDiffWorkAround );
JarDiffEntry entry = (JarDiffEntry) _jarDiffEntries.get( key );
// If entry is not found, then the querty has not been made.
if ( entry == null )
{
if ( _log.isInformationalLevel() )
{
_log.addInformational( "servlet.log.info.jardiff.gen", res.getName(), dreq.getCurrentVersionId(),
res.getReturnVersionId() );
}
File f = generateJarDiff( catalog, dreq, res, doJarDiffWorkAround );
if ( f == null )
{
_log.addWarning( "servlet.log.warning.jardiff.failed", res.getName(), dreq.getCurrentVersionId(),
res.getReturnVersionId() );
}
// Store entry in table
entry = new JarDiffEntry( f );
_jarDiffEntries.put( key, entry );
}
// Check for no JarDiff to return
if ( entry.getJarDiffFile() == null )
{
return null;
}
else
{
return DownloadResponse.getFileDownloadResponse( entry.getJarDiffFile(), _jarDiffMimeType,
entry.getJarDiffFile().lastModified(),
res.getReturnVersionId() );
}
} | [
"public",
"synchronized",
"DownloadResponse",
"getJarDiffEntry",
"(",
"ResourceCatalog",
"catalog",
",",
"DownloadRequest",
"dreq",
",",
"JnlpResource",
"res",
")",
"{",
"if",
"(",
"dreq",
".",
"getCurrentVersionId",
"(",
")",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"// check whether the request is from javaws 1.0/1.0.1",
"// do not generate minimal jardiff if it is from 1.0/1.0.1",
"boolean",
"doJarDiffWorkAround",
"=",
"isJavawsVersion",
"(",
"dreq",
",",
"\"1.0*\"",
")",
";",
"// First do a lookup to find a match",
"JarDiffKey",
"key",
"=",
"new",
"JarDiffKey",
"(",
"res",
".",
"getName",
"(",
")",
",",
"dreq",
".",
"getCurrentVersionId",
"(",
")",
",",
"res",
".",
"getReturnVersionId",
"(",
")",
",",
"!",
"doJarDiffWorkAround",
")",
";",
"JarDiffEntry",
"entry",
"=",
"(",
"JarDiffEntry",
")",
"_jarDiffEntries",
".",
"get",
"(",
"key",
")",
";",
"// If entry is not found, then the querty has not been made.",
"if",
"(",
"entry",
"==",
"null",
")",
"{",
"if",
"(",
"_log",
".",
"isInformationalLevel",
"(",
")",
")",
"{",
"_log",
".",
"addInformational",
"(",
"\"servlet.log.info.jardiff.gen\"",
",",
"res",
".",
"getName",
"(",
")",
",",
"dreq",
".",
"getCurrentVersionId",
"(",
")",
",",
"res",
".",
"getReturnVersionId",
"(",
")",
")",
";",
"}",
"File",
"f",
"=",
"generateJarDiff",
"(",
"catalog",
",",
"dreq",
",",
"res",
",",
"doJarDiffWorkAround",
")",
";",
"if",
"(",
"f",
"==",
"null",
")",
"{",
"_log",
".",
"addWarning",
"(",
"\"servlet.log.warning.jardiff.failed\"",
",",
"res",
".",
"getName",
"(",
")",
",",
"dreq",
".",
"getCurrentVersionId",
"(",
")",
",",
"res",
".",
"getReturnVersionId",
"(",
")",
")",
";",
"}",
"// Store entry in table",
"entry",
"=",
"new",
"JarDiffEntry",
"(",
"f",
")",
";",
"_jarDiffEntries",
".",
"put",
"(",
"key",
",",
"entry",
")",
";",
"}",
"// Check for no JarDiff to return",
"if",
"(",
"entry",
".",
"getJarDiffFile",
"(",
")",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"else",
"{",
"return",
"DownloadResponse",
".",
"getFileDownloadResponse",
"(",
"entry",
".",
"getJarDiffFile",
"(",
")",
",",
"_jarDiffMimeType",
",",
"entry",
".",
"getJarDiffFile",
"(",
")",
".",
"lastModified",
"(",
")",
",",
"res",
".",
"getReturnVersionId",
"(",
")",
")",
";",
"}",
"}"
] | Returns a JarDiff for the given request
@param catalog TODO
@param dreq TODO
@param res TODO
@return TODO | [
"Returns",
"a",
"JarDiff",
"for",
"the",
"given",
"request"
] | 38fdd1d21f063f21716cfcd61ebeabd963487576 | https://github.com/mojohaus/webstart/blob/38fdd1d21f063f21716cfcd61ebeabd963487576/webstart-jnlp-servlet/src/main/java/jnlp/sample/servlet/JarDiffHandler.java#L207-L254 |
3,661 | mojohaus/webstart | webstart-jnlp-servlet/src/main/java/jnlp/sample/servlet/JarDiffHandler.java | JarDiffHandler.download | private boolean download( URL target, File file )
{
_log.addDebug( "JarDiffHandler: Doing download" );
boolean ret = true;
boolean delete = false;
// use bufferedstream for better performance
BufferedInputStream in = null;
BufferedOutputStream out = null;
try
{
in = new BufferedInputStream( target.openStream() );
out = new BufferedOutputStream( new FileOutputStream( file ) );
int read = 0;
int totalRead = 0;
byte[] buf = new byte[BUF_SIZE];
while ( ( read = in.read( buf ) ) != -1 )
{
out.write( buf, 0, read );
totalRead += read;
}
_log.addDebug( "total read: " + totalRead );
_log.addDebug( "Wrote URL " + target.toString() + " to file " + file );
}
catch ( IOException ioe )
{
_log.addDebug( "Got exception while downloading resource: " + ioe );
ret = false;
if ( file != null )
{
delete = true;
}
}
finally
{
try
{
in.close();
in = null;
}
catch ( IOException ioe )
{
_log.addDebug( "Got exception while downloading resource: " + ioe );
}
try
{
out.close();
out = null;
}
catch ( IOException ioe )
{
_log.addDebug( "Got exception while downloading resource: " + ioe );
}
if ( delete )
{
file.delete();
}
}
return ret;
} | java | private boolean download( URL target, File file )
{
_log.addDebug( "JarDiffHandler: Doing download" );
boolean ret = true;
boolean delete = false;
// use bufferedstream for better performance
BufferedInputStream in = null;
BufferedOutputStream out = null;
try
{
in = new BufferedInputStream( target.openStream() );
out = new BufferedOutputStream( new FileOutputStream( file ) );
int read = 0;
int totalRead = 0;
byte[] buf = new byte[BUF_SIZE];
while ( ( read = in.read( buf ) ) != -1 )
{
out.write( buf, 0, read );
totalRead += read;
}
_log.addDebug( "total read: " + totalRead );
_log.addDebug( "Wrote URL " + target.toString() + " to file " + file );
}
catch ( IOException ioe )
{
_log.addDebug( "Got exception while downloading resource: " + ioe );
ret = false;
if ( file != null )
{
delete = true;
}
}
finally
{
try
{
in.close();
in = null;
}
catch ( IOException ioe )
{
_log.addDebug( "Got exception while downloading resource: " + ioe );
}
try
{
out.close();
out = null;
}
catch ( IOException ioe )
{
_log.addDebug( "Got exception while downloading resource: " + ioe );
}
if ( delete )
{
file.delete();
}
}
return ret;
} | [
"private",
"boolean",
"download",
"(",
"URL",
"target",
",",
"File",
"file",
")",
"{",
"_log",
".",
"addDebug",
"(",
"\"JarDiffHandler: Doing download\"",
")",
";",
"boolean",
"ret",
"=",
"true",
";",
"boolean",
"delete",
"=",
"false",
";",
"// use bufferedstream for better performance",
"BufferedInputStream",
"in",
"=",
"null",
";",
"BufferedOutputStream",
"out",
"=",
"null",
";",
"try",
"{",
"in",
"=",
"new",
"BufferedInputStream",
"(",
"target",
".",
"openStream",
"(",
")",
")",
";",
"out",
"=",
"new",
"BufferedOutputStream",
"(",
"new",
"FileOutputStream",
"(",
"file",
")",
")",
";",
"int",
"read",
"=",
"0",
";",
"int",
"totalRead",
"=",
"0",
";",
"byte",
"[",
"]",
"buf",
"=",
"new",
"byte",
"[",
"BUF_SIZE",
"]",
";",
"while",
"(",
"(",
"read",
"=",
"in",
".",
"read",
"(",
"buf",
")",
")",
"!=",
"-",
"1",
")",
"{",
"out",
".",
"write",
"(",
"buf",
",",
"0",
",",
"read",
")",
";",
"totalRead",
"+=",
"read",
";",
"}",
"_log",
".",
"addDebug",
"(",
"\"total read: \"",
"+",
"totalRead",
")",
";",
"_log",
".",
"addDebug",
"(",
"\"Wrote URL \"",
"+",
"target",
".",
"toString",
"(",
")",
"+",
"\" to file \"",
"+",
"file",
")",
";",
"}",
"catch",
"(",
"IOException",
"ioe",
")",
"{",
"_log",
".",
"addDebug",
"(",
"\"Got exception while downloading resource: \"",
"+",
"ioe",
")",
";",
"ret",
"=",
"false",
";",
"if",
"(",
"file",
"!=",
"null",
")",
"{",
"delete",
"=",
"true",
";",
"}",
"}",
"finally",
"{",
"try",
"{",
"in",
".",
"close",
"(",
")",
";",
"in",
"=",
"null",
";",
"}",
"catch",
"(",
"IOException",
"ioe",
")",
"{",
"_log",
".",
"addDebug",
"(",
"\"Got exception while downloading resource: \"",
"+",
"ioe",
")",
";",
"}",
"try",
"{",
"out",
".",
"close",
"(",
")",
";",
"out",
"=",
"null",
";",
"}",
"catch",
"(",
"IOException",
"ioe",
")",
"{",
"_log",
".",
"addDebug",
"(",
"\"Got exception while downloading resource: \"",
"+",
"ioe",
")",
";",
"}",
"if",
"(",
"delete",
")",
"{",
"file",
".",
"delete",
"(",
")",
";",
"}",
"}",
"return",
"ret",
";",
"}"
] | Download resource to the given file | [
"Download",
"resource",
"to",
"the",
"given",
"file"
] | 38fdd1d21f063f21716cfcd61ebeabd963487576 | https://github.com/mojohaus/webstart/blob/38fdd1d21f063f21716cfcd61ebeabd963487576/webstart-jnlp-servlet/src/main/java/jnlp/sample/servlet/JarDiffHandler.java#L306-L376 |
3,662 | mojohaus/webstart | webstart-jnlp-servlet/src/main/java/jnlp/sample/servlet/JarDiffHandler.java | JarDiffHandler.getRealPath | private String getRealPath( String path )
throws IOException
{
URL fileURL = _servletContext.getResource( path );
File tempDir = (File) _servletContext.getAttribute( "javax.servlet.context.tempdir" );
// download file into temp dir
if ( fileURL != null )
{
File newFile = File.createTempFile( "temp", ".jar", tempDir );
if ( download( fileURL, newFile ) )
{
String filePath = newFile.getPath();
return filePath;
}
}
return null;
} | java | private String getRealPath( String path )
throws IOException
{
URL fileURL = _servletContext.getResource( path );
File tempDir = (File) _servletContext.getAttribute( "javax.servlet.context.tempdir" );
// download file into temp dir
if ( fileURL != null )
{
File newFile = File.createTempFile( "temp", ".jar", tempDir );
if ( download( fileURL, newFile ) )
{
String filePath = newFile.getPath();
return filePath;
}
}
return null;
} | [
"private",
"String",
"getRealPath",
"(",
"String",
"path",
")",
"throws",
"IOException",
"{",
"URL",
"fileURL",
"=",
"_servletContext",
".",
"getResource",
"(",
"path",
")",
";",
"File",
"tempDir",
"=",
"(",
"File",
")",
"_servletContext",
".",
"getAttribute",
"(",
"\"javax.servlet.context.tempdir\"",
")",
";",
"// download file into temp dir",
"if",
"(",
"fileURL",
"!=",
"null",
")",
"{",
"File",
"newFile",
"=",
"File",
".",
"createTempFile",
"(",
"\"temp\"",
",",
"\".jar\"",
",",
"tempDir",
")",
";",
"if",
"(",
"download",
"(",
"fileURL",
",",
"newFile",
")",
")",
"{",
"String",
"filePath",
"=",
"newFile",
".",
"getPath",
"(",
")",
";",
"return",
"filePath",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | so it can be used to generate jardiff | [
"so",
"it",
"can",
"be",
"used",
"to",
"generate",
"jardiff"
] | 38fdd1d21f063f21716cfcd61ebeabd963487576 | https://github.com/mojohaus/webstart/blob/38fdd1d21f063f21716cfcd61ebeabd963487576/webstart-jnlp-servlet/src/main/java/jnlp/sample/servlet/JarDiffHandler.java#L381-L400 |
3,663 | mojohaus/webstart | webstart-jnlp-servlet/src/main/java/jnlp/sample/servlet/Logger.java | Logger.addFatal | public void addFatal( String key, Throwable throwable )
{
logEvent( FATAL, getString( key ), throwable );
} | java | public void addFatal( String key, Throwable throwable )
{
logEvent( FATAL, getString( key ), throwable );
} | [
"public",
"void",
"addFatal",
"(",
"String",
"key",
",",
"Throwable",
"throwable",
")",
"{",
"logEvent",
"(",
"FATAL",
",",
"getString",
"(",
"key",
")",
",",
"throwable",
")",
";",
"}"
] | Logging API. Fatal, Warning, and Informational are localized | [
"Logging",
"API",
".",
"Fatal",
"Warning",
"and",
"Informational",
"are",
"localized"
] | 38fdd1d21f063f21716cfcd61ebeabd963487576 | https://github.com/mojohaus/webstart/blob/38fdd1d21f063f21716cfcd61ebeabd963487576/webstart-jnlp-servlet/src/main/java/jnlp/sample/servlet/Logger.java#L138-L141 |
3,664 | mojohaus/webstart | webstart-jnlp-servlet/src/main/java/jnlp/sample/servlet/Logger.java | Logger.getString | private String getString( String key )
{
try
{
return _resources.getString( key );
}
catch ( MissingResourceException mre )
{
return "Missing resource for: " + key;
}
} | java | private String getString( String key )
{
try
{
return _resources.getString( key );
}
catch ( MissingResourceException mre )
{
return "Missing resource for: " + key;
}
} | [
"private",
"String",
"getString",
"(",
"String",
"key",
")",
"{",
"try",
"{",
"return",
"_resources",
".",
"getString",
"(",
"key",
")",
";",
"}",
"catch",
"(",
"MissingResourceException",
"mre",
")",
"{",
"return",
"\"Missing resource for: \"",
"+",
"key",
";",
"}",
"}"
] | Returns a string from the resources | [
"Returns",
"a",
"string",
"from",
"the",
"resources"
] | 38fdd1d21f063f21716cfcd61ebeabd963487576 | https://github.com/mojohaus/webstart/blob/38fdd1d21f063f21716cfcd61ebeabd963487576/webstart-jnlp-servlet/src/main/java/jnlp/sample/servlet/Logger.java#L216-L226 |
3,665 | mojohaus/webstart | webstart-jnlp-servlet/src/main/java/jnlp/sample/servlet/Logger.java | Logger.applyPattern | private String applyPattern( String key, Object[] messageArguments )
{
String message = getString( key );
// MessageFormat formatter = new MessageFormat( message );
String output = MessageFormat.format( message, messageArguments );
return output;
} | java | private String applyPattern( String key, Object[] messageArguments )
{
String message = getString( key );
// MessageFormat formatter = new MessageFormat( message );
String output = MessageFormat.format( message, messageArguments );
return output;
} | [
"private",
"String",
"applyPattern",
"(",
"String",
"key",
",",
"Object",
"[",
"]",
"messageArguments",
")",
"{",
"String",
"message",
"=",
"getString",
"(",
"key",
")",
";",
"// MessageFormat formatter = new MessageFormat( message );",
"String",
"output",
"=",
"MessageFormat",
".",
"format",
"(",
"message",
",",
"messageArguments",
")",
";",
"return",
"output",
";",
"}"
] | Helper function that applies the messageArguments to a message from the resource object | [
"Helper",
"function",
"that",
"applies",
"the",
"messageArguments",
"to",
"a",
"message",
"from",
"the",
"resource",
"object"
] | 38fdd1d21f063f21716cfcd61ebeabd963487576 | https://github.com/mojohaus/webstart/blob/38fdd1d21f063f21716cfcd61ebeabd963487576/webstart-jnlp-servlet/src/main/java/jnlp/sample/servlet/Logger.java#L249-L255 |
3,666 | mojohaus/webstart | webstart-jnlp-servlet/src/main/java/jnlp/sample/servlet/Logger.java | Logger.logEvent | private synchronized void logEvent( int level, String string, Throwable throwable )
{
// Check if the event should be logged
if ( level > _loggingLevel )
{
return;
}
if ( _logFile != null )
{
// No logfile specified, log using servlet context
PrintWriter pw = null;
try
{
pw = new PrintWriter( new FileWriter( _logFile, true ) );
pw.println( _servletName + "(" + level + "): " + string );
if ( throwable != null )
{
throwable.printStackTrace( pw );
}
pw.close();
// Do a return here. An exception will cause a fall through to
// do _servletContex logging API
return;
}
catch ( IOException ioe )
{
/* just ignore */
}
}
// Otherwise, write to servlet context log
if ( throwable == null )
{
_servletContext.log( string );
}
else
{
_servletContext.log( string, throwable );
}
} | java | private synchronized void logEvent( int level, String string, Throwable throwable )
{
// Check if the event should be logged
if ( level > _loggingLevel )
{
return;
}
if ( _logFile != null )
{
// No logfile specified, log using servlet context
PrintWriter pw = null;
try
{
pw = new PrintWriter( new FileWriter( _logFile, true ) );
pw.println( _servletName + "(" + level + "): " + string );
if ( throwable != null )
{
throwable.printStackTrace( pw );
}
pw.close();
// Do a return here. An exception will cause a fall through to
// do _servletContex logging API
return;
}
catch ( IOException ioe )
{
/* just ignore */
}
}
// Otherwise, write to servlet context log
if ( throwable == null )
{
_servletContext.log( string );
}
else
{
_servletContext.log( string, throwable );
}
} | [
"private",
"synchronized",
"void",
"logEvent",
"(",
"int",
"level",
",",
"String",
"string",
",",
"Throwable",
"throwable",
")",
"{",
"// Check if the event should be logged",
"if",
"(",
"level",
">",
"_loggingLevel",
")",
"{",
"return",
";",
"}",
"if",
"(",
"_logFile",
"!=",
"null",
")",
"{",
"// No logfile specified, log using servlet context",
"PrintWriter",
"pw",
"=",
"null",
";",
"try",
"{",
"pw",
"=",
"new",
"PrintWriter",
"(",
"new",
"FileWriter",
"(",
"_logFile",
",",
"true",
")",
")",
";",
"pw",
".",
"println",
"(",
"_servletName",
"+",
"\"(\"",
"+",
"level",
"+",
"\"): \"",
"+",
"string",
")",
";",
"if",
"(",
"throwable",
"!=",
"null",
")",
"{",
"throwable",
".",
"printStackTrace",
"(",
"pw",
")",
";",
"}",
"pw",
".",
"close",
"(",
")",
";",
"// Do a return here. An exception will cause a fall through to",
"// do _servletContex logging API",
"return",
";",
"}",
"catch",
"(",
"IOException",
"ioe",
")",
"{",
"/* just ignore */",
"}",
"}",
"// Otherwise, write to servlet context log",
"if",
"(",
"throwable",
"==",
"null",
")",
"{",
"_servletContext",
".",
"log",
"(",
"string",
")",
";",
"}",
"else",
"{",
"_servletContext",
".",
"log",
"(",
"string",
",",
"throwable",
")",
";",
"}",
"}"
] | The method that actually does the logging | [
"The",
"method",
"that",
"actually",
"does",
"the",
"logging"
] | 38fdd1d21f063f21716cfcd61ebeabd963487576 | https://github.com/mojohaus/webstart/blob/38fdd1d21f063f21716cfcd61ebeabd963487576/webstart-jnlp-servlet/src/main/java/jnlp/sample/servlet/Logger.java#L258-L298 |
3,667 | mojohaus/webstart | webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/util/DefaultArtifactUtil.java | DefaultArtifactUtil.artifactContainsClass | public boolean artifactContainsClass( Artifact artifact, final String mainClass )
throws MojoExecutionException
{
boolean containsClass = true;
// JarArchiver.grabFilesAndDirs()
URL url;
try
{
url = artifact.getFile().toURI().toURL();
}
catch ( MalformedURLException e )
{
throw new MojoExecutionException( "Could not get artifact url: " + artifact.getFile(), e );
}
ClassLoader cl = new java.net.URLClassLoader( new URL[]{url} );
Class<?> c = null;
try
{
c = Class.forName( mainClass, false, cl );
}
catch ( ClassNotFoundException e )
{
getLogger().debug( "artifact " + artifact + " doesn't contain the main class: " + mainClass );
containsClass = false;
}
catch ( Throwable t )
{
getLogger().info( "artifact " + artifact + " seems to contain the main class: " + mainClass +
" but the jar doesn't seem to contain all dependencies " + t.getMessage() );
}
if ( c != null )
{
getLogger().debug( "Checking if the loaded class contains a main method." );
try
{
c.getMethod( "main", String[].class );
}
catch ( NoSuchMethodException e )
{
getLogger().warn(
"The specified main class (" + mainClass + ") doesn't seem to contain a main method... " +
"Please check your configuration." + e.getMessage() );
}
catch ( NoClassDefFoundError e )
{
// undocumented in SDK 5.0. is this due to the ClassLoader lazy loading the Method
// thus making this a case tackled by the JVM Spec (Ref 5.3.5)!
// Reported as Incident 633981 to Sun just in case ...
getLogger().warn( "Something failed while checking if the main class contains the main() method. " +
"This is probably due to the limited classpath we have provided to the class loader. " +
"The specified main class (" + mainClass +
") found in the jar is *assumed* to contain a main method... " + e.getMessage() );
}
catch ( Throwable t )
{
getLogger().error( "Unknown error: Couldn't check if the main class has a main method. " +
"The specified main class (" + mainClass +
") found in the jar is *assumed* to contain a main method...", t );
}
}
return containsClass;
} | java | public boolean artifactContainsClass( Artifact artifact, final String mainClass )
throws MojoExecutionException
{
boolean containsClass = true;
// JarArchiver.grabFilesAndDirs()
URL url;
try
{
url = artifact.getFile().toURI().toURL();
}
catch ( MalformedURLException e )
{
throw new MojoExecutionException( "Could not get artifact url: " + artifact.getFile(), e );
}
ClassLoader cl = new java.net.URLClassLoader( new URL[]{url} );
Class<?> c = null;
try
{
c = Class.forName( mainClass, false, cl );
}
catch ( ClassNotFoundException e )
{
getLogger().debug( "artifact " + artifact + " doesn't contain the main class: " + mainClass );
containsClass = false;
}
catch ( Throwable t )
{
getLogger().info( "artifact " + artifact + " seems to contain the main class: " + mainClass +
" but the jar doesn't seem to contain all dependencies " + t.getMessage() );
}
if ( c != null )
{
getLogger().debug( "Checking if the loaded class contains a main method." );
try
{
c.getMethod( "main", String[].class );
}
catch ( NoSuchMethodException e )
{
getLogger().warn(
"The specified main class (" + mainClass + ") doesn't seem to contain a main method... " +
"Please check your configuration." + e.getMessage() );
}
catch ( NoClassDefFoundError e )
{
// undocumented in SDK 5.0. is this due to the ClassLoader lazy loading the Method
// thus making this a case tackled by the JVM Spec (Ref 5.3.5)!
// Reported as Incident 633981 to Sun just in case ...
getLogger().warn( "Something failed while checking if the main class contains the main() method. " +
"This is probably due to the limited classpath we have provided to the class loader. " +
"The specified main class (" + mainClass +
") found in the jar is *assumed* to contain a main method... " + e.getMessage() );
}
catch ( Throwable t )
{
getLogger().error( "Unknown error: Couldn't check if the main class has a main method. " +
"The specified main class (" + mainClass +
") found in the jar is *assumed* to contain a main method...", t );
}
}
return containsClass;
} | [
"public",
"boolean",
"artifactContainsClass",
"(",
"Artifact",
"artifact",
",",
"final",
"String",
"mainClass",
")",
"throws",
"MojoExecutionException",
"{",
"boolean",
"containsClass",
"=",
"true",
";",
"// JarArchiver.grabFilesAndDirs()",
"URL",
"url",
";",
"try",
"{",
"url",
"=",
"artifact",
".",
"getFile",
"(",
")",
".",
"toURI",
"(",
")",
".",
"toURL",
"(",
")",
";",
"}",
"catch",
"(",
"MalformedURLException",
"e",
")",
"{",
"throw",
"new",
"MojoExecutionException",
"(",
"\"Could not get artifact url: \"",
"+",
"artifact",
".",
"getFile",
"(",
")",
",",
"e",
")",
";",
"}",
"ClassLoader",
"cl",
"=",
"new",
"java",
".",
"net",
".",
"URLClassLoader",
"(",
"new",
"URL",
"[",
"]",
"{",
"url",
"}",
")",
";",
"Class",
"<",
"?",
">",
"c",
"=",
"null",
";",
"try",
"{",
"c",
"=",
"Class",
".",
"forName",
"(",
"mainClass",
",",
"false",
",",
"cl",
")",
";",
"}",
"catch",
"(",
"ClassNotFoundException",
"e",
")",
"{",
"getLogger",
"(",
")",
".",
"debug",
"(",
"\"artifact \"",
"+",
"artifact",
"+",
"\" doesn't contain the main class: \"",
"+",
"mainClass",
")",
";",
"containsClass",
"=",
"false",
";",
"}",
"catch",
"(",
"Throwable",
"t",
")",
"{",
"getLogger",
"(",
")",
".",
"info",
"(",
"\"artifact \"",
"+",
"artifact",
"+",
"\" seems to contain the main class: \"",
"+",
"mainClass",
"+",
"\" but the jar doesn't seem to contain all dependencies \"",
"+",
"t",
".",
"getMessage",
"(",
")",
")",
";",
"}",
"if",
"(",
"c",
"!=",
"null",
")",
"{",
"getLogger",
"(",
")",
".",
"debug",
"(",
"\"Checking if the loaded class contains a main method.\"",
")",
";",
"try",
"{",
"c",
".",
"getMethod",
"(",
"\"main\"",
",",
"String",
"[",
"]",
".",
"class",
")",
";",
"}",
"catch",
"(",
"NoSuchMethodException",
"e",
")",
"{",
"getLogger",
"(",
")",
".",
"warn",
"(",
"\"The specified main class (\"",
"+",
"mainClass",
"+",
"\") doesn't seem to contain a main method... \"",
"+",
"\"Please check your configuration.\"",
"+",
"e",
".",
"getMessage",
"(",
")",
")",
";",
"}",
"catch",
"(",
"NoClassDefFoundError",
"e",
")",
"{",
"// undocumented in SDK 5.0. is this due to the ClassLoader lazy loading the Method",
"// thus making this a case tackled by the JVM Spec (Ref 5.3.5)!",
"// Reported as Incident 633981 to Sun just in case ...",
"getLogger",
"(",
")",
".",
"warn",
"(",
"\"Something failed while checking if the main class contains the main() method. \"",
"+",
"\"This is probably due to the limited classpath we have provided to the class loader. \"",
"+",
"\"The specified main class (\"",
"+",
"mainClass",
"+",
"\") found in the jar is *assumed* to contain a main method... \"",
"+",
"e",
".",
"getMessage",
"(",
")",
")",
";",
"}",
"catch",
"(",
"Throwable",
"t",
")",
"{",
"getLogger",
"(",
")",
".",
"error",
"(",
"\"Unknown error: Couldn't check if the main class has a main method. \"",
"+",
"\"The specified main class (\"",
"+",
"mainClass",
"+",
"\") found in the jar is *assumed* to contain a main method...\"",
",",
"t",
")",
";",
"}",
"}",
"return",
"containsClass",
";",
"}"
] | Tests if the given fully qualified name exists in the given artifact.
@param artifact artifact to test
@param mainClass the fully qualified name to find in artifact
@return {@code true} if given artifact contains the given fqn, {@code false} otherwise
@throws MojoExecutionException if artifact file url is mal formed | [
"Tests",
"if",
"the",
"given",
"fully",
"qualified",
"name",
"exists",
"in",
"the",
"given",
"artifact",
"."
] | 38fdd1d21f063f21716cfcd61ebeabd963487576 | https://github.com/mojohaus/webstart/blob/38fdd1d21f063f21716cfcd61ebeabd963487576/webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/util/DefaultArtifactUtil.java#L202-L267 |
3,668 | mojohaus/webstart | webstart-jnlp-servlet/src/main/java/jnlp/sample/jardiff/JarDiff.java | JarDiff.main | public static void main( String[] args )
throws IOException
{
boolean diff = true;
boolean minimal = true;
String outputFile = "out.jardiff";
for ( int counter = 0; counter < args.length; counter++ )
{
// for backward compatibilty with 1.0.1/1.0
if ( args[counter].equals( "-nonminimal" ) || args[counter].equals( "-n" ) )
{
minimal = false;
}
else if ( args[counter].equals( "-creatediff" ) || args[counter].equals( "-c" ) )
{
diff = true;
}
else if ( args[counter].equals( "-applydiff" ) || args[counter].equals( "-a" ) )
{
diff = false;
}
else if ( args[counter].equals( "-debug" ) || args[counter].equals( "-d" ) )
{
_debug = true;
}
else if ( args[counter].equals( "-output" ) || args[counter].equals( "-o" ) )
{
if ( ++counter < args.length )
{
outputFile = args[counter];
}
}
else if ( args[counter].equals( "-applydiff" ) || args[counter].equals( "-a" ) )
{
diff = false;
}
else
{
if ( ( counter + 2 ) != args.length )
{
showHelp();
System.exit( 0 );
}
if ( diff )
{
try
{
OutputStream os = new FileOutputStream( outputFile );
JarDiff.createPatch( args[counter], args[counter + 1], os, minimal );
os.close();
}
catch ( IOException ioe )
{
try
{
System.out.println( getResources().getString( "jardiff.error.create" ) + " " + ioe );
}
catch ( MissingResourceException mre )
{
}
}
}
else
{
try
{
OutputStream os = new FileOutputStream( outputFile );
new JarDiffPatcher().applyPatch( null, args[counter], args[counter + 1], os );
os.close();
}
catch ( IOException ioe )
{
try
{
System.out.println( getResources().getString( "jardiff.error.apply" ) + " " + ioe );
}
catch ( MissingResourceException mre )
{
}
}
}
System.exit( 0 );
}
}
showHelp();
} | java | public static void main( String[] args )
throws IOException
{
boolean diff = true;
boolean minimal = true;
String outputFile = "out.jardiff";
for ( int counter = 0; counter < args.length; counter++ )
{
// for backward compatibilty with 1.0.1/1.0
if ( args[counter].equals( "-nonminimal" ) || args[counter].equals( "-n" ) )
{
minimal = false;
}
else if ( args[counter].equals( "-creatediff" ) || args[counter].equals( "-c" ) )
{
diff = true;
}
else if ( args[counter].equals( "-applydiff" ) || args[counter].equals( "-a" ) )
{
diff = false;
}
else if ( args[counter].equals( "-debug" ) || args[counter].equals( "-d" ) )
{
_debug = true;
}
else if ( args[counter].equals( "-output" ) || args[counter].equals( "-o" ) )
{
if ( ++counter < args.length )
{
outputFile = args[counter];
}
}
else if ( args[counter].equals( "-applydiff" ) || args[counter].equals( "-a" ) )
{
diff = false;
}
else
{
if ( ( counter + 2 ) != args.length )
{
showHelp();
System.exit( 0 );
}
if ( diff )
{
try
{
OutputStream os = new FileOutputStream( outputFile );
JarDiff.createPatch( args[counter], args[counter + 1], os, minimal );
os.close();
}
catch ( IOException ioe )
{
try
{
System.out.println( getResources().getString( "jardiff.error.create" ) + " " + ioe );
}
catch ( MissingResourceException mre )
{
}
}
}
else
{
try
{
OutputStream os = new FileOutputStream( outputFile );
new JarDiffPatcher().applyPatch( null, args[counter], args[counter + 1], os );
os.close();
}
catch ( IOException ioe )
{
try
{
System.out.println( getResources().getString( "jardiff.error.apply" ) + " " + ioe );
}
catch ( MissingResourceException mre )
{
}
}
}
System.exit( 0 );
}
}
showHelp();
} | [
"public",
"static",
"void",
"main",
"(",
"String",
"[",
"]",
"args",
")",
"throws",
"IOException",
"{",
"boolean",
"diff",
"=",
"true",
";",
"boolean",
"minimal",
"=",
"true",
";",
"String",
"outputFile",
"=",
"\"out.jardiff\"",
";",
"for",
"(",
"int",
"counter",
"=",
"0",
";",
"counter",
"<",
"args",
".",
"length",
";",
"counter",
"++",
")",
"{",
"// for backward compatibilty with 1.0.1/1.0",
"if",
"(",
"args",
"[",
"counter",
"]",
".",
"equals",
"(",
"\"-nonminimal\"",
")",
"||",
"args",
"[",
"counter",
"]",
".",
"equals",
"(",
"\"-n\"",
")",
")",
"{",
"minimal",
"=",
"false",
";",
"}",
"else",
"if",
"(",
"args",
"[",
"counter",
"]",
".",
"equals",
"(",
"\"-creatediff\"",
")",
"||",
"args",
"[",
"counter",
"]",
".",
"equals",
"(",
"\"-c\"",
")",
")",
"{",
"diff",
"=",
"true",
";",
"}",
"else",
"if",
"(",
"args",
"[",
"counter",
"]",
".",
"equals",
"(",
"\"-applydiff\"",
")",
"||",
"args",
"[",
"counter",
"]",
".",
"equals",
"(",
"\"-a\"",
")",
")",
"{",
"diff",
"=",
"false",
";",
"}",
"else",
"if",
"(",
"args",
"[",
"counter",
"]",
".",
"equals",
"(",
"\"-debug\"",
")",
"||",
"args",
"[",
"counter",
"]",
".",
"equals",
"(",
"\"-d\"",
")",
")",
"{",
"_debug",
"=",
"true",
";",
"}",
"else",
"if",
"(",
"args",
"[",
"counter",
"]",
".",
"equals",
"(",
"\"-output\"",
")",
"||",
"args",
"[",
"counter",
"]",
".",
"equals",
"(",
"\"-o\"",
")",
")",
"{",
"if",
"(",
"++",
"counter",
"<",
"args",
".",
"length",
")",
"{",
"outputFile",
"=",
"args",
"[",
"counter",
"]",
";",
"}",
"}",
"else",
"if",
"(",
"args",
"[",
"counter",
"]",
".",
"equals",
"(",
"\"-applydiff\"",
")",
"||",
"args",
"[",
"counter",
"]",
".",
"equals",
"(",
"\"-a\"",
")",
")",
"{",
"diff",
"=",
"false",
";",
"}",
"else",
"{",
"if",
"(",
"(",
"counter",
"+",
"2",
")",
"!=",
"args",
".",
"length",
")",
"{",
"showHelp",
"(",
")",
";",
"System",
".",
"exit",
"(",
"0",
")",
";",
"}",
"if",
"(",
"diff",
")",
"{",
"try",
"{",
"OutputStream",
"os",
"=",
"new",
"FileOutputStream",
"(",
"outputFile",
")",
";",
"JarDiff",
".",
"createPatch",
"(",
"args",
"[",
"counter",
"]",
",",
"args",
"[",
"counter",
"+",
"1",
"]",
",",
"os",
",",
"minimal",
")",
";",
"os",
".",
"close",
"(",
")",
";",
"}",
"catch",
"(",
"IOException",
"ioe",
")",
"{",
"try",
"{",
"System",
".",
"out",
".",
"println",
"(",
"getResources",
"(",
")",
".",
"getString",
"(",
"\"jardiff.error.create\"",
")",
"+",
"\" \"",
"+",
"ioe",
")",
";",
"}",
"catch",
"(",
"MissingResourceException",
"mre",
")",
"{",
"}",
"}",
"}",
"else",
"{",
"try",
"{",
"OutputStream",
"os",
"=",
"new",
"FileOutputStream",
"(",
"outputFile",
")",
";",
"new",
"JarDiffPatcher",
"(",
")",
".",
"applyPatch",
"(",
"null",
",",
"args",
"[",
"counter",
"]",
",",
"args",
"[",
"counter",
"+",
"1",
"]",
",",
"os",
")",
";",
"os",
".",
"close",
"(",
")",
";",
"}",
"catch",
"(",
"IOException",
"ioe",
")",
"{",
"try",
"{",
"System",
".",
"out",
".",
"println",
"(",
"getResources",
"(",
")",
".",
"getString",
"(",
"\"jardiff.error.apply\"",
")",
"+",
"\" \"",
"+",
"ioe",
")",
";",
"}",
"catch",
"(",
"MissingResourceException",
"mre",
")",
"{",
"}",
"}",
"}",
"System",
".",
"exit",
"(",
"0",
")",
";",
"}",
"}",
"showHelp",
"(",
")",
";",
"}"
] | -creatediff -applydiff -debug -output file | [
"-",
"creatediff",
"-",
"applydiff",
"-",
"debug",
"-",
"output",
"file"
] | 38fdd1d21f063f21716cfcd61ebeabd963487576 | https://github.com/mojohaus/webstart/blob/38fdd1d21f063f21716cfcd61ebeabd963487576/webstart-jnlp-servlet/src/main/java/jnlp/sample/jardiff/JarDiff.java#L700-L788 |
3,669 | mojohaus/webstart | webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/AbstractJnlpMojo.java | AbstractJnlpMojo.processDependencies | private void processDependencies()
throws MojoExecutionException
{
processDependency( getProject().getArtifact() );
AndArtifactFilter filter = new AndArtifactFilter();
// filter.add( new ScopeArtifactFilter( dependencySet.getScope() ) );
if ( dependencies != null && dependencies.getIncludes() != null && !dependencies.getIncludes().isEmpty() )
{
filter.add( new IncludesArtifactFilter( dependencies.getIncludes() ) );
}
if ( dependencies != null && dependencies.getExcludes() != null && !dependencies.getExcludes().isEmpty() )
{
filter.add( new ExcludesArtifactFilter( dependencies.getExcludes() ) );
}
Collection<Artifact> artifacts =
isExcludeTransitive() ? getProject().getDependencyArtifacts() : getProject().getArtifacts();
for ( Artifact artifact : artifacts )
{
if ( filter.include( artifact ) )
{
processDependency( artifact );
}
}
} | java | private void processDependencies()
throws MojoExecutionException
{
processDependency( getProject().getArtifact() );
AndArtifactFilter filter = new AndArtifactFilter();
// filter.add( new ScopeArtifactFilter( dependencySet.getScope() ) );
if ( dependencies != null && dependencies.getIncludes() != null && !dependencies.getIncludes().isEmpty() )
{
filter.add( new IncludesArtifactFilter( dependencies.getIncludes() ) );
}
if ( dependencies != null && dependencies.getExcludes() != null && !dependencies.getExcludes().isEmpty() )
{
filter.add( new ExcludesArtifactFilter( dependencies.getExcludes() ) );
}
Collection<Artifact> artifacts =
isExcludeTransitive() ? getProject().getDependencyArtifacts() : getProject().getArtifacts();
for ( Artifact artifact : artifacts )
{
if ( filter.include( artifact ) )
{
processDependency( artifact );
}
}
} | [
"private",
"void",
"processDependencies",
"(",
")",
"throws",
"MojoExecutionException",
"{",
"processDependency",
"(",
"getProject",
"(",
")",
".",
"getArtifact",
"(",
")",
")",
";",
"AndArtifactFilter",
"filter",
"=",
"new",
"AndArtifactFilter",
"(",
")",
";",
"// filter.add( new ScopeArtifactFilter( dependencySet.getScope() ) );",
"if",
"(",
"dependencies",
"!=",
"null",
"&&",
"dependencies",
".",
"getIncludes",
"(",
")",
"!=",
"null",
"&&",
"!",
"dependencies",
".",
"getIncludes",
"(",
")",
".",
"isEmpty",
"(",
")",
")",
"{",
"filter",
".",
"add",
"(",
"new",
"IncludesArtifactFilter",
"(",
"dependencies",
".",
"getIncludes",
"(",
")",
")",
")",
";",
"}",
"if",
"(",
"dependencies",
"!=",
"null",
"&&",
"dependencies",
".",
"getExcludes",
"(",
")",
"!=",
"null",
"&&",
"!",
"dependencies",
".",
"getExcludes",
"(",
")",
".",
"isEmpty",
"(",
")",
")",
"{",
"filter",
".",
"add",
"(",
"new",
"ExcludesArtifactFilter",
"(",
"dependencies",
".",
"getExcludes",
"(",
")",
")",
")",
";",
"}",
"Collection",
"<",
"Artifact",
">",
"artifacts",
"=",
"isExcludeTransitive",
"(",
")",
"?",
"getProject",
"(",
")",
".",
"getDependencyArtifacts",
"(",
")",
":",
"getProject",
"(",
")",
".",
"getArtifacts",
"(",
")",
";",
"for",
"(",
"Artifact",
"artifact",
":",
"artifacts",
")",
"{",
"if",
"(",
"filter",
".",
"include",
"(",
"artifact",
")",
")",
"{",
"processDependency",
"(",
"artifact",
")",
";",
"}",
"}",
"}"
] | Iterate through all the top level and transitive dependencies declared in the project and
collect all the runtime scope dependencies for inclusion in the .zip and signing.
@throws MojoExecutionException if could not process dependencies | [
"Iterate",
"through",
"all",
"the",
"top",
"level",
"and",
"transitive",
"dependencies",
"declared",
"in",
"the",
"project",
"and",
"collect",
"all",
"the",
"runtime",
"scope",
"dependencies",
"for",
"inclusion",
"in",
"the",
".",
"zip",
"and",
"signing",
"."
] | 38fdd1d21f063f21716cfcd61ebeabd963487576 | https://github.com/mojohaus/webstart/blob/38fdd1d21f063f21716cfcd61ebeabd963487576/webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/AbstractJnlpMojo.java#L493-L521 |
3,670 | mojohaus/webstart | webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/AbstractBaseJnlpMojo.java | AbstractBaseJnlpMojo.getResourcesDirectory | protected File getResourcesDirectory()
{
if ( resourcesDirectory == null )
{
resourcesDirectory = new File( getProject().getBasedir(), DEFAULT_RESOURCES_DIR );
}
return resourcesDirectory;
} | java | protected File getResourcesDirectory()
{
if ( resourcesDirectory == null )
{
resourcesDirectory = new File( getProject().getBasedir(), DEFAULT_RESOURCES_DIR );
}
return resourcesDirectory;
} | [
"protected",
"File",
"getResourcesDirectory",
"(",
")",
"{",
"if",
"(",
"resourcesDirectory",
"==",
"null",
")",
"{",
"resourcesDirectory",
"=",
"new",
"File",
"(",
"getProject",
"(",
")",
".",
"getBasedir",
"(",
")",
",",
"DEFAULT_RESOURCES_DIR",
")",
";",
"}",
"return",
"resourcesDirectory",
";",
"}"
] | Returns the location of the directory containing
non-jar resources that are to be included in the JNLP bundle.
@return Returns the value of the resourcesDirectory field, never null. | [
"Returns",
"the",
"location",
"of",
"the",
"directory",
"containing",
"non",
"-",
"jar",
"resources",
"that",
"are",
"to",
"be",
"included",
"in",
"the",
"JNLP",
"bundle",
"."
] | 38fdd1d21f063f21716cfcd61ebeabd963487576 | https://github.com/mojohaus/webstart/blob/38fdd1d21f063f21716cfcd61ebeabd963487576/webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/AbstractBaseJnlpMojo.java#L455-L465 |
3,671 | mojohaus/webstart | webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/AbstractBaseJnlpMojo.java | AbstractBaseJnlpMojo.signOrRenameJars | protected void signOrRenameJars()
throws MojoExecutionException
{
if ( sign != null )
{
try
{
ClassLoader loader = getCompileClassLoader();
sign.init( getWorkDirectory(), getLog().isDebugEnabled(), signTool, securityDispatcher, loader );
}
catch ( MalformedURLException e )
{
throw new MojoExecutionException( "Could not create classloader", e );
}
if ( unsignAlreadySignedJars )
{
removeExistingSignatures( getLibDirectory() );
}
if ( isPack200() )
{
//TODO tchemit use a temporary directory to pack-unpack
// http://java.sun.com/j2se/1.5.0/docs/guide/deployment/deployment-guide/pack200.html
// we need to pack then unpack the files before signing them
unpackJars( getLibDirectory() );
// As out current Pack200 ant tasks don't give us the ability to use a temporary area for
// creating those temporary packing, we have to delete the temporary files.
ioUtil.deleteFiles( getLibDirectory(), unprocessedPack200FileFilter );
// specs says that one should do it twice when there are unsigned jars??
// Pack200.unpackJars( applicationDirectory, updatedPack200FileFilter );
}
if ( MapUtils.isNotEmpty( updateManifestEntries ) )
{
updateManifestEntries( getLibDirectory() );
}
int signedJars = signJars( getLibDirectory() );
if ( signedJars != getModifiedJnlpArtifacts().size() )
{
throw new IllegalStateException(
"The number of signed artifacts (" + signedJars + ") differ from the number of modified " +
"artifacts (" + getModifiedJnlpArtifacts().size() + "). Implementation error" );
}
}
else
{
makeUnprocessedFilesFinal( getLibDirectory() );
}
if ( isPack200() )
{
verboseLog( "-- Pack jars" );
pack200Jars( getLibDirectory(), processedJarFileFilter );
}
} | java | protected void signOrRenameJars()
throws MojoExecutionException
{
if ( sign != null )
{
try
{
ClassLoader loader = getCompileClassLoader();
sign.init( getWorkDirectory(), getLog().isDebugEnabled(), signTool, securityDispatcher, loader );
}
catch ( MalformedURLException e )
{
throw new MojoExecutionException( "Could not create classloader", e );
}
if ( unsignAlreadySignedJars )
{
removeExistingSignatures( getLibDirectory() );
}
if ( isPack200() )
{
//TODO tchemit use a temporary directory to pack-unpack
// http://java.sun.com/j2se/1.5.0/docs/guide/deployment/deployment-guide/pack200.html
// we need to pack then unpack the files before signing them
unpackJars( getLibDirectory() );
// As out current Pack200 ant tasks don't give us the ability to use a temporary area for
// creating those temporary packing, we have to delete the temporary files.
ioUtil.deleteFiles( getLibDirectory(), unprocessedPack200FileFilter );
// specs says that one should do it twice when there are unsigned jars??
// Pack200.unpackJars( applicationDirectory, updatedPack200FileFilter );
}
if ( MapUtils.isNotEmpty( updateManifestEntries ) )
{
updateManifestEntries( getLibDirectory() );
}
int signedJars = signJars( getLibDirectory() );
if ( signedJars != getModifiedJnlpArtifacts().size() )
{
throw new IllegalStateException(
"The number of signed artifacts (" + signedJars + ") differ from the number of modified " +
"artifacts (" + getModifiedJnlpArtifacts().size() + "). Implementation error" );
}
}
else
{
makeUnprocessedFilesFinal( getLibDirectory() );
}
if ( isPack200() )
{
verboseLog( "-- Pack jars" );
pack200Jars( getLibDirectory(), processedJarFileFilter );
}
} | [
"protected",
"void",
"signOrRenameJars",
"(",
")",
"throws",
"MojoExecutionException",
"{",
"if",
"(",
"sign",
"!=",
"null",
")",
"{",
"try",
"{",
"ClassLoader",
"loader",
"=",
"getCompileClassLoader",
"(",
")",
";",
"sign",
".",
"init",
"(",
"getWorkDirectory",
"(",
")",
",",
"getLog",
"(",
")",
".",
"isDebugEnabled",
"(",
")",
",",
"signTool",
",",
"securityDispatcher",
",",
"loader",
")",
";",
"}",
"catch",
"(",
"MalformedURLException",
"e",
")",
"{",
"throw",
"new",
"MojoExecutionException",
"(",
"\"Could not create classloader\"",
",",
"e",
")",
";",
"}",
"if",
"(",
"unsignAlreadySignedJars",
")",
"{",
"removeExistingSignatures",
"(",
"getLibDirectory",
"(",
")",
")",
";",
"}",
"if",
"(",
"isPack200",
"(",
")",
")",
"{",
"//TODO tchemit use a temporary directory to pack-unpack",
"// http://java.sun.com/j2se/1.5.0/docs/guide/deployment/deployment-guide/pack200.html",
"// we need to pack then unpack the files before signing them",
"unpackJars",
"(",
"getLibDirectory",
"(",
")",
")",
";",
"// As out current Pack200 ant tasks don't give us the ability to use a temporary area for",
"// creating those temporary packing, we have to delete the temporary files.",
"ioUtil",
".",
"deleteFiles",
"(",
"getLibDirectory",
"(",
")",
",",
"unprocessedPack200FileFilter",
")",
";",
"// specs says that one should do it twice when there are unsigned jars??",
"// Pack200.unpackJars( applicationDirectory, updatedPack200FileFilter );",
"}",
"if",
"(",
"MapUtils",
".",
"isNotEmpty",
"(",
"updateManifestEntries",
")",
")",
"{",
"updateManifestEntries",
"(",
"getLibDirectory",
"(",
")",
")",
";",
"}",
"int",
"signedJars",
"=",
"signJars",
"(",
"getLibDirectory",
"(",
")",
")",
";",
"if",
"(",
"signedJars",
"!=",
"getModifiedJnlpArtifacts",
"(",
")",
".",
"size",
"(",
")",
")",
"{",
"throw",
"new",
"IllegalStateException",
"(",
"\"The number of signed artifacts (\"",
"+",
"signedJars",
"+",
"\") differ from the number of modified \"",
"+",
"\"artifacts (\"",
"+",
"getModifiedJnlpArtifacts",
"(",
")",
".",
"size",
"(",
")",
"+",
"\"). Implementation error\"",
")",
";",
"}",
"}",
"else",
"{",
"makeUnprocessedFilesFinal",
"(",
"getLibDirectory",
"(",
")",
")",
";",
"}",
"if",
"(",
"isPack200",
"(",
")",
")",
"{",
"verboseLog",
"(",
"\"-- Pack jars\"",
")",
";",
"pack200Jars",
"(",
"getLibDirectory",
"(",
")",
",",
"processedJarFileFilter",
")",
";",
"}",
"}"
] | If sign is enabled, sign the jars, otherwise rename them into final jars
@throws MojoExecutionException if can not sign or rename jars | [
"If",
"sign",
"is",
"enabled",
"sign",
"the",
"jars",
"otherwise",
"rename",
"them",
"into",
"final",
"jars"
] | 38fdd1d21f063f21716cfcd61ebeabd963487576 | https://github.com/mojohaus/webstart/blob/38fdd1d21f063f21716cfcd61ebeabd963487576/webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/AbstractBaseJnlpMojo.java#L666-L728 |
3,672 | mojohaus/webstart | webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/AbstractBaseJnlpMojo.java | AbstractBaseJnlpMojo.verboseLog | protected void verboseLog( String msg )
{
if ( isVerbose() )
{
getLog().info( msg );
}
else
{
getLog().debug( msg );
}
} | java | protected void verboseLog( String msg )
{
if ( isVerbose() )
{
getLog().info( msg );
}
else
{
getLog().debug( msg );
}
} | [
"protected",
"void",
"verboseLog",
"(",
"String",
"msg",
")",
"{",
"if",
"(",
"isVerbose",
"(",
")",
")",
"{",
"getLog",
"(",
")",
".",
"info",
"(",
"msg",
")",
";",
"}",
"else",
"{",
"getLog",
"(",
")",
".",
"debug",
"(",
"msg",
")",
";",
"}",
"}"
] | Log as info when verbose or info is enabled, as debug otherwise.
@param msg the message to display | [
"Log",
"as",
"info",
"when",
"verbose",
"or",
"info",
"is",
"enabled",
"as",
"debug",
"otherwise",
"."
] | 38fdd1d21f063f21716cfcd61ebeabd963487576 | https://github.com/mojohaus/webstart/blob/38fdd1d21f063f21716cfcd61ebeabd963487576/webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/AbstractBaseJnlpMojo.java#L785-L795 |
3,673 | mojohaus/webstart | webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/AbstractBaseJnlpMojo.java | AbstractBaseJnlpMojo.removeExistingSignatures | private int removeExistingSignatures( File workDirectory )
throws MojoExecutionException
{
getLog().info( "-- Remove existing signatures" );
// cleanup tempDir if exists
File tempDir = new File( workDirectory, "temp_extracted_jars" );
ioUtil.removeDirectory( tempDir );
// recreate temp dir
ioUtil.makeDirectoryIfNecessary( tempDir );
// process jars
File[] jarFiles = workDirectory.listFiles( unprocessedJarFileFilter );
for ( File jarFile : jarFiles )
{
if ( isJarSigned( jarFile ) )
{
if ( !canUnsign )
{
throw new MojoExecutionException(
"neverUnsignAlreadySignedJar is set to true and a jar file [" + jarFile +
" was asked to be unsign,\n please prefer use in this case an extension for " +
"signed jars or not set to true the neverUnsignAlreadySignedJar parameter, Make " +
"your choice:)" );
}
verboseLog( "Remove signature " + toProcessFile( jarFile ).getName() );
signTool.unsign( jarFile, isVerbose() );
}
else
{
verboseLog( "Skip not signed " + toProcessFile( jarFile ).getName() );
}
}
// cleanup tempDir
ioUtil.removeDirectory( tempDir );
return jarFiles.length; // FIXME this is wrong. Not all jars are signed.
} | java | private int removeExistingSignatures( File workDirectory )
throws MojoExecutionException
{
getLog().info( "-- Remove existing signatures" );
// cleanup tempDir if exists
File tempDir = new File( workDirectory, "temp_extracted_jars" );
ioUtil.removeDirectory( tempDir );
// recreate temp dir
ioUtil.makeDirectoryIfNecessary( tempDir );
// process jars
File[] jarFiles = workDirectory.listFiles( unprocessedJarFileFilter );
for ( File jarFile : jarFiles )
{
if ( isJarSigned( jarFile ) )
{
if ( !canUnsign )
{
throw new MojoExecutionException(
"neverUnsignAlreadySignedJar is set to true and a jar file [" + jarFile +
" was asked to be unsign,\n please prefer use in this case an extension for " +
"signed jars or not set to true the neverUnsignAlreadySignedJar parameter, Make " +
"your choice:)" );
}
verboseLog( "Remove signature " + toProcessFile( jarFile ).getName() );
signTool.unsign( jarFile, isVerbose() );
}
else
{
verboseLog( "Skip not signed " + toProcessFile( jarFile ).getName() );
}
}
// cleanup tempDir
ioUtil.removeDirectory( tempDir );
return jarFiles.length; // FIXME this is wrong. Not all jars are signed.
} | [
"private",
"int",
"removeExistingSignatures",
"(",
"File",
"workDirectory",
")",
"throws",
"MojoExecutionException",
"{",
"getLog",
"(",
")",
".",
"info",
"(",
"\"-- Remove existing signatures\"",
")",
";",
"// cleanup tempDir if exists",
"File",
"tempDir",
"=",
"new",
"File",
"(",
"workDirectory",
",",
"\"temp_extracted_jars\"",
")",
";",
"ioUtil",
".",
"removeDirectory",
"(",
"tempDir",
")",
";",
"// recreate temp dir",
"ioUtil",
".",
"makeDirectoryIfNecessary",
"(",
"tempDir",
")",
";",
"// process jars",
"File",
"[",
"]",
"jarFiles",
"=",
"workDirectory",
".",
"listFiles",
"(",
"unprocessedJarFileFilter",
")",
";",
"for",
"(",
"File",
"jarFile",
":",
"jarFiles",
")",
"{",
"if",
"(",
"isJarSigned",
"(",
"jarFile",
")",
")",
"{",
"if",
"(",
"!",
"canUnsign",
")",
"{",
"throw",
"new",
"MojoExecutionException",
"(",
"\"neverUnsignAlreadySignedJar is set to true and a jar file [\"",
"+",
"jarFile",
"+",
"\" was asked to be unsign,\\n please prefer use in this case an extension for \"",
"+",
"\"signed jars or not set to true the neverUnsignAlreadySignedJar parameter, Make \"",
"+",
"\"your choice:)\"",
")",
";",
"}",
"verboseLog",
"(",
"\"Remove signature \"",
"+",
"toProcessFile",
"(",
"jarFile",
")",
".",
"getName",
"(",
")",
")",
";",
"signTool",
".",
"unsign",
"(",
"jarFile",
",",
"isVerbose",
"(",
")",
")",
";",
"}",
"else",
"{",
"verboseLog",
"(",
"\"Skip not signed \"",
"+",
"toProcessFile",
"(",
"jarFile",
")",
".",
"getName",
"(",
")",
")",
";",
"}",
"}",
"// cleanup tempDir",
"ioUtil",
".",
"removeDirectory",
"(",
"tempDir",
")",
";",
"return",
"jarFiles",
".",
"length",
";",
"// FIXME this is wrong. Not all jars are signed.",
"}"
] | Removes the signature of the files in the specified directory which satisfy the
specified filter.
@param workDirectory working directory used to unsign jars
@return the number of unsigned jars
@throws MojoExecutionException if could not remove signatures | [
"Removes",
"the",
"signature",
"of",
"the",
"files",
"in",
"the",
"specified",
"directory",
"which",
"satisfy",
"the",
"specified",
"filter",
"."
] | 38fdd1d21f063f21716cfcd61ebeabd963487576 | https://github.com/mojohaus/webstart/blob/38fdd1d21f063f21716cfcd61ebeabd963487576/webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/AbstractBaseJnlpMojo.java#L982-L1023 |
3,674 | mojohaus/webstart | webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/JnlpDownloadServletMojo.java | JnlpDownloadServletMojo.checkConfiguration | private void checkConfiguration()
throws MojoExecutionException
{
checkDependencyFilenameStrategy();
if ( CollectionUtils.isEmpty( jnlpFiles ) )
{
throw new MojoExecutionException(
"Configuration error: At least one <jnlpFile> element must be specified" );
}
if ( jnlpFiles.size() == 1 && StringUtils.isEmpty( jnlpFiles.get( 0 ).getOutputFilename() ) )
{
getLog().debug( "Jnlp output file name not specified in single set of jnlpFiles. " +
"Using default output file name: launch.jnlp." );
jnlpFiles.get( 0 ).setOutputFilename( "launch.jnlp" );
}
// ---
// check Jnlp files configuration
// ---
Set<String> filenames = new LinkedHashSet<>( jnlpFiles.size() );
for ( JnlpFile jnlpFile : jnlpFiles )
{
if ( !filenames.add( jnlpFile.getOutputFilename() ) )
{
throw new MojoExecutionException( "Configuration error: Unique JNLP filenames must be provided. " +
"The following file name appears more than once [" +
jnlpFile.getOutputFilename() + "]." );
}
checkJnlpFileConfiguration( jnlpFile );
}
if ( CollectionUtils.isNotEmpty( commonJarResources ) )
{
// ---
// --- checkCommonJarResources();
// ---
for ( JarResource jarResource : commonJarResources )
{
checkMandatoryJarResourceFields( jarResource );
if ( jarResource.getMainClass() != null )
{
throw new MojoExecutionException( "Configuration Error: A mainClass must not be specified " +
"on a JarResource in the commonJarResources collection." );
}
}
// ---
// check for duplicate jar resources
// Checks that any jarResources defined in the jnlpFile elements are not also defined in
// commonJarResources.
// ---
for ( JnlpFile jnlpFile : jnlpFiles )
{
for ( JarResource jarResource : jnlpFile.getJarResources() )
{
if ( commonJarResources.contains( jarResource ) )
{
String message = "Configuration Error: The jar resource element for artifact " + jarResource +
" defined in common jar resources is duplicated in the jar " +
"resources configuration of the jnlp file identified by the template file " +
jnlpFile.getInputTemplate() + ".";
throw new MojoExecutionException( message );
}
}
}
}
} | java | private void checkConfiguration()
throws MojoExecutionException
{
checkDependencyFilenameStrategy();
if ( CollectionUtils.isEmpty( jnlpFiles ) )
{
throw new MojoExecutionException(
"Configuration error: At least one <jnlpFile> element must be specified" );
}
if ( jnlpFiles.size() == 1 && StringUtils.isEmpty( jnlpFiles.get( 0 ).getOutputFilename() ) )
{
getLog().debug( "Jnlp output file name not specified in single set of jnlpFiles. " +
"Using default output file name: launch.jnlp." );
jnlpFiles.get( 0 ).setOutputFilename( "launch.jnlp" );
}
// ---
// check Jnlp files configuration
// ---
Set<String> filenames = new LinkedHashSet<>( jnlpFiles.size() );
for ( JnlpFile jnlpFile : jnlpFiles )
{
if ( !filenames.add( jnlpFile.getOutputFilename() ) )
{
throw new MojoExecutionException( "Configuration error: Unique JNLP filenames must be provided. " +
"The following file name appears more than once [" +
jnlpFile.getOutputFilename() + "]." );
}
checkJnlpFileConfiguration( jnlpFile );
}
if ( CollectionUtils.isNotEmpty( commonJarResources ) )
{
// ---
// --- checkCommonJarResources();
// ---
for ( JarResource jarResource : commonJarResources )
{
checkMandatoryJarResourceFields( jarResource );
if ( jarResource.getMainClass() != null )
{
throw new MojoExecutionException( "Configuration Error: A mainClass must not be specified " +
"on a JarResource in the commonJarResources collection." );
}
}
// ---
// check for duplicate jar resources
// Checks that any jarResources defined in the jnlpFile elements are not also defined in
// commonJarResources.
// ---
for ( JnlpFile jnlpFile : jnlpFiles )
{
for ( JarResource jarResource : jnlpFile.getJarResources() )
{
if ( commonJarResources.contains( jarResource ) )
{
String message = "Configuration Error: The jar resource element for artifact " + jarResource +
" defined in common jar resources is duplicated in the jar " +
"resources configuration of the jnlp file identified by the template file " +
jnlpFile.getInputTemplate() + ".";
throw new MojoExecutionException( message );
}
}
}
}
} | [
"private",
"void",
"checkConfiguration",
"(",
")",
"throws",
"MojoExecutionException",
"{",
"checkDependencyFilenameStrategy",
"(",
")",
";",
"if",
"(",
"CollectionUtils",
".",
"isEmpty",
"(",
"jnlpFiles",
")",
")",
"{",
"throw",
"new",
"MojoExecutionException",
"(",
"\"Configuration error: At least one <jnlpFile> element must be specified\"",
")",
";",
"}",
"if",
"(",
"jnlpFiles",
".",
"size",
"(",
")",
"==",
"1",
"&&",
"StringUtils",
".",
"isEmpty",
"(",
"jnlpFiles",
".",
"get",
"(",
"0",
")",
".",
"getOutputFilename",
"(",
")",
")",
")",
"{",
"getLog",
"(",
")",
".",
"debug",
"(",
"\"Jnlp output file name not specified in single set of jnlpFiles. \"",
"+",
"\"Using default output file name: launch.jnlp.\"",
")",
";",
"jnlpFiles",
".",
"get",
"(",
"0",
")",
".",
"setOutputFilename",
"(",
"\"launch.jnlp\"",
")",
";",
"}",
"// ---",
"// check Jnlp files configuration",
"// ---",
"Set",
"<",
"String",
">",
"filenames",
"=",
"new",
"LinkedHashSet",
"<>",
"(",
"jnlpFiles",
".",
"size",
"(",
")",
")",
";",
"for",
"(",
"JnlpFile",
"jnlpFile",
":",
"jnlpFiles",
")",
"{",
"if",
"(",
"!",
"filenames",
".",
"add",
"(",
"jnlpFile",
".",
"getOutputFilename",
"(",
")",
")",
")",
"{",
"throw",
"new",
"MojoExecutionException",
"(",
"\"Configuration error: Unique JNLP filenames must be provided. \"",
"+",
"\"The following file name appears more than once [\"",
"+",
"jnlpFile",
".",
"getOutputFilename",
"(",
")",
"+",
"\"].\"",
")",
";",
"}",
"checkJnlpFileConfiguration",
"(",
"jnlpFile",
")",
";",
"}",
"if",
"(",
"CollectionUtils",
".",
"isNotEmpty",
"(",
"commonJarResources",
")",
")",
"{",
"// ---",
"// --- checkCommonJarResources();",
"// ---",
"for",
"(",
"JarResource",
"jarResource",
":",
"commonJarResources",
")",
"{",
"checkMandatoryJarResourceFields",
"(",
"jarResource",
")",
";",
"if",
"(",
"jarResource",
".",
"getMainClass",
"(",
")",
"!=",
"null",
")",
"{",
"throw",
"new",
"MojoExecutionException",
"(",
"\"Configuration Error: A mainClass must not be specified \"",
"+",
"\"on a JarResource in the commonJarResources collection.\"",
")",
";",
"}",
"}",
"// ---",
"// check for duplicate jar resources",
"// Checks that any jarResources defined in the jnlpFile elements are not also defined in",
"// commonJarResources.",
"// ---",
"for",
"(",
"JnlpFile",
"jnlpFile",
":",
"jnlpFiles",
")",
"{",
"for",
"(",
"JarResource",
"jarResource",
":",
"jnlpFile",
".",
"getJarResources",
"(",
")",
")",
"{",
"if",
"(",
"commonJarResources",
".",
"contains",
"(",
"jarResource",
")",
")",
"{",
"String",
"message",
"=",
"\"Configuration Error: The jar resource element for artifact \"",
"+",
"jarResource",
"+",
"\" defined in common jar resources is duplicated in the jar \"",
"+",
"\"resources configuration of the jnlp file identified by the template file \"",
"+",
"jnlpFile",
".",
"getInputTemplate",
"(",
")",
"+",
"\".\"",
";",
"throw",
"new",
"MojoExecutionException",
"(",
"message",
")",
";",
"}",
"}",
"}",
"}",
"}"
] | Confirms that all plugin configuration provided by the user
in the pom.xml file is valid.
@throws MojoExecutionException if any user configuration is invalid. | [
"Confirms",
"that",
"all",
"plugin",
"configuration",
"provided",
"by",
"the",
"user",
"in",
"the",
"pom",
".",
"xml",
"file",
"is",
"valid",
"."
] | 38fdd1d21f063f21716cfcd61ebeabd963487576 | https://github.com/mojohaus/webstart/blob/38fdd1d21f063f21716cfcd61ebeabd963487576/webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/JnlpDownloadServletMojo.java#L235-L311 |
3,675 | mojohaus/webstart | webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/JnlpDownloadServletMojo.java | JnlpDownloadServletMojo.checkJnlpFileConfiguration | private void checkJnlpFileConfiguration( JnlpFile jnlpFile )
throws MojoExecutionException
{
if ( StringUtils.isBlank( jnlpFile.getOutputFilename() ) )
{
throw new MojoExecutionException(
"Configuration error: An outputFilename must be specified for each jnlpFile element" );
}
if ( StringUtils.isNotBlank( jnlpFile.getTemplateFilename() ) )
{
getLog().warn(
"jnlpFile.templateFilename is deprecated (since 1.0-beta-5), use now the jnlpFile.inputTemplate instead." );
jnlpFile.setInputTemplate( jnlpFile.getTemplateFilename() );
}
// if ( StringUtils.isBlank( jnlpFile.getInputTemplate() ) )
// {
// verboseLog(
// "No templateFilename found for " + jnlpFile.getOutputFilename() + ". Will use the default template." );
// }
// else
// {
// File templateFile = new File( getTemplateDirectory(), jnlpFile.getInputTemplate() );
//
// if ( !templateFile.isFile() )
// {
// throw new MojoExecutionException(
// "The specified JNLP template does not exist: [" + templateFile + "]" );
// }
// }
List<JarResource> jnlpJarResources = jnlpFile.getJarResources();
if ( CollectionUtils.isEmpty( jnlpJarResources ) )
{
throw new MojoExecutionException(
"Configuration error: A non-empty <jarResources> element must be specified in the plugin " +
"configuration for the JNLP file named [" + jnlpFile.getOutputFilename() + "]" );
}
// ---
// find out the jar resource with a main class (can only get one)
// ---
JarResource mainJarResource = null;
for ( JarResource jarResource : jnlpJarResources )
{
checkMandatoryJarResourceFields( jarResource );
if ( jarResource.getMainClass() != null )
{
if ( mainJarResource != null )
{
// alreay found
throw new MojoExecutionException(
"Configuration error: More than one <jarResource> element has been declared " +
"with a <mainClass> element in the configuration for JNLP file [" +
jnlpFile.getOutputFilename() +
"]" );
}
jnlpFile.setMainClass( jarResource.getMainClass() );
mainJarResource = jarResource;
}
}
if ( mainJarResource == null )
{
throw new MojoExecutionException( "Configuration error: Exactly one <jarResource> element must " +
"be declared with a <mainClass> element in the configuration for JNLP file [" +
jnlpFile.getOutputFilename() + "]" );
}
} | java | private void checkJnlpFileConfiguration( JnlpFile jnlpFile )
throws MojoExecutionException
{
if ( StringUtils.isBlank( jnlpFile.getOutputFilename() ) )
{
throw new MojoExecutionException(
"Configuration error: An outputFilename must be specified for each jnlpFile element" );
}
if ( StringUtils.isNotBlank( jnlpFile.getTemplateFilename() ) )
{
getLog().warn(
"jnlpFile.templateFilename is deprecated (since 1.0-beta-5), use now the jnlpFile.inputTemplate instead." );
jnlpFile.setInputTemplate( jnlpFile.getTemplateFilename() );
}
// if ( StringUtils.isBlank( jnlpFile.getInputTemplate() ) )
// {
// verboseLog(
// "No templateFilename found for " + jnlpFile.getOutputFilename() + ". Will use the default template." );
// }
// else
// {
// File templateFile = new File( getTemplateDirectory(), jnlpFile.getInputTemplate() );
//
// if ( !templateFile.isFile() )
// {
// throw new MojoExecutionException(
// "The specified JNLP template does not exist: [" + templateFile + "]" );
// }
// }
List<JarResource> jnlpJarResources = jnlpFile.getJarResources();
if ( CollectionUtils.isEmpty( jnlpJarResources ) )
{
throw new MojoExecutionException(
"Configuration error: A non-empty <jarResources> element must be specified in the plugin " +
"configuration for the JNLP file named [" + jnlpFile.getOutputFilename() + "]" );
}
// ---
// find out the jar resource with a main class (can only get one)
// ---
JarResource mainJarResource = null;
for ( JarResource jarResource : jnlpJarResources )
{
checkMandatoryJarResourceFields( jarResource );
if ( jarResource.getMainClass() != null )
{
if ( mainJarResource != null )
{
// alreay found
throw new MojoExecutionException(
"Configuration error: More than one <jarResource> element has been declared " +
"with a <mainClass> element in the configuration for JNLP file [" +
jnlpFile.getOutputFilename() +
"]" );
}
jnlpFile.setMainClass( jarResource.getMainClass() );
mainJarResource = jarResource;
}
}
if ( mainJarResource == null )
{
throw new MojoExecutionException( "Configuration error: Exactly one <jarResource> element must " +
"be declared with a <mainClass> element in the configuration for JNLP file [" +
jnlpFile.getOutputFilename() + "]" );
}
} | [
"private",
"void",
"checkJnlpFileConfiguration",
"(",
"JnlpFile",
"jnlpFile",
")",
"throws",
"MojoExecutionException",
"{",
"if",
"(",
"StringUtils",
".",
"isBlank",
"(",
"jnlpFile",
".",
"getOutputFilename",
"(",
")",
")",
")",
"{",
"throw",
"new",
"MojoExecutionException",
"(",
"\"Configuration error: An outputFilename must be specified for each jnlpFile element\"",
")",
";",
"}",
"if",
"(",
"StringUtils",
".",
"isNotBlank",
"(",
"jnlpFile",
".",
"getTemplateFilename",
"(",
")",
")",
")",
"{",
"getLog",
"(",
")",
".",
"warn",
"(",
"\"jnlpFile.templateFilename is deprecated (since 1.0-beta-5), use now the jnlpFile.inputTemplate instead.\"",
")",
";",
"jnlpFile",
".",
"setInputTemplate",
"(",
"jnlpFile",
".",
"getTemplateFilename",
"(",
")",
")",
";",
"}",
"// if ( StringUtils.isBlank( jnlpFile.getInputTemplate() ) )",
"// {",
"// verboseLog(",
"// \"No templateFilename found for \" + jnlpFile.getOutputFilename() + \". Will use the default template.\" );",
"// }",
"// else",
"// {",
"// File templateFile = new File( getTemplateDirectory(), jnlpFile.getInputTemplate() );",
"//",
"// if ( !templateFile.isFile() )",
"// {",
"// throw new MojoExecutionException(",
"// \"The specified JNLP template does not exist: [\" + templateFile + \"]\" );",
"// }",
"// }",
"List",
"<",
"JarResource",
">",
"jnlpJarResources",
"=",
"jnlpFile",
".",
"getJarResources",
"(",
")",
";",
"if",
"(",
"CollectionUtils",
".",
"isEmpty",
"(",
"jnlpJarResources",
")",
")",
"{",
"throw",
"new",
"MojoExecutionException",
"(",
"\"Configuration error: A non-empty <jarResources> element must be specified in the plugin \"",
"+",
"\"configuration for the JNLP file named [\"",
"+",
"jnlpFile",
".",
"getOutputFilename",
"(",
")",
"+",
"\"]\"",
")",
";",
"}",
"// ---",
"// find out the jar resource with a main class (can only get one)",
"// ---",
"JarResource",
"mainJarResource",
"=",
"null",
";",
"for",
"(",
"JarResource",
"jarResource",
":",
"jnlpJarResources",
")",
"{",
"checkMandatoryJarResourceFields",
"(",
"jarResource",
")",
";",
"if",
"(",
"jarResource",
".",
"getMainClass",
"(",
")",
"!=",
"null",
")",
"{",
"if",
"(",
"mainJarResource",
"!=",
"null",
")",
"{",
"// alreay found",
"throw",
"new",
"MojoExecutionException",
"(",
"\"Configuration error: More than one <jarResource> element has been declared \"",
"+",
"\"with a <mainClass> element in the configuration for JNLP file [\"",
"+",
"jnlpFile",
".",
"getOutputFilename",
"(",
")",
"+",
"\"]\"",
")",
";",
"}",
"jnlpFile",
".",
"setMainClass",
"(",
"jarResource",
".",
"getMainClass",
"(",
")",
")",
";",
"mainJarResource",
"=",
"jarResource",
";",
"}",
"}",
"if",
"(",
"mainJarResource",
"==",
"null",
")",
"{",
"throw",
"new",
"MojoExecutionException",
"(",
"\"Configuration error: Exactly one <jarResource> element must \"",
"+",
"\"be declared with a <mainClass> element in the configuration for JNLP file [\"",
"+",
"jnlpFile",
".",
"getOutputFilename",
"(",
")",
"+",
"\"]\"",
")",
";",
"}",
"}"
] | Checks the validity of a single jnlpFile configuration element.
@param jnlpFile The configuration element to be checked.
@throws MojoExecutionException if the config element is invalid. | [
"Checks",
"the",
"validity",
"of",
"a",
"single",
"jnlpFile",
"configuration",
"element",
"."
] | 38fdd1d21f063f21716cfcd61ebeabd963487576 | https://github.com/mojohaus/webstart/blob/38fdd1d21f063f21716cfcd61ebeabd963487576/webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/JnlpDownloadServletMojo.java#L319-L394 |
3,676 | mojohaus/webstart | webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/JnlpDownloadServletMojo.java | JnlpDownloadServletMojo.generateVersionXml | private void generateVersionXml( Set<ResolvedJarResource> jarResources )
throws MojoExecutionException
{
VersionXmlGenerator generator = new VersionXmlGenerator( getEncoding() );
generator.generate( getLibDirectory(), jarResources );
} | java | private void generateVersionXml( Set<ResolvedJarResource> jarResources )
throws MojoExecutionException
{
VersionXmlGenerator generator = new VersionXmlGenerator( getEncoding() );
generator.generate( getLibDirectory(), jarResources );
} | [
"private",
"void",
"generateVersionXml",
"(",
"Set",
"<",
"ResolvedJarResource",
">",
"jarResources",
")",
"throws",
"MojoExecutionException",
"{",
"VersionXmlGenerator",
"generator",
"=",
"new",
"VersionXmlGenerator",
"(",
"getEncoding",
"(",
")",
")",
";",
"generator",
".",
"generate",
"(",
"getLibDirectory",
"(",
")",
",",
"jarResources",
")",
";",
"}"
] | Generates a version.xml file for all the jarResources configured either in jnlpFile elements
or in the commonJarResources element.
@throws MojoExecutionException if could not generate the xml version file | [
"Generates",
"a",
"version",
".",
"xml",
"file",
"for",
"all",
"the",
"jarResources",
"configured",
"either",
"in",
"jnlpFile",
"elements",
"or",
"in",
"the",
"commonJarResources",
"element",
"."
] | 38fdd1d21f063f21716cfcd61ebeabd963487576 | https://github.com/mojohaus/webstart/blob/38fdd1d21f063f21716cfcd61ebeabd963487576/webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/JnlpDownloadServletMojo.java#L643-L649 |
3,677 | mojohaus/webstart | webstart-jnlp-servlet/src/main/java/jnlp/sample/servlet/JnlpFileHandler.java | JnlpFileHandler.getUrlPrefix | private String getUrlPrefix( HttpServletRequest req )
{
StringBuilder url = new StringBuilder();
String scheme = req.getScheme();
int port = req.getServerPort();
url.append( scheme ); // http, https
url.append( "://" );
url.append( req.getServerName() );
if ( ( scheme.equals( "http" ) && port != 80 ) || ( scheme.equals( "https" ) && port != 443 ) )
{
url.append( ':' );
url.append( req.getServerPort() );
}
return url.toString();
} | java | private String getUrlPrefix( HttpServletRequest req )
{
StringBuilder url = new StringBuilder();
String scheme = req.getScheme();
int port = req.getServerPort();
url.append( scheme ); // http, https
url.append( "://" );
url.append( req.getServerName() );
if ( ( scheme.equals( "http" ) && port != 80 ) || ( scheme.equals( "https" ) && port != 443 ) )
{
url.append( ':' );
url.append( req.getServerPort() );
}
return url.toString();
} | [
"private",
"String",
"getUrlPrefix",
"(",
"HttpServletRequest",
"req",
")",
"{",
"StringBuilder",
"url",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"String",
"scheme",
"=",
"req",
".",
"getScheme",
"(",
")",
";",
"int",
"port",
"=",
"req",
".",
"getServerPort",
"(",
")",
";",
"url",
".",
"append",
"(",
"scheme",
")",
";",
"// http, https",
"url",
".",
"append",
"(",
"\"://\"",
")",
";",
"url",
".",
"append",
"(",
"req",
".",
"getServerName",
"(",
")",
")",
";",
"if",
"(",
"(",
"scheme",
".",
"equals",
"(",
"\"http\"",
")",
"&&",
"port",
"!=",
"80",
")",
"||",
"(",
"scheme",
".",
"equals",
"(",
"\"https\"",
")",
"&&",
"port",
"!=",
"443",
")",
")",
"{",
"url",
".",
"append",
"(",
"'",
"'",
")",
";",
"url",
".",
"append",
"(",
"req",
".",
"getServerPort",
"(",
")",
")",
";",
"}",
"return",
"url",
".",
"toString",
"(",
")",
";",
"}"
] | This code is heavily inspired by the stuff in HttpUtils.getRequestURL | [
"This",
"code",
"is",
"heavily",
"inspired",
"by",
"the",
"stuff",
"in",
"HttpUtils",
".",
"getRequestURL"
] | 38fdd1d21f063f21716cfcd61ebeabd963487576 | https://github.com/mojohaus/webstart/blob/38fdd1d21f063f21716cfcd61ebeabd963487576/webstart-jnlp-servlet/src/main/java/jnlp/sample/servlet/JnlpFileHandler.java#L362-L376 |
3,678 | mojohaus/webstart | webstart-jnlp-servlet/src/main/java/jnlp/sample/servlet/JnlpDownloadServlet.java | JnlpDownloadServlet.validateRequest | private void validateRequest( DownloadRequest dreq )
throws ErrorResponseException
{
String path = dreq.getPath();
if ( path.endsWith( ResourceCatalog.VERSION_XML_FILENAME ) || path.indexOf( "__" ) != -1 )
{
throw new ErrorResponseException( DownloadResponse.getNoContentResponse() );
}
} | java | private void validateRequest( DownloadRequest dreq )
throws ErrorResponseException
{
String path = dreq.getPath();
if ( path.endsWith( ResourceCatalog.VERSION_XML_FILENAME ) || path.indexOf( "__" ) != -1 )
{
throw new ErrorResponseException( DownloadResponse.getNoContentResponse() );
}
} | [
"private",
"void",
"validateRequest",
"(",
"DownloadRequest",
"dreq",
")",
"throws",
"ErrorResponseException",
"{",
"String",
"path",
"=",
"dreq",
".",
"getPath",
"(",
")",
";",
"if",
"(",
"path",
".",
"endsWith",
"(",
"ResourceCatalog",
".",
"VERSION_XML_FILENAME",
")",
"||",
"path",
".",
"indexOf",
"(",
"\"__\"",
")",
"!=",
"-",
"1",
")",
"{",
"throw",
"new",
"ErrorResponseException",
"(",
"DownloadResponse",
".",
"getNoContentResponse",
"(",
")",
")",
";",
"}",
"}"
] | Make sure that it is a valid request. This is also the place to implement the
reverse IP lookup | [
"Make",
"sure",
"that",
"it",
"is",
"a",
"valid",
"request",
".",
"This",
"is",
"also",
"the",
"place",
"to",
"implement",
"the",
"reverse",
"IP",
"lookup"
] | 38fdd1d21f063f21716cfcd61ebeabd963487576 | https://github.com/mojohaus/webstart/blob/38fdd1d21f063f21716cfcd61ebeabd963487576/webstart-jnlp-servlet/src/main/java/jnlp/sample/servlet/JnlpDownloadServlet.java#L247-L255 |
3,679 | mojohaus/webstart | webstart-jnlp-servlet/src/main/java/jnlp/sample/servlet/JnlpDownloadServlet.java | JnlpDownloadServlet.locateResource | private JnlpResource locateResource( DownloadRequest dreq )
throws IOException, ErrorResponseException
{
if ( dreq.getVersion() == null )
{
return handleBasicDownload( dreq );
}
else
{
return handleVersionRequest( dreq );
}
} | java | private JnlpResource locateResource( DownloadRequest dreq )
throws IOException, ErrorResponseException
{
if ( dreq.getVersion() == null )
{
return handleBasicDownload( dreq );
}
else
{
return handleVersionRequest( dreq );
}
} | [
"private",
"JnlpResource",
"locateResource",
"(",
"DownloadRequest",
"dreq",
")",
"throws",
"IOException",
",",
"ErrorResponseException",
"{",
"if",
"(",
"dreq",
".",
"getVersion",
"(",
")",
"==",
"null",
")",
"{",
"return",
"handleBasicDownload",
"(",
"dreq",
")",
";",
"}",
"else",
"{",
"return",
"handleVersionRequest",
"(",
"dreq",
")",
";",
"}",
"}"
] | Interprets the download request and convert it into a resource that is
part of the Web Archive. | [
"Interprets",
"the",
"download",
"request",
"and",
"convert",
"it",
"into",
"a",
"resource",
"that",
"is",
"part",
"of",
"the",
"Web",
"Archive",
"."
] | 38fdd1d21f063f21716cfcd61ebeabd963487576 | https://github.com/mojohaus/webstart/blob/38fdd1d21f063f21716cfcd61ebeabd963487576/webstart-jnlp-servlet/src/main/java/jnlp/sample/servlet/JnlpDownloadServlet.java#L261-L272 |
3,680 | mojohaus/webstart | webstart-jnlp-servlet/src/main/java/jnlp/sample/servlet/JnlpDownloadServlet.java | JnlpDownloadServlet.constructResponse | private DownloadResponse constructResponse( JnlpResource jnlpres, DownloadRequest dreq )
throws IOException
{
String path = jnlpres.getPath();
if ( jnlpres.isJnlpFile() )
{
// It is a JNLP file. It need to be macro-expanded, so it is handled differently
boolean supportQuery = JarDiffHandler.isJavawsVersion( dreq, "1.5+" );
_log.addDebug( "SupportQuery in Href: " + supportQuery );
// only support query string in href for 1.5 and above
if ( supportQuery )
{
return _jnlpFileHandler.getJnlpFileEx( jnlpres, dreq );
}
else
{
return _jnlpFileHandler.getJnlpFile( jnlpres, dreq );
}
}
// Check if a JARDiff can be returned
if ( dreq.getCurrentVersionId() != null && jnlpres.isJarFile() )
{
DownloadResponse response = _jarDiffHandler.getJarDiffEntry( _resourceCatalog, dreq, jnlpres );
if ( response != null )
{
_log.addInformational( "servlet.log.info.jardiff.response" );
return response;
}
}
// check and see if we can use pack resource
JnlpResource jr =
new JnlpResource( getServletContext(), jnlpres.getName(), jnlpres.getVersionId(), jnlpres.getOSList(),
jnlpres.getArchList(), jnlpres.getLocaleList(), jnlpres.getPath(),
jnlpres.getReturnVersionId(), dreq.getEncoding() );
_log.addDebug( "Real resource returned: " + jr );
// Return WAR file resource
return DownloadResponse.getFileDownloadResponse( jr.getResource(), jr.getMimeType(), jr.getLastModified(),
jr.getReturnVersionId() );
} | java | private DownloadResponse constructResponse( JnlpResource jnlpres, DownloadRequest dreq )
throws IOException
{
String path = jnlpres.getPath();
if ( jnlpres.isJnlpFile() )
{
// It is a JNLP file. It need to be macro-expanded, so it is handled differently
boolean supportQuery = JarDiffHandler.isJavawsVersion( dreq, "1.5+" );
_log.addDebug( "SupportQuery in Href: " + supportQuery );
// only support query string in href for 1.5 and above
if ( supportQuery )
{
return _jnlpFileHandler.getJnlpFileEx( jnlpres, dreq );
}
else
{
return _jnlpFileHandler.getJnlpFile( jnlpres, dreq );
}
}
// Check if a JARDiff can be returned
if ( dreq.getCurrentVersionId() != null && jnlpres.isJarFile() )
{
DownloadResponse response = _jarDiffHandler.getJarDiffEntry( _resourceCatalog, dreq, jnlpres );
if ( response != null )
{
_log.addInformational( "servlet.log.info.jardiff.response" );
return response;
}
}
// check and see if we can use pack resource
JnlpResource jr =
new JnlpResource( getServletContext(), jnlpres.getName(), jnlpres.getVersionId(), jnlpres.getOSList(),
jnlpres.getArchList(), jnlpres.getLocaleList(), jnlpres.getPath(),
jnlpres.getReturnVersionId(), dreq.getEncoding() );
_log.addDebug( "Real resource returned: " + jr );
// Return WAR file resource
return DownloadResponse.getFileDownloadResponse( jr.getResource(), jr.getMimeType(), jr.getLastModified(),
jr.getReturnVersionId() );
} | [
"private",
"DownloadResponse",
"constructResponse",
"(",
"JnlpResource",
"jnlpres",
",",
"DownloadRequest",
"dreq",
")",
"throws",
"IOException",
"{",
"String",
"path",
"=",
"jnlpres",
".",
"getPath",
"(",
")",
";",
"if",
"(",
"jnlpres",
".",
"isJnlpFile",
"(",
")",
")",
"{",
"// It is a JNLP file. It need to be macro-expanded, so it is handled differently",
"boolean",
"supportQuery",
"=",
"JarDiffHandler",
".",
"isJavawsVersion",
"(",
"dreq",
",",
"\"1.5+\"",
")",
";",
"_log",
".",
"addDebug",
"(",
"\"SupportQuery in Href: \"",
"+",
"supportQuery",
")",
";",
"// only support query string in href for 1.5 and above",
"if",
"(",
"supportQuery",
")",
"{",
"return",
"_jnlpFileHandler",
".",
"getJnlpFileEx",
"(",
"jnlpres",
",",
"dreq",
")",
";",
"}",
"else",
"{",
"return",
"_jnlpFileHandler",
".",
"getJnlpFile",
"(",
"jnlpres",
",",
"dreq",
")",
";",
"}",
"}",
"// Check if a JARDiff can be returned",
"if",
"(",
"dreq",
".",
"getCurrentVersionId",
"(",
")",
"!=",
"null",
"&&",
"jnlpres",
".",
"isJarFile",
"(",
")",
")",
"{",
"DownloadResponse",
"response",
"=",
"_jarDiffHandler",
".",
"getJarDiffEntry",
"(",
"_resourceCatalog",
",",
"dreq",
",",
"jnlpres",
")",
";",
"if",
"(",
"response",
"!=",
"null",
")",
"{",
"_log",
".",
"addInformational",
"(",
"\"servlet.log.info.jardiff.response\"",
")",
";",
"return",
"response",
";",
"}",
"}",
"// check and see if we can use pack resource",
"JnlpResource",
"jr",
"=",
"new",
"JnlpResource",
"(",
"getServletContext",
"(",
")",
",",
"jnlpres",
".",
"getName",
"(",
")",
",",
"jnlpres",
".",
"getVersionId",
"(",
")",
",",
"jnlpres",
".",
"getOSList",
"(",
")",
",",
"jnlpres",
".",
"getArchList",
"(",
")",
",",
"jnlpres",
".",
"getLocaleList",
"(",
")",
",",
"jnlpres",
".",
"getPath",
"(",
")",
",",
"jnlpres",
".",
"getReturnVersionId",
"(",
")",
",",
"dreq",
".",
"getEncoding",
"(",
")",
")",
";",
"_log",
".",
"addDebug",
"(",
"\"Real resource returned: \"",
"+",
"jr",
")",
";",
"// Return WAR file resource",
"return",
"DownloadResponse",
".",
"getFileDownloadResponse",
"(",
"jr",
".",
"getResource",
"(",
")",
",",
"jr",
".",
"getMimeType",
"(",
")",
",",
"jr",
".",
"getLastModified",
"(",
")",
",",
"jr",
".",
"getReturnVersionId",
"(",
")",
")",
";",
"}"
] | Given a DownloadPath and a DownloadRequest, it constructs the data stream to return
to the requester | [
"Given",
"a",
"DownloadPath",
"and",
"a",
"DownloadRequest",
"it",
"constructs",
"the",
"data",
"stream",
"to",
"return",
"to",
"the",
"requester"
] | 38fdd1d21f063f21716cfcd61ebeabd963487576 | https://github.com/mojohaus/webstart/blob/38fdd1d21f063f21716cfcd61ebeabd963487576/webstart-jnlp-servlet/src/main/java/jnlp/sample/servlet/JnlpDownloadServlet.java#L303-L346 |
3,681 | mojohaus/webstart | webstart-jnlp-servlet/src/main/java/jnlp/sample/util/VersionID.java | VersionID.matchTuple | private boolean matchTuple( Object o )
{
// Check for null and type
if ( o == null || !( o instanceof VersionID ) )
{
return false;
}
VersionID vid = (VersionID) o;
// Normalize arrays
String[] t1 = normalize( _tuple, vid._tuple.length );
String[] t2 = normalize( vid._tuple, _tuple.length );
// Check contents
for ( int i = 0; i < t1.length; i++ )
{
Object o1 = getValueAsObject( t1[i] );
Object o2 = getValueAsObject( t2[i] );
if ( !o1.equals( o2 ) )
{
return false;
}
}
return true;
} | java | private boolean matchTuple( Object o )
{
// Check for null and type
if ( o == null || !( o instanceof VersionID ) )
{
return false;
}
VersionID vid = (VersionID) o;
// Normalize arrays
String[] t1 = normalize( _tuple, vid._tuple.length );
String[] t2 = normalize( vid._tuple, _tuple.length );
// Check contents
for ( int i = 0; i < t1.length; i++ )
{
Object o1 = getValueAsObject( t1[i] );
Object o2 = getValueAsObject( t2[i] );
if ( !o1.equals( o2 ) )
{
return false;
}
}
return true;
} | [
"private",
"boolean",
"matchTuple",
"(",
"Object",
"o",
")",
"{",
"// Check for null and type",
"if",
"(",
"o",
"==",
"null",
"||",
"!",
"(",
"o",
"instanceof",
"VersionID",
")",
")",
"{",
"return",
"false",
";",
"}",
"VersionID",
"vid",
"=",
"(",
"VersionID",
")",
"o",
";",
"// Normalize arrays",
"String",
"[",
"]",
"t1",
"=",
"normalize",
"(",
"_tuple",
",",
"vid",
".",
"_tuple",
".",
"length",
")",
";",
"String",
"[",
"]",
"t2",
"=",
"normalize",
"(",
"vid",
".",
"_tuple",
",",
"_tuple",
".",
"length",
")",
";",
"// Check contents",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"t1",
".",
"length",
";",
"i",
"++",
")",
"{",
"Object",
"o1",
"=",
"getValueAsObject",
"(",
"t1",
"[",
"i",
"]",
")",
";",
"Object",
"o2",
"=",
"getValueAsObject",
"(",
"t2",
"[",
"i",
"]",
")",
";",
"if",
"(",
"!",
"o1",
".",
"equals",
"(",
"o2",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Compares if two version IDs are equal
@param o TODO
@return TODO | [
"Compares",
"if",
"two",
"version",
"IDs",
"are",
"equal"
] | 38fdd1d21f063f21716cfcd61ebeabd963487576 | https://github.com/mojohaus/webstart/blob/38fdd1d21f063f21716cfcd61ebeabd963487576/webstart-jnlp-servlet/src/main/java/jnlp/sample/util/VersionID.java#L186-L210 |
3,682 | mojohaus/webstart | webstart-jnlp-servlet/src/main/java/jnlp/sample/util/VersionID.java | VersionID.isGreaterThanOrEqualHelper | private boolean isGreaterThanOrEqualHelper( VersionID vid, boolean allowEqual )
{
if ( _isCompound )
{
if ( !_rest.isGreaterThanOrEqualHelper( vid, allowEqual ) )
{
return false;
}
}
// Normalize the two strings
String[] t1 = normalize( _tuple, vid._tuple.length );
String[] t2 = normalize( vid._tuple, _tuple.length );
for ( int i = 0; i < t1.length; i++ )
{
// Compare current element
Object e1 = getValueAsObject( t1[i] );
Object e2 = getValueAsObject( t2[i] );
if ( e1.equals( e2 ) )
{
// So far so good
}
else
{
if ( e1 instanceof Integer && e2 instanceof Integer )
{
return (Integer) e1 > (Integer) e2;
}
else
{
String s1 = t1[i];
String s2 = t2[i];
return s1.compareTo( s2 ) > 0;
}
}
}
// If we get here, they are equal
return allowEqual;
} | java | private boolean isGreaterThanOrEqualHelper( VersionID vid, boolean allowEqual )
{
if ( _isCompound )
{
if ( !_rest.isGreaterThanOrEqualHelper( vid, allowEqual ) )
{
return false;
}
}
// Normalize the two strings
String[] t1 = normalize( _tuple, vid._tuple.length );
String[] t2 = normalize( vid._tuple, _tuple.length );
for ( int i = 0; i < t1.length; i++ )
{
// Compare current element
Object e1 = getValueAsObject( t1[i] );
Object e2 = getValueAsObject( t2[i] );
if ( e1.equals( e2 ) )
{
// So far so good
}
else
{
if ( e1 instanceof Integer && e2 instanceof Integer )
{
return (Integer) e1 > (Integer) e2;
}
else
{
String s1 = t1[i];
String s2 = t2[i];
return s1.compareTo( s2 ) > 0;
}
}
}
// If we get here, they are equal
return allowEqual;
} | [
"private",
"boolean",
"isGreaterThanOrEqualHelper",
"(",
"VersionID",
"vid",
",",
"boolean",
"allowEqual",
")",
"{",
"if",
"(",
"_isCompound",
")",
"{",
"if",
"(",
"!",
"_rest",
".",
"isGreaterThanOrEqualHelper",
"(",
"vid",
",",
"allowEqual",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"// Normalize the two strings",
"String",
"[",
"]",
"t1",
"=",
"normalize",
"(",
"_tuple",
",",
"vid",
".",
"_tuple",
".",
"length",
")",
";",
"String",
"[",
"]",
"t2",
"=",
"normalize",
"(",
"vid",
".",
"_tuple",
",",
"_tuple",
".",
"length",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"t1",
".",
"length",
";",
"i",
"++",
")",
"{",
"// Compare current element",
"Object",
"e1",
"=",
"getValueAsObject",
"(",
"t1",
"[",
"i",
"]",
")",
";",
"Object",
"e2",
"=",
"getValueAsObject",
"(",
"t2",
"[",
"i",
"]",
")",
";",
"if",
"(",
"e1",
".",
"equals",
"(",
"e2",
")",
")",
"{",
"// So far so good",
"}",
"else",
"{",
"if",
"(",
"e1",
"instanceof",
"Integer",
"&&",
"e2",
"instanceof",
"Integer",
")",
"{",
"return",
"(",
"Integer",
")",
"e1",
">",
"(",
"Integer",
")",
"e2",
";",
"}",
"else",
"{",
"String",
"s1",
"=",
"t1",
"[",
"i",
"]",
";",
"String",
"s2",
"=",
"t2",
"[",
"i",
"]",
";",
"return",
"s1",
".",
"compareTo",
"(",
"s2",
")",
">",
"0",
";",
"}",
"}",
"}",
"// If we get here, they are equal",
"return",
"allowEqual",
";",
"}"
] | Compares if 'this' is greater than vid
@param vid TODO
@param allowEqual TODO
@return TODO | [
"Compares",
"if",
"this",
"is",
"greater",
"than",
"vid"
] | 38fdd1d21f063f21716cfcd61ebeabd963487576 | https://github.com/mojohaus/webstart/blob/38fdd1d21f063f21716cfcd61ebeabd963487576/webstart-jnlp-servlet/src/main/java/jnlp/sample/util/VersionID.java#L243-L283 |
3,683 | mojohaus/webstart | webstart-jnlp-servlet/src/main/java/jnlp/sample/util/VersionID.java | VersionID.isPrefixMatch | public boolean isPrefixMatch( VersionID vid )
{
if ( _isCompound )
{
if ( !_rest.isPrefixMatch( vid ) )
{
return false;
}
}
// Make sure that vid is at least as long as the prefix
String[] t2 = normalize( vid._tuple, _tuple.length );
for ( int i = 0; i < _tuple.length; i++ )
{
Object e1 = _tuple[i];
Object e2 = t2[i];
if ( e1.equals( e2 ) )
{
// So far so good
}
else
{
// Not a prefix
return false;
}
}
return true;
} | java | public boolean isPrefixMatch( VersionID vid )
{
if ( _isCompound )
{
if ( !_rest.isPrefixMatch( vid ) )
{
return false;
}
}
// Make sure that vid is at least as long as the prefix
String[] t2 = normalize( vid._tuple, _tuple.length );
for ( int i = 0; i < _tuple.length; i++ )
{
Object e1 = _tuple[i];
Object e2 = t2[i];
if ( e1.equals( e2 ) )
{
// So far so good
}
else
{
// Not a prefix
return false;
}
}
return true;
} | [
"public",
"boolean",
"isPrefixMatch",
"(",
"VersionID",
"vid",
")",
"{",
"if",
"(",
"_isCompound",
")",
"{",
"if",
"(",
"!",
"_rest",
".",
"isPrefixMatch",
"(",
"vid",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"// Make sure that vid is at least as long as the prefix",
"String",
"[",
"]",
"t2",
"=",
"normalize",
"(",
"vid",
".",
"_tuple",
",",
"_tuple",
".",
"length",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"_tuple",
".",
"length",
";",
"i",
"++",
")",
"{",
"Object",
"e1",
"=",
"_tuple",
"[",
"i",
"]",
";",
"Object",
"e2",
"=",
"t2",
"[",
"i",
"]",
";",
"if",
"(",
"e1",
".",
"equals",
"(",
"e2",
")",
")",
"{",
"// So far so good",
"}",
"else",
"{",
"// Not a prefix",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Checks if 'this' is a prefix of vid
@param vid TODO
@return TODO | [
"Checks",
"if",
"this",
"is",
"a",
"prefix",
"of",
"vid"
] | 38fdd1d21f063f21716cfcd61ebeabd963487576 | https://github.com/mojohaus/webstart/blob/38fdd1d21f063f21716cfcd61ebeabd963487576/webstart-jnlp-servlet/src/main/java/jnlp/sample/util/VersionID.java#L291-L319 |
3,684 | mojohaus/webstart | webstart-jnlp-servlet/src/main/java/jnlp/sample/util/VersionID.java | VersionID.normalize | private String[] normalize( String[] list, int minlength )
{
if ( list.length < minlength )
{
// Need to do padding
String[] newlist = new String[minlength];
System.arraycopy( list, 0, newlist, 0, list.length );
Arrays.fill( newlist, list.length, newlist.length, "0" );
return newlist;
}
else
{
return list;
}
} | java | private String[] normalize( String[] list, int minlength )
{
if ( list.length < minlength )
{
// Need to do padding
String[] newlist = new String[minlength];
System.arraycopy( list, 0, newlist, 0, list.length );
Arrays.fill( newlist, list.length, newlist.length, "0" );
return newlist;
}
else
{
return list;
}
} | [
"private",
"String",
"[",
"]",
"normalize",
"(",
"String",
"[",
"]",
"list",
",",
"int",
"minlength",
")",
"{",
"if",
"(",
"list",
".",
"length",
"<",
"minlength",
")",
"{",
"// Need to do padding",
"String",
"[",
"]",
"newlist",
"=",
"new",
"String",
"[",
"minlength",
"]",
";",
"System",
".",
"arraycopy",
"(",
"list",
",",
"0",
",",
"newlist",
",",
"0",
",",
"list",
".",
"length",
")",
";",
"Arrays",
".",
"fill",
"(",
"newlist",
",",
"list",
".",
"length",
",",
"newlist",
".",
"length",
",",
"\"0\"",
")",
";",
"return",
"newlist",
";",
"}",
"else",
"{",
"return",
"list",
";",
"}",
"}"
] | Normalize an array to a certain length
@param list TODO
@param minlength TODO
@return TODO | [
"Normalize",
"an",
"array",
"to",
"a",
"certain",
"length"
] | 38fdd1d21f063f21716cfcd61ebeabd963487576 | https://github.com/mojohaus/webstart/blob/38fdd1d21f063f21716cfcd61ebeabd963487576/webstart-jnlp-servlet/src/main/java/jnlp/sample/util/VersionID.java#L328-L342 |
3,685 | mojohaus/webstart | webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/dependency/task/UpdateManifestTask.java | UpdateManifestTask.createManifest | private Manifest createManifest( File jar, Map<String, String> manifestentries )
throws MojoExecutionException
{
JarFile jarFile = null;
try
{
jarFile = new JarFile( jar );
// read manifest from jar
Manifest manifest = jarFile.getManifest();
if ( manifest == null || manifest.getMainAttributes().isEmpty() )
{
manifest = new Manifest();
manifest.getMainAttributes().putValue( Attributes.Name.MANIFEST_VERSION.toString(), "1.0" );
}
// add or overwrite entries
Set<Map.Entry<String, String>> entrySet = manifestentries.entrySet();
for ( Map.Entry<String, String> entry : entrySet )
{
manifest.getMainAttributes().putValue( entry.getKey(), entry.getValue() );
}
return manifest;
}
catch ( IOException e )
{
throw new MojoExecutionException( "Error while reading manifest from " + jar.getAbsolutePath(), e );
}
finally
{
ioUtil.close( jarFile );
}
} | java | private Manifest createManifest( File jar, Map<String, String> manifestentries )
throws MojoExecutionException
{
JarFile jarFile = null;
try
{
jarFile = new JarFile( jar );
// read manifest from jar
Manifest manifest = jarFile.getManifest();
if ( manifest == null || manifest.getMainAttributes().isEmpty() )
{
manifest = new Manifest();
manifest.getMainAttributes().putValue( Attributes.Name.MANIFEST_VERSION.toString(), "1.0" );
}
// add or overwrite entries
Set<Map.Entry<String, String>> entrySet = manifestentries.entrySet();
for ( Map.Entry<String, String> entry : entrySet )
{
manifest.getMainAttributes().putValue( entry.getKey(), entry.getValue() );
}
return manifest;
}
catch ( IOException e )
{
throw new MojoExecutionException( "Error while reading manifest from " + jar.getAbsolutePath(), e );
}
finally
{
ioUtil.close( jarFile );
}
} | [
"private",
"Manifest",
"createManifest",
"(",
"File",
"jar",
",",
"Map",
"<",
"String",
",",
"String",
">",
"manifestentries",
")",
"throws",
"MojoExecutionException",
"{",
"JarFile",
"jarFile",
"=",
"null",
";",
"try",
"{",
"jarFile",
"=",
"new",
"JarFile",
"(",
"jar",
")",
";",
"// read manifest from jar",
"Manifest",
"manifest",
"=",
"jarFile",
".",
"getManifest",
"(",
")",
";",
"if",
"(",
"manifest",
"==",
"null",
"||",
"manifest",
".",
"getMainAttributes",
"(",
")",
".",
"isEmpty",
"(",
")",
")",
"{",
"manifest",
"=",
"new",
"Manifest",
"(",
")",
";",
"manifest",
".",
"getMainAttributes",
"(",
")",
".",
"putValue",
"(",
"Attributes",
".",
"Name",
".",
"MANIFEST_VERSION",
".",
"toString",
"(",
")",
",",
"\"1.0\"",
")",
";",
"}",
"// add or overwrite entries",
"Set",
"<",
"Map",
".",
"Entry",
"<",
"String",
",",
"String",
">",
">",
"entrySet",
"=",
"manifestentries",
".",
"entrySet",
"(",
")",
";",
"for",
"(",
"Map",
".",
"Entry",
"<",
"String",
",",
"String",
">",
"entry",
":",
"entrySet",
")",
"{",
"manifest",
".",
"getMainAttributes",
"(",
")",
".",
"putValue",
"(",
"entry",
".",
"getKey",
"(",
")",
",",
"entry",
".",
"getValue",
"(",
")",
")",
";",
"}",
"return",
"manifest",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"throw",
"new",
"MojoExecutionException",
"(",
"\"Error while reading manifest from \"",
"+",
"jar",
".",
"getAbsolutePath",
"(",
")",
",",
"e",
")",
";",
"}",
"finally",
"{",
"ioUtil",
".",
"close",
"(",
"jarFile",
")",
";",
"}",
"}"
] | Create the new manifest from the existing jar file and the new entries.
@param jar
@param manifestentries
@return Manifest
@throws MojoExecutionException | [
"Create",
"the",
"new",
"manifest",
"from",
"the",
"existing",
"jar",
"file",
"and",
"the",
"new",
"entries",
"."
] | 38fdd1d21f063f21716cfcd61ebeabd963487576 | https://github.com/mojohaus/webstart/blob/38fdd1d21f063f21716cfcd61ebeabd963487576/webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/dependency/task/UpdateManifestTask.java#L172-L206 |
3,686 | mojohaus/webstart | webstart-jnlp-servlet/src/main/java/jnlp/sample/util/VersionString.java | VersionString.contains | public boolean contains( VersionID m )
{
for ( Object _versionId : _versionIds )
{
VersionID vi = (VersionID) _versionId;
boolean check = vi.match( m );
if ( check )
{
return true;
}
}
return false;
} | java | public boolean contains( VersionID m )
{
for ( Object _versionId : _versionIds )
{
VersionID vi = (VersionID) _versionId;
boolean check = vi.match( m );
if ( check )
{
return true;
}
}
return false;
} | [
"public",
"boolean",
"contains",
"(",
"VersionID",
"m",
")",
"{",
"for",
"(",
"Object",
"_versionId",
":",
"_versionIds",
")",
"{",
"VersionID",
"vi",
"=",
"(",
"VersionID",
")",
"_versionId",
";",
"boolean",
"check",
"=",
"vi",
".",
"match",
"(",
"m",
")",
";",
"if",
"(",
"check",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Check if this VersionString object contains the VersionID m
@param m TODO
@return TODO | [
"Check",
"if",
"this",
"VersionString",
"object",
"contains",
"the",
"VersionID",
"m"
] | 38fdd1d21f063f21716cfcd61ebeabd963487576 | https://github.com/mojohaus/webstart/blob/38fdd1d21f063f21716cfcd61ebeabd963487576/webstart-jnlp-servlet/src/main/java/jnlp/sample/util/VersionString.java#L79-L91 |
3,687 | mojohaus/webstart | webstart-jnlp-servlet/src/main/java/jnlp/sample/util/VersionString.java | VersionString.containsGreaterThan | public boolean containsGreaterThan( VersionID m )
{
for ( Object _versionId : _versionIds )
{
VersionID vi = (VersionID) _versionId;
boolean check = vi.isGreaterThan( m );
if ( check )
{
return true;
}
}
return false;
} | java | public boolean containsGreaterThan( VersionID m )
{
for ( Object _versionId : _versionIds )
{
VersionID vi = (VersionID) _versionId;
boolean check = vi.isGreaterThan( m );
if ( check )
{
return true;
}
}
return false;
} | [
"public",
"boolean",
"containsGreaterThan",
"(",
"VersionID",
"m",
")",
"{",
"for",
"(",
"Object",
"_versionId",
":",
"_versionIds",
")",
"{",
"VersionID",
"vi",
"=",
"(",
"VersionID",
")",
"_versionId",
";",
"boolean",
"check",
"=",
"vi",
".",
"isGreaterThan",
"(",
"m",
")",
";",
"if",
"(",
"check",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Check if this VersionString object contains anything greater than m
@param m TODO
@return TODO | [
"Check",
"if",
"this",
"VersionString",
"object",
"contains",
"anything",
"greater",
"than",
"m"
] | 38fdd1d21f063f21716cfcd61ebeabd963487576 | https://github.com/mojohaus/webstart/blob/38fdd1d21f063f21716cfcd61ebeabd963487576/webstart-jnlp-servlet/src/main/java/jnlp/sample/util/VersionString.java#L110-L122 |
3,688 | mojohaus/webstart | webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/sign/SignConfig.java | SignConfig.createSignRequest | public JarSignerRequest createSignRequest( File jarToSign, File signedJar )
throws MojoExecutionException
{
JarSignerSignRequest request = new JarSignerSignRequest();
request.setAlias( getAlias() );
request.setKeystore( getKeystore() );
request.setSigfile( getSigfile() );
request.setStoretype( getStoretype() );
request.setWorkingDirectory( workDirectory );
request.setMaxMemory( getMaxMemory() );
request.setVerbose( isVerbose() );
request.setArchive( jarToSign );
request.setSignedjar( signedJar );
request.setTsaLocation( getTsaLocation() );
request.setProviderArg( getProviderArg() );
request.setProviderClass( getProviderClass() );
// Special handling for passwords through the Maven Security Dispatcher
request.setKeypass( decrypt( keypass ) );
request.setStorepass( decrypt( storepass ) );
if ( !arguments.isEmpty() )
{
request.setArguments( arguments.toArray( new String[arguments.size()] ) );
}
return request;
} | java | public JarSignerRequest createSignRequest( File jarToSign, File signedJar )
throws MojoExecutionException
{
JarSignerSignRequest request = new JarSignerSignRequest();
request.setAlias( getAlias() );
request.setKeystore( getKeystore() );
request.setSigfile( getSigfile() );
request.setStoretype( getStoretype() );
request.setWorkingDirectory( workDirectory );
request.setMaxMemory( getMaxMemory() );
request.setVerbose( isVerbose() );
request.setArchive( jarToSign );
request.setSignedjar( signedJar );
request.setTsaLocation( getTsaLocation() );
request.setProviderArg( getProviderArg() );
request.setProviderClass( getProviderClass() );
// Special handling for passwords through the Maven Security Dispatcher
request.setKeypass( decrypt( keypass ) );
request.setStorepass( decrypt( storepass ) );
if ( !arguments.isEmpty() )
{
request.setArguments( arguments.toArray( new String[arguments.size()] ) );
}
return request;
} | [
"public",
"JarSignerRequest",
"createSignRequest",
"(",
"File",
"jarToSign",
",",
"File",
"signedJar",
")",
"throws",
"MojoExecutionException",
"{",
"JarSignerSignRequest",
"request",
"=",
"new",
"JarSignerSignRequest",
"(",
")",
";",
"request",
".",
"setAlias",
"(",
"getAlias",
"(",
")",
")",
";",
"request",
".",
"setKeystore",
"(",
"getKeystore",
"(",
")",
")",
";",
"request",
".",
"setSigfile",
"(",
"getSigfile",
"(",
")",
")",
";",
"request",
".",
"setStoretype",
"(",
"getStoretype",
"(",
")",
")",
";",
"request",
".",
"setWorkingDirectory",
"(",
"workDirectory",
")",
";",
"request",
".",
"setMaxMemory",
"(",
"getMaxMemory",
"(",
")",
")",
";",
"request",
".",
"setVerbose",
"(",
"isVerbose",
"(",
")",
")",
";",
"request",
".",
"setArchive",
"(",
"jarToSign",
")",
";",
"request",
".",
"setSignedjar",
"(",
"signedJar",
")",
";",
"request",
".",
"setTsaLocation",
"(",
"getTsaLocation",
"(",
")",
")",
";",
"request",
".",
"setProviderArg",
"(",
"getProviderArg",
"(",
")",
")",
";",
"request",
".",
"setProviderClass",
"(",
"getProviderClass",
"(",
")",
")",
";",
"// Special handling for passwords through the Maven Security Dispatcher",
"request",
".",
"setKeypass",
"(",
"decrypt",
"(",
"keypass",
")",
")",
";",
"request",
".",
"setStorepass",
"(",
"decrypt",
"(",
"storepass",
")",
")",
";",
"if",
"(",
"!",
"arguments",
".",
"isEmpty",
"(",
")",
")",
"{",
"request",
".",
"setArguments",
"(",
"arguments",
".",
"toArray",
"(",
"new",
"String",
"[",
"arguments",
".",
"size",
"(",
")",
"]",
")",
")",
";",
"}",
"return",
"request",
";",
"}"
] | Creates a jarsigner request to do a sign operation.
@param jarToSign the location of the jar to sign
@param signedJar the optional location of the signed jar to produce (if not set, will use the original location)
@return the jarsigner request
@throws MojoExecutionException if something wrong occurs | [
"Creates",
"a",
"jarsigner",
"request",
"to",
"do",
"a",
"sign",
"operation",
"."
] | 38fdd1d21f063f21716cfcd61ebeabd963487576 | https://github.com/mojohaus/webstart/blob/38fdd1d21f063f21716cfcd61ebeabd963487576/webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/sign/SignConfig.java#L318-L345 |
3,689 | mojohaus/webstart | webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/sign/SignConfig.java | SignConfig.createVerifyRequest | public JarSignerRequest createVerifyRequest( File jarFile, boolean certs )
{
JarSignerVerifyRequest request = new JarSignerVerifyRequest();
request.setCerts( certs );
request.setWorkingDirectory( workDirectory );
request.setMaxMemory( getMaxMemory() );
request.setVerbose( isVerbose() );
request.setArchive( jarFile );
return request;
} | java | public JarSignerRequest createVerifyRequest( File jarFile, boolean certs )
{
JarSignerVerifyRequest request = new JarSignerVerifyRequest();
request.setCerts( certs );
request.setWorkingDirectory( workDirectory );
request.setMaxMemory( getMaxMemory() );
request.setVerbose( isVerbose() );
request.setArchive( jarFile );
return request;
} | [
"public",
"JarSignerRequest",
"createVerifyRequest",
"(",
"File",
"jarFile",
",",
"boolean",
"certs",
")",
"{",
"JarSignerVerifyRequest",
"request",
"=",
"new",
"JarSignerVerifyRequest",
"(",
")",
";",
"request",
".",
"setCerts",
"(",
"certs",
")",
";",
"request",
".",
"setWorkingDirectory",
"(",
"workDirectory",
")",
";",
"request",
".",
"setMaxMemory",
"(",
"getMaxMemory",
"(",
")",
")",
";",
"request",
".",
"setVerbose",
"(",
"isVerbose",
"(",
")",
")",
";",
"request",
".",
"setArchive",
"(",
"jarFile",
")",
";",
"return",
"request",
";",
"}"
] | Creates a jarsigner request to do a verify operation.
@param jarFile the location of the jar to sign
@param certs flag to show certificates details
@return the jarsigner request | [
"Creates",
"a",
"jarsigner",
"request",
"to",
"do",
"a",
"verify",
"operation",
"."
] | 38fdd1d21f063f21716cfcd61ebeabd963487576 | https://github.com/mojohaus/webstart/blob/38fdd1d21f063f21716cfcd61ebeabd963487576/webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/sign/SignConfig.java#L354-L363 |
3,690 | mojohaus/webstart | webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/sign/SignConfig.java | SignConfig.createKeyGenRequest | public KeyToolGenerateKeyPairRequest createKeyGenRequest( File keystoreFile )
{
KeyToolGenerateKeyPairRequest request = new KeyToolGenerateKeyPairRequest();
request.setAlias( getAlias() );
request.setDname( getDname() );
request.setKeyalg( getKeyalg() );
request.setKeypass( getKeypass() );
request.setKeysize( getKeysize() );
request.setKeystore( getKeystore() );
request.setSigalg( getSigalg() );
request.setStorepass( getStorepass() );
request.setStoretype( getStoretype() );
request.setValidity( getValidity() );
request.setVerbose( isVerbose() );
request.setWorkingDirectory( workDirectory );
return request;
} | java | public KeyToolGenerateKeyPairRequest createKeyGenRequest( File keystoreFile )
{
KeyToolGenerateKeyPairRequest request = new KeyToolGenerateKeyPairRequest();
request.setAlias( getAlias() );
request.setDname( getDname() );
request.setKeyalg( getKeyalg() );
request.setKeypass( getKeypass() );
request.setKeysize( getKeysize() );
request.setKeystore( getKeystore() );
request.setSigalg( getSigalg() );
request.setStorepass( getStorepass() );
request.setStoretype( getStoretype() );
request.setValidity( getValidity() );
request.setVerbose( isVerbose() );
request.setWorkingDirectory( workDirectory );
return request;
} | [
"public",
"KeyToolGenerateKeyPairRequest",
"createKeyGenRequest",
"(",
"File",
"keystoreFile",
")",
"{",
"KeyToolGenerateKeyPairRequest",
"request",
"=",
"new",
"KeyToolGenerateKeyPairRequest",
"(",
")",
";",
"request",
".",
"setAlias",
"(",
"getAlias",
"(",
")",
")",
";",
"request",
".",
"setDname",
"(",
"getDname",
"(",
")",
")",
";",
"request",
".",
"setKeyalg",
"(",
"getKeyalg",
"(",
")",
")",
";",
"request",
".",
"setKeypass",
"(",
"getKeypass",
"(",
")",
")",
";",
"request",
".",
"setKeysize",
"(",
"getKeysize",
"(",
")",
")",
";",
"request",
".",
"setKeystore",
"(",
"getKeystore",
"(",
")",
")",
";",
"request",
".",
"setSigalg",
"(",
"getSigalg",
"(",
")",
")",
";",
"request",
".",
"setStorepass",
"(",
"getStorepass",
"(",
")",
")",
";",
"request",
".",
"setStoretype",
"(",
"getStoretype",
"(",
")",
")",
";",
"request",
".",
"setValidity",
"(",
"getValidity",
"(",
")",
")",
";",
"request",
".",
"setVerbose",
"(",
"isVerbose",
"(",
")",
")",
";",
"request",
".",
"setWorkingDirectory",
"(",
"workDirectory",
")",
";",
"return",
"request",
";",
"}"
] | Creates a keytool request to do a key store generation operation.
@param keystoreFile the location of the key store file to generate
@return the keytool request | [
"Creates",
"a",
"keytool",
"request",
"to",
"do",
"a",
"key",
"store",
"generation",
"operation",
"."
] | 38fdd1d21f063f21716cfcd61ebeabd963487576 | https://github.com/mojohaus/webstart/blob/38fdd1d21f063f21716cfcd61ebeabd963487576/webstart-maven-plugin/src/main/java/org/codehaus/mojo/webstart/sign/SignConfig.java#L371-L387 |
3,691 | GwtMaterialDesign/gwt-material-table | src/main/java/gwt/material/design/client/ui/table/cell/Column.java | Column.onBrowserEvent | public void onBrowserEvent(Context context, Element elem, final T object, NativeEvent event) {
final int index = context.getIndex();
ValueUpdater<C> valueUpdater = (fieldUpdater == null) ? null : (ValueUpdater<C>) value -> {
fieldUpdater.update(index, object, value);
};
cell.onBrowserEvent(context, elem, getValue(object), event, valueUpdater);
} | java | public void onBrowserEvent(Context context, Element elem, final T object, NativeEvent event) {
final int index = context.getIndex();
ValueUpdater<C> valueUpdater = (fieldUpdater == null) ? null : (ValueUpdater<C>) value -> {
fieldUpdater.update(index, object, value);
};
cell.onBrowserEvent(context, elem, getValue(object), event, valueUpdater);
} | [
"public",
"void",
"onBrowserEvent",
"(",
"Context",
"context",
",",
"Element",
"elem",
",",
"final",
"T",
"object",
",",
"NativeEvent",
"event",
")",
"{",
"final",
"int",
"index",
"=",
"context",
".",
"getIndex",
"(",
")",
";",
"ValueUpdater",
"<",
"C",
">",
"valueUpdater",
"=",
"(",
"fieldUpdater",
"==",
"null",
")",
"?",
"null",
":",
"(",
"ValueUpdater",
"<",
"C",
">",
")",
"value",
"->",
"{",
"fieldUpdater",
".",
"update",
"(",
"index",
",",
"object",
",",
"value",
")",
";",
"}",
";",
"cell",
".",
"onBrowserEvent",
"(",
"context",
",",
"elem",
",",
"getValue",
"(",
"object",
")",
",",
"event",
",",
"valueUpdater",
")",
";",
"}"
] | Handle a browser event that took place within the column.
@param context the cell context
@param elem the parent Element
@param object the base object to be updated
@param event the native browser event | [
"Handle",
"a",
"browser",
"event",
"that",
"took",
"place",
"within",
"the",
"column",
"."
] | 1352cafdcbff747bc1f302e709ed376df6642ef5 | https://github.com/GwtMaterialDesign/gwt-material-table/blob/1352cafdcbff747bc1f302e709ed376df6642ef5/src/main/java/gwt/material/design/client/ui/table/cell/Column.java#L107-L113 |
3,692 | GwtMaterialDesign/gwt-material-table | src/main/java/gwt/material/design/client/ui/table/cell/Column.java | Column.render | public void render(Context context, T object, SafeHtmlBuilder sb) {
cell.render(context, getValue(object), sb);
} | java | public void render(Context context, T object, SafeHtmlBuilder sb) {
cell.render(context, getValue(object), sb);
} | [
"public",
"void",
"render",
"(",
"Context",
"context",
",",
"T",
"object",
",",
"SafeHtmlBuilder",
"sb",
")",
"{",
"cell",
".",
"render",
"(",
"context",
",",
"getValue",
"(",
"object",
")",
",",
"sb",
")",
";",
"}"
] | Render the object into the cell.
@param object the object to render
@param sb the buffer to render into | [
"Render",
"the",
"object",
"into",
"the",
"cell",
"."
] | 1352cafdcbff747bc1f302e709ed376df6642ef5 | https://github.com/GwtMaterialDesign/gwt-material-table/blob/1352cafdcbff747bc1f302e709ed376df6642ef5/src/main/java/gwt/material/design/client/ui/table/cell/Column.java#L137-L139 |
3,693 | GwtMaterialDesign/gwt-material-table | src/main/java/gwt/material/design/client/ui/table/cell/Column.java | Column.setStyleProperty | public final void setStyleProperty(StyleName styleName, String value) {
if(styleProps == null) {
styleProps = new HashMap<>();
}
styleProps.put(styleName, value);
} | java | public final void setStyleProperty(StyleName styleName, String value) {
if(styleProps == null) {
styleProps = new HashMap<>();
}
styleProps.put(styleName, value);
} | [
"public",
"final",
"void",
"setStyleProperty",
"(",
"StyleName",
"styleName",
",",
"String",
"value",
")",
"{",
"if",
"(",
"styleProps",
"==",
"null",
")",
"{",
"styleProps",
"=",
"new",
"HashMap",
"<>",
"(",
")",
";",
"}",
"styleProps",
".",
"put",
"(",
"styleName",
",",
"value",
")",
";",
"}"
] | Set a style property using its name as the key. Please ensure the style name and value
are appropriately configured or it may result in unexpected behavior.
@param styleName the style name as seen here {@link Style#STYLE_Z_INDEX} for example.
@param value the string value required for the given style property. | [
"Set",
"a",
"style",
"property",
"using",
"its",
"name",
"as",
"the",
"key",
".",
"Please",
"ensure",
"the",
"style",
"name",
"and",
"value",
"are",
"appropriately",
"configured",
"or",
"it",
"may",
"result",
"in",
"unexpected",
"behavior",
"."
] | 1352cafdcbff747bc1f302e709ed376df6642ef5 | https://github.com/GwtMaterialDesign/gwt-material-table/blob/1352cafdcbff747bc1f302e709ed376df6642ef5/src/main/java/gwt/material/design/client/ui/table/cell/Column.java#L277-L282 |
3,694 | GwtMaterialDesign/gwt-material-table | src/main/java/gwt/material/design/client/ui/table/cell/Column.java | Column.getStyleProperty | public final String getStyleProperty(StyleName styleName) {
return styleProps!=null ? styleProps.get(styleName) : null;
} | java | public final String getStyleProperty(StyleName styleName) {
return styleProps!=null ? styleProps.get(styleName) : null;
} | [
"public",
"final",
"String",
"getStyleProperty",
"(",
"StyleName",
"styleName",
")",
"{",
"return",
"styleProps",
"!=",
"null",
"?",
"styleProps",
".",
"get",
"(",
"styleName",
")",
":",
"null",
";",
"}"
] | Get a styles property.
@param styleName the styles name as represented in a {@link Style} class.
@return null if the style property is not set. | [
"Get",
"a",
"styles",
"property",
"."
] | 1352cafdcbff747bc1f302e709ed376df6642ef5 | https://github.com/GwtMaterialDesign/gwt-material-table/blob/1352cafdcbff747bc1f302e709ed376df6642ef5/src/main/java/gwt/material/design/client/ui/table/cell/Column.java#L289-L291 |
3,695 | GwtMaterialDesign/gwt-material-table | src/main/java/gwt/material/design/client/ui/table/cell/Column.java | Column.setWidth | public final void setWidth(String width) {
this.width = width;
this.dynamicWidth = width != null && width.contains("%");
} | java | public final void setWidth(String width) {
this.width = width;
this.dynamicWidth = width != null && width.contains("%");
} | [
"public",
"final",
"void",
"setWidth",
"(",
"String",
"width",
")",
"{",
"this",
".",
"width",
"=",
"width",
";",
"this",
".",
"dynamicWidth",
"=",
"width",
"!=",
"null",
"&&",
"width",
".",
"contains",
"(",
"\"%\"",
")",
";",
"}"
] | Set the columns header width. | [
"Set",
"the",
"columns",
"header",
"width",
"."
] | 1352cafdcbff747bc1f302e709ed376df6642ef5 | https://github.com/GwtMaterialDesign/gwt-material-table/blob/1352cafdcbff747bc1f302e709ed376df6642ef5/src/main/java/gwt/material/design/client/ui/table/cell/Column.java#L357-L360 |
3,696 | GwtMaterialDesign/gwt-material-table | src/main/java/gwt/material/design/client/data/infinite/InfiniteDataView.java | InfiniteDataView.loaded | public void loaded(int startIndex, List<T> data, boolean cacheData) {
loaded(startIndex, data, getTotalRows(), cacheData);
} | java | public void loaded(int startIndex, List<T> data, boolean cacheData) {
loaded(startIndex, data, getTotalRows(), cacheData);
} | [
"public",
"void",
"loaded",
"(",
"int",
"startIndex",
",",
"List",
"<",
"T",
">",
"data",
",",
"boolean",
"cacheData",
")",
"{",
"loaded",
"(",
"startIndex",
",",
"data",
",",
"getTotalRows",
"(",
")",
",",
"cacheData",
")",
";",
"}"
] | Provide the option to load data with a cache parameter. | [
"Provide",
"the",
"option",
"to",
"load",
"data",
"with",
"a",
"cache",
"parameter",
"."
] | 1352cafdcbff747bc1f302e709ed376df6642ef5 | https://github.com/GwtMaterialDesign/gwt-material-table/blob/1352cafdcbff747bc1f302e709ed376df6642ef5/src/main/java/gwt/material/design/client/data/infinite/InfiniteDataView.java#L425-L427 |
3,697 | GwtMaterialDesign/gwt-material-table | src/main/java/gwt/material/design/client/data/infinite/InfiniteDataView.java | InfiniteDataView.getVisibleRowCapacity | public int getVisibleRowCapacity() {
int rh = getCalculatedRowHeight();
double visibleHeight = getVisibleHeight();
int rows = (int) ((visibleHeight < 1) ? 0 : Math.floor(visibleHeight / rh));
int calcHeight = rh * rows;
while (calcHeight < visibleHeight) {
rows++;
calcHeight = rh * rows;
}
logger.finest("row height: " + rh + " visibleHeight: " + visibleHeight + " visible rows: "
+ rows + " calcHeight: " + calcHeight);
return rows;
} | java | public int getVisibleRowCapacity() {
int rh = getCalculatedRowHeight();
double visibleHeight = getVisibleHeight();
int rows = (int) ((visibleHeight < 1) ? 0 : Math.floor(visibleHeight / rh));
int calcHeight = rh * rows;
while (calcHeight < visibleHeight) {
rows++;
calcHeight = rh * rows;
}
logger.finest("row height: " + rh + " visibleHeight: " + visibleHeight + " visible rows: "
+ rows + " calcHeight: " + calcHeight);
return rows;
} | [
"public",
"int",
"getVisibleRowCapacity",
"(",
")",
"{",
"int",
"rh",
"=",
"getCalculatedRowHeight",
"(",
")",
";",
"double",
"visibleHeight",
"=",
"getVisibleHeight",
"(",
")",
";",
"int",
"rows",
"=",
"(",
"int",
")",
"(",
"(",
"visibleHeight",
"<",
"1",
")",
"?",
"0",
":",
"Math",
".",
"floor",
"(",
"visibleHeight",
"/",
"rh",
")",
")",
";",
"int",
"calcHeight",
"=",
"rh",
"*",
"rows",
";",
"while",
"(",
"calcHeight",
"<",
"visibleHeight",
")",
"{",
"rows",
"++",
";",
"calcHeight",
"=",
"rh",
"*",
"rows",
";",
"}",
"logger",
".",
"finest",
"(",
"\"row height: \"",
"+",
"rh",
"+",
"\" visibleHeight: \"",
"+",
"visibleHeight",
"+",
"\" visible rows: \"",
"+",
"rows",
"+",
"\" calcHeight: \"",
"+",
"calcHeight",
")",
";",
"return",
"rows",
";",
"}"
] | Returns the total number of rows that are visible given
the current grid height. | [
"Returns",
"the",
"total",
"number",
"of",
"rows",
"that",
"are",
"visible",
"given",
"the",
"current",
"grid",
"height",
"."
] | 1352cafdcbff747bc1f302e709ed376df6642ef5 | https://github.com/GwtMaterialDesign/gwt-material-table/blob/1352cafdcbff747bc1f302e709ed376df6642ef5/src/main/java/gwt/material/design/client/data/infinite/InfiniteDataView.java#L467-L482 |
3,698 | GwtMaterialDesign/gwt-material-table | src/main/java/gwt/material/design/client/ui/table/cell/FrozenProperties.java | FrozenProperties.setHeaderStyleProperty | public FrozenProperties setHeaderStyleProperty(StyleName styleName, String value) {
headerStyleProps.put(styleName, value);
return this;
} | java | public FrozenProperties setHeaderStyleProperty(StyleName styleName, String value) {
headerStyleProps.put(styleName, value);
return this;
} | [
"public",
"FrozenProperties",
"setHeaderStyleProperty",
"(",
"StyleName",
"styleName",
",",
"String",
"value",
")",
"{",
"headerStyleProps",
".",
"put",
"(",
"styleName",
",",
"value",
")",
";",
"return",
"this",
";",
"}"
] | Set a header style property using its name as the key. Please ensure the style name and value
are appropriately configured or it may result in unexpected behavior.
@param styleName the style name as seen here {@link Style#STYLE_Z_INDEX} for example.
@param value the string value required for the given style property. | [
"Set",
"a",
"header",
"style",
"property",
"using",
"its",
"name",
"as",
"the",
"key",
".",
"Please",
"ensure",
"the",
"style",
"name",
"and",
"value",
"are",
"appropriately",
"configured",
"or",
"it",
"may",
"result",
"in",
"unexpected",
"behavior",
"."
] | 1352cafdcbff747bc1f302e709ed376df6642ef5 | https://github.com/GwtMaterialDesign/gwt-material-table/blob/1352cafdcbff747bc1f302e709ed376df6642ef5/src/main/java/gwt/material/design/client/ui/table/cell/FrozenProperties.java#L104-L107 |
3,699 | GwtMaterialDesign/gwt-material-table | src/main/java/gwt/material/design/client/ui/table/CellBasedWidgetImpl.java | CellBasedWidgetImpl.isFocusable | public boolean isFocusable(Element elem) {
return focusableTypes.contains(elem.getTagName().toLowerCase(Locale.ROOT))
|| elem.getTabIndex() >= 0;
} | java | public boolean isFocusable(Element elem) {
return focusableTypes.contains(elem.getTagName().toLowerCase(Locale.ROOT))
|| elem.getTabIndex() >= 0;
} | [
"public",
"boolean",
"isFocusable",
"(",
"Element",
"elem",
")",
"{",
"return",
"focusableTypes",
".",
"contains",
"(",
"elem",
".",
"getTagName",
"(",
")",
".",
"toLowerCase",
"(",
"Locale",
".",
"ROOT",
")",
")",
"||",
"elem",
".",
"getTabIndex",
"(",
")",
">=",
"0",
";",
"}"
] | Check if an element is focusable. If an element is focusable, the cell
widget should not steal focus from it.
@param elem the element
@return true if the element is focusable, false if not | [
"Check",
"if",
"an",
"element",
"is",
"focusable",
".",
"If",
"an",
"element",
"is",
"focusable",
"the",
"cell",
"widget",
"should",
"not",
"steal",
"focus",
"from",
"it",
"."
] | 1352cafdcbff747bc1f302e709ed376df6642ef5 | https://github.com/GwtMaterialDesign/gwt-material-table/blob/1352cafdcbff747bc1f302e709ed376df6642ef5/src/main/java/gwt/material/design/client/ui/table/CellBasedWidgetImpl.java#L94-L97 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.