id
int32 0
165k
| repo
stringlengths 7
58
| path
stringlengths 12
218
| func_name
stringlengths 3
140
| original_string
stringlengths 73
34.1k
| language
stringclasses 1
value | code
stringlengths 73
34.1k
| code_tokens
list | docstring
stringlengths 3
16k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 105
339
|
|---|---|---|---|---|---|---|---|---|---|---|---|
21,900
|
RoaringBitmap/RoaringBitmap
|
roaringbitmap/src/main/java/org/roaringbitmap/RoaringBitmap.java
|
RoaringBitmap.select
|
@Override
public int select(int j) {
long leftover = Util.toUnsignedLong(j);
for (int i = 0; i < this.highLowContainer.size(); i++) {
Container c = this.highLowContainer.getContainerAtIndex(i);
int thiscard = c.getCardinality();
if (thiscard > leftover) {
int keycontrib = this.highLowContainer.getKeyAtIndex(i) << 16;
int lowcontrib = Util.toIntUnsigned(c.select((int)leftover));
return lowcontrib + keycontrib;
}
leftover -= thiscard;
}
throw new IllegalArgumentException("You are trying to select the "
+ j + "th value when the cardinality is "
+ this.getCardinality() + ".");
}
|
java
|
@Override
public int select(int j) {
long leftover = Util.toUnsignedLong(j);
for (int i = 0; i < this.highLowContainer.size(); i++) {
Container c = this.highLowContainer.getContainerAtIndex(i);
int thiscard = c.getCardinality();
if (thiscard > leftover) {
int keycontrib = this.highLowContainer.getKeyAtIndex(i) << 16;
int lowcontrib = Util.toIntUnsigned(c.select((int)leftover));
return lowcontrib + keycontrib;
}
leftover -= thiscard;
}
throw new IllegalArgumentException("You are trying to select the "
+ j + "th value when the cardinality is "
+ this.getCardinality() + ".");
}
|
[
"@",
"Override",
"public",
"int",
"select",
"(",
"int",
"j",
")",
"{",
"long",
"leftover",
"=",
"Util",
".",
"toUnsignedLong",
"(",
"j",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"highLowContainer",
".",
"size",
"(",
")",
";",
"i",
"++",
")",
"{",
"Container",
"c",
"=",
"this",
".",
"highLowContainer",
".",
"getContainerAtIndex",
"(",
"i",
")",
";",
"int",
"thiscard",
"=",
"c",
".",
"getCardinality",
"(",
")",
";",
"if",
"(",
"thiscard",
">",
"leftover",
")",
"{",
"int",
"keycontrib",
"=",
"this",
".",
"highLowContainer",
".",
"getKeyAtIndex",
"(",
"i",
")",
"<<",
"16",
";",
"int",
"lowcontrib",
"=",
"Util",
".",
"toIntUnsigned",
"(",
"c",
".",
"select",
"(",
"(",
"int",
")",
"leftover",
")",
")",
";",
"return",
"lowcontrib",
"+",
"keycontrib",
";",
"}",
"leftover",
"-=",
"thiscard",
";",
"}",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"You are trying to select the \"",
"+",
"j",
"+",
"\"th value when the cardinality is \"",
"+",
"this",
".",
"getCardinality",
"(",
")",
"+",
"\".\"",
")",
";",
"}"
] |
Return the jth value stored in this bitmap. The provided value
needs to be smaller than the cardinality otherwise an
IllegalArgumentException
exception is thrown.
@param j index of the value
@return the value
@see <a href="https://en.wikipedia.org/wiki/Selection_algorithm">Selection algorithm</a>
|
[
"Return",
"the",
"jth",
"value",
"stored",
"in",
"this",
"bitmap",
".",
"The",
"provided",
"value",
"needs",
"to",
"be",
"smaller",
"than",
"the",
"cardinality",
"otherwise",
"an",
"IllegalArgumentException",
"exception",
"is",
"thrown",
"."
] |
b26fd0a1330fd4d2877f4d74feb69ceb812e9efa
|
https://github.com/RoaringBitmap/RoaringBitmap/blob/b26fd0a1330fd4d2877f4d74feb69ceb812e9efa/roaringbitmap/src/main/java/org/roaringbitmap/RoaringBitmap.java#L2326-L2342
|
21,901
|
RoaringBitmap/RoaringBitmap
|
roaringbitmap/src/main/java/org/roaringbitmap/RoaringBitmap.java
|
RoaringBitmap.maximumSerializedSize
|
public static long maximumSerializedSize(long cardinality, long universe_size) {
long contnbr = (universe_size + 65535) / 65536;
if (contnbr > cardinality) {
contnbr = cardinality;
// we can't have more containers than we have values
}
final long headermax = Math.max(8, 4 + (contnbr + 7) / 8) + 8 * contnbr;
final long valsarray = 2 * cardinality;
final long valsbitmap = contnbr * 8192;
final long valsbest = Math.min(valsarray, valsbitmap);
return valsbest + headermax;
}
|
java
|
public static long maximumSerializedSize(long cardinality, long universe_size) {
long contnbr = (universe_size + 65535) / 65536;
if (contnbr > cardinality) {
contnbr = cardinality;
// we can't have more containers than we have values
}
final long headermax = Math.max(8, 4 + (contnbr + 7) / 8) + 8 * contnbr;
final long valsarray = 2 * cardinality;
final long valsbitmap = contnbr * 8192;
final long valsbest = Math.min(valsarray, valsbitmap);
return valsbest + headermax;
}
|
[
"public",
"static",
"long",
"maximumSerializedSize",
"(",
"long",
"cardinality",
",",
"long",
"universe_size",
")",
"{",
"long",
"contnbr",
"=",
"(",
"universe_size",
"+",
"65535",
")",
"/",
"65536",
";",
"if",
"(",
"contnbr",
">",
"cardinality",
")",
"{",
"contnbr",
"=",
"cardinality",
";",
"// we can't have more containers than we have values",
"}",
"final",
"long",
"headermax",
"=",
"Math",
".",
"max",
"(",
"8",
",",
"4",
"+",
"(",
"contnbr",
"+",
"7",
")",
"/",
"8",
")",
"+",
"8",
"*",
"contnbr",
";",
"final",
"long",
"valsarray",
"=",
"2",
"*",
"cardinality",
";",
"final",
"long",
"valsbitmap",
"=",
"contnbr",
"*",
"8192",
";",
"final",
"long",
"valsbest",
"=",
"Math",
".",
"min",
"(",
"valsarray",
",",
"valsbitmap",
")",
";",
"return",
"valsbest",
"+",
"headermax",
";",
"}"
] |
Assume that one wants to store "cardinality" integers in [0, universe_size), this function
returns an upper bound on the serialized size in bytes.
@param cardinality maximal cardinality
@param universe_size maximal value
@return upper bound on the serialized size in bytes of the bitmap
|
[
"Assume",
"that",
"one",
"wants",
"to",
"store",
"cardinality",
"integers",
"in",
"[",
"0",
"universe_size",
")",
"this",
"function",
"returns",
"an",
"upper",
"bound",
"on",
"the",
"serialized",
"size",
"in",
"bytes",
"."
] |
b26fd0a1330fd4d2877f4d74feb69ceb812e9efa
|
https://github.com/RoaringBitmap/RoaringBitmap/blob/b26fd0a1330fd4d2877f4d74feb69ceb812e9efa/roaringbitmap/src/main/java/org/roaringbitmap/RoaringBitmap.java#L2532-L2543
|
21,902
|
RoaringBitmap/RoaringBitmap
|
roaringbitmap/src/main/java/org/roaringbitmap/RoaringBitmap.java
|
RoaringBitmap.selectRangeWithoutCopy
|
private static RoaringBitmap selectRangeWithoutCopy(RoaringBitmap rb, final long rangeStart,
final long rangeEnd) {
final int hbStart = Util.toIntUnsigned(Util.highbits(rangeStart));
final int lbStart = Util.toIntUnsigned(Util.lowbits(rangeStart));
final int hbLast = Util.toIntUnsigned(Util.highbits(rangeEnd - 1));
final int lbLast = Util.toIntUnsigned(Util.lowbits(rangeEnd - 1));
RoaringBitmap answer = new RoaringBitmap();
assert(rangeStart >= 0 && rangeEnd >= 0);
if (rangeEnd <= rangeStart) {
return answer;
}
if (hbStart == hbLast) {
final int i = rb.highLowContainer.getIndex((short) hbStart);
if (i >= 0) {
final Container c = rb.highLowContainer.getContainerAtIndex(i).remove(0, lbStart)
.iremove(lbLast + 1, Util.maxLowBitAsInteger() + 1);
if (!c.isEmpty()) {
answer.highLowContainer.append((short) hbStart, c);
}
}
return answer;
}
int ifirst = rb.highLowContainer.getIndex((short) hbStart);
int ilast = rb.highLowContainer.getIndex((short) hbLast);
if (ifirst >= 0) {
final Container c = rb.highLowContainer.getContainerAtIndex(ifirst).remove(0, lbStart);
if (!c.isEmpty()) {
answer.highLowContainer.append((short) hbStart, c);
}
}
// revised to loop on ints
for (int hb = hbStart + 1; hb <= hbLast - 1; ++hb) {
final int i = rb.highLowContainer.getIndex((short)hb);
final int j = answer.highLowContainer.getIndex((short) hb);
assert j < 0;
if (i >= 0) {
final Container c = rb.highLowContainer.getContainerAtIndex(i);
answer.highLowContainer.insertNewKeyValueAt(-j - 1, (short)hb, c);
}
}
if (ilast >= 0) {
final Container c = rb.highLowContainer.getContainerAtIndex(ilast).remove(lbLast + 1,
Util.maxLowBitAsInteger() + 1);
if (!c.isEmpty()) {
answer.highLowContainer.append((short) hbLast, c);
}
}
return answer;
}
|
java
|
private static RoaringBitmap selectRangeWithoutCopy(RoaringBitmap rb, final long rangeStart,
final long rangeEnd) {
final int hbStart = Util.toIntUnsigned(Util.highbits(rangeStart));
final int lbStart = Util.toIntUnsigned(Util.lowbits(rangeStart));
final int hbLast = Util.toIntUnsigned(Util.highbits(rangeEnd - 1));
final int lbLast = Util.toIntUnsigned(Util.lowbits(rangeEnd - 1));
RoaringBitmap answer = new RoaringBitmap();
assert(rangeStart >= 0 && rangeEnd >= 0);
if (rangeEnd <= rangeStart) {
return answer;
}
if (hbStart == hbLast) {
final int i = rb.highLowContainer.getIndex((short) hbStart);
if (i >= 0) {
final Container c = rb.highLowContainer.getContainerAtIndex(i).remove(0, lbStart)
.iremove(lbLast + 1, Util.maxLowBitAsInteger() + 1);
if (!c.isEmpty()) {
answer.highLowContainer.append((short) hbStart, c);
}
}
return answer;
}
int ifirst = rb.highLowContainer.getIndex((short) hbStart);
int ilast = rb.highLowContainer.getIndex((short) hbLast);
if (ifirst >= 0) {
final Container c = rb.highLowContainer.getContainerAtIndex(ifirst).remove(0, lbStart);
if (!c.isEmpty()) {
answer.highLowContainer.append((short) hbStart, c);
}
}
// revised to loop on ints
for (int hb = hbStart + 1; hb <= hbLast - 1; ++hb) {
final int i = rb.highLowContainer.getIndex((short)hb);
final int j = answer.highLowContainer.getIndex((short) hb);
assert j < 0;
if (i >= 0) {
final Container c = rb.highLowContainer.getContainerAtIndex(i);
answer.highLowContainer.insertNewKeyValueAt(-j - 1, (short)hb, c);
}
}
if (ilast >= 0) {
final Container c = rb.highLowContainer.getContainerAtIndex(ilast).remove(lbLast + 1,
Util.maxLowBitAsInteger() + 1);
if (!c.isEmpty()) {
answer.highLowContainer.append((short) hbLast, c);
}
}
return answer;
}
|
[
"private",
"static",
"RoaringBitmap",
"selectRangeWithoutCopy",
"(",
"RoaringBitmap",
"rb",
",",
"final",
"long",
"rangeStart",
",",
"final",
"long",
"rangeEnd",
")",
"{",
"final",
"int",
"hbStart",
"=",
"Util",
".",
"toIntUnsigned",
"(",
"Util",
".",
"highbits",
"(",
"rangeStart",
")",
")",
";",
"final",
"int",
"lbStart",
"=",
"Util",
".",
"toIntUnsigned",
"(",
"Util",
".",
"lowbits",
"(",
"rangeStart",
")",
")",
";",
"final",
"int",
"hbLast",
"=",
"Util",
".",
"toIntUnsigned",
"(",
"Util",
".",
"highbits",
"(",
"rangeEnd",
"-",
"1",
")",
")",
";",
"final",
"int",
"lbLast",
"=",
"Util",
".",
"toIntUnsigned",
"(",
"Util",
".",
"lowbits",
"(",
"rangeEnd",
"-",
"1",
")",
")",
";",
"RoaringBitmap",
"answer",
"=",
"new",
"RoaringBitmap",
"(",
")",
";",
"assert",
"(",
"rangeStart",
">=",
"0",
"&&",
"rangeEnd",
">=",
"0",
")",
";",
"if",
"(",
"rangeEnd",
"<=",
"rangeStart",
")",
"{",
"return",
"answer",
";",
"}",
"if",
"(",
"hbStart",
"==",
"hbLast",
")",
"{",
"final",
"int",
"i",
"=",
"rb",
".",
"highLowContainer",
".",
"getIndex",
"(",
"(",
"short",
")",
"hbStart",
")",
";",
"if",
"(",
"i",
">=",
"0",
")",
"{",
"final",
"Container",
"c",
"=",
"rb",
".",
"highLowContainer",
".",
"getContainerAtIndex",
"(",
"i",
")",
".",
"remove",
"(",
"0",
",",
"lbStart",
")",
".",
"iremove",
"(",
"lbLast",
"+",
"1",
",",
"Util",
".",
"maxLowBitAsInteger",
"(",
")",
"+",
"1",
")",
";",
"if",
"(",
"!",
"c",
".",
"isEmpty",
"(",
")",
")",
"{",
"answer",
".",
"highLowContainer",
".",
"append",
"(",
"(",
"short",
")",
"hbStart",
",",
"c",
")",
";",
"}",
"}",
"return",
"answer",
";",
"}",
"int",
"ifirst",
"=",
"rb",
".",
"highLowContainer",
".",
"getIndex",
"(",
"(",
"short",
")",
"hbStart",
")",
";",
"int",
"ilast",
"=",
"rb",
".",
"highLowContainer",
".",
"getIndex",
"(",
"(",
"short",
")",
"hbLast",
")",
";",
"if",
"(",
"ifirst",
">=",
"0",
")",
"{",
"final",
"Container",
"c",
"=",
"rb",
".",
"highLowContainer",
".",
"getContainerAtIndex",
"(",
"ifirst",
")",
".",
"remove",
"(",
"0",
",",
"lbStart",
")",
";",
"if",
"(",
"!",
"c",
".",
"isEmpty",
"(",
")",
")",
"{",
"answer",
".",
"highLowContainer",
".",
"append",
"(",
"(",
"short",
")",
"hbStart",
",",
"c",
")",
";",
"}",
"}",
"// revised to loop on ints",
"for",
"(",
"int",
"hb",
"=",
"hbStart",
"+",
"1",
";",
"hb",
"<=",
"hbLast",
"-",
"1",
";",
"++",
"hb",
")",
"{",
"final",
"int",
"i",
"=",
"rb",
".",
"highLowContainer",
".",
"getIndex",
"(",
"(",
"short",
")",
"hb",
")",
";",
"final",
"int",
"j",
"=",
"answer",
".",
"highLowContainer",
".",
"getIndex",
"(",
"(",
"short",
")",
"hb",
")",
";",
"assert",
"j",
"<",
"0",
";",
"if",
"(",
"i",
">=",
"0",
")",
"{",
"final",
"Container",
"c",
"=",
"rb",
".",
"highLowContainer",
".",
"getContainerAtIndex",
"(",
"i",
")",
";",
"answer",
".",
"highLowContainer",
".",
"insertNewKeyValueAt",
"(",
"-",
"j",
"-",
"1",
",",
"(",
"short",
")",
"hb",
",",
"c",
")",
";",
"}",
"}",
"if",
"(",
"ilast",
">=",
"0",
")",
"{",
"final",
"Container",
"c",
"=",
"rb",
".",
"highLowContainer",
".",
"getContainerAtIndex",
"(",
"ilast",
")",
".",
"remove",
"(",
"lbLast",
"+",
"1",
",",
"Util",
".",
"maxLowBitAsInteger",
"(",
")",
"+",
"1",
")",
";",
"if",
"(",
"!",
"c",
".",
"isEmpty",
"(",
")",
")",
"{",
"answer",
".",
"highLowContainer",
".",
"append",
"(",
"(",
"short",
")",
"hbLast",
",",
"c",
")",
";",
"}",
"}",
"return",
"answer",
";",
"}"
] |
had formerly failed if rangeEnd==0
|
[
"had",
"formerly",
"failed",
"if",
"rangeEnd",
"==",
"0"
] |
b26fd0a1330fd4d2877f4d74feb69ceb812e9efa
|
https://github.com/RoaringBitmap/RoaringBitmap/blob/b26fd0a1330fd4d2877f4d74feb69ceb812e9efa/roaringbitmap/src/main/java/org/roaringbitmap/RoaringBitmap.java#L2602-L2656
|
21,903
|
RoaringBitmap/RoaringBitmap
|
roaringbitmap/src/main/java/org/roaringbitmap/RoaringBitmap.java
|
RoaringBitmap.toArray
|
@Override
public int[] toArray() {
final int[] array = new int[this.getCardinality()];
int pos = 0, pos2 = 0;
while (pos < this.highLowContainer.size()) {
final int hs = this.highLowContainer.getKeyAtIndex(pos) << 16;
Container c = this.highLowContainer.getContainerAtIndex(pos++);
c.fillLeastSignificant16bits(array, pos2, hs);
pos2 += c.getCardinality();
}
return array;
}
|
java
|
@Override
public int[] toArray() {
final int[] array = new int[this.getCardinality()];
int pos = 0, pos2 = 0;
while (pos < this.highLowContainer.size()) {
final int hs = this.highLowContainer.getKeyAtIndex(pos) << 16;
Container c = this.highLowContainer.getContainerAtIndex(pos++);
c.fillLeastSignificant16bits(array, pos2, hs);
pos2 += c.getCardinality();
}
return array;
}
|
[
"@",
"Override",
"public",
"int",
"[",
"]",
"toArray",
"(",
")",
"{",
"final",
"int",
"[",
"]",
"array",
"=",
"new",
"int",
"[",
"this",
".",
"getCardinality",
"(",
")",
"]",
";",
"int",
"pos",
"=",
"0",
",",
"pos2",
"=",
"0",
";",
"while",
"(",
"pos",
"<",
"this",
".",
"highLowContainer",
".",
"size",
"(",
")",
")",
"{",
"final",
"int",
"hs",
"=",
"this",
".",
"highLowContainer",
".",
"getKeyAtIndex",
"(",
"pos",
")",
"<<",
"16",
";",
"Container",
"c",
"=",
"this",
".",
"highLowContainer",
".",
"getContainerAtIndex",
"(",
"pos",
"++",
")",
";",
"c",
".",
"fillLeastSignificant16bits",
"(",
"array",
",",
"pos2",
",",
"hs",
")",
";",
"pos2",
"+=",
"c",
".",
"getCardinality",
"(",
")",
";",
"}",
"return",
"array",
";",
"}"
] |
Return the set values as an array, if the cardinality is smaller than 2147483648.
The integer values are in sorted order.
@return array representing the set values.
|
[
"Return",
"the",
"set",
"values",
"as",
"an",
"array",
"if",
"the",
"cardinality",
"is",
"smaller",
"than",
"2147483648",
".",
"The",
"integer",
"values",
"are",
"in",
"sorted",
"order",
"."
] |
b26fd0a1330fd4d2877f4d74feb69ceb812e9efa
|
https://github.com/RoaringBitmap/RoaringBitmap/blob/b26fd0a1330fd4d2877f4d74feb69ceb812e9efa/roaringbitmap/src/main/java/org/roaringbitmap/RoaringBitmap.java#L2665-L2676
|
21,904
|
RoaringBitmap/RoaringBitmap
|
roaringbitmap/src/main/java/org/roaringbitmap/buffer/BufferFastAggregation.java
|
BufferFastAggregation.convertToImmutable
|
public static Iterator<ImmutableRoaringBitmap> convertToImmutable(
final Iterator<MutableRoaringBitmap> i) {
return new Iterator<ImmutableRoaringBitmap>() {
@Override
public boolean hasNext() {
return i.hasNext();
}
@Override
public ImmutableRoaringBitmap next() {
return i.next();
}
@Override
public void remove() {};
};
}
|
java
|
public static Iterator<ImmutableRoaringBitmap> convertToImmutable(
final Iterator<MutableRoaringBitmap> i) {
return new Iterator<ImmutableRoaringBitmap>() {
@Override
public boolean hasNext() {
return i.hasNext();
}
@Override
public ImmutableRoaringBitmap next() {
return i.next();
}
@Override
public void remove() {};
};
}
|
[
"public",
"static",
"Iterator",
"<",
"ImmutableRoaringBitmap",
">",
"convertToImmutable",
"(",
"final",
"Iterator",
"<",
"MutableRoaringBitmap",
">",
"i",
")",
"{",
"return",
"new",
"Iterator",
"<",
"ImmutableRoaringBitmap",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"boolean",
"hasNext",
"(",
")",
"{",
"return",
"i",
".",
"hasNext",
"(",
")",
";",
"}",
"@",
"Override",
"public",
"ImmutableRoaringBitmap",
"next",
"(",
")",
"{",
"return",
"i",
".",
"next",
"(",
")",
";",
"}",
"@",
"Override",
"public",
"void",
"remove",
"(",
")",
"{",
"}",
";",
"}",
";",
"}"
] |
Convenience method converting one type of iterator into another, to avoid unnecessary warnings.
@param i input bitmaps
@return an iterator over the provided iterator, with a different type
|
[
"Convenience",
"method",
"converting",
"one",
"type",
"of",
"iterator",
"into",
"another",
"to",
"avoid",
"unnecessary",
"warnings",
"."
] |
b26fd0a1330fd4d2877f4d74feb69ceb812e9efa
|
https://github.com/RoaringBitmap/RoaringBitmap/blob/b26fd0a1330fd4d2877f4d74feb69ceb812e9efa/roaringbitmap/src/main/java/org/roaringbitmap/buffer/BufferFastAggregation.java#L68-L87
|
21,905
|
authorjapps/zerocode
|
core/src/main/java/org/jsmart/zerocode/core/httpclient/BasicHttpClient.java
|
BasicHttpClient.execute
|
public Response execute(String httpUrl,
String methodName,
Map<String, Object> headers,
Map<String, Object> queryParams,
Object body) throws Exception {
httpclient = createHttpClient();
// ---------------------------
// Handle request body content
// ---------------------------
String reqBodyAsString = handleRequestBody(body);
// -----------------------------------
// Handle the url and query parameters
// -----------------------------------
httpUrl = handleUrlAndQueryParams(httpUrl, queryParams);
RequestBuilder requestBuilder = createRequestBuilder(httpUrl, methodName, headers, reqBodyAsString);
// ------------------
// Handle the headers
// ------------------
handleHeaders(headers, requestBuilder);
// ------------------
// Handle cookies
// ------------------
addCookieToHeader(requestBuilder);
CloseableHttpResponse httpResponse = httpclient.execute(requestBuilder.build());
// --------------------
// Handle the response
// --------------------
return handleResponse(httpResponse);
}
|
java
|
public Response execute(String httpUrl,
String methodName,
Map<String, Object> headers,
Map<String, Object> queryParams,
Object body) throws Exception {
httpclient = createHttpClient();
// ---------------------------
// Handle request body content
// ---------------------------
String reqBodyAsString = handleRequestBody(body);
// -----------------------------------
// Handle the url and query parameters
// -----------------------------------
httpUrl = handleUrlAndQueryParams(httpUrl, queryParams);
RequestBuilder requestBuilder = createRequestBuilder(httpUrl, methodName, headers, reqBodyAsString);
// ------------------
// Handle the headers
// ------------------
handleHeaders(headers, requestBuilder);
// ------------------
// Handle cookies
// ------------------
addCookieToHeader(requestBuilder);
CloseableHttpResponse httpResponse = httpclient.execute(requestBuilder.build());
// --------------------
// Handle the response
// --------------------
return handleResponse(httpResponse);
}
|
[
"public",
"Response",
"execute",
"(",
"String",
"httpUrl",
",",
"String",
"methodName",
",",
"Map",
"<",
"String",
",",
"Object",
">",
"headers",
",",
"Map",
"<",
"String",
",",
"Object",
">",
"queryParams",
",",
"Object",
"body",
")",
"throws",
"Exception",
"{",
"httpclient",
"=",
"createHttpClient",
"(",
")",
";",
"// ---------------------------",
"// Handle request body content",
"// ---------------------------",
"String",
"reqBodyAsString",
"=",
"handleRequestBody",
"(",
"body",
")",
";",
"// -----------------------------------",
"// Handle the url and query parameters",
"// -----------------------------------",
"httpUrl",
"=",
"handleUrlAndQueryParams",
"(",
"httpUrl",
",",
"queryParams",
")",
";",
"RequestBuilder",
"requestBuilder",
"=",
"createRequestBuilder",
"(",
"httpUrl",
",",
"methodName",
",",
"headers",
",",
"reqBodyAsString",
")",
";",
"// ------------------",
"// Handle the headers",
"// ------------------",
"handleHeaders",
"(",
"headers",
",",
"requestBuilder",
")",
";",
"// ------------------",
"// Handle cookies",
"// ------------------",
"addCookieToHeader",
"(",
"requestBuilder",
")",
";",
"CloseableHttpResponse",
"httpResponse",
"=",
"httpclient",
".",
"execute",
"(",
"requestBuilder",
".",
"build",
"(",
")",
")",
";",
"// --------------------",
"// Handle the response",
"// --------------------",
"return",
"handleResponse",
"(",
"httpResponse",
")",
";",
"}"
] |
Override this method in case you want to execute the http call differently via your http client.
Otherwise the framework falls back to this implementation by default.
@param httpUrl : path to end point
@param methodName : e.g. GET, PUT etc
@param headers : headers, cookies etc
@param queryParams : key-value query params after the ? in the url
@param body : json body
@return : Http response consists of status code, entity, headers, cookies etc
@throws Exception
|
[
"Override",
"this",
"method",
"in",
"case",
"you",
"want",
"to",
"execute",
"the",
"http",
"call",
"differently",
"via",
"your",
"http",
"client",
".",
"Otherwise",
"the",
"framework",
"falls",
"back",
"to",
"this",
"implementation",
"by",
"default",
"."
] |
d66a3e8778d2eb5e4f0006bfcccfc0922ceb7cef
|
https://github.com/authorjapps/zerocode/blob/d66a3e8778d2eb5e4f0006bfcccfc0922ceb7cef/core/src/main/java/org/jsmart/zerocode/core/httpclient/BasicHttpClient.java#L108-L144
|
21,906
|
authorjapps/zerocode
|
core/src/main/java/org/jsmart/zerocode/core/httpclient/BasicHttpClient.java
|
BasicHttpClient.handleResponse
|
public Response handleResponse(CloseableHttpResponse httpResponse) throws IOException {
Response serverResponse = createCharsetResponse(httpResponse);
Header[] allHeaders = httpResponse.getAllHeaders();
Response.ResponseBuilder responseBuilder = Response.fromResponse(serverResponse);
for (Header thisHeader : allHeaders) {
String headerKey = thisHeader.getName();
responseBuilder = responseBuilder.header(headerKey, thisHeader.getValue());
handleHttpSession(serverResponse, headerKey);
}
return responseBuilder.build();
}
|
java
|
public Response handleResponse(CloseableHttpResponse httpResponse) throws IOException {
Response serverResponse = createCharsetResponse(httpResponse);
Header[] allHeaders = httpResponse.getAllHeaders();
Response.ResponseBuilder responseBuilder = Response.fromResponse(serverResponse);
for (Header thisHeader : allHeaders) {
String headerKey = thisHeader.getName();
responseBuilder = responseBuilder.header(headerKey, thisHeader.getValue());
handleHttpSession(serverResponse, headerKey);
}
return responseBuilder.build();
}
|
[
"public",
"Response",
"handleResponse",
"(",
"CloseableHttpResponse",
"httpResponse",
")",
"throws",
"IOException",
"{",
"Response",
"serverResponse",
"=",
"createCharsetResponse",
"(",
"httpResponse",
")",
";",
"Header",
"[",
"]",
"allHeaders",
"=",
"httpResponse",
".",
"getAllHeaders",
"(",
")",
";",
"Response",
".",
"ResponseBuilder",
"responseBuilder",
"=",
"Response",
".",
"fromResponse",
"(",
"serverResponse",
")",
";",
"for",
"(",
"Header",
"thisHeader",
":",
"allHeaders",
")",
"{",
"String",
"headerKey",
"=",
"thisHeader",
".",
"getName",
"(",
")",
";",
"responseBuilder",
"=",
"responseBuilder",
".",
"header",
"(",
"headerKey",
",",
"thisHeader",
".",
"getValue",
"(",
")",
")",
";",
"handleHttpSession",
"(",
"serverResponse",
",",
"headerKey",
")",
";",
"}",
"return",
"responseBuilder",
".",
"build",
"(",
")",
";",
"}"
] |
Once the client executes the http call, then it receives the http response. This method takes care of handling
that. In case you need to handle it differently you can override this method.
@param httpResponse : Received Apache http response from the server
@return : Effective response with handled http session.
@throws IOException
|
[
"Once",
"the",
"client",
"executes",
"the",
"http",
"call",
"then",
"it",
"receives",
"the",
"http",
"response",
".",
"This",
"method",
"takes",
"care",
"of",
"handling",
"that",
".",
"In",
"case",
"you",
"need",
"to",
"handle",
"it",
"differently",
"you",
"can",
"override",
"this",
"method",
"."
] |
d66a3e8778d2eb5e4f0006bfcccfc0922ceb7cef
|
https://github.com/authorjapps/zerocode/blob/d66a3e8778d2eb5e4f0006bfcccfc0922ceb7cef/core/src/main/java/org/jsmart/zerocode/core/httpclient/BasicHttpClient.java#L155-L168
|
21,907
|
authorjapps/zerocode
|
core/src/main/java/org/jsmart/zerocode/core/httpclient/BasicHttpClient.java
|
BasicHttpClient.createDefaultRequestBuilder
|
public RequestBuilder createDefaultRequestBuilder(String httpUrl, String methodName, String reqBodyAsString) {
RequestBuilder requestBuilder = RequestBuilder
.create(methodName)
.setUri(httpUrl);
if (reqBodyAsString != null) {
HttpEntity httpEntity = EntityBuilder.create()
.setContentType(APPLICATION_JSON)
.setText(reqBodyAsString)
.build();
requestBuilder.setEntity(httpEntity);
}
return requestBuilder;
}
|
java
|
public RequestBuilder createDefaultRequestBuilder(String httpUrl, String methodName, String reqBodyAsString) {
RequestBuilder requestBuilder = RequestBuilder
.create(methodName)
.setUri(httpUrl);
if (reqBodyAsString != null) {
HttpEntity httpEntity = EntityBuilder.create()
.setContentType(APPLICATION_JSON)
.setText(reqBodyAsString)
.build();
requestBuilder.setEntity(httpEntity);
}
return requestBuilder;
}
|
[
"public",
"RequestBuilder",
"createDefaultRequestBuilder",
"(",
"String",
"httpUrl",
",",
"String",
"methodName",
",",
"String",
"reqBodyAsString",
")",
"{",
"RequestBuilder",
"requestBuilder",
"=",
"RequestBuilder",
".",
"create",
"(",
"methodName",
")",
".",
"setUri",
"(",
"httpUrl",
")",
";",
"if",
"(",
"reqBodyAsString",
"!=",
"null",
")",
"{",
"HttpEntity",
"httpEntity",
"=",
"EntityBuilder",
".",
"create",
"(",
")",
".",
"setContentType",
"(",
"APPLICATION_JSON",
")",
".",
"setText",
"(",
"reqBodyAsString",
")",
".",
"build",
"(",
")",
";",
"requestBuilder",
".",
"setEntity",
"(",
"httpEntity",
")",
";",
"}",
"return",
"requestBuilder",
";",
"}"
] |
This is the usual http request builder most widely used using Apache Http Client. In case you want to build
or prepare the requests differently, you can override this method.
Please see the following request builder to handle file uploads.
- BasicHttpClient#createFileUploadRequestBuilder(java.lang.String, java.lang.String, java.lang.String)
You can override this method via @UseHttpClient(YourCustomHttpClient.class)
@param httpUrl
@param methodName
@param reqBodyAsString
@return
|
[
"This",
"is",
"the",
"usual",
"http",
"request",
"builder",
"most",
"widely",
"used",
"using",
"Apache",
"Http",
"Client",
".",
"In",
"case",
"you",
"want",
"to",
"build",
"or",
"prepare",
"the",
"requests",
"differently",
"you",
"can",
"override",
"this",
"method",
"."
] |
d66a3e8778d2eb5e4f0006bfcccfc0922ceb7cef
|
https://github.com/authorjapps/zerocode/blob/d66a3e8778d2eb5e4f0006bfcccfc0922ceb7cef/core/src/main/java/org/jsmart/zerocode/core/httpclient/BasicHttpClient.java#L279-L292
|
21,908
|
authorjapps/zerocode
|
core/src/main/java/org/jsmart/zerocode/core/httpclient/BasicHttpClient.java
|
BasicHttpClient.createFileUploadRequestBuilder
|
public RequestBuilder createFileUploadRequestBuilder(String httpUrl, String methodName, String reqBodyAsString) throws IOException {
Map<String, Object> fileFieldNameValueMap = getFileFieldNameValue(reqBodyAsString);
List<String> fileFieldsList = (List<String>) fileFieldNameValueMap.get(FILES_FIELD);
MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder.create();
/*
* Allow fileFieldsList to be null.
* fileFieldsList can be null if multipart/form-data is sent without any files
* Refer Issue #168 - Raised and fixed by santhoshTpixler
*/
if(fileFieldsList != null) {
buildAllFilesToUpload(fileFieldsList, multipartEntityBuilder);
}
buildOtherRequestParams(fileFieldNameValueMap, multipartEntityBuilder);
buildMultiPartBoundary(fileFieldNameValueMap, multipartEntityBuilder);
return createUploadRequestBuilder(httpUrl, methodName, multipartEntityBuilder);
}
|
java
|
public RequestBuilder createFileUploadRequestBuilder(String httpUrl, String methodName, String reqBodyAsString) throws IOException {
Map<String, Object> fileFieldNameValueMap = getFileFieldNameValue(reqBodyAsString);
List<String> fileFieldsList = (List<String>) fileFieldNameValueMap.get(FILES_FIELD);
MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder.create();
/*
* Allow fileFieldsList to be null.
* fileFieldsList can be null if multipart/form-data is sent without any files
* Refer Issue #168 - Raised and fixed by santhoshTpixler
*/
if(fileFieldsList != null) {
buildAllFilesToUpload(fileFieldsList, multipartEntityBuilder);
}
buildOtherRequestParams(fileFieldNameValueMap, multipartEntityBuilder);
buildMultiPartBoundary(fileFieldNameValueMap, multipartEntityBuilder);
return createUploadRequestBuilder(httpUrl, methodName, multipartEntityBuilder);
}
|
[
"public",
"RequestBuilder",
"createFileUploadRequestBuilder",
"(",
"String",
"httpUrl",
",",
"String",
"methodName",
",",
"String",
"reqBodyAsString",
")",
"throws",
"IOException",
"{",
"Map",
"<",
"String",
",",
"Object",
">",
"fileFieldNameValueMap",
"=",
"getFileFieldNameValue",
"(",
"reqBodyAsString",
")",
";",
"List",
"<",
"String",
">",
"fileFieldsList",
"=",
"(",
"List",
"<",
"String",
">",
")",
"fileFieldNameValueMap",
".",
"get",
"(",
"FILES_FIELD",
")",
";",
"MultipartEntityBuilder",
"multipartEntityBuilder",
"=",
"MultipartEntityBuilder",
".",
"create",
"(",
")",
";",
"/*\n\t * Allow fileFieldsList to be null.\n\t * fileFieldsList can be null if multipart/form-data is sent without any files\n\t * Refer Issue #168 - Raised and fixed by santhoshTpixler\n\t */",
"if",
"(",
"fileFieldsList",
"!=",
"null",
")",
"{",
"buildAllFilesToUpload",
"(",
"fileFieldsList",
",",
"multipartEntityBuilder",
")",
";",
"}",
"buildOtherRequestParams",
"(",
"fileFieldNameValueMap",
",",
"multipartEntityBuilder",
")",
";",
"buildMultiPartBoundary",
"(",
"fileFieldNameValueMap",
",",
"multipartEntityBuilder",
")",
";",
"return",
"createUploadRequestBuilder",
"(",
"httpUrl",
",",
"methodName",
",",
"multipartEntityBuilder",
")",
";",
"}"
] |
This is the http request builder for file uploads, using Apache Http Client. In case you want to build
or prepare the requests differently, you can override this method.
Note-
With file uploads you can send more headers too from the testcase to the server, except "Content-Type" because
this is reserved for "multipart/form-data" which the client sends to server during the file uploads. You can
also send more request-params and "boundary" from the test cases if needed. The boundary defaults to an unique
string of local-date-time-stamp if not provided in the request.
You can override this method via @UseHttpClient(YourCustomHttpClient.class)
@param httpUrl
@param methodName
@param reqBodyAsString
@return
@throws IOException
|
[
"This",
"is",
"the",
"http",
"request",
"builder",
"for",
"file",
"uploads",
"using",
"Apache",
"Http",
"Client",
".",
"In",
"case",
"you",
"want",
"to",
"build",
"or",
"prepare",
"the",
"requests",
"differently",
"you",
"can",
"override",
"this",
"method",
"."
] |
d66a3e8778d2eb5e4f0006bfcccfc0922ceb7cef
|
https://github.com/authorjapps/zerocode/blob/d66a3e8778d2eb5e4f0006bfcccfc0922ceb7cef/core/src/main/java/org/jsmart/zerocode/core/httpclient/BasicHttpClient.java#L340-L361
|
21,909
|
authorjapps/zerocode
|
core/src/main/java/org/jsmart/zerocode/core/httpclient/BasicHttpClient.java
|
BasicHttpClient.handleHttpSession
|
public void handleHttpSession(Response serverResponse, String headerKey) {
/** ---------------
* Session handled
* ----------------
*/
if ("Set-Cookie".equals(headerKey)) {
COOKIE_JSESSIONID_VALUE = serverResponse.getMetadata().get(headerKey);
}
}
|
java
|
public void handleHttpSession(Response serverResponse, String headerKey) {
/** ---------------
* Session handled
* ----------------
*/
if ("Set-Cookie".equals(headerKey)) {
COOKIE_JSESSIONID_VALUE = serverResponse.getMetadata().get(headerKey);
}
}
|
[
"public",
"void",
"handleHttpSession",
"(",
"Response",
"serverResponse",
",",
"String",
"headerKey",
")",
"{",
"/** ---------------\n * Session handled\n * ----------------\n */",
"if",
"(",
"\"Set-Cookie\"",
".",
"equals",
"(",
"headerKey",
")",
")",
"{",
"COOKIE_JSESSIONID_VALUE",
"=",
"serverResponse",
".",
"getMetadata",
"(",
")",
".",
"get",
"(",
"headerKey",
")",
";",
"}",
"}"
] |
This method handles the http session to be maintained between the calls.
In case the session is not needed or to be handled differently, then this
method can be overridden to do nothing or to roll your own feature.
@param serverResponse
@param headerKey
|
[
"This",
"method",
"handles",
"the",
"http",
"session",
"to",
"be",
"maintained",
"between",
"the",
"calls",
".",
"In",
"case",
"the",
"session",
"is",
"not",
"needed",
"or",
"to",
"be",
"handled",
"differently",
"then",
"this",
"method",
"can",
"be",
"overridden",
"to",
"do",
"nothing",
"or",
"to",
"roll",
"your",
"own",
"feature",
"."
] |
d66a3e8778d2eb5e4f0006bfcccfc0922ceb7cef
|
https://github.com/authorjapps/zerocode/blob/d66a3e8778d2eb5e4f0006bfcccfc0922ceb7cef/core/src/main/java/org/jsmart/zerocode/core/httpclient/BasicHttpClient.java#L371-L379
|
21,910
|
authorjapps/zerocode
|
core/src/main/java/org/jsmart/zerocode/core/engine/preprocessor/ZeroCodeExternalFileProcessorImpl.java
|
ZeroCodeExternalFileProcessorImpl.digReplaceContent
|
void digReplaceContent(Map<String, Object> map) {
map.entrySet().stream().forEach(entry -> {
Object value = entry.getValue();
if (value instanceof Map) {
digReplaceContent((Map<String, Object>) value);
} else {
LOGGER.debug("Leaf node found = {}, checking for any external json file...", value);
if (value != null && value.toString().contains(JSON_PAYLOAD_FILE)) {
LOGGER.info("Found external JSON file place holder = {}. Replacing with content", value);
String valueString = value.toString();
String token = getJsonFilePhToken(valueString);
if (token != null && token.startsWith(JSON_PAYLOAD_FILE)) {
String resourceJsonFile = token.substring(JSON_PAYLOAD_FILE.length());
try {
Object jsonFileContent = objectMapper.readTree(readJsonAsString(resourceJsonFile));
entry.setValue(jsonFileContent);
} catch (Exception exx) {
LOGGER.error("External file reference exception - {}", exx.getMessage());
throw new RuntimeException(exx);
}
}
// ----------------------------------------------------
// Extension- for XML file type in case a ticket raised
// ----------------------------------------------------
/*
else if (token != null && token.startsWith(XML_FILE)) {
}
*/
// ---------------------------------------------------
// Extension- for Other types in case a ticket raised
// ---------------------------------------------------
/*
else if (token != null && token.startsWith(OTHER_FILE)) {
}
*/
}
}
});
}
|
java
|
void digReplaceContent(Map<String, Object> map) {
map.entrySet().stream().forEach(entry -> {
Object value = entry.getValue();
if (value instanceof Map) {
digReplaceContent((Map<String, Object>) value);
} else {
LOGGER.debug("Leaf node found = {}, checking for any external json file...", value);
if (value != null && value.toString().contains(JSON_PAYLOAD_FILE)) {
LOGGER.info("Found external JSON file place holder = {}. Replacing with content", value);
String valueString = value.toString();
String token = getJsonFilePhToken(valueString);
if (token != null && token.startsWith(JSON_PAYLOAD_FILE)) {
String resourceJsonFile = token.substring(JSON_PAYLOAD_FILE.length());
try {
Object jsonFileContent = objectMapper.readTree(readJsonAsString(resourceJsonFile));
entry.setValue(jsonFileContent);
} catch (Exception exx) {
LOGGER.error("External file reference exception - {}", exx.getMessage());
throw new RuntimeException(exx);
}
}
// ----------------------------------------------------
// Extension- for XML file type in case a ticket raised
// ----------------------------------------------------
/*
else if (token != null && token.startsWith(XML_FILE)) {
}
*/
// ---------------------------------------------------
// Extension- for Other types in case a ticket raised
// ---------------------------------------------------
/*
else if (token != null && token.startsWith(OTHER_FILE)) {
}
*/
}
}
});
}
|
[
"void",
"digReplaceContent",
"(",
"Map",
"<",
"String",
",",
"Object",
">",
"map",
")",
"{",
"map",
".",
"entrySet",
"(",
")",
".",
"stream",
"(",
")",
".",
"forEach",
"(",
"entry",
"->",
"{",
"Object",
"value",
"=",
"entry",
".",
"getValue",
"(",
")",
";",
"if",
"(",
"value",
"instanceof",
"Map",
")",
"{",
"digReplaceContent",
"(",
"(",
"Map",
"<",
"String",
",",
"Object",
">",
")",
"value",
")",
";",
"}",
"else",
"{",
"LOGGER",
".",
"debug",
"(",
"\"Leaf node found = {}, checking for any external json file...\"",
",",
"value",
")",
";",
"if",
"(",
"value",
"!=",
"null",
"&&",
"value",
".",
"toString",
"(",
")",
".",
"contains",
"(",
"JSON_PAYLOAD_FILE",
")",
")",
"{",
"LOGGER",
".",
"info",
"(",
"\"Found external JSON file place holder = {}. Replacing with content\"",
",",
"value",
")",
";",
"String",
"valueString",
"=",
"value",
".",
"toString",
"(",
")",
";",
"String",
"token",
"=",
"getJsonFilePhToken",
"(",
"valueString",
")",
";",
"if",
"(",
"token",
"!=",
"null",
"&&",
"token",
".",
"startsWith",
"(",
"JSON_PAYLOAD_FILE",
")",
")",
"{",
"String",
"resourceJsonFile",
"=",
"token",
".",
"substring",
"(",
"JSON_PAYLOAD_FILE",
".",
"length",
"(",
")",
")",
";",
"try",
"{",
"Object",
"jsonFileContent",
"=",
"objectMapper",
".",
"readTree",
"(",
"readJsonAsString",
"(",
"resourceJsonFile",
")",
")",
";",
"entry",
".",
"setValue",
"(",
"jsonFileContent",
")",
";",
"}",
"catch",
"(",
"Exception",
"exx",
")",
"{",
"LOGGER",
".",
"error",
"(",
"\"External file reference exception - {}\"",
",",
"exx",
".",
"getMessage",
"(",
")",
")",
";",
"throw",
"new",
"RuntimeException",
"(",
"exx",
")",
";",
"}",
"}",
"// ----------------------------------------------------",
"// Extension- for XML file type in case a ticket raised",
"// ----------------------------------------------------",
"/*\n else if (token != null && token.startsWith(XML_FILE)) {\n\n }\n */",
"// ---------------------------------------------------",
"// Extension- for Other types in case a ticket raised",
"// ---------------------------------------------------",
"/*\n else if (token != null && token.startsWith(OTHER_FILE)) {\n\n }\n */",
"}",
"}",
"}",
")",
";",
"}"
] |
Digs deep into the nested map and looks for external file reference,if found, replaces the place holder with
the file content. This is handy when the engineers wants to drive the common contents from a central place.
@param map A map representing the key-value pairs, can be nested
|
[
"Digs",
"deep",
"into",
"the",
"nested",
"map",
"and",
"looks",
"for",
"external",
"file",
"reference",
"if",
"found",
"replaces",
"the",
"place",
"holder",
"with",
"the",
"file",
"content",
".",
"This",
"is",
"handy",
"when",
"the",
"engineers",
"wants",
"to",
"drive",
"the",
"common",
"contents",
"from",
"a",
"central",
"place",
"."
] |
d66a3e8778d2eb5e4f0006bfcccfc0922ceb7cef
|
https://github.com/authorjapps/zerocode/blob/d66a3e8778d2eb5e4f0006bfcccfc0922ceb7cef/core/src/main/java/org/jsmart/zerocode/core/engine/preprocessor/ZeroCodeExternalFileProcessorImpl.java#L113-L159
|
21,911
|
authorjapps/zerocode
|
core/src/main/java/org/jsmart/zerocode/core/runner/ZeroCodePackageRunner.java
|
ZeroCodePackageRunner.getChildren
|
@Override
protected List<ScenarioSpec> getChildren() {
TestPackageRoot rootPackageAnnotation = testClass.getAnnotation(TestPackageRoot.class);
JsonTestCases jsonTestCasesAnnotation = testClass.getAnnotation(JsonTestCases.class);
validateSuiteAnnotationPresent(rootPackageAnnotation, jsonTestCasesAnnotation);
if (rootPackageAnnotation != null) {
/*
* Different scenarios with same name -or- Same scenarios with same name more than once is prevented
*/
smartUtils.checkDuplicateScenarios(rootPackageAnnotation.value());
return smartUtils.getScenarioSpecListByPackage(rootPackageAnnotation.value());
} else {
List<JsonTestCase> jsonTestCases = Arrays.asList(testClass.getAnnotationsByType(JsonTestCase.class));
List<String> allEndPointFiles = jsonTestCases.stream()
.map(thisTestCase -> thisTestCase.value())
.collect(Collectors.toList());
return allEndPointFiles.stream()
.map(testResource -> {
try {
return smartUtils.jsonFileToJava(testResource, ScenarioSpec.class);
} catch (IOException e) {
throw new RuntimeException("Exception while deserializing to Spec. Details: " + e);
}
})
.collect(Collectors.toList());
}
}
|
java
|
@Override
protected List<ScenarioSpec> getChildren() {
TestPackageRoot rootPackageAnnotation = testClass.getAnnotation(TestPackageRoot.class);
JsonTestCases jsonTestCasesAnnotation = testClass.getAnnotation(JsonTestCases.class);
validateSuiteAnnotationPresent(rootPackageAnnotation, jsonTestCasesAnnotation);
if (rootPackageAnnotation != null) {
/*
* Different scenarios with same name -or- Same scenarios with same name more than once is prevented
*/
smartUtils.checkDuplicateScenarios(rootPackageAnnotation.value());
return smartUtils.getScenarioSpecListByPackage(rootPackageAnnotation.value());
} else {
List<JsonTestCase> jsonTestCases = Arrays.asList(testClass.getAnnotationsByType(JsonTestCase.class));
List<String> allEndPointFiles = jsonTestCases.stream()
.map(thisTestCase -> thisTestCase.value())
.collect(Collectors.toList());
return allEndPointFiles.stream()
.map(testResource -> {
try {
return smartUtils.jsonFileToJava(testResource, ScenarioSpec.class);
} catch (IOException e) {
throw new RuntimeException("Exception while deserializing to Spec. Details: " + e);
}
})
.collect(Collectors.toList());
}
}
|
[
"@",
"Override",
"protected",
"List",
"<",
"ScenarioSpec",
">",
"getChildren",
"(",
")",
"{",
"TestPackageRoot",
"rootPackageAnnotation",
"=",
"testClass",
".",
"getAnnotation",
"(",
"TestPackageRoot",
".",
"class",
")",
";",
"JsonTestCases",
"jsonTestCasesAnnotation",
"=",
"testClass",
".",
"getAnnotation",
"(",
"JsonTestCases",
".",
"class",
")",
";",
"validateSuiteAnnotationPresent",
"(",
"rootPackageAnnotation",
",",
"jsonTestCasesAnnotation",
")",
";",
"if",
"(",
"rootPackageAnnotation",
"!=",
"null",
")",
"{",
"/*\n * Different scenarios with same name -or- Same scenarios with same name more than once is prevented\n */",
"smartUtils",
".",
"checkDuplicateScenarios",
"(",
"rootPackageAnnotation",
".",
"value",
"(",
")",
")",
";",
"return",
"smartUtils",
".",
"getScenarioSpecListByPackage",
"(",
"rootPackageAnnotation",
".",
"value",
"(",
")",
")",
";",
"}",
"else",
"{",
"List",
"<",
"JsonTestCase",
">",
"jsonTestCases",
"=",
"Arrays",
".",
"asList",
"(",
"testClass",
".",
"getAnnotationsByType",
"(",
"JsonTestCase",
".",
"class",
")",
")",
";",
"List",
"<",
"String",
">",
"allEndPointFiles",
"=",
"jsonTestCases",
".",
"stream",
"(",
")",
".",
"map",
"(",
"thisTestCase",
"->",
"thisTestCase",
".",
"value",
"(",
")",
")",
".",
"collect",
"(",
"Collectors",
".",
"toList",
"(",
")",
")",
";",
"return",
"allEndPointFiles",
".",
"stream",
"(",
")",
".",
"map",
"(",
"testResource",
"->",
"{",
"try",
"{",
"return",
"smartUtils",
".",
"jsonFileToJava",
"(",
"testResource",
",",
"ScenarioSpec",
".",
"class",
")",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"Exception while deserializing to Spec. Details: \"",
"+",
"e",
")",
";",
"}",
"}",
")",
".",
"collect",
"(",
"Collectors",
".",
"toList",
"(",
")",
")",
";",
"}",
"}"
] |
Returns a list of objects that define the children of this Runner.
|
[
"Returns",
"a",
"list",
"of",
"objects",
"that",
"define",
"the",
"children",
"of",
"this",
"Runner",
"."
] |
d66a3e8778d2eb5e4f0006bfcccfc0922ceb7cef
|
https://github.com/authorjapps/zerocode/blob/d66a3e8778d2eb5e4f0006bfcccfc0922ceb7cef/core/src/main/java/org/jsmart/zerocode/core/runner/ZeroCodePackageRunner.java#L75-L105
|
21,912
|
authorjapps/zerocode
|
core/src/main/java/org/jsmart/zerocode/core/runner/StepNotificationHandler.java
|
StepNotificationHandler.maxEntryLengthOf
|
private int maxEntryLengthOf(List<AssertionReport> failureReportList) {
final Integer maxLength = ofNullable(failureReportList).orElse(Collections.emptyList()).stream()
.map(report -> report.toString().length())
.max(Comparator.naturalOrder())
//.min(Comparator.naturalOrder())
.get();
return maxLength > MAX_LINE_LENGTH ? MAX_LINE_LENGTH : maxLength;
}
|
java
|
private int maxEntryLengthOf(List<AssertionReport> failureReportList) {
final Integer maxLength = ofNullable(failureReportList).orElse(Collections.emptyList()).stream()
.map(report -> report.toString().length())
.max(Comparator.naturalOrder())
//.min(Comparator.naturalOrder())
.get();
return maxLength > MAX_LINE_LENGTH ? MAX_LINE_LENGTH : maxLength;
}
|
[
"private",
"int",
"maxEntryLengthOf",
"(",
"List",
"<",
"AssertionReport",
">",
"failureReportList",
")",
"{",
"final",
"Integer",
"maxLength",
"=",
"ofNullable",
"(",
"failureReportList",
")",
".",
"orElse",
"(",
"Collections",
".",
"emptyList",
"(",
")",
")",
".",
"stream",
"(",
")",
".",
"map",
"(",
"report",
"->",
"report",
".",
"toString",
"(",
")",
".",
"length",
"(",
")",
")",
".",
"max",
"(",
"Comparator",
".",
"naturalOrder",
"(",
")",
")",
"//.min(Comparator.naturalOrder())",
".",
"get",
"(",
")",
";",
"return",
"maxLength",
">",
"MAX_LINE_LENGTH",
"?",
"MAX_LINE_LENGTH",
":",
"maxLength",
";",
"}"
] |
all private functions below
|
[
"all",
"private",
"functions",
"below"
] |
d66a3e8778d2eb5e4f0006bfcccfc0922ceb7cef
|
https://github.com/authorjapps/zerocode/blob/d66a3e8778d2eb5e4f0006bfcccfc0922ceb7cef/core/src/main/java/org/jsmart/zerocode/core/runner/StepNotificationHandler.java#L80-L87
|
21,913
|
nguyenq/tess4j
|
src/main/java/net/sourceforge/tess4j/Tesseract1.java
|
Tesseract1.setHocr
|
public void setHocr(boolean hocr) {
this.renderedFormat = hocr ? RenderedFormat.HOCR : RenderedFormat.TEXT;
prop.setProperty("tessedit_create_hocr", hocr ? "1" : "0");
}
|
java
|
public void setHocr(boolean hocr) {
this.renderedFormat = hocr ? RenderedFormat.HOCR : RenderedFormat.TEXT;
prop.setProperty("tessedit_create_hocr", hocr ? "1" : "0");
}
|
[
"public",
"void",
"setHocr",
"(",
"boolean",
"hocr",
")",
"{",
"this",
".",
"renderedFormat",
"=",
"hocr",
"?",
"RenderedFormat",
".",
"HOCR",
":",
"RenderedFormat",
".",
"TEXT",
";",
"prop",
".",
"setProperty",
"(",
"\"tessedit_create_hocr\"",
",",
"hocr",
"?",
"\"1\"",
":",
"\"0\"",
")",
";",
"}"
] |
Enables hocr output.
@param hocr to enable or disable hocr output
|
[
"Enables",
"hocr",
"output",
"."
] |
cfcd4a8a44042f150b4aaf7bdf5ffc485a2236e1
|
https://github.com/nguyenq/tess4j/blob/cfcd4a8a44042f150b4aaf7bdf5ffc485a2236e1/src/main/java/net/sourceforge/tess4j/Tesseract1.java#L135-L138
|
21,914
|
nguyenq/tess4j
|
src/main/java/net/sourceforge/tess4j/Tesseract1.java
|
Tesseract1.setTessVariable
|
@Override
public void setTessVariable(String key, String value) {
prop.setProperty(key, value);
}
|
java
|
@Override
public void setTessVariable(String key, String value) {
prop.setProperty(key, value);
}
|
[
"@",
"Override",
"public",
"void",
"setTessVariable",
"(",
"String",
"key",
",",
"String",
"value",
")",
"{",
"prop",
".",
"setProperty",
"(",
"key",
",",
"value",
")",
";",
"}"
] |
Set the value of Tesseract's internal parameter.
@param key variable name, e.g., <code>tessedit_create_hocr</code>,
<code>tessedit_char_whitelist</code>, etc.
@param value value for corresponding variable, e.g., "1", "0",
"0123456789", etc.
|
[
"Set",
"the",
"value",
"of",
"Tesseract",
"s",
"internal",
"parameter",
"."
] |
cfcd4a8a44042f150b4aaf7bdf5ffc485a2236e1
|
https://github.com/nguyenq/tess4j/blob/cfcd4a8a44042f150b4aaf7bdf5ffc485a2236e1/src/main/java/net/sourceforge/tess4j/Tesseract1.java#L148-L151
|
21,915
|
nguyenq/tess4j
|
src/main/java/net/sourceforge/tess4j/Tesseract1.java
|
Tesseract1.init
|
protected void init() {
handle = TessBaseAPICreate();
StringArray sarray = new StringArray(configList.toArray(new String[0]));
PointerByReference configs = new PointerByReference();
configs.setPointer(sarray);
TessBaseAPIInit1(handle, datapath, language, ocrEngineMode, configs, configList.size());
if (psm > -1) {
TessBaseAPISetPageSegMode(handle, psm);
}
}
|
java
|
protected void init() {
handle = TessBaseAPICreate();
StringArray sarray = new StringArray(configList.toArray(new String[0]));
PointerByReference configs = new PointerByReference();
configs.setPointer(sarray);
TessBaseAPIInit1(handle, datapath, language, ocrEngineMode, configs, configList.size());
if (psm > -1) {
TessBaseAPISetPageSegMode(handle, psm);
}
}
|
[
"protected",
"void",
"init",
"(",
")",
"{",
"handle",
"=",
"TessBaseAPICreate",
"(",
")",
";",
"StringArray",
"sarray",
"=",
"new",
"StringArray",
"(",
"configList",
".",
"toArray",
"(",
"new",
"String",
"[",
"0",
"]",
")",
")",
";",
"PointerByReference",
"configs",
"=",
"new",
"PointerByReference",
"(",
")",
";",
"configs",
".",
"setPointer",
"(",
"sarray",
")",
";",
"TessBaseAPIInit1",
"(",
"handle",
",",
"datapath",
",",
"language",
",",
"ocrEngineMode",
",",
"configs",
",",
"configList",
".",
"size",
"(",
")",
")",
";",
"if",
"(",
"psm",
">",
"-",
"1",
")",
"{",
"TessBaseAPISetPageSegMode",
"(",
"handle",
",",
"psm",
")",
";",
"}",
"}"
] |
Initializes Tesseract engine.
|
[
"Initializes",
"Tesseract",
"engine",
"."
] |
cfcd4a8a44042f150b4aaf7bdf5ffc485a2236e1
|
https://github.com/nguyenq/tess4j/blob/cfcd4a8a44042f150b4aaf7bdf5ffc485a2236e1/src/main/java/net/sourceforge/tess4j/Tesseract1.java#L406-L415
|
21,916
|
nguyenq/tess4j
|
src/main/java/net/sourceforge/tess4j/Tesseract1.java
|
Tesseract1.setTessVariables
|
protected void setTessVariables() {
Enumeration<?> em = prop.propertyNames();
while (em.hasMoreElements()) {
String key = (String) em.nextElement();
TessBaseAPISetVariable(handle, key, prop.getProperty(key));
}
}
|
java
|
protected void setTessVariables() {
Enumeration<?> em = prop.propertyNames();
while (em.hasMoreElements()) {
String key = (String) em.nextElement();
TessBaseAPISetVariable(handle, key, prop.getProperty(key));
}
}
|
[
"protected",
"void",
"setTessVariables",
"(",
")",
"{",
"Enumeration",
"<",
"?",
">",
"em",
"=",
"prop",
".",
"propertyNames",
"(",
")",
";",
"while",
"(",
"em",
".",
"hasMoreElements",
"(",
")",
")",
"{",
"String",
"key",
"=",
"(",
"String",
")",
"em",
".",
"nextElement",
"(",
")",
";",
"TessBaseAPISetVariable",
"(",
"handle",
",",
"key",
",",
"prop",
".",
"getProperty",
"(",
"key",
")",
")",
";",
"}",
"}"
] |
Sets Tesseract's internal parameters.
|
[
"Sets",
"Tesseract",
"s",
"internal",
"parameters",
"."
] |
cfcd4a8a44042f150b4aaf7bdf5ffc485a2236e1
|
https://github.com/nguyenq/tess4j/blob/cfcd4a8a44042f150b4aaf7bdf5ffc485a2236e1/src/main/java/net/sourceforge/tess4j/Tesseract1.java#L420-L426
|
21,917
|
nguyenq/tess4j
|
src/main/java/net/sourceforge/tess4j/Tesseract1.java
|
Tesseract1.createDocuments
|
@Override
public void createDocuments(String filename, String outputbase, List<RenderedFormat> formats) throws TesseractException {
createDocuments(new String[]{filename}, new String[]{outputbase}, formats);
}
|
java
|
@Override
public void createDocuments(String filename, String outputbase, List<RenderedFormat> formats) throws TesseractException {
createDocuments(new String[]{filename}, new String[]{outputbase}, formats);
}
|
[
"@",
"Override",
"public",
"void",
"createDocuments",
"(",
"String",
"filename",
",",
"String",
"outputbase",
",",
"List",
"<",
"RenderedFormat",
">",
"formats",
")",
"throws",
"TesseractException",
"{",
"createDocuments",
"(",
"new",
"String",
"[",
"]",
"{",
"filename",
"}",
",",
"new",
"String",
"[",
"]",
"{",
"outputbase",
"}",
",",
"formats",
")",
";",
"}"
] |
Creates documents for given renderer.
@param filename input image
@param outputbase output filename without extension
@param formats types of renderer
@throws TesseractException
|
[
"Creates",
"documents",
"for",
"given",
"renderer",
"."
] |
cfcd4a8a44042f150b4aaf7bdf5ffc485a2236e1
|
https://github.com/nguyenq/tess4j/blob/cfcd4a8a44042f150b4aaf7bdf5ffc485a2236e1/src/main/java/net/sourceforge/tess4j/Tesseract1.java#L579-L582
|
21,918
|
nguyenq/tess4j
|
src/main/java/net/sourceforge/tess4j/Tesseract1.java
|
Tesseract1.getSegmentedRegions
|
@Override
public List<Rectangle> getSegmentedRegions(BufferedImage bi, int pageIteratorLevel) throws TesseractException {
init();
setTessVariables();
try {
List<Rectangle> list = new ArrayList<Rectangle>();
setImage(bi, null);
Boxa boxes = TessBaseAPIGetComponentImages(handle, pageIteratorLevel, TRUE, null, null);
int boxCount = Leptonica1.boxaGetCount(boxes);
for (int i = 0; i < boxCount; i++) {
Box box = Leptonica1.boxaGetBox(boxes, i, L_CLONE);
if (box == null) {
continue;
}
list.add(new Rectangle(box.x, box.y, box.w, box.h));
PointerByReference pRef = new PointerByReference();
pRef.setValue(box.getPointer());
Leptonica1.boxDestroy(pRef);
}
PointerByReference pRef = new PointerByReference();
pRef.setValue(boxes.getPointer());
Leptonica1.boxaDestroy(pRef);
return list;
} catch (IOException ioe) {
// skip the problematic image
logger.warn(ioe.getMessage(), ioe);
throw new TesseractException(ioe);
} finally {
dispose();
}
}
|
java
|
@Override
public List<Rectangle> getSegmentedRegions(BufferedImage bi, int pageIteratorLevel) throws TesseractException {
init();
setTessVariables();
try {
List<Rectangle> list = new ArrayList<Rectangle>();
setImage(bi, null);
Boxa boxes = TessBaseAPIGetComponentImages(handle, pageIteratorLevel, TRUE, null, null);
int boxCount = Leptonica1.boxaGetCount(boxes);
for (int i = 0; i < boxCount; i++) {
Box box = Leptonica1.boxaGetBox(boxes, i, L_CLONE);
if (box == null) {
continue;
}
list.add(new Rectangle(box.x, box.y, box.w, box.h));
PointerByReference pRef = new PointerByReference();
pRef.setValue(box.getPointer());
Leptonica1.boxDestroy(pRef);
}
PointerByReference pRef = new PointerByReference();
pRef.setValue(boxes.getPointer());
Leptonica1.boxaDestroy(pRef);
return list;
} catch (IOException ioe) {
// skip the problematic image
logger.warn(ioe.getMessage(), ioe);
throw new TesseractException(ioe);
} finally {
dispose();
}
}
|
[
"@",
"Override",
"public",
"List",
"<",
"Rectangle",
">",
"getSegmentedRegions",
"(",
"BufferedImage",
"bi",
",",
"int",
"pageIteratorLevel",
")",
"throws",
"TesseractException",
"{",
"init",
"(",
")",
";",
"setTessVariables",
"(",
")",
";",
"try",
"{",
"List",
"<",
"Rectangle",
">",
"list",
"=",
"new",
"ArrayList",
"<",
"Rectangle",
">",
"(",
")",
";",
"setImage",
"(",
"bi",
",",
"null",
")",
";",
"Boxa",
"boxes",
"=",
"TessBaseAPIGetComponentImages",
"(",
"handle",
",",
"pageIteratorLevel",
",",
"TRUE",
",",
"null",
",",
"null",
")",
";",
"int",
"boxCount",
"=",
"Leptonica1",
".",
"boxaGetCount",
"(",
"boxes",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"boxCount",
";",
"i",
"++",
")",
"{",
"Box",
"box",
"=",
"Leptonica1",
".",
"boxaGetBox",
"(",
"boxes",
",",
"i",
",",
"L_CLONE",
")",
";",
"if",
"(",
"box",
"==",
"null",
")",
"{",
"continue",
";",
"}",
"list",
".",
"add",
"(",
"new",
"Rectangle",
"(",
"box",
".",
"x",
",",
"box",
".",
"y",
",",
"box",
".",
"w",
",",
"box",
".",
"h",
")",
")",
";",
"PointerByReference",
"pRef",
"=",
"new",
"PointerByReference",
"(",
")",
";",
"pRef",
".",
"setValue",
"(",
"box",
".",
"getPointer",
"(",
")",
")",
";",
"Leptonica1",
".",
"boxDestroy",
"(",
"pRef",
")",
";",
"}",
"PointerByReference",
"pRef",
"=",
"new",
"PointerByReference",
"(",
")",
";",
"pRef",
".",
"setValue",
"(",
"boxes",
".",
"getPointer",
"(",
")",
")",
";",
"Leptonica1",
".",
"boxaDestroy",
"(",
"pRef",
")",
";",
"return",
"list",
";",
"}",
"catch",
"(",
"IOException",
"ioe",
")",
"{",
"// skip the problematic image",
"logger",
".",
"warn",
"(",
"ioe",
".",
"getMessage",
"(",
")",
",",
"ioe",
")",
";",
"throw",
"new",
"TesseractException",
"(",
"ioe",
")",
";",
"}",
"finally",
"{",
"dispose",
"(",
")",
";",
"}",
"}"
] |
Gets segmented regions at specified page iterator level.
@param bi input image
@param pageIteratorLevel TessPageIteratorLevel enum
@return list of <code>Rectangle</code>
@throws TesseractException
|
[
"Gets",
"segmented",
"regions",
"at",
"specified",
"page",
"iterator",
"level",
"."
] |
cfcd4a8a44042f150b4aaf7bdf5ffc485a2236e1
|
https://github.com/nguyenq/tess4j/blob/cfcd4a8a44042f150b4aaf7bdf5ffc485a2236e1/src/main/java/net/sourceforge/tess4j/Tesseract1.java#L654-L688
|
21,919
|
nguyenq/tess4j
|
src/main/java/net/sourceforge/tess4j/Tesseract1.java
|
Tesseract1.createDocumentsWithResults
|
@Override
public List<OCRResult> createDocumentsWithResults(String[] filenames, String[] outputbases, List<ITesseract.RenderedFormat> formats, int pageIteratorLevel) throws TesseractException {
if (filenames.length != outputbases.length) {
throw new RuntimeException("The two arrays must match in length.");
}
init();
setTessVariables();
List<OCRResult> results = new ArrayList<OCRResult>();
try {
for (int i = 0; i < filenames.length; i++) {
File inputFile = new File(filenames[i]);
File imageFile = null;
try {
// if PDF, convert to multi-page TIFF
imageFile = ImageIOHelper.getImageFile(inputFile);
TessResultRenderer renderer = createRenderers(outputbases[i], formats);
int meanTextConfidence = createDocuments(imageFile.getPath(), renderer);
List<Word> words = meanTextConfidence > 0 ? getRecognizedWords(pageIteratorLevel) : new ArrayList<Word>();
results.add(new OCRResult(meanTextConfidence, words));
TessDeleteResultRenderer(renderer);
} catch (Exception e) {
// skip the problematic image file
logger.warn(e.getMessage(), e);
} finally {
// delete temporary TIFF image for PDF
if (imageFile != null && imageFile.exists() && imageFile != inputFile && imageFile.getName().startsWith("multipage") && imageFile.getName().endsWith(ImageIOHelper.TIFF_EXT)) {
imageFile.delete();
}
}
}
} finally {
dispose();
}
return results;
}
|
java
|
@Override
public List<OCRResult> createDocumentsWithResults(String[] filenames, String[] outputbases, List<ITesseract.RenderedFormat> formats, int pageIteratorLevel) throws TesseractException {
if (filenames.length != outputbases.length) {
throw new RuntimeException("The two arrays must match in length.");
}
init();
setTessVariables();
List<OCRResult> results = new ArrayList<OCRResult>();
try {
for (int i = 0; i < filenames.length; i++) {
File inputFile = new File(filenames[i]);
File imageFile = null;
try {
// if PDF, convert to multi-page TIFF
imageFile = ImageIOHelper.getImageFile(inputFile);
TessResultRenderer renderer = createRenderers(outputbases[i], formats);
int meanTextConfidence = createDocuments(imageFile.getPath(), renderer);
List<Word> words = meanTextConfidence > 0 ? getRecognizedWords(pageIteratorLevel) : new ArrayList<Word>();
results.add(new OCRResult(meanTextConfidence, words));
TessDeleteResultRenderer(renderer);
} catch (Exception e) {
// skip the problematic image file
logger.warn(e.getMessage(), e);
} finally {
// delete temporary TIFF image for PDF
if (imageFile != null && imageFile.exists() && imageFile != inputFile && imageFile.getName().startsWith("multipage") && imageFile.getName().endsWith(ImageIOHelper.TIFF_EXT)) {
imageFile.delete();
}
}
}
} finally {
dispose();
}
return results;
}
|
[
"@",
"Override",
"public",
"List",
"<",
"OCRResult",
">",
"createDocumentsWithResults",
"(",
"String",
"[",
"]",
"filenames",
",",
"String",
"[",
"]",
"outputbases",
",",
"List",
"<",
"ITesseract",
".",
"RenderedFormat",
">",
"formats",
",",
"int",
"pageIteratorLevel",
")",
"throws",
"TesseractException",
"{",
"if",
"(",
"filenames",
".",
"length",
"!=",
"outputbases",
".",
"length",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"The two arrays must match in length.\"",
")",
";",
"}",
"init",
"(",
")",
";",
"setTessVariables",
"(",
")",
";",
"List",
"<",
"OCRResult",
">",
"results",
"=",
"new",
"ArrayList",
"<",
"OCRResult",
">",
"(",
")",
";",
"try",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"filenames",
".",
"length",
";",
"i",
"++",
")",
"{",
"File",
"inputFile",
"=",
"new",
"File",
"(",
"filenames",
"[",
"i",
"]",
")",
";",
"File",
"imageFile",
"=",
"null",
";",
"try",
"{",
"// if PDF, convert to multi-page TIFF",
"imageFile",
"=",
"ImageIOHelper",
".",
"getImageFile",
"(",
"inputFile",
")",
";",
"TessResultRenderer",
"renderer",
"=",
"createRenderers",
"(",
"outputbases",
"[",
"i",
"]",
",",
"formats",
")",
";",
"int",
"meanTextConfidence",
"=",
"createDocuments",
"(",
"imageFile",
".",
"getPath",
"(",
")",
",",
"renderer",
")",
";",
"List",
"<",
"Word",
">",
"words",
"=",
"meanTextConfidence",
">",
"0",
"?",
"getRecognizedWords",
"(",
"pageIteratorLevel",
")",
":",
"new",
"ArrayList",
"<",
"Word",
">",
"(",
")",
";",
"results",
".",
"add",
"(",
"new",
"OCRResult",
"(",
"meanTextConfidence",
",",
"words",
")",
")",
";",
"TessDeleteResultRenderer",
"(",
"renderer",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"// skip the problematic image file",
"logger",
".",
"warn",
"(",
"e",
".",
"getMessage",
"(",
")",
",",
"e",
")",
";",
"}",
"finally",
"{",
"// delete temporary TIFF image for PDF",
"if",
"(",
"imageFile",
"!=",
"null",
"&&",
"imageFile",
".",
"exists",
"(",
")",
"&&",
"imageFile",
"!=",
"inputFile",
"&&",
"imageFile",
".",
"getName",
"(",
")",
".",
"startsWith",
"(",
"\"multipage\"",
")",
"&&",
"imageFile",
".",
"getName",
"(",
")",
".",
"endsWith",
"(",
"ImageIOHelper",
".",
"TIFF_EXT",
")",
")",
"{",
"imageFile",
".",
"delete",
"(",
")",
";",
"}",
"}",
"}",
"}",
"finally",
"{",
"dispose",
"(",
")",
";",
"}",
"return",
"results",
";",
"}"
] |
Creates documents with OCR results for given renderers at specified page
iterator level.
@param filenames array of input files
@param outputbases array of output filenames without extension
@param formats types of renderer
@return OCR results
@throws TesseractException
|
[
"Creates",
"documents",
"with",
"OCR",
"results",
"for",
"given",
"renderers",
"at",
"specified",
"page",
"iterator",
"level",
"."
] |
cfcd4a8a44042f150b4aaf7bdf5ffc485a2236e1
|
https://github.com/nguyenq/tess4j/blob/cfcd4a8a44042f150b4aaf7bdf5ffc485a2236e1/src/main/java/net/sourceforge/tess4j/Tesseract1.java#L747-L787
|
21,920
|
nguyenq/tess4j
|
src/main/java/net/sourceforge/tess4j/util/LoadLibs.java
|
LoadLibs.extractTessResources
|
public static synchronized File extractTessResources(String resourceName) {
File targetPath = null;
try {
targetPath = new File(TESS4J_TEMP_DIR, resourceName);
Enumeration<URL> resources = LoadLibs.class.getClassLoader().getResources(resourceName);
while (resources.hasMoreElements()) {
URL resourceUrl = resources.nextElement();
copyResources(resourceUrl, targetPath);
}
} catch (IOException | URISyntaxException e) {
logger.warn(e.getMessage(), e);
}
return targetPath;
}
|
java
|
public static synchronized File extractTessResources(String resourceName) {
File targetPath = null;
try {
targetPath = new File(TESS4J_TEMP_DIR, resourceName);
Enumeration<URL> resources = LoadLibs.class.getClassLoader().getResources(resourceName);
while (resources.hasMoreElements()) {
URL resourceUrl = resources.nextElement();
copyResources(resourceUrl, targetPath);
}
} catch (IOException | URISyntaxException e) {
logger.warn(e.getMessage(), e);
}
return targetPath;
}
|
[
"public",
"static",
"synchronized",
"File",
"extractTessResources",
"(",
"String",
"resourceName",
")",
"{",
"File",
"targetPath",
"=",
"null",
";",
"try",
"{",
"targetPath",
"=",
"new",
"File",
"(",
"TESS4J_TEMP_DIR",
",",
"resourceName",
")",
";",
"Enumeration",
"<",
"URL",
">",
"resources",
"=",
"LoadLibs",
".",
"class",
".",
"getClassLoader",
"(",
")",
".",
"getResources",
"(",
"resourceName",
")",
";",
"while",
"(",
"resources",
".",
"hasMoreElements",
"(",
")",
")",
"{",
"URL",
"resourceUrl",
"=",
"resources",
".",
"nextElement",
"(",
")",
";",
"copyResources",
"(",
"resourceUrl",
",",
"targetPath",
")",
";",
"}",
"}",
"catch",
"(",
"IOException",
"|",
"URISyntaxException",
"e",
")",
"{",
"logger",
".",
"warn",
"(",
"e",
".",
"getMessage",
"(",
")",
",",
"e",
")",
";",
"}",
"return",
"targetPath",
";",
"}"
] |
Extracts tesseract resources to temp folder.
@param resourceName name of file or directory
@return target path, which could be file or directory
|
[
"Extracts",
"tesseract",
"resources",
"to",
"temp",
"folder",
"."
] |
cfcd4a8a44042f150b4aaf7bdf5ffc485a2236e1
|
https://github.com/nguyenq/tess4j/blob/cfcd4a8a44042f150b4aaf7bdf5ffc485a2236e1/src/main/java/net/sourceforge/tess4j/util/LoadLibs.java#L104-L120
|
21,921
|
nguyenq/tess4j
|
src/main/java/net/sourceforge/tess4j/util/LoadLibs.java
|
LoadLibs.copyResources
|
static void copyResources(URL resourceUrl, File targetPath) throws IOException, URISyntaxException {
if (resourceUrl == null) {
return;
}
URLConnection urlConnection = resourceUrl.openConnection();
/**
* Copy resources either from inside jar or from project folder.
*/
if (urlConnection instanceof JarURLConnection) {
copyJarResourceToPath((JarURLConnection) urlConnection, targetPath);
} else if (VFS_PROTOCOL.equals(resourceUrl.getProtocol())) {
VirtualFile virtualFileOrFolder = VFS.getChild(resourceUrl.toURI());
copyFromWarToFolder(virtualFileOrFolder, targetPath);
} else {
File file = new File(resourceUrl.getPath());
if (file.isDirectory()) {
for (File resourceFile : FileUtils.listFiles(file, null, true)) {
int index = resourceFile.getPath().lastIndexOf(targetPath.getName()) + targetPath.getName().length();
File targetFile = new File(targetPath, resourceFile.getPath().substring(index));
if (!targetFile.exists() || targetFile.length() != resourceFile.length()) {
if (resourceFile.isFile()) {
FileUtils.copyFile(resourceFile, targetFile);
}
}
}
} else {
if (!targetPath.exists() || targetPath.length() != file.length()) {
FileUtils.copyFile(file, targetPath);
}
}
}
}
|
java
|
static void copyResources(URL resourceUrl, File targetPath) throws IOException, URISyntaxException {
if (resourceUrl == null) {
return;
}
URLConnection urlConnection = resourceUrl.openConnection();
/**
* Copy resources either from inside jar or from project folder.
*/
if (urlConnection instanceof JarURLConnection) {
copyJarResourceToPath((JarURLConnection) urlConnection, targetPath);
} else if (VFS_PROTOCOL.equals(resourceUrl.getProtocol())) {
VirtualFile virtualFileOrFolder = VFS.getChild(resourceUrl.toURI());
copyFromWarToFolder(virtualFileOrFolder, targetPath);
} else {
File file = new File(resourceUrl.getPath());
if (file.isDirectory()) {
for (File resourceFile : FileUtils.listFiles(file, null, true)) {
int index = resourceFile.getPath().lastIndexOf(targetPath.getName()) + targetPath.getName().length();
File targetFile = new File(targetPath, resourceFile.getPath().substring(index));
if (!targetFile.exists() || targetFile.length() != resourceFile.length()) {
if (resourceFile.isFile()) {
FileUtils.copyFile(resourceFile, targetFile);
}
}
}
} else {
if (!targetPath.exists() || targetPath.length() != file.length()) {
FileUtils.copyFile(file, targetPath);
}
}
}
}
|
[
"static",
"void",
"copyResources",
"(",
"URL",
"resourceUrl",
",",
"File",
"targetPath",
")",
"throws",
"IOException",
",",
"URISyntaxException",
"{",
"if",
"(",
"resourceUrl",
"==",
"null",
")",
"{",
"return",
";",
"}",
"URLConnection",
"urlConnection",
"=",
"resourceUrl",
".",
"openConnection",
"(",
")",
";",
"/**\n * Copy resources either from inside jar or from project folder.\n */",
"if",
"(",
"urlConnection",
"instanceof",
"JarURLConnection",
")",
"{",
"copyJarResourceToPath",
"(",
"(",
"JarURLConnection",
")",
"urlConnection",
",",
"targetPath",
")",
";",
"}",
"else",
"if",
"(",
"VFS_PROTOCOL",
".",
"equals",
"(",
"resourceUrl",
".",
"getProtocol",
"(",
")",
")",
")",
"{",
"VirtualFile",
"virtualFileOrFolder",
"=",
"VFS",
".",
"getChild",
"(",
"resourceUrl",
".",
"toURI",
"(",
")",
")",
";",
"copyFromWarToFolder",
"(",
"virtualFileOrFolder",
",",
"targetPath",
")",
";",
"}",
"else",
"{",
"File",
"file",
"=",
"new",
"File",
"(",
"resourceUrl",
".",
"getPath",
"(",
")",
")",
";",
"if",
"(",
"file",
".",
"isDirectory",
"(",
")",
")",
"{",
"for",
"(",
"File",
"resourceFile",
":",
"FileUtils",
".",
"listFiles",
"(",
"file",
",",
"null",
",",
"true",
")",
")",
"{",
"int",
"index",
"=",
"resourceFile",
".",
"getPath",
"(",
")",
".",
"lastIndexOf",
"(",
"targetPath",
".",
"getName",
"(",
")",
")",
"+",
"targetPath",
".",
"getName",
"(",
")",
".",
"length",
"(",
")",
";",
"File",
"targetFile",
"=",
"new",
"File",
"(",
"targetPath",
",",
"resourceFile",
".",
"getPath",
"(",
")",
".",
"substring",
"(",
"index",
")",
")",
";",
"if",
"(",
"!",
"targetFile",
".",
"exists",
"(",
")",
"||",
"targetFile",
".",
"length",
"(",
")",
"!=",
"resourceFile",
".",
"length",
"(",
")",
")",
"{",
"if",
"(",
"resourceFile",
".",
"isFile",
"(",
")",
")",
"{",
"FileUtils",
".",
"copyFile",
"(",
"resourceFile",
",",
"targetFile",
")",
";",
"}",
"}",
"}",
"}",
"else",
"{",
"if",
"(",
"!",
"targetPath",
".",
"exists",
"(",
")",
"||",
"targetPath",
".",
"length",
"(",
")",
"!=",
"file",
".",
"length",
"(",
")",
")",
"{",
"FileUtils",
".",
"copyFile",
"(",
"file",
",",
"targetPath",
")",
";",
"}",
"}",
"}",
"}"
] |
Copies resources to target folder.
@param resourceUrl
@param targetPath
@return
|
[
"Copies",
"resources",
"to",
"target",
"folder",
"."
] |
cfcd4a8a44042f150b4aaf7bdf5ffc485a2236e1
|
https://github.com/nguyenq/tess4j/blob/cfcd4a8a44042f150b4aaf7bdf5ffc485a2236e1/src/main/java/net/sourceforge/tess4j/util/LoadLibs.java#L129-L162
|
21,922
|
nguyenq/tess4j
|
src/main/java/net/sourceforge/tess4j/util/LoadLibs.java
|
LoadLibs.copyJarResourceToPath
|
static void copyJarResourceToPath(JarURLConnection jarConnection, File destPath) {
try (JarFile jarFile = jarConnection.getJarFile()) {
String jarConnectionEntryName = jarConnection.getEntryName();
if (!jarConnectionEntryName.endsWith("/")) {
jarConnectionEntryName += "/";
}
/**
* Iterate all entries in the jar file.
*/
for (Enumeration<JarEntry> e = jarFile.entries(); e.hasMoreElements();) {
JarEntry jarEntry = e.nextElement();
String jarEntryName = jarEntry.getName();
/**
* Extract files only if they match the path.
*/
if (jarEntryName.startsWith(jarConnectionEntryName)) {
String filename = jarEntryName.substring(jarConnectionEntryName.length());
File targetFile = new File(destPath, filename);
if (jarEntry.isDirectory()) {
targetFile.mkdirs();
} else {
if (!targetFile.exists() || targetFile.length() != jarEntry.getSize()) {
try (InputStream is = jarFile.getInputStream(jarEntry);
OutputStream out = FileUtils.openOutputStream(targetFile)) {
IOUtils.copy(is, out);
}
}
}
}
}
} catch (IOException e) {
logger.warn(e.getMessage(), e);
}
}
|
java
|
static void copyJarResourceToPath(JarURLConnection jarConnection, File destPath) {
try (JarFile jarFile = jarConnection.getJarFile()) {
String jarConnectionEntryName = jarConnection.getEntryName();
if (!jarConnectionEntryName.endsWith("/")) {
jarConnectionEntryName += "/";
}
/**
* Iterate all entries in the jar file.
*/
for (Enumeration<JarEntry> e = jarFile.entries(); e.hasMoreElements();) {
JarEntry jarEntry = e.nextElement();
String jarEntryName = jarEntry.getName();
/**
* Extract files only if they match the path.
*/
if (jarEntryName.startsWith(jarConnectionEntryName)) {
String filename = jarEntryName.substring(jarConnectionEntryName.length());
File targetFile = new File(destPath, filename);
if (jarEntry.isDirectory()) {
targetFile.mkdirs();
} else {
if (!targetFile.exists() || targetFile.length() != jarEntry.getSize()) {
try (InputStream is = jarFile.getInputStream(jarEntry);
OutputStream out = FileUtils.openOutputStream(targetFile)) {
IOUtils.copy(is, out);
}
}
}
}
}
} catch (IOException e) {
logger.warn(e.getMessage(), e);
}
}
|
[
"static",
"void",
"copyJarResourceToPath",
"(",
"JarURLConnection",
"jarConnection",
",",
"File",
"destPath",
")",
"{",
"try",
"(",
"JarFile",
"jarFile",
"=",
"jarConnection",
".",
"getJarFile",
"(",
")",
")",
"{",
"String",
"jarConnectionEntryName",
"=",
"jarConnection",
".",
"getEntryName",
"(",
")",
";",
"if",
"(",
"!",
"jarConnectionEntryName",
".",
"endsWith",
"(",
"\"/\"",
")",
")",
"{",
"jarConnectionEntryName",
"+=",
"\"/\"",
";",
"}",
"/**\n * Iterate all entries in the jar file.\n */",
"for",
"(",
"Enumeration",
"<",
"JarEntry",
">",
"e",
"=",
"jarFile",
".",
"entries",
"(",
")",
";",
"e",
".",
"hasMoreElements",
"(",
")",
";",
")",
"{",
"JarEntry",
"jarEntry",
"=",
"e",
".",
"nextElement",
"(",
")",
";",
"String",
"jarEntryName",
"=",
"jarEntry",
".",
"getName",
"(",
")",
";",
"/**\n * Extract files only if they match the path.\n */",
"if",
"(",
"jarEntryName",
".",
"startsWith",
"(",
"jarConnectionEntryName",
")",
")",
"{",
"String",
"filename",
"=",
"jarEntryName",
".",
"substring",
"(",
"jarConnectionEntryName",
".",
"length",
"(",
")",
")",
";",
"File",
"targetFile",
"=",
"new",
"File",
"(",
"destPath",
",",
"filename",
")",
";",
"if",
"(",
"jarEntry",
".",
"isDirectory",
"(",
")",
")",
"{",
"targetFile",
".",
"mkdirs",
"(",
")",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"targetFile",
".",
"exists",
"(",
")",
"||",
"targetFile",
".",
"length",
"(",
")",
"!=",
"jarEntry",
".",
"getSize",
"(",
")",
")",
"{",
"try",
"(",
"InputStream",
"is",
"=",
"jarFile",
".",
"getInputStream",
"(",
"jarEntry",
")",
";",
"OutputStream",
"out",
"=",
"FileUtils",
".",
"openOutputStream",
"(",
"targetFile",
")",
")",
"{",
"IOUtils",
".",
"copy",
"(",
"is",
",",
"out",
")",
";",
"}",
"}",
"}",
"}",
"}",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"logger",
".",
"warn",
"(",
"e",
".",
"getMessage",
"(",
")",
",",
"e",
")",
";",
"}",
"}"
] |
Copies resources from the jar file of the current thread and extract it
to the destination path.
@param jarConnection
@param destPath destination file or directory
|
[
"Copies",
"resources",
"from",
"the",
"jar",
"file",
"of",
"the",
"current",
"thread",
"and",
"extract",
"it",
"to",
"the",
"destination",
"path",
"."
] |
cfcd4a8a44042f150b4aaf7bdf5ffc485a2236e1
|
https://github.com/nguyenq/tess4j/blob/cfcd4a8a44042f150b4aaf7bdf5ffc485a2236e1/src/main/java/net/sourceforge/tess4j/util/LoadLibs.java#L171-L207
|
21,923
|
nguyenq/tess4j
|
src/main/java/net/sourceforge/tess4j/util/LoadLibs.java
|
LoadLibs.copyFromWarToFolder
|
static void copyFromWarToFolder(VirtualFile virtualFileOrFolder, File targetFolder) throws IOException {
if (virtualFileOrFolder.isDirectory() && !virtualFileOrFolder.getName().contains(".")) {
if (targetFolder.getName().equalsIgnoreCase(virtualFileOrFolder.getName())) {
for (VirtualFile innerFileOrFolder : virtualFileOrFolder.getChildren()) {
copyFromWarToFolder(innerFileOrFolder, targetFolder);
}
} else {
File innerTargetFolder = new File(targetFolder, virtualFileOrFolder.getName());
innerTargetFolder.mkdir();
for (VirtualFile innerFileOrFolder : virtualFileOrFolder.getChildren()) {
copyFromWarToFolder(innerFileOrFolder, innerTargetFolder);
}
}
} else {
File targetFile = new File(targetFolder, virtualFileOrFolder.getName());
if (!targetFile.exists() || targetFile.length() != virtualFileOrFolder.getSize()) {
FileUtils.copyURLToFile(virtualFileOrFolder.asFileURL(), targetFile);
}
}
}
|
java
|
static void copyFromWarToFolder(VirtualFile virtualFileOrFolder, File targetFolder) throws IOException {
if (virtualFileOrFolder.isDirectory() && !virtualFileOrFolder.getName().contains(".")) {
if (targetFolder.getName().equalsIgnoreCase(virtualFileOrFolder.getName())) {
for (VirtualFile innerFileOrFolder : virtualFileOrFolder.getChildren()) {
copyFromWarToFolder(innerFileOrFolder, targetFolder);
}
} else {
File innerTargetFolder = new File(targetFolder, virtualFileOrFolder.getName());
innerTargetFolder.mkdir();
for (VirtualFile innerFileOrFolder : virtualFileOrFolder.getChildren()) {
copyFromWarToFolder(innerFileOrFolder, innerTargetFolder);
}
}
} else {
File targetFile = new File(targetFolder, virtualFileOrFolder.getName());
if (!targetFile.exists() || targetFile.length() != virtualFileOrFolder.getSize()) {
FileUtils.copyURLToFile(virtualFileOrFolder.asFileURL(), targetFile);
}
}
}
|
[
"static",
"void",
"copyFromWarToFolder",
"(",
"VirtualFile",
"virtualFileOrFolder",
",",
"File",
"targetFolder",
")",
"throws",
"IOException",
"{",
"if",
"(",
"virtualFileOrFolder",
".",
"isDirectory",
"(",
")",
"&&",
"!",
"virtualFileOrFolder",
".",
"getName",
"(",
")",
".",
"contains",
"(",
"\".\"",
")",
")",
"{",
"if",
"(",
"targetFolder",
".",
"getName",
"(",
")",
".",
"equalsIgnoreCase",
"(",
"virtualFileOrFolder",
".",
"getName",
"(",
")",
")",
")",
"{",
"for",
"(",
"VirtualFile",
"innerFileOrFolder",
":",
"virtualFileOrFolder",
".",
"getChildren",
"(",
")",
")",
"{",
"copyFromWarToFolder",
"(",
"innerFileOrFolder",
",",
"targetFolder",
")",
";",
"}",
"}",
"else",
"{",
"File",
"innerTargetFolder",
"=",
"new",
"File",
"(",
"targetFolder",
",",
"virtualFileOrFolder",
".",
"getName",
"(",
")",
")",
";",
"innerTargetFolder",
".",
"mkdir",
"(",
")",
";",
"for",
"(",
"VirtualFile",
"innerFileOrFolder",
":",
"virtualFileOrFolder",
".",
"getChildren",
"(",
")",
")",
"{",
"copyFromWarToFolder",
"(",
"innerFileOrFolder",
",",
"innerTargetFolder",
")",
";",
"}",
"}",
"}",
"else",
"{",
"File",
"targetFile",
"=",
"new",
"File",
"(",
"targetFolder",
",",
"virtualFileOrFolder",
".",
"getName",
"(",
")",
")",
";",
"if",
"(",
"!",
"targetFile",
".",
"exists",
"(",
")",
"||",
"targetFile",
".",
"length",
"(",
")",
"!=",
"virtualFileOrFolder",
".",
"getSize",
"(",
")",
")",
"{",
"FileUtils",
".",
"copyURLToFile",
"(",
"virtualFileOrFolder",
".",
"asFileURL",
"(",
")",
",",
"targetFile",
")",
";",
"}",
"}",
"}"
] |
Copies resources from WAR to target folder.
@param virtualFileOrFolder
@param targetFolder
@throws IOException
|
[
"Copies",
"resources",
"from",
"WAR",
"to",
"target",
"folder",
"."
] |
cfcd4a8a44042f150b4aaf7bdf5ffc485a2236e1
|
https://github.com/nguyenq/tess4j/blob/cfcd4a8a44042f150b4aaf7bdf5ffc485a2236e1/src/main/java/net/sourceforge/tess4j/util/LoadLibs.java#L216-L235
|
21,924
|
nguyenq/tess4j
|
src/main/java/com/recognition/software/jdeskew/ImageDeskew.java
|
ImageDeskew.getSkewAngle
|
public double getSkewAngle() {
ImageDeskew.HoughLine[] hl;
double sum = 0.0;
int count = 0;
// perform Hough Transformation
calc();
// top 20 of the detected lines in the image
hl = getTop(20);
if (hl.length >= 20) {
// average angle of the lines
for (int i = 0; i < 19; i++) {
sum += hl[i].alpha;
count++;
}
return (sum / count);
} else {
return 0.0d;
}
}
|
java
|
public double getSkewAngle() {
ImageDeskew.HoughLine[] hl;
double sum = 0.0;
int count = 0;
// perform Hough Transformation
calc();
// top 20 of the detected lines in the image
hl = getTop(20);
if (hl.length >= 20) {
// average angle of the lines
for (int i = 0; i < 19; i++) {
sum += hl[i].alpha;
count++;
}
return (sum / count);
} else {
return 0.0d;
}
}
|
[
"public",
"double",
"getSkewAngle",
"(",
")",
"{",
"ImageDeskew",
".",
"HoughLine",
"[",
"]",
"hl",
";",
"double",
"sum",
"=",
"0.0",
";",
"int",
"count",
"=",
"0",
";",
"// perform Hough Transformation",
"calc",
"(",
")",
";",
"// top 20 of the detected lines in the image",
"hl",
"=",
"getTop",
"(",
"20",
")",
";",
"if",
"(",
"hl",
".",
"length",
">=",
"20",
")",
"{",
"// average angle of the lines",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"19",
";",
"i",
"++",
")",
"{",
"sum",
"+=",
"hl",
"[",
"i",
"]",
".",
"alpha",
";",
"count",
"++",
";",
"}",
"return",
"(",
"sum",
"/",
"count",
")",
";",
"}",
"else",
"{",
"return",
"0.0d",
";",
"}",
"}"
] |
Calculates the skew angle of the image cImage.
@return
|
[
"Calculates",
"the",
"skew",
"angle",
"of",
"the",
"image",
"cImage",
"."
] |
cfcd4a8a44042f150b4aaf7bdf5ffc485a2236e1
|
https://github.com/nguyenq/tess4j/blob/cfcd4a8a44042f150b4aaf7bdf5ffc485a2236e1/src/main/java/com/recognition/software/jdeskew/ImageDeskew.java#L60-L80
|
21,925
|
nguyenq/tess4j
|
src/main/java/com/recognition/software/jdeskew/ImageDeskew.java
|
ImageDeskew.getTop
|
private ImageDeskew.HoughLine[] getTop(int count) {
ImageDeskew.HoughLine[] hl = new ImageDeskew.HoughLine[count];
for (int i = 0; i < count; i++) {
hl[i] = new ImageDeskew.HoughLine();
}
ImageDeskew.HoughLine tmp;
for (int i = 0; i < (this.cHMatrix.length - 1); i++) {
if (this.cHMatrix[i] > hl[count - 1].count) {
hl[count - 1].count = this.cHMatrix[i];
hl[count - 1].index = i;
int j = count - 1;
while ((j > 0) && (hl[j].count > hl[j - 1].count)) {
tmp = hl[j];
hl[j] = hl[j - 1];
hl[j - 1] = tmp;
j--;
}
}
}
int alphaIndex;
int dIndex;
for (int i = 0; i < count; i++) {
dIndex = hl[i].index / cSteps; // integer division, no
// remainder
alphaIndex = hl[i].index - dIndex * cSteps;
hl[i].alpha = getAlpha(alphaIndex);
hl[i].d = dIndex + cDMin;
}
return hl;
}
|
java
|
private ImageDeskew.HoughLine[] getTop(int count) {
ImageDeskew.HoughLine[] hl = new ImageDeskew.HoughLine[count];
for (int i = 0; i < count; i++) {
hl[i] = new ImageDeskew.HoughLine();
}
ImageDeskew.HoughLine tmp;
for (int i = 0; i < (this.cHMatrix.length - 1); i++) {
if (this.cHMatrix[i] > hl[count - 1].count) {
hl[count - 1].count = this.cHMatrix[i];
hl[count - 1].index = i;
int j = count - 1;
while ((j > 0) && (hl[j].count > hl[j - 1].count)) {
tmp = hl[j];
hl[j] = hl[j - 1];
hl[j - 1] = tmp;
j--;
}
}
}
int alphaIndex;
int dIndex;
for (int i = 0; i < count; i++) {
dIndex = hl[i].index / cSteps; // integer division, no
// remainder
alphaIndex = hl[i].index - dIndex * cSteps;
hl[i].alpha = getAlpha(alphaIndex);
hl[i].d = dIndex + cDMin;
}
return hl;
}
|
[
"private",
"ImageDeskew",
".",
"HoughLine",
"[",
"]",
"getTop",
"(",
"int",
"count",
")",
"{",
"ImageDeskew",
".",
"HoughLine",
"[",
"]",
"hl",
"=",
"new",
"ImageDeskew",
".",
"HoughLine",
"[",
"count",
"]",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"count",
";",
"i",
"++",
")",
"{",
"hl",
"[",
"i",
"]",
"=",
"new",
"ImageDeskew",
".",
"HoughLine",
"(",
")",
";",
"}",
"ImageDeskew",
".",
"HoughLine",
"tmp",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"(",
"this",
".",
"cHMatrix",
".",
"length",
"-",
"1",
")",
";",
"i",
"++",
")",
"{",
"if",
"(",
"this",
".",
"cHMatrix",
"[",
"i",
"]",
">",
"hl",
"[",
"count",
"-",
"1",
"]",
".",
"count",
")",
"{",
"hl",
"[",
"count",
"-",
"1",
"]",
".",
"count",
"=",
"this",
".",
"cHMatrix",
"[",
"i",
"]",
";",
"hl",
"[",
"count",
"-",
"1",
"]",
".",
"index",
"=",
"i",
";",
"int",
"j",
"=",
"count",
"-",
"1",
";",
"while",
"(",
"(",
"j",
">",
"0",
")",
"&&",
"(",
"hl",
"[",
"j",
"]",
".",
"count",
">",
"hl",
"[",
"j",
"-",
"1",
"]",
".",
"count",
")",
")",
"{",
"tmp",
"=",
"hl",
"[",
"j",
"]",
";",
"hl",
"[",
"j",
"]",
"=",
"hl",
"[",
"j",
"-",
"1",
"]",
";",
"hl",
"[",
"j",
"-",
"1",
"]",
"=",
"tmp",
";",
"j",
"--",
";",
"}",
"}",
"}",
"int",
"alphaIndex",
";",
"int",
"dIndex",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"count",
";",
"i",
"++",
")",
"{",
"dIndex",
"=",
"hl",
"[",
"i",
"]",
".",
"index",
"/",
"cSteps",
";",
"// integer division, no",
"// remainder",
"alphaIndex",
"=",
"hl",
"[",
"i",
"]",
".",
"index",
"-",
"dIndex",
"*",
"cSteps",
";",
"hl",
"[",
"i",
"]",
".",
"alpha",
"=",
"getAlpha",
"(",
"alphaIndex",
")",
";",
"hl",
"[",
"i",
"]",
".",
"d",
"=",
"dIndex",
"+",
"cDMin",
";",
"}",
"return",
"hl",
";",
"}"
] |
calculate the count lines in the image with most points
|
[
"calculate",
"the",
"count",
"lines",
"in",
"the",
"image",
"with",
"most",
"points"
] |
cfcd4a8a44042f150b4aaf7bdf5ffc485a2236e1
|
https://github.com/nguyenq/tess4j/blob/cfcd4a8a44042f150b4aaf7bdf5ffc485a2236e1/src/main/java/com/recognition/software/jdeskew/ImageDeskew.java#L83-L118
|
21,926
|
nguyenq/tess4j
|
src/main/java/net/sourceforge/tess4j/util/ImageIOHelper.java
|
ImageIOHelper.setDPIViaAPI
|
private static IIOMetadata setDPIViaAPI(IIOMetadata imageMetadata, int dpiX, int dpiY)
throws IIOInvalidTreeException {
// Derive the TIFFDirectory from the metadata.
TIFFDirectory dir = TIFFDirectory.createFromMetadata(imageMetadata);
// Get {X,Y}Resolution tags.
BaselineTIFFTagSet base = BaselineTIFFTagSet.getInstance();
TIFFTag tagXRes = base.getTag(BaselineTIFFTagSet.TAG_X_RESOLUTION);
TIFFTag tagYRes = base.getTag(BaselineTIFFTagSet.TAG_Y_RESOLUTION);
// Create {X,Y}Resolution fields.
TIFFField fieldXRes = new TIFFField(tagXRes, TIFFTag.TIFF_RATIONAL,
1, new long[][]{{dpiX, 1}});
TIFFField fieldYRes = new TIFFField(tagYRes, TIFFTag.TIFF_RATIONAL,
1, new long[][]{{dpiY, 1}});
// Append {X,Y}Resolution fields to directory.
dir.addTIFFField(fieldXRes);
dir.addTIFFField(fieldYRes);
// Convert to metadata object.
IIOMetadata metadata = dir.getAsMetadata();
// Add other metadata.
IIOMetadataNode root = new IIOMetadataNode("javax_imageio_1.0");
IIOMetadataNode horiz = new IIOMetadataNode("HorizontalPixelSize");
horiz.setAttribute("value", Double.toString(25.4f / dpiX));
IIOMetadataNode vert = new IIOMetadataNode("VerticalPixelSize");
vert.setAttribute("value", Double.toString(25.4f / dpiY));
IIOMetadataNode dim = new IIOMetadataNode("Dimension");
dim.appendChild(horiz);
dim.appendChild(vert);
root.appendChild(dim);
metadata.mergeTree("javax_imageio_1.0", root);
return metadata;
}
|
java
|
private static IIOMetadata setDPIViaAPI(IIOMetadata imageMetadata, int dpiX, int dpiY)
throws IIOInvalidTreeException {
// Derive the TIFFDirectory from the metadata.
TIFFDirectory dir = TIFFDirectory.createFromMetadata(imageMetadata);
// Get {X,Y}Resolution tags.
BaselineTIFFTagSet base = BaselineTIFFTagSet.getInstance();
TIFFTag tagXRes = base.getTag(BaselineTIFFTagSet.TAG_X_RESOLUTION);
TIFFTag tagYRes = base.getTag(BaselineTIFFTagSet.TAG_Y_RESOLUTION);
// Create {X,Y}Resolution fields.
TIFFField fieldXRes = new TIFFField(tagXRes, TIFFTag.TIFF_RATIONAL,
1, new long[][]{{dpiX, 1}});
TIFFField fieldYRes = new TIFFField(tagYRes, TIFFTag.TIFF_RATIONAL,
1, new long[][]{{dpiY, 1}});
// Append {X,Y}Resolution fields to directory.
dir.addTIFFField(fieldXRes);
dir.addTIFFField(fieldYRes);
// Convert to metadata object.
IIOMetadata metadata = dir.getAsMetadata();
// Add other metadata.
IIOMetadataNode root = new IIOMetadataNode("javax_imageio_1.0");
IIOMetadataNode horiz = new IIOMetadataNode("HorizontalPixelSize");
horiz.setAttribute("value", Double.toString(25.4f / dpiX));
IIOMetadataNode vert = new IIOMetadataNode("VerticalPixelSize");
vert.setAttribute("value", Double.toString(25.4f / dpiY));
IIOMetadataNode dim = new IIOMetadataNode("Dimension");
dim.appendChild(horiz);
dim.appendChild(vert);
root.appendChild(dim);
metadata.mergeTree("javax_imageio_1.0", root);
return metadata;
}
|
[
"private",
"static",
"IIOMetadata",
"setDPIViaAPI",
"(",
"IIOMetadata",
"imageMetadata",
",",
"int",
"dpiX",
",",
"int",
"dpiY",
")",
"throws",
"IIOInvalidTreeException",
"{",
"// Derive the TIFFDirectory from the metadata.",
"TIFFDirectory",
"dir",
"=",
"TIFFDirectory",
".",
"createFromMetadata",
"(",
"imageMetadata",
")",
";",
"// Get {X,Y}Resolution tags.",
"BaselineTIFFTagSet",
"base",
"=",
"BaselineTIFFTagSet",
".",
"getInstance",
"(",
")",
";",
"TIFFTag",
"tagXRes",
"=",
"base",
".",
"getTag",
"(",
"BaselineTIFFTagSet",
".",
"TAG_X_RESOLUTION",
")",
";",
"TIFFTag",
"tagYRes",
"=",
"base",
".",
"getTag",
"(",
"BaselineTIFFTagSet",
".",
"TAG_Y_RESOLUTION",
")",
";",
"// Create {X,Y}Resolution fields.",
"TIFFField",
"fieldXRes",
"=",
"new",
"TIFFField",
"(",
"tagXRes",
",",
"TIFFTag",
".",
"TIFF_RATIONAL",
",",
"1",
",",
"new",
"long",
"[",
"]",
"[",
"]",
"{",
"{",
"dpiX",
",",
"1",
"}",
"}",
")",
";",
"TIFFField",
"fieldYRes",
"=",
"new",
"TIFFField",
"(",
"tagYRes",
",",
"TIFFTag",
".",
"TIFF_RATIONAL",
",",
"1",
",",
"new",
"long",
"[",
"]",
"[",
"]",
"{",
"{",
"dpiY",
",",
"1",
"}",
"}",
")",
";",
"// Append {X,Y}Resolution fields to directory.",
"dir",
".",
"addTIFFField",
"(",
"fieldXRes",
")",
";",
"dir",
".",
"addTIFFField",
"(",
"fieldYRes",
")",
";",
"// Convert to metadata object.",
"IIOMetadata",
"metadata",
"=",
"dir",
".",
"getAsMetadata",
"(",
")",
";",
"// Add other metadata.",
"IIOMetadataNode",
"root",
"=",
"new",
"IIOMetadataNode",
"(",
"\"javax_imageio_1.0\"",
")",
";",
"IIOMetadataNode",
"horiz",
"=",
"new",
"IIOMetadataNode",
"(",
"\"HorizontalPixelSize\"",
")",
";",
"horiz",
".",
"setAttribute",
"(",
"\"value\"",
",",
"Double",
".",
"toString",
"(",
"25.4f",
"/",
"dpiX",
")",
")",
";",
"IIOMetadataNode",
"vert",
"=",
"new",
"IIOMetadataNode",
"(",
"\"VerticalPixelSize\"",
")",
";",
"vert",
".",
"setAttribute",
"(",
"\"value\"",
",",
"Double",
".",
"toString",
"(",
"25.4f",
"/",
"dpiY",
")",
")",
";",
"IIOMetadataNode",
"dim",
"=",
"new",
"IIOMetadataNode",
"(",
"\"Dimension\"",
")",
";",
"dim",
".",
"appendChild",
"(",
"horiz",
")",
";",
"dim",
".",
"appendChild",
"(",
"vert",
")",
";",
"root",
".",
"appendChild",
"(",
"dim",
")",
";",
"metadata",
".",
"mergeTree",
"(",
"\"javax_imageio_1.0\"",
",",
"root",
")",
";",
"return",
"metadata",
";",
"}"
] |
Set DPI using API.
@param imageMetadata original IIOMetadata
@param dpiX horizontal resolution
@param dpiY vertical resolution
@return modified IIOMetadata
@throws IIOInvalidTreeException
|
[
"Set",
"DPI",
"using",
"API",
"."
] |
cfcd4a8a44042f150b4aaf7bdf5ffc485a2236e1
|
https://github.com/nguyenq/tess4j/blob/cfcd4a8a44042f150b4aaf7bdf5ffc485a2236e1/src/main/java/net/sourceforge/tess4j/util/ImageIOHelper.java#L215-L251
|
21,927
|
nguyenq/tess4j
|
src/main/java/net/sourceforge/tess4j/util/ImageIOHelper.java
|
ImageIOHelper.getImageFileFormat
|
public static String getImageFileFormat(File imageFile) {
String imageFileName = imageFile.getName();
String imageFormat = imageFileName.substring(imageFileName.lastIndexOf('.') + 1);
if (imageFormat.matches("(pbm|pgm|ppm)")) {
imageFormat = "pnm";
} else if (imageFormat.matches("(jp2|j2k|jpf|jpx|jpm)")) {
imageFormat = "jpeg2000";
}
return imageFormat;
}
|
java
|
public static String getImageFileFormat(File imageFile) {
String imageFileName = imageFile.getName();
String imageFormat = imageFileName.substring(imageFileName.lastIndexOf('.') + 1);
if (imageFormat.matches("(pbm|pgm|ppm)")) {
imageFormat = "pnm";
} else if (imageFormat.matches("(jp2|j2k|jpf|jpx|jpm)")) {
imageFormat = "jpeg2000";
}
return imageFormat;
}
|
[
"public",
"static",
"String",
"getImageFileFormat",
"(",
"File",
"imageFile",
")",
"{",
"String",
"imageFileName",
"=",
"imageFile",
".",
"getName",
"(",
")",
";",
"String",
"imageFormat",
"=",
"imageFileName",
".",
"substring",
"(",
"imageFileName",
".",
"lastIndexOf",
"(",
"'",
"'",
")",
"+",
"1",
")",
";",
"if",
"(",
"imageFormat",
".",
"matches",
"(",
"\"(pbm|pgm|ppm)\"",
")",
")",
"{",
"imageFormat",
"=",
"\"pnm\"",
";",
"}",
"else",
"if",
"(",
"imageFormat",
".",
"matches",
"(",
"\"(jp2|j2k|jpf|jpx|jpm)\"",
")",
")",
"{",
"imageFormat",
"=",
"\"jpeg2000\"",
";",
"}",
"return",
"imageFormat",
";",
"}"
] |
Gets image file format.
@param imageFile input image file
@return image file format
|
[
"Gets",
"image",
"file",
"format",
"."
] |
cfcd4a8a44042f150b4aaf7bdf5ffc485a2236e1
|
https://github.com/nguyenq/tess4j/blob/cfcd4a8a44042f150b4aaf7bdf5ffc485a2236e1/src/main/java/net/sourceforge/tess4j/util/ImageIOHelper.java#L306-L315
|
21,928
|
nguyenq/tess4j
|
src/main/java/net/sourceforge/tess4j/util/ImageIOHelper.java
|
ImageIOHelper.getImageFile
|
public static File getImageFile(File inputFile) throws IOException {
File imageFile = inputFile;
if (inputFile.getName().toLowerCase().endsWith(".pdf")) {
imageFile = PdfUtilities.convertPdf2Tiff(inputFile);
}
return imageFile;
}
|
java
|
public static File getImageFile(File inputFile) throws IOException {
File imageFile = inputFile;
if (inputFile.getName().toLowerCase().endsWith(".pdf")) {
imageFile = PdfUtilities.convertPdf2Tiff(inputFile);
}
return imageFile;
}
|
[
"public",
"static",
"File",
"getImageFile",
"(",
"File",
"inputFile",
")",
"throws",
"IOException",
"{",
"File",
"imageFile",
"=",
"inputFile",
";",
"if",
"(",
"inputFile",
".",
"getName",
"(",
")",
".",
"toLowerCase",
"(",
")",
".",
"endsWith",
"(",
"\".pdf\"",
")",
")",
"{",
"imageFile",
"=",
"PdfUtilities",
".",
"convertPdf2Tiff",
"(",
"inputFile",
")",
";",
"}",
"return",
"imageFile",
";",
"}"
] |
Gets image file. Convert to multi-page TIFF if given PDF.
@param inputFile input file (common image or PDF)
@return image file
@throws IOException
|
[
"Gets",
"image",
"file",
".",
"Convert",
"to",
"multi",
"-",
"page",
"TIFF",
"if",
"given",
"PDF",
"."
] |
cfcd4a8a44042f150b4aaf7bdf5ffc485a2236e1
|
https://github.com/nguyenq/tess4j/blob/cfcd4a8a44042f150b4aaf7bdf5ffc485a2236e1/src/main/java/net/sourceforge/tess4j/util/ImageIOHelper.java#L324-L330
|
21,929
|
nguyenq/tess4j
|
src/main/java/net/sourceforge/tess4j/util/ImageIOHelper.java
|
ImageIOHelper.deskewImage
|
public static File deskewImage(File imageFile, double minimumDeskewThreshold) throws IOException {
List<BufferedImage> imageList = getImageList(imageFile);
for (int i = 0; i < imageList.size(); i++) {
BufferedImage bi = imageList.get(i);
ImageDeskew deskew = new ImageDeskew(bi);
double imageSkewAngle = deskew.getSkewAngle();
if ((imageSkewAngle > minimumDeskewThreshold || imageSkewAngle < -(minimumDeskewThreshold))) {
bi = ImageUtil.rotate(bi, -imageSkewAngle, bi.getWidth() / 2, bi.getHeight() / 2);
imageList.set(i, bi); // replace original with deskewed image
}
}
File tempImageFile = File.createTempFile(FilenameUtils.getBaseName(imageFile.getName()), ".tif");
mergeTiff(imageList.toArray(new BufferedImage[0]), tempImageFile);
return tempImageFile;
}
|
java
|
public static File deskewImage(File imageFile, double minimumDeskewThreshold) throws IOException {
List<BufferedImage> imageList = getImageList(imageFile);
for (int i = 0; i < imageList.size(); i++) {
BufferedImage bi = imageList.get(i);
ImageDeskew deskew = new ImageDeskew(bi);
double imageSkewAngle = deskew.getSkewAngle();
if ((imageSkewAngle > minimumDeskewThreshold || imageSkewAngle < -(minimumDeskewThreshold))) {
bi = ImageUtil.rotate(bi, -imageSkewAngle, bi.getWidth() / 2, bi.getHeight() / 2);
imageList.set(i, bi); // replace original with deskewed image
}
}
File tempImageFile = File.createTempFile(FilenameUtils.getBaseName(imageFile.getName()), ".tif");
mergeTiff(imageList.toArray(new BufferedImage[0]), tempImageFile);
return tempImageFile;
}
|
[
"public",
"static",
"File",
"deskewImage",
"(",
"File",
"imageFile",
",",
"double",
"minimumDeskewThreshold",
")",
"throws",
"IOException",
"{",
"List",
"<",
"BufferedImage",
">",
"imageList",
"=",
"getImageList",
"(",
"imageFile",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"imageList",
".",
"size",
"(",
")",
";",
"i",
"++",
")",
"{",
"BufferedImage",
"bi",
"=",
"imageList",
".",
"get",
"(",
"i",
")",
";",
"ImageDeskew",
"deskew",
"=",
"new",
"ImageDeskew",
"(",
"bi",
")",
";",
"double",
"imageSkewAngle",
"=",
"deskew",
".",
"getSkewAngle",
"(",
")",
";",
"if",
"(",
"(",
"imageSkewAngle",
">",
"minimumDeskewThreshold",
"||",
"imageSkewAngle",
"<",
"-",
"(",
"minimumDeskewThreshold",
")",
")",
")",
"{",
"bi",
"=",
"ImageUtil",
".",
"rotate",
"(",
"bi",
",",
"-",
"imageSkewAngle",
",",
"bi",
".",
"getWidth",
"(",
")",
"/",
"2",
",",
"bi",
".",
"getHeight",
"(",
")",
"/",
"2",
")",
";",
"imageList",
".",
"set",
"(",
"i",
",",
"bi",
")",
";",
"// replace original with deskewed image",
"}",
"}",
"File",
"tempImageFile",
"=",
"File",
".",
"createTempFile",
"(",
"FilenameUtils",
".",
"getBaseName",
"(",
"imageFile",
".",
"getName",
"(",
")",
")",
",",
"\".tif\"",
")",
";",
"mergeTiff",
"(",
"imageList",
".",
"toArray",
"(",
"new",
"BufferedImage",
"[",
"0",
"]",
")",
",",
"tempImageFile",
")",
";",
"return",
"tempImageFile",
";",
"}"
] |
Deskews image.
@param imageFile input image
@param minimumDeskewThreshold minimum deskew threshold (typically, 0.05d)
@return temporary multi-page TIFF image file
@throws IOException
|
[
"Deskews",
"image",
"."
] |
cfcd4a8a44042f150b4aaf7bdf5ffc485a2236e1
|
https://github.com/nguyenq/tess4j/blob/cfcd4a8a44042f150b4aaf7bdf5ffc485a2236e1/src/main/java/net/sourceforge/tess4j/util/ImageIOHelper.java#L604-L621
|
21,930
|
nguyenq/tess4j
|
src/main/java/net/sourceforge/tess4j/util/ImageIOHelper.java
|
ImageIOHelper.readImageData
|
public static Map<String, String> readImageData(IIOImage oimage) {
Map<String, String> dict = new HashMap<String, String>();
IIOMetadata imageMetadata = oimage.getMetadata();
if (imageMetadata != null) {
IIOMetadataNode dimNode = (IIOMetadataNode) imageMetadata.getAsTree("javax_imageio_1.0");
NodeList nodes = dimNode.getElementsByTagName("HorizontalPixelSize");
int dpiX;
if (nodes.getLength() > 0) {
float dpcWidth = Float.parseFloat(nodes.item(0).getAttributes().item(0).getNodeValue());
dpiX = (int) Math.round(25.4f / dpcWidth);
} else {
dpiX = Toolkit.getDefaultToolkit().getScreenResolution();
}
dict.put("dpiX", String.valueOf(dpiX));
nodes = dimNode.getElementsByTagName("VerticalPixelSize");
int dpiY;
if (nodes.getLength() > 0) {
float dpcHeight = Float.parseFloat(nodes.item(0).getAttributes().item(0).getNodeValue());
dpiY = (int) Math.round(25.4f / dpcHeight);
} else {
dpiY = Toolkit.getDefaultToolkit().getScreenResolution();
}
dict.put("dpiY", String.valueOf(dpiY));
}
return dict;
}
|
java
|
public static Map<String, String> readImageData(IIOImage oimage) {
Map<String, String> dict = new HashMap<String, String>();
IIOMetadata imageMetadata = oimage.getMetadata();
if (imageMetadata != null) {
IIOMetadataNode dimNode = (IIOMetadataNode) imageMetadata.getAsTree("javax_imageio_1.0");
NodeList nodes = dimNode.getElementsByTagName("HorizontalPixelSize");
int dpiX;
if (nodes.getLength() > 0) {
float dpcWidth = Float.parseFloat(nodes.item(0).getAttributes().item(0).getNodeValue());
dpiX = (int) Math.round(25.4f / dpcWidth);
} else {
dpiX = Toolkit.getDefaultToolkit().getScreenResolution();
}
dict.put("dpiX", String.valueOf(dpiX));
nodes = dimNode.getElementsByTagName("VerticalPixelSize");
int dpiY;
if (nodes.getLength() > 0) {
float dpcHeight = Float.parseFloat(nodes.item(0).getAttributes().item(0).getNodeValue());
dpiY = (int) Math.round(25.4f / dpcHeight);
} else {
dpiY = Toolkit.getDefaultToolkit().getScreenResolution();
}
dict.put("dpiY", String.valueOf(dpiY));
}
return dict;
}
|
[
"public",
"static",
"Map",
"<",
"String",
",",
"String",
">",
"readImageData",
"(",
"IIOImage",
"oimage",
")",
"{",
"Map",
"<",
"String",
",",
"String",
">",
"dict",
"=",
"new",
"HashMap",
"<",
"String",
",",
"String",
">",
"(",
")",
";",
"IIOMetadata",
"imageMetadata",
"=",
"oimage",
".",
"getMetadata",
"(",
")",
";",
"if",
"(",
"imageMetadata",
"!=",
"null",
")",
"{",
"IIOMetadataNode",
"dimNode",
"=",
"(",
"IIOMetadataNode",
")",
"imageMetadata",
".",
"getAsTree",
"(",
"\"javax_imageio_1.0\"",
")",
";",
"NodeList",
"nodes",
"=",
"dimNode",
".",
"getElementsByTagName",
"(",
"\"HorizontalPixelSize\"",
")",
";",
"int",
"dpiX",
";",
"if",
"(",
"nodes",
".",
"getLength",
"(",
")",
">",
"0",
")",
"{",
"float",
"dpcWidth",
"=",
"Float",
".",
"parseFloat",
"(",
"nodes",
".",
"item",
"(",
"0",
")",
".",
"getAttributes",
"(",
")",
".",
"item",
"(",
"0",
")",
".",
"getNodeValue",
"(",
")",
")",
";",
"dpiX",
"=",
"(",
"int",
")",
"Math",
".",
"round",
"(",
"25.4f",
"/",
"dpcWidth",
")",
";",
"}",
"else",
"{",
"dpiX",
"=",
"Toolkit",
".",
"getDefaultToolkit",
"(",
")",
".",
"getScreenResolution",
"(",
")",
";",
"}",
"dict",
".",
"put",
"(",
"\"dpiX\"",
",",
"String",
".",
"valueOf",
"(",
"dpiX",
")",
")",
";",
"nodes",
"=",
"dimNode",
".",
"getElementsByTagName",
"(",
"\"VerticalPixelSize\"",
")",
";",
"int",
"dpiY",
";",
"if",
"(",
"nodes",
".",
"getLength",
"(",
")",
">",
"0",
")",
"{",
"float",
"dpcHeight",
"=",
"Float",
".",
"parseFloat",
"(",
"nodes",
".",
"item",
"(",
"0",
")",
".",
"getAttributes",
"(",
")",
".",
"item",
"(",
"0",
")",
".",
"getNodeValue",
"(",
")",
")",
";",
"dpiY",
"=",
"(",
"int",
")",
"Math",
".",
"round",
"(",
"25.4f",
"/",
"dpcHeight",
")",
";",
"}",
"else",
"{",
"dpiY",
"=",
"Toolkit",
".",
"getDefaultToolkit",
"(",
")",
".",
"getScreenResolution",
"(",
")",
";",
"}",
"dict",
".",
"put",
"(",
"\"dpiY\"",
",",
"String",
".",
"valueOf",
"(",
"dpiY",
")",
")",
";",
"}",
"return",
"dict",
";",
"}"
] |
Reads image meta data.
@param oimage
@return a map of meta data
|
[
"Reads",
"image",
"meta",
"data",
"."
] |
cfcd4a8a44042f150b4aaf7bdf5ffc485a2236e1
|
https://github.com/nguyenq/tess4j/blob/cfcd4a8a44042f150b4aaf7bdf5ffc485a2236e1/src/main/java/net/sourceforge/tess4j/util/ImageIOHelper.java#L629-L657
|
21,931
|
nguyenq/tess4j
|
src/main/java/net/sourceforge/tess4j/util/ImageHelper.java
|
ImageHelper.convertImageToGrayscale
|
public static BufferedImage convertImageToGrayscale(BufferedImage image) {
BufferedImage tmp = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_BYTE_GRAY);
Graphics2D g2 = tmp.createGraphics();
g2.drawImage(image, 0, 0, null);
g2.dispose();
return tmp;
}
|
java
|
public static BufferedImage convertImageToGrayscale(BufferedImage image) {
BufferedImage tmp = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_BYTE_GRAY);
Graphics2D g2 = tmp.createGraphics();
g2.drawImage(image, 0, 0, null);
g2.dispose();
return tmp;
}
|
[
"public",
"static",
"BufferedImage",
"convertImageToGrayscale",
"(",
"BufferedImage",
"image",
")",
"{",
"BufferedImage",
"tmp",
"=",
"new",
"BufferedImage",
"(",
"image",
".",
"getWidth",
"(",
")",
",",
"image",
".",
"getHeight",
"(",
")",
",",
"BufferedImage",
".",
"TYPE_BYTE_GRAY",
")",
";",
"Graphics2D",
"g2",
"=",
"tmp",
".",
"createGraphics",
"(",
")",
";",
"g2",
".",
"drawImage",
"(",
"image",
",",
"0",
",",
"0",
",",
"null",
")",
";",
"g2",
".",
"dispose",
"(",
")",
";",
"return",
"tmp",
";",
"}"
] |
A simple method to convert an image to gray scale.
@param image input image
@return a monochrome image
|
[
"A",
"simple",
"method",
"to",
"convert",
"an",
"image",
"to",
"gray",
"scale",
"."
] |
cfcd4a8a44042f150b4aaf7bdf5ffc485a2236e1
|
https://github.com/nguyenq/tess4j/blob/cfcd4a8a44042f150b4aaf7bdf5ffc485a2236e1/src/main/java/net/sourceforge/tess4j/util/ImageHelper.java#L128-L134
|
21,932
|
nguyenq/tess4j
|
src/main/java/net/sourceforge/tess4j/util/ImageHelper.java
|
ImageHelper.invertImageColor
|
public static BufferedImage invertImageColor(BufferedImage image) {
BufferedImage tmp = new BufferedImage(image.getWidth(), image.getHeight(), image.getType());
BufferedImageOp invertOp = new LookupOp(new ShortLookupTable(0, invertTable), null);
return invertOp.filter(image, tmp);
}
|
java
|
public static BufferedImage invertImageColor(BufferedImage image) {
BufferedImage tmp = new BufferedImage(image.getWidth(), image.getHeight(), image.getType());
BufferedImageOp invertOp = new LookupOp(new ShortLookupTable(0, invertTable), null);
return invertOp.filter(image, tmp);
}
|
[
"public",
"static",
"BufferedImage",
"invertImageColor",
"(",
"BufferedImage",
"image",
")",
"{",
"BufferedImage",
"tmp",
"=",
"new",
"BufferedImage",
"(",
"image",
".",
"getWidth",
"(",
")",
",",
"image",
".",
"getHeight",
"(",
")",
",",
"image",
".",
"getType",
"(",
")",
")",
";",
"BufferedImageOp",
"invertOp",
"=",
"new",
"LookupOp",
"(",
"new",
"ShortLookupTable",
"(",
"0",
",",
"invertTable",
")",
",",
"null",
")",
";",
"return",
"invertOp",
".",
"filter",
"(",
"image",
",",
"tmp",
")",
";",
"}"
] |
Inverts image color.
@param image input image
@return an inverted-color image
|
[
"Inverts",
"image",
"color",
"."
] |
cfcd4a8a44042f150b4aaf7bdf5ffc485a2236e1
|
https://github.com/nguyenq/tess4j/blob/cfcd4a8a44042f150b4aaf7bdf5ffc485a2236e1/src/main/java/net/sourceforge/tess4j/util/ImageHelper.java#L151-L155
|
21,933
|
nguyenq/tess4j
|
src/main/java/net/sourceforge/tess4j/util/ImageHelper.java
|
ImageHelper.rotateImage
|
public static BufferedImage rotateImage(BufferedImage image, double angle) {
double theta = Math.toRadians(angle);
double sin = Math.abs(Math.sin(theta));
double cos = Math.abs(Math.cos(theta));
int w = image.getWidth();
int h = image.getHeight();
int newW = (int) Math.floor(w * cos + h * sin);
int newH = (int) Math.floor(h * cos + w * sin);
BufferedImage tmp = new BufferedImage(newW, newH, image.getType());
Graphics2D g2d = tmp.createGraphics();
g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BICUBIC);
g2d.translate((newW - w) / 2, (newH - h) / 2);
g2d.rotate(theta, w / 2, h / 2);
g2d.drawImage(image, 0, 0, null);
g2d.dispose();
return tmp;
}
|
java
|
public static BufferedImage rotateImage(BufferedImage image, double angle) {
double theta = Math.toRadians(angle);
double sin = Math.abs(Math.sin(theta));
double cos = Math.abs(Math.cos(theta));
int w = image.getWidth();
int h = image.getHeight();
int newW = (int) Math.floor(w * cos + h * sin);
int newH = (int) Math.floor(h * cos + w * sin);
BufferedImage tmp = new BufferedImage(newW, newH, image.getType());
Graphics2D g2d = tmp.createGraphics();
g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BICUBIC);
g2d.translate((newW - w) / 2, (newH - h) / 2);
g2d.rotate(theta, w / 2, h / 2);
g2d.drawImage(image, 0, 0, null);
g2d.dispose();
return tmp;
}
|
[
"public",
"static",
"BufferedImage",
"rotateImage",
"(",
"BufferedImage",
"image",
",",
"double",
"angle",
")",
"{",
"double",
"theta",
"=",
"Math",
".",
"toRadians",
"(",
"angle",
")",
";",
"double",
"sin",
"=",
"Math",
".",
"abs",
"(",
"Math",
".",
"sin",
"(",
"theta",
")",
")",
";",
"double",
"cos",
"=",
"Math",
".",
"abs",
"(",
"Math",
".",
"cos",
"(",
"theta",
")",
")",
";",
"int",
"w",
"=",
"image",
".",
"getWidth",
"(",
")",
";",
"int",
"h",
"=",
"image",
".",
"getHeight",
"(",
")",
";",
"int",
"newW",
"=",
"(",
"int",
")",
"Math",
".",
"floor",
"(",
"w",
"*",
"cos",
"+",
"h",
"*",
"sin",
")",
";",
"int",
"newH",
"=",
"(",
"int",
")",
"Math",
".",
"floor",
"(",
"h",
"*",
"cos",
"+",
"w",
"*",
"sin",
")",
";",
"BufferedImage",
"tmp",
"=",
"new",
"BufferedImage",
"(",
"newW",
",",
"newH",
",",
"image",
".",
"getType",
"(",
")",
")",
";",
"Graphics2D",
"g2d",
"=",
"tmp",
".",
"createGraphics",
"(",
")",
";",
"g2d",
".",
"setRenderingHint",
"(",
"RenderingHints",
".",
"KEY_INTERPOLATION",
",",
"RenderingHints",
".",
"VALUE_INTERPOLATION_BICUBIC",
")",
";",
"g2d",
".",
"translate",
"(",
"(",
"newW",
"-",
"w",
")",
"/",
"2",
",",
"(",
"newH",
"-",
"h",
")",
"/",
"2",
")",
";",
"g2d",
".",
"rotate",
"(",
"theta",
",",
"w",
"/",
"2",
",",
"h",
"/",
"2",
")",
";",
"g2d",
".",
"drawImage",
"(",
"image",
",",
"0",
",",
"0",
",",
"null",
")",
";",
"g2d",
".",
"dispose",
"(",
")",
";",
"return",
"tmp",
";",
"}"
] |
Rotates an image.
@param image the original image
@param angle the degree of rotation
@return a rotated image
|
[
"Rotates",
"an",
"image",
"."
] |
cfcd4a8a44042f150b4aaf7bdf5ffc485a2236e1
|
https://github.com/nguyenq/tess4j/blob/cfcd4a8a44042f150b4aaf7bdf5ffc485a2236e1/src/main/java/net/sourceforge/tess4j/util/ImageHelper.java#L164-L182
|
21,934
|
nguyenq/tess4j
|
src/main/java/net/sourceforge/tess4j/util/ImageHelper.java
|
ImageHelper.getClipboardImage
|
public static Image getClipboardImage() {
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
try {
return (Image) clipboard.getData(DataFlavor.imageFlavor);
} catch (Exception e) {
return null;
}
}
|
java
|
public static Image getClipboardImage() {
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
try {
return (Image) clipboard.getData(DataFlavor.imageFlavor);
} catch (Exception e) {
return null;
}
}
|
[
"public",
"static",
"Image",
"getClipboardImage",
"(",
")",
"{",
"Clipboard",
"clipboard",
"=",
"Toolkit",
".",
"getDefaultToolkit",
"(",
")",
".",
"getSystemClipboard",
"(",
")",
";",
"try",
"{",
"return",
"(",
"Image",
")",
"clipboard",
".",
"getData",
"(",
"DataFlavor",
".",
"imageFlavor",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"return",
"null",
";",
"}",
"}"
] |
Gets an image from Clipboard.
@return image
|
[
"Gets",
"an",
"image",
"from",
"Clipboard",
"."
] |
cfcd4a8a44042f150b4aaf7bdf5ffc485a2236e1
|
https://github.com/nguyenq/tess4j/blob/cfcd4a8a44042f150b4aaf7bdf5ffc485a2236e1/src/main/java/net/sourceforge/tess4j/util/ImageHelper.java#L189-L196
|
21,935
|
nguyenq/tess4j
|
src/main/java/com/recognition/software/jdeskew/ImageUtil.java
|
ImageUtil.rotate
|
public static BufferedImage rotate(BufferedImage image, double angle, int cx, int cy) {
int width = image.getWidth(null);
int height = image.getHeight(null);
int minX, minY, maxX, maxY;
minX = minY = maxX = maxY = 0;
int[] corners = {0, 0, width, 0, width, height, 0, height};
double theta = Math.toRadians(angle);
for (int i = 0; i < corners.length; i += 2) {
int x = (int) (Math.cos(theta) * (corners[i] - cx)
- Math.sin(theta) * (corners[i + 1] - cy) + cx);
int y = (int) (Math.sin(theta) * (corners[i] - cx)
+ Math.cos(theta) * (corners[i + 1] - cy) + cy);
if (x > maxX) {
maxX = x;
}
if (x < minX) {
minX = x;
}
if (y > maxY) {
maxY = y;
}
if (y < minY) {
minY = y;
}
}
cx = (cx - minX);
cy = (cy - minY);
BufferedImage bi = new BufferedImage((maxX - minX), (maxY - minY),
image.getType());
Graphics2D g2 = bi.createGraphics();
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BICUBIC);
g2.setBackground(Color.white);
g2.fillRect(0, 0, bi.getWidth(), bi.getHeight());
AffineTransform at = new AffineTransform();
at.rotate(theta, cx, cy);
g2.setTransform(at);
g2.drawImage(image, -minX, -minY, null);
g2.dispose();
return bi;
}
|
java
|
public static BufferedImage rotate(BufferedImage image, double angle, int cx, int cy) {
int width = image.getWidth(null);
int height = image.getHeight(null);
int minX, minY, maxX, maxY;
minX = minY = maxX = maxY = 0;
int[] corners = {0, 0, width, 0, width, height, 0, height};
double theta = Math.toRadians(angle);
for (int i = 0; i < corners.length; i += 2) {
int x = (int) (Math.cos(theta) * (corners[i] - cx)
- Math.sin(theta) * (corners[i + 1] - cy) + cx);
int y = (int) (Math.sin(theta) * (corners[i] - cx)
+ Math.cos(theta) * (corners[i + 1] - cy) + cy);
if (x > maxX) {
maxX = x;
}
if (x < minX) {
minX = x;
}
if (y > maxY) {
maxY = y;
}
if (y < minY) {
minY = y;
}
}
cx = (cx - minX);
cy = (cy - minY);
BufferedImage bi = new BufferedImage((maxX - minX), (maxY - minY),
image.getType());
Graphics2D g2 = bi.createGraphics();
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BICUBIC);
g2.setBackground(Color.white);
g2.fillRect(0, 0, bi.getWidth(), bi.getHeight());
AffineTransform at = new AffineTransform();
at.rotate(theta, cx, cy);
g2.setTransform(at);
g2.drawImage(image, -minX, -minY, null);
g2.dispose();
return bi;
}
|
[
"public",
"static",
"BufferedImage",
"rotate",
"(",
"BufferedImage",
"image",
",",
"double",
"angle",
",",
"int",
"cx",
",",
"int",
"cy",
")",
"{",
"int",
"width",
"=",
"image",
".",
"getWidth",
"(",
"null",
")",
";",
"int",
"height",
"=",
"image",
".",
"getHeight",
"(",
"null",
")",
";",
"int",
"minX",
",",
"minY",
",",
"maxX",
",",
"maxY",
";",
"minX",
"=",
"minY",
"=",
"maxX",
"=",
"maxY",
"=",
"0",
";",
"int",
"[",
"]",
"corners",
"=",
"{",
"0",
",",
"0",
",",
"width",
",",
"0",
",",
"width",
",",
"height",
",",
"0",
",",
"height",
"}",
";",
"double",
"theta",
"=",
"Math",
".",
"toRadians",
"(",
"angle",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"corners",
".",
"length",
";",
"i",
"+=",
"2",
")",
"{",
"int",
"x",
"=",
"(",
"int",
")",
"(",
"Math",
".",
"cos",
"(",
"theta",
")",
"*",
"(",
"corners",
"[",
"i",
"]",
"-",
"cx",
")",
"-",
"Math",
".",
"sin",
"(",
"theta",
")",
"*",
"(",
"corners",
"[",
"i",
"+",
"1",
"]",
"-",
"cy",
")",
"+",
"cx",
")",
";",
"int",
"y",
"=",
"(",
"int",
")",
"(",
"Math",
".",
"sin",
"(",
"theta",
")",
"*",
"(",
"corners",
"[",
"i",
"]",
"-",
"cx",
")",
"+",
"Math",
".",
"cos",
"(",
"theta",
")",
"*",
"(",
"corners",
"[",
"i",
"+",
"1",
"]",
"-",
"cy",
")",
"+",
"cy",
")",
";",
"if",
"(",
"x",
">",
"maxX",
")",
"{",
"maxX",
"=",
"x",
";",
"}",
"if",
"(",
"x",
"<",
"minX",
")",
"{",
"minX",
"=",
"x",
";",
"}",
"if",
"(",
"y",
">",
"maxY",
")",
"{",
"maxY",
"=",
"y",
";",
"}",
"if",
"(",
"y",
"<",
"minY",
")",
"{",
"minY",
"=",
"y",
";",
"}",
"}",
"cx",
"=",
"(",
"cx",
"-",
"minX",
")",
";",
"cy",
"=",
"(",
"cy",
"-",
"minY",
")",
";",
"BufferedImage",
"bi",
"=",
"new",
"BufferedImage",
"(",
"(",
"maxX",
"-",
"minX",
")",
",",
"(",
"maxY",
"-",
"minY",
")",
",",
"image",
".",
"getType",
"(",
")",
")",
";",
"Graphics2D",
"g2",
"=",
"bi",
".",
"createGraphics",
"(",
")",
";",
"g2",
".",
"setRenderingHint",
"(",
"RenderingHints",
".",
"KEY_INTERPOLATION",
",",
"RenderingHints",
".",
"VALUE_INTERPOLATION_BICUBIC",
")",
";",
"g2",
".",
"setBackground",
"(",
"Color",
".",
"white",
")",
";",
"g2",
".",
"fillRect",
"(",
"0",
",",
"0",
",",
"bi",
".",
"getWidth",
"(",
")",
",",
"bi",
".",
"getHeight",
"(",
")",
")",
";",
"AffineTransform",
"at",
"=",
"new",
"AffineTransform",
"(",
")",
";",
"at",
".",
"rotate",
"(",
"theta",
",",
"cx",
",",
"cy",
")",
";",
"g2",
".",
"setTransform",
"(",
"at",
")",
";",
"g2",
".",
"drawImage",
"(",
"image",
",",
"-",
"minX",
",",
"-",
"minY",
",",
"null",
")",
";",
"g2",
".",
"dispose",
"(",
")",
";",
"return",
"bi",
";",
"}"
] |
Rotates image.
@param image source image
@param angle by degrees
@param cx x-coordinate of pivot point
@param cy y-coordinate of pivot point
@return rotated image
|
[
"Rotates",
"image",
"."
] |
cfcd4a8a44042f150b4aaf7bdf5ffc485a2236e1
|
https://github.com/nguyenq/tess4j/blob/cfcd4a8a44042f150b4aaf7bdf5ffc485a2236e1/src/main/java/com/recognition/software/jdeskew/ImageUtil.java#L83-L137
|
21,936
|
nguyenq/tess4j
|
src/main/java/net/sourceforge/tess4j/util/Utils.java
|
Utils.writeFile
|
public static void writeFile(byte[] data, File outFile) throws IOException {
// create parent dirs when necessary
if (outFile.getParentFile() != null) {
outFile.getParentFile().mkdirs();
}
try (FileOutputStream fos = new FileOutputStream(outFile)) {
fos.write(data);
}
}
|
java
|
public static void writeFile(byte[] data, File outFile) throws IOException {
// create parent dirs when necessary
if (outFile.getParentFile() != null) {
outFile.getParentFile().mkdirs();
}
try (FileOutputStream fos = new FileOutputStream(outFile)) {
fos.write(data);
}
}
|
[
"public",
"static",
"void",
"writeFile",
"(",
"byte",
"[",
"]",
"data",
",",
"File",
"outFile",
")",
"throws",
"IOException",
"{",
"// create parent dirs when necessary",
"if",
"(",
"outFile",
".",
"getParentFile",
"(",
")",
"!=",
"null",
")",
"{",
"outFile",
".",
"getParentFile",
"(",
")",
".",
"mkdirs",
"(",
")",
";",
"}",
"try",
"(",
"FileOutputStream",
"fos",
"=",
"new",
"FileOutputStream",
"(",
"outFile",
")",
")",
"{",
"fos",
".",
"write",
"(",
"data",
")",
";",
"}",
"}"
] |
Writes byte array to file.
@param data byte array
@param outFile output file
@throws IOException
|
[
"Writes",
"byte",
"array",
"to",
"file",
"."
] |
cfcd4a8a44042f150b4aaf7bdf5ffc485a2236e1
|
https://github.com/nguyenq/tess4j/blob/cfcd4a8a44042f150b4aaf7bdf5ffc485a2236e1/src/main/java/net/sourceforge/tess4j/util/Utils.java#L38-L46
|
21,937
|
nguyenq/tess4j
|
src/main/java/net/sourceforge/tess4j/util/Utils.java
|
Utils.getConstantName
|
public static String getConstantName(Object value, Class c) {
for (Field f : c.getDeclaredFields()) {
int mod = f.getModifiers();
if (Modifier.isStatic(mod) && Modifier.isPublic(mod) && Modifier.isFinal(mod)) {
try {
if (f.get(null).equals(value)) {
return f.getName();
}
} catch (IllegalAccessException e) {
return String.valueOf(value);
}
}
}
return String.valueOf(value);
}
|
java
|
public static String getConstantName(Object value, Class c) {
for (Field f : c.getDeclaredFields()) {
int mod = f.getModifiers();
if (Modifier.isStatic(mod) && Modifier.isPublic(mod) && Modifier.isFinal(mod)) {
try {
if (f.get(null).equals(value)) {
return f.getName();
}
} catch (IllegalAccessException e) {
return String.valueOf(value);
}
}
}
return String.valueOf(value);
}
|
[
"public",
"static",
"String",
"getConstantName",
"(",
"Object",
"value",
",",
"Class",
"c",
")",
"{",
"for",
"(",
"Field",
"f",
":",
"c",
".",
"getDeclaredFields",
"(",
")",
")",
"{",
"int",
"mod",
"=",
"f",
".",
"getModifiers",
"(",
")",
";",
"if",
"(",
"Modifier",
".",
"isStatic",
"(",
"mod",
")",
"&&",
"Modifier",
".",
"isPublic",
"(",
"mod",
")",
"&&",
"Modifier",
".",
"isFinal",
"(",
"mod",
")",
")",
"{",
"try",
"{",
"if",
"(",
"f",
".",
"get",
"(",
"null",
")",
".",
"equals",
"(",
"value",
")",
")",
"{",
"return",
"f",
".",
"getName",
"(",
")",
";",
"}",
"}",
"catch",
"(",
"IllegalAccessException",
"e",
")",
"{",
"return",
"String",
".",
"valueOf",
"(",
"value",
")",
";",
"}",
"}",
"}",
"return",
"String",
".",
"valueOf",
"(",
"value",
")",
";",
"}"
] |
Gets user-friendly name of the public static final constant defined in a
class or an interface for display purpose.
@param value the constant value
@param c type of class or interface
@return name
|
[
"Gets",
"user",
"-",
"friendly",
"name",
"of",
"the",
"public",
"static",
"final",
"constant",
"defined",
"in",
"a",
"class",
"or",
"an",
"interface",
"for",
"display",
"purpose",
"."
] |
cfcd4a8a44042f150b4aaf7bdf5ffc485a2236e1
|
https://github.com/nguyenq/tess4j/blob/cfcd4a8a44042f150b4aaf7bdf5ffc485a2236e1/src/main/java/net/sourceforge/tess4j/util/Utils.java#L56-L70
|
21,938
|
nguyenq/tess4j
|
src/main/java/net/sourceforge/tess4j/Tesseract.java
|
Tesseract.setImage
|
protected void setImage(int xsize, int ysize, ByteBuffer buf, Rectangle rect, int bpp) {
int bytespp = bpp / 8;
int bytespl = (int) Math.ceil(xsize * bpp / 8.0);
api.TessBaseAPISetImage(handle, buf, xsize, ysize, bytespp, bytespl);
if (rect != null && !rect.isEmpty()) {
api.TessBaseAPISetRectangle(handle, rect.x, rect.y, rect.width, rect.height);
}
}
|
java
|
protected void setImage(int xsize, int ysize, ByteBuffer buf, Rectangle rect, int bpp) {
int bytespp = bpp / 8;
int bytespl = (int) Math.ceil(xsize * bpp / 8.0);
api.TessBaseAPISetImage(handle, buf, xsize, ysize, bytespp, bytespl);
if (rect != null && !rect.isEmpty()) {
api.TessBaseAPISetRectangle(handle, rect.x, rect.y, rect.width, rect.height);
}
}
|
[
"protected",
"void",
"setImage",
"(",
"int",
"xsize",
",",
"int",
"ysize",
",",
"ByteBuffer",
"buf",
",",
"Rectangle",
"rect",
",",
"int",
"bpp",
")",
"{",
"int",
"bytespp",
"=",
"bpp",
"/",
"8",
";",
"int",
"bytespl",
"=",
"(",
"int",
")",
"Math",
".",
"ceil",
"(",
"xsize",
"*",
"bpp",
"/",
"8.0",
")",
";",
"api",
".",
"TessBaseAPISetImage",
"(",
"handle",
",",
"buf",
",",
"xsize",
",",
"ysize",
",",
"bytespp",
",",
"bytespl",
")",
";",
"if",
"(",
"rect",
"!=",
"null",
"&&",
"!",
"rect",
".",
"isEmpty",
"(",
")",
")",
"{",
"api",
".",
"TessBaseAPISetRectangle",
"(",
"handle",
",",
"rect",
".",
"x",
",",
"rect",
".",
"y",
",",
"rect",
".",
"width",
",",
"rect",
".",
"height",
")",
";",
"}",
"}"
] |
Sets image to be processed.
@param xsize width of image
@param ysize height of image
@param buf pixel data
@param rect the bounding rectangle defines the region of the image to be
recognized. A rectangle of zero dimension or <code>null</code> indicates
the whole image.
@param bpp bits per pixel, represents the bit depth of the image, with 1
for binary bitmap, 8 for gray, and 24 for color RGB.
|
[
"Sets",
"image",
"to",
"be",
"processed",
"."
] |
cfcd4a8a44042f150b4aaf7bdf5ffc485a2236e1
|
https://github.com/nguyenq/tess4j/blob/cfcd4a8a44042f150b4aaf7bdf5ffc485a2236e1/src/main/java/net/sourceforge/tess4j/Tesseract.java#L479-L487
|
21,939
|
nguyenq/tess4j
|
src/main/java/net/sourceforge/tess4j/Tesseract.java
|
Tesseract.getOCRText
|
protected String getOCRText(String filename, int pageNum) {
if (filename != null && !filename.isEmpty()) {
api.TessBaseAPISetInputName(handle, filename);
}
Pointer utf8Text = renderedFormat == RenderedFormat.HOCR ? api.TessBaseAPIGetHOCRText(handle, pageNum - 1) : api.TessBaseAPIGetUTF8Text(handle);
String str = utf8Text.getString(0);
api.TessDeleteText(utf8Text);
return str;
}
|
java
|
protected String getOCRText(String filename, int pageNum) {
if (filename != null && !filename.isEmpty()) {
api.TessBaseAPISetInputName(handle, filename);
}
Pointer utf8Text = renderedFormat == RenderedFormat.HOCR ? api.TessBaseAPIGetHOCRText(handle, pageNum - 1) : api.TessBaseAPIGetUTF8Text(handle);
String str = utf8Text.getString(0);
api.TessDeleteText(utf8Text);
return str;
}
|
[
"protected",
"String",
"getOCRText",
"(",
"String",
"filename",
",",
"int",
"pageNum",
")",
"{",
"if",
"(",
"filename",
"!=",
"null",
"&&",
"!",
"filename",
".",
"isEmpty",
"(",
")",
")",
"{",
"api",
".",
"TessBaseAPISetInputName",
"(",
"handle",
",",
"filename",
")",
";",
"}",
"Pointer",
"utf8Text",
"=",
"renderedFormat",
"==",
"RenderedFormat",
".",
"HOCR",
"?",
"api",
".",
"TessBaseAPIGetHOCRText",
"(",
"handle",
",",
"pageNum",
"-",
"1",
")",
":",
"api",
".",
"TessBaseAPIGetUTF8Text",
"(",
"handle",
")",
";",
"String",
"str",
"=",
"utf8Text",
".",
"getString",
"(",
"0",
")",
";",
"api",
".",
"TessDeleteText",
"(",
"utf8Text",
")",
";",
"return",
"str",
";",
"}"
] |
Gets recognized text.
@param filename input file name. Needed only for reading a UNLV zone
file.
@param pageNum page number; needed for hocr paging.
@return the recognized text
|
[
"Gets",
"recognized",
"text",
"."
] |
cfcd4a8a44042f150b4aaf7bdf5ffc485a2236e1
|
https://github.com/nguyenq/tess4j/blob/cfcd4a8a44042f150b4aaf7bdf5ffc485a2236e1/src/main/java/net/sourceforge/tess4j/Tesseract.java#L497-L506
|
21,940
|
nguyenq/tess4j
|
src/main/java/net/sourceforge/tess4j/Tesseract.java
|
Tesseract.createRenderers
|
private TessResultRenderer createRenderers(String outputbase, List<RenderedFormat> formats) {
TessResultRenderer renderer = null;
for (RenderedFormat format : formats) {
switch (format) {
case TEXT:
if (renderer == null) {
renderer = api.TessTextRendererCreate(outputbase);
} else {
api.TessResultRendererInsert(renderer, api.TessTextRendererCreate(outputbase));
}
break;
case HOCR:
if (renderer == null) {
renderer = api.TessHOcrRendererCreate(outputbase);
} else {
api.TessResultRendererInsert(renderer, api.TessHOcrRendererCreate(outputbase));
}
break;
case PDF:
String dataPath = api.TessBaseAPIGetDatapath(handle);
boolean textonly = String.valueOf(TRUE).equals(prop.getProperty("textonly_pdf"));
if (renderer == null) {
renderer = api.TessPDFRendererCreate(outputbase, dataPath, textonly ? TRUE : FALSE);
} else {
api.TessResultRendererInsert(renderer, api.TessPDFRendererCreate(outputbase, dataPath, textonly ? TRUE : FALSE));
}
break;
case BOX:
if (renderer == null) {
renderer = api.TessBoxTextRendererCreate(outputbase);
} else {
api.TessResultRendererInsert(renderer, api.TessBoxTextRendererCreate(outputbase));
}
break;
case UNLV:
if (renderer == null) {
renderer = api.TessUnlvRendererCreate(outputbase);
} else {
api.TessResultRendererInsert(renderer, api.TessUnlvRendererCreate(outputbase));
}
break;
case ALTO:
if (renderer == null) {
renderer = api.TessAltoRendererCreate(outputbase);
} else {
api.TessResultRendererInsert(renderer, api.TessAltoRendererCreate(outputbase));
}
break;
case TSV:
if (renderer == null) {
renderer = api.TessTsvRendererCreate(outputbase);
} else {
api.TessResultRendererInsert(renderer, api.TessTsvRendererCreate(outputbase));
}
break;
case LSTMBOX:
if (renderer == null) {
renderer = api.TessLSTMBoxRendererCreate(outputbase);
} else {
api.TessResultRendererInsert(renderer, api.TessLSTMBoxRendererCreate(outputbase));
}
break;
case WORDSTRBOX:
if (renderer == null) {
renderer = api.TessWordStrBoxRendererCreate(outputbase);
} else {
api.TessResultRendererInsert(renderer, api.TessWordStrBoxRendererCreate(outputbase));
}
break;
}
}
return renderer;
}
|
java
|
private TessResultRenderer createRenderers(String outputbase, List<RenderedFormat> formats) {
TessResultRenderer renderer = null;
for (RenderedFormat format : formats) {
switch (format) {
case TEXT:
if (renderer == null) {
renderer = api.TessTextRendererCreate(outputbase);
} else {
api.TessResultRendererInsert(renderer, api.TessTextRendererCreate(outputbase));
}
break;
case HOCR:
if (renderer == null) {
renderer = api.TessHOcrRendererCreate(outputbase);
} else {
api.TessResultRendererInsert(renderer, api.TessHOcrRendererCreate(outputbase));
}
break;
case PDF:
String dataPath = api.TessBaseAPIGetDatapath(handle);
boolean textonly = String.valueOf(TRUE).equals(prop.getProperty("textonly_pdf"));
if (renderer == null) {
renderer = api.TessPDFRendererCreate(outputbase, dataPath, textonly ? TRUE : FALSE);
} else {
api.TessResultRendererInsert(renderer, api.TessPDFRendererCreate(outputbase, dataPath, textonly ? TRUE : FALSE));
}
break;
case BOX:
if (renderer == null) {
renderer = api.TessBoxTextRendererCreate(outputbase);
} else {
api.TessResultRendererInsert(renderer, api.TessBoxTextRendererCreate(outputbase));
}
break;
case UNLV:
if (renderer == null) {
renderer = api.TessUnlvRendererCreate(outputbase);
} else {
api.TessResultRendererInsert(renderer, api.TessUnlvRendererCreate(outputbase));
}
break;
case ALTO:
if (renderer == null) {
renderer = api.TessAltoRendererCreate(outputbase);
} else {
api.TessResultRendererInsert(renderer, api.TessAltoRendererCreate(outputbase));
}
break;
case TSV:
if (renderer == null) {
renderer = api.TessTsvRendererCreate(outputbase);
} else {
api.TessResultRendererInsert(renderer, api.TessTsvRendererCreate(outputbase));
}
break;
case LSTMBOX:
if (renderer == null) {
renderer = api.TessLSTMBoxRendererCreate(outputbase);
} else {
api.TessResultRendererInsert(renderer, api.TessLSTMBoxRendererCreate(outputbase));
}
break;
case WORDSTRBOX:
if (renderer == null) {
renderer = api.TessWordStrBoxRendererCreate(outputbase);
} else {
api.TessResultRendererInsert(renderer, api.TessWordStrBoxRendererCreate(outputbase));
}
break;
}
}
return renderer;
}
|
[
"private",
"TessResultRenderer",
"createRenderers",
"(",
"String",
"outputbase",
",",
"List",
"<",
"RenderedFormat",
">",
"formats",
")",
"{",
"TessResultRenderer",
"renderer",
"=",
"null",
";",
"for",
"(",
"RenderedFormat",
"format",
":",
"formats",
")",
"{",
"switch",
"(",
"format",
")",
"{",
"case",
"TEXT",
":",
"if",
"(",
"renderer",
"==",
"null",
")",
"{",
"renderer",
"=",
"api",
".",
"TessTextRendererCreate",
"(",
"outputbase",
")",
";",
"}",
"else",
"{",
"api",
".",
"TessResultRendererInsert",
"(",
"renderer",
",",
"api",
".",
"TessTextRendererCreate",
"(",
"outputbase",
")",
")",
";",
"}",
"break",
";",
"case",
"HOCR",
":",
"if",
"(",
"renderer",
"==",
"null",
")",
"{",
"renderer",
"=",
"api",
".",
"TessHOcrRendererCreate",
"(",
"outputbase",
")",
";",
"}",
"else",
"{",
"api",
".",
"TessResultRendererInsert",
"(",
"renderer",
",",
"api",
".",
"TessHOcrRendererCreate",
"(",
"outputbase",
")",
")",
";",
"}",
"break",
";",
"case",
"PDF",
":",
"String",
"dataPath",
"=",
"api",
".",
"TessBaseAPIGetDatapath",
"(",
"handle",
")",
";",
"boolean",
"textonly",
"=",
"String",
".",
"valueOf",
"(",
"TRUE",
")",
".",
"equals",
"(",
"prop",
".",
"getProperty",
"(",
"\"textonly_pdf\"",
")",
")",
";",
"if",
"(",
"renderer",
"==",
"null",
")",
"{",
"renderer",
"=",
"api",
".",
"TessPDFRendererCreate",
"(",
"outputbase",
",",
"dataPath",
",",
"textonly",
"?",
"TRUE",
":",
"FALSE",
")",
";",
"}",
"else",
"{",
"api",
".",
"TessResultRendererInsert",
"(",
"renderer",
",",
"api",
".",
"TessPDFRendererCreate",
"(",
"outputbase",
",",
"dataPath",
",",
"textonly",
"?",
"TRUE",
":",
"FALSE",
")",
")",
";",
"}",
"break",
";",
"case",
"BOX",
":",
"if",
"(",
"renderer",
"==",
"null",
")",
"{",
"renderer",
"=",
"api",
".",
"TessBoxTextRendererCreate",
"(",
"outputbase",
")",
";",
"}",
"else",
"{",
"api",
".",
"TessResultRendererInsert",
"(",
"renderer",
",",
"api",
".",
"TessBoxTextRendererCreate",
"(",
"outputbase",
")",
")",
";",
"}",
"break",
";",
"case",
"UNLV",
":",
"if",
"(",
"renderer",
"==",
"null",
")",
"{",
"renderer",
"=",
"api",
".",
"TessUnlvRendererCreate",
"(",
"outputbase",
")",
";",
"}",
"else",
"{",
"api",
".",
"TessResultRendererInsert",
"(",
"renderer",
",",
"api",
".",
"TessUnlvRendererCreate",
"(",
"outputbase",
")",
")",
";",
"}",
"break",
";",
"case",
"ALTO",
":",
"if",
"(",
"renderer",
"==",
"null",
")",
"{",
"renderer",
"=",
"api",
".",
"TessAltoRendererCreate",
"(",
"outputbase",
")",
";",
"}",
"else",
"{",
"api",
".",
"TessResultRendererInsert",
"(",
"renderer",
",",
"api",
".",
"TessAltoRendererCreate",
"(",
"outputbase",
")",
")",
";",
"}",
"break",
";",
"case",
"TSV",
":",
"if",
"(",
"renderer",
"==",
"null",
")",
"{",
"renderer",
"=",
"api",
".",
"TessTsvRendererCreate",
"(",
"outputbase",
")",
";",
"}",
"else",
"{",
"api",
".",
"TessResultRendererInsert",
"(",
"renderer",
",",
"api",
".",
"TessTsvRendererCreate",
"(",
"outputbase",
")",
")",
";",
"}",
"break",
";",
"case",
"LSTMBOX",
":",
"if",
"(",
"renderer",
"==",
"null",
")",
"{",
"renderer",
"=",
"api",
".",
"TessLSTMBoxRendererCreate",
"(",
"outputbase",
")",
";",
"}",
"else",
"{",
"api",
".",
"TessResultRendererInsert",
"(",
"renderer",
",",
"api",
".",
"TessLSTMBoxRendererCreate",
"(",
"outputbase",
")",
")",
";",
"}",
"break",
";",
"case",
"WORDSTRBOX",
":",
"if",
"(",
"renderer",
"==",
"null",
")",
"{",
"renderer",
"=",
"api",
".",
"TessWordStrBoxRendererCreate",
"(",
"outputbase",
")",
";",
"}",
"else",
"{",
"api",
".",
"TessResultRendererInsert",
"(",
"renderer",
",",
"api",
".",
"TessWordStrBoxRendererCreate",
"(",
"outputbase",
")",
")",
";",
"}",
"break",
";",
"}",
"}",
"return",
"renderer",
";",
"}"
] |
Creates renderers for given formats.
@param outputbase
@param formats
@return
|
[
"Creates",
"renderers",
"for",
"given",
"formats",
"."
] |
cfcd4a8a44042f150b4aaf7bdf5ffc485a2236e1
|
https://github.com/nguyenq/tess4j/blob/cfcd4a8a44042f150b4aaf7bdf5ffc485a2236e1/src/main/java/net/sourceforge/tess4j/Tesseract.java#L515-L589
|
21,941
|
nguyenq/tess4j
|
src/main/java/net/sourceforge/tess4j/Tesseract.java
|
Tesseract.getRecognizedWords
|
private List<Word> getRecognizedWords(int pageIteratorLevel) {
List<Word> words = new ArrayList<Word>();
try {
TessResultIterator ri = api.TessBaseAPIGetIterator(handle);
TessPageIterator pi = api.TessResultIteratorGetPageIterator(ri);
api.TessPageIteratorBegin(pi);
do {
Pointer ptr = api.TessResultIteratorGetUTF8Text(ri, pageIteratorLevel);
String text = ptr.getString(0);
api.TessDeleteText(ptr);
float confidence = api.TessResultIteratorConfidence(ri, pageIteratorLevel);
IntBuffer leftB = IntBuffer.allocate(1);
IntBuffer topB = IntBuffer.allocate(1);
IntBuffer rightB = IntBuffer.allocate(1);
IntBuffer bottomB = IntBuffer.allocate(1);
api.TessPageIteratorBoundingBox(pi, pageIteratorLevel, leftB, topB, rightB, bottomB);
int left = leftB.get();
int top = topB.get();
int right = rightB.get();
int bottom = bottomB.get();
Word word = new Word(text, confidence, new Rectangle(left, top, right - left, bottom - top));
words.add(word);
} while (api.TessPageIteratorNext(pi, pageIteratorLevel) == TRUE);
} catch (Exception e) {
logger.warn(e.getMessage(), e);
}
return words;
}
|
java
|
private List<Word> getRecognizedWords(int pageIteratorLevel) {
List<Word> words = new ArrayList<Word>();
try {
TessResultIterator ri = api.TessBaseAPIGetIterator(handle);
TessPageIterator pi = api.TessResultIteratorGetPageIterator(ri);
api.TessPageIteratorBegin(pi);
do {
Pointer ptr = api.TessResultIteratorGetUTF8Text(ri, pageIteratorLevel);
String text = ptr.getString(0);
api.TessDeleteText(ptr);
float confidence = api.TessResultIteratorConfidence(ri, pageIteratorLevel);
IntBuffer leftB = IntBuffer.allocate(1);
IntBuffer topB = IntBuffer.allocate(1);
IntBuffer rightB = IntBuffer.allocate(1);
IntBuffer bottomB = IntBuffer.allocate(1);
api.TessPageIteratorBoundingBox(pi, pageIteratorLevel, leftB, topB, rightB, bottomB);
int left = leftB.get();
int top = topB.get();
int right = rightB.get();
int bottom = bottomB.get();
Word word = new Word(text, confidence, new Rectangle(left, top, right - left, bottom - top));
words.add(word);
} while (api.TessPageIteratorNext(pi, pageIteratorLevel) == TRUE);
} catch (Exception e) {
logger.warn(e.getMessage(), e);
}
return words;
}
|
[
"private",
"List",
"<",
"Word",
">",
"getRecognizedWords",
"(",
"int",
"pageIteratorLevel",
")",
"{",
"List",
"<",
"Word",
">",
"words",
"=",
"new",
"ArrayList",
"<",
"Word",
">",
"(",
")",
";",
"try",
"{",
"TessResultIterator",
"ri",
"=",
"api",
".",
"TessBaseAPIGetIterator",
"(",
"handle",
")",
";",
"TessPageIterator",
"pi",
"=",
"api",
".",
"TessResultIteratorGetPageIterator",
"(",
"ri",
")",
";",
"api",
".",
"TessPageIteratorBegin",
"(",
"pi",
")",
";",
"do",
"{",
"Pointer",
"ptr",
"=",
"api",
".",
"TessResultIteratorGetUTF8Text",
"(",
"ri",
",",
"pageIteratorLevel",
")",
";",
"String",
"text",
"=",
"ptr",
".",
"getString",
"(",
"0",
")",
";",
"api",
".",
"TessDeleteText",
"(",
"ptr",
")",
";",
"float",
"confidence",
"=",
"api",
".",
"TessResultIteratorConfidence",
"(",
"ri",
",",
"pageIteratorLevel",
")",
";",
"IntBuffer",
"leftB",
"=",
"IntBuffer",
".",
"allocate",
"(",
"1",
")",
";",
"IntBuffer",
"topB",
"=",
"IntBuffer",
".",
"allocate",
"(",
"1",
")",
";",
"IntBuffer",
"rightB",
"=",
"IntBuffer",
".",
"allocate",
"(",
"1",
")",
";",
"IntBuffer",
"bottomB",
"=",
"IntBuffer",
".",
"allocate",
"(",
"1",
")",
";",
"api",
".",
"TessPageIteratorBoundingBox",
"(",
"pi",
",",
"pageIteratorLevel",
",",
"leftB",
",",
"topB",
",",
"rightB",
",",
"bottomB",
")",
";",
"int",
"left",
"=",
"leftB",
".",
"get",
"(",
")",
";",
"int",
"top",
"=",
"topB",
".",
"get",
"(",
")",
";",
"int",
"right",
"=",
"rightB",
".",
"get",
"(",
")",
";",
"int",
"bottom",
"=",
"bottomB",
".",
"get",
"(",
")",
";",
"Word",
"word",
"=",
"new",
"Word",
"(",
"text",
",",
"confidence",
",",
"new",
"Rectangle",
"(",
"left",
",",
"top",
",",
"right",
"-",
"left",
",",
"bottom",
"-",
"top",
")",
")",
";",
"words",
".",
"add",
"(",
"word",
")",
";",
"}",
"while",
"(",
"api",
".",
"TessPageIteratorNext",
"(",
"pi",
",",
"pageIteratorLevel",
")",
"==",
"TRUE",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"logger",
".",
"warn",
"(",
"e",
".",
"getMessage",
"(",
")",
",",
"e",
")",
";",
"}",
"return",
"words",
";",
"}"
] |
Gets result words at specified page iterator level from recognized pages.
@param pageIteratorLevel TessPageIteratorLevel enum
@return list of <code>Word</code>
|
[
"Gets",
"result",
"words",
"at",
"specified",
"page",
"iterator",
"level",
"from",
"recognized",
"pages",
"."
] |
cfcd4a8a44042f150b4aaf7bdf5ffc485a2236e1
|
https://github.com/nguyenq/tess4j/blob/cfcd4a8a44042f150b4aaf7bdf5ffc485a2236e1/src/main/java/net/sourceforge/tess4j/Tesseract.java#L818-L848
|
21,942
|
youseries/urule
|
urule-console/src/main/java/com/bstek/urule/console/repository/database/journal/DatabaseJournal.java
|
DatabaseJournal.initInstanceRevisionAndJanitor
|
protected void initInstanceRevisionAndJanitor() throws Exception {
databaseRevision = new DatabaseRevision();
// Get the local file revision from disk (upgrade; see JCR-1087)
long localFileRevision = 0L;
if (getRevision() != null) {
InstanceRevision currentFileRevision = new FileRevision(new File(getRevision()), true);
localFileRevision = currentFileRevision.get();
currentFileRevision.close();
}
// Now write the localFileRevision (or 0 if it does not exist) to the LOCAL_REVISIONS
// table, but only if the LOCAL_REVISIONS table has no entry yet for this cluster node
long localRevision = databaseRevision.init(localFileRevision);
log.info("Initialized local revision to " + localRevision);
// Start the clean-up thread if necessary.
if (janitorEnabled) {
janitorThread = new Thread(new RevisionTableJanitor(), "Jackrabbit-ClusterRevisionJanitor");
janitorThread.setDaemon(true);
janitorThread.start();
log.info("Cluster revision janitor thread started; first run scheduled at " + janitorNextRun.getTime());
} else {
log.info("Cluster revision janitor thread not started");
}
}
|
java
|
protected void initInstanceRevisionAndJanitor() throws Exception {
databaseRevision = new DatabaseRevision();
// Get the local file revision from disk (upgrade; see JCR-1087)
long localFileRevision = 0L;
if (getRevision() != null) {
InstanceRevision currentFileRevision = new FileRevision(new File(getRevision()), true);
localFileRevision = currentFileRevision.get();
currentFileRevision.close();
}
// Now write the localFileRevision (or 0 if it does not exist) to the LOCAL_REVISIONS
// table, but only if the LOCAL_REVISIONS table has no entry yet for this cluster node
long localRevision = databaseRevision.init(localFileRevision);
log.info("Initialized local revision to " + localRevision);
// Start the clean-up thread if necessary.
if (janitorEnabled) {
janitorThread = new Thread(new RevisionTableJanitor(), "Jackrabbit-ClusterRevisionJanitor");
janitorThread.setDaemon(true);
janitorThread.start();
log.info("Cluster revision janitor thread started; first run scheduled at " + janitorNextRun.getTime());
} else {
log.info("Cluster revision janitor thread not started");
}
}
|
[
"protected",
"void",
"initInstanceRevisionAndJanitor",
"(",
")",
"throws",
"Exception",
"{",
"databaseRevision",
"=",
"new",
"DatabaseRevision",
"(",
")",
";",
"// Get the local file revision from disk (upgrade; see JCR-1087)",
"long",
"localFileRevision",
"=",
"0L",
";",
"if",
"(",
"getRevision",
"(",
")",
"!=",
"null",
")",
"{",
"InstanceRevision",
"currentFileRevision",
"=",
"new",
"FileRevision",
"(",
"new",
"File",
"(",
"getRevision",
"(",
")",
")",
",",
"true",
")",
";",
"localFileRevision",
"=",
"currentFileRevision",
".",
"get",
"(",
")",
";",
"currentFileRevision",
".",
"close",
"(",
")",
";",
"}",
"// Now write the localFileRevision (or 0 if it does not exist) to the LOCAL_REVISIONS",
"// table, but only if the LOCAL_REVISIONS table has no entry yet for this cluster node",
"long",
"localRevision",
"=",
"databaseRevision",
".",
"init",
"(",
"localFileRevision",
")",
";",
"log",
".",
"info",
"(",
"\"Initialized local revision to \"",
"+",
"localRevision",
")",
";",
"// Start the clean-up thread if necessary.",
"if",
"(",
"janitorEnabled",
")",
"{",
"janitorThread",
"=",
"new",
"Thread",
"(",
"new",
"RevisionTableJanitor",
"(",
")",
",",
"\"Jackrabbit-ClusterRevisionJanitor\"",
")",
";",
"janitorThread",
".",
"setDaemon",
"(",
"true",
")",
";",
"janitorThread",
".",
"start",
"(",
")",
";",
"log",
".",
"info",
"(",
"\"Cluster revision janitor thread started; first run scheduled at \"",
"+",
"janitorNextRun",
".",
"getTime",
"(",
")",
")",
";",
"}",
"else",
"{",
"log",
".",
"info",
"(",
"\"Cluster revision janitor thread not started\"",
")",
";",
"}",
"}"
] |
Initialize the instance revision manager and the janitor thread.
@throws JournalException on error
|
[
"Initialize",
"the",
"instance",
"revision",
"manager",
"and",
"the",
"janitor",
"thread",
"."
] |
3fa0eb4439e97aa292e744bcbd88a9faa36661d8
|
https://github.com/youseries/urule/blob/3fa0eb4439e97aa292e744bcbd88a9faa36661d8/urule-console/src/main/java/com/bstek/urule/console/repository/database/journal/DatabaseJournal.java#L306-L331
|
21,943
|
youseries/urule
|
urule-console/src/main/java/com/bstek/urule/console/repository/database/journal/DatabaseJournal.java
|
DatabaseJournal.append
|
protected void append(AppendRecord record, InputStream in, int length)
throws JournalException {
try {
conHelper.exec(insertRevisionStmtSQL, record.getRevision(), getId(), record.getProducerId(),
new StreamWrapper(in, length));
} catch (SQLException e) {
String msg = "Unable to append revision " + lockedRevision + ".";
throw new JournalException(msg, e);
}
}
|
java
|
protected void append(AppendRecord record, InputStream in, int length)
throws JournalException {
try {
conHelper.exec(insertRevisionStmtSQL, record.getRevision(), getId(), record.getProducerId(),
new StreamWrapper(in, length));
} catch (SQLException e) {
String msg = "Unable to append revision " + lockedRevision + ".";
throw new JournalException(msg, e);
}
}
|
[
"protected",
"void",
"append",
"(",
"AppendRecord",
"record",
",",
"InputStream",
"in",
",",
"int",
"length",
")",
"throws",
"JournalException",
"{",
"try",
"{",
"conHelper",
".",
"exec",
"(",
"insertRevisionStmtSQL",
",",
"record",
".",
"getRevision",
"(",
")",
",",
"getId",
"(",
")",
",",
"record",
".",
"getProducerId",
"(",
")",
",",
"new",
"StreamWrapper",
"(",
"in",
",",
"length",
")",
")",
";",
"}",
"catch",
"(",
"SQLException",
"e",
")",
"{",
"String",
"msg",
"=",
"\"Unable to append revision \"",
"+",
"lockedRevision",
"+",
"\".\"",
";",
"throw",
"new",
"JournalException",
"(",
"msg",
",",
"e",
")",
";",
"}",
"}"
] |
We have already saved away the revision for this record.
|
[
"We",
"have",
"already",
"saved",
"away",
"the",
"revision",
"for",
"this",
"record",
"."
] |
3fa0eb4439e97aa292e744bcbd88a9faa36661d8
|
https://github.com/youseries/urule/blob/3fa0eb4439e97aa292e744bcbd88a9faa36661d8/urule-console/src/main/java/com/bstek/urule/console/repository/database/journal/DatabaseJournal.java#L458-L469
|
21,944
|
youseries/urule
|
urule-console/src/main/java/com/bstek/urule/console/repository/database/journal/DatabaseJournal.java
|
DatabaseJournal.checkLocalRevisionSchema
|
private void checkLocalRevisionSchema() throws Exception {
InputStream localRevisionDDLStream = null;
InputStream in = org.apache.jackrabbit.core.journal.DatabaseJournal.class.getResourceAsStream(databaseType + ".ddl");
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
String sql = reader.readLine();
while (sql != null) {
// Skip comments and empty lines, and select only the statement to create the LOCAL_REVISIONS
// table.
if (!sql.startsWith("#") && sql.length() > 0 && sql.indexOf(LOCAL_REVISIONS_TABLE) != -1) {
localRevisionDDLStream = new ByteArrayInputStream(sql.getBytes());
break;
}
// read next sql stmt
sql = reader.readLine();
}
} finally {
IOUtils.closeQuietly(in);
}
// Run the schema check for the single table
new CheckSchemaOperation(conHelper, localRevisionDDLStream, schemaObjectPrefix
+ LOCAL_REVISIONS_TABLE).addVariableReplacement(
CheckSchemaOperation.SCHEMA_OBJECT_PREFIX_VARIABLE, schemaObjectPrefix).run();
}
|
java
|
private void checkLocalRevisionSchema() throws Exception {
InputStream localRevisionDDLStream = null;
InputStream in = org.apache.jackrabbit.core.journal.DatabaseJournal.class.getResourceAsStream(databaseType + ".ddl");
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
String sql = reader.readLine();
while (sql != null) {
// Skip comments and empty lines, and select only the statement to create the LOCAL_REVISIONS
// table.
if (!sql.startsWith("#") && sql.length() > 0 && sql.indexOf(LOCAL_REVISIONS_TABLE) != -1) {
localRevisionDDLStream = new ByteArrayInputStream(sql.getBytes());
break;
}
// read next sql stmt
sql = reader.readLine();
}
} finally {
IOUtils.closeQuietly(in);
}
// Run the schema check for the single table
new CheckSchemaOperation(conHelper, localRevisionDDLStream, schemaObjectPrefix
+ LOCAL_REVISIONS_TABLE).addVariableReplacement(
CheckSchemaOperation.SCHEMA_OBJECT_PREFIX_VARIABLE, schemaObjectPrefix).run();
}
|
[
"private",
"void",
"checkLocalRevisionSchema",
"(",
")",
"throws",
"Exception",
"{",
"InputStream",
"localRevisionDDLStream",
"=",
"null",
";",
"InputStream",
"in",
"=",
"org",
".",
"apache",
".",
"jackrabbit",
".",
"core",
".",
"journal",
".",
"DatabaseJournal",
".",
"class",
".",
"getResourceAsStream",
"(",
"databaseType",
"+",
"\".ddl\"",
")",
";",
"try",
"{",
"BufferedReader",
"reader",
"=",
"new",
"BufferedReader",
"(",
"new",
"InputStreamReader",
"(",
"in",
")",
")",
";",
"String",
"sql",
"=",
"reader",
".",
"readLine",
"(",
")",
";",
"while",
"(",
"sql",
"!=",
"null",
")",
"{",
"// Skip comments and empty lines, and select only the statement to create the LOCAL_REVISIONS",
"// table.",
"if",
"(",
"!",
"sql",
".",
"startsWith",
"(",
"\"#\"",
")",
"&&",
"sql",
".",
"length",
"(",
")",
">",
"0",
"&&",
"sql",
".",
"indexOf",
"(",
"LOCAL_REVISIONS_TABLE",
")",
"!=",
"-",
"1",
")",
"{",
"localRevisionDDLStream",
"=",
"new",
"ByteArrayInputStream",
"(",
"sql",
".",
"getBytes",
"(",
")",
")",
";",
"break",
";",
"}",
"// read next sql stmt",
"sql",
"=",
"reader",
".",
"readLine",
"(",
")",
";",
"}",
"}",
"finally",
"{",
"IOUtils",
".",
"closeQuietly",
"(",
"in",
")",
";",
"}",
"// Run the schema check for the single table",
"new",
"CheckSchemaOperation",
"(",
"conHelper",
",",
"localRevisionDDLStream",
",",
"schemaObjectPrefix",
"+",
"LOCAL_REVISIONS_TABLE",
")",
".",
"addVariableReplacement",
"(",
"CheckSchemaOperation",
".",
"SCHEMA_OBJECT_PREFIX_VARIABLE",
",",
"schemaObjectPrefix",
")",
".",
"run",
"(",
")",
";",
"}"
] |
Checks if the local revision schema objects exist and creates them if they
don't exist yet.
@throws Exception if an error occurs
|
[
"Checks",
"if",
"the",
"local",
"revision",
"schema",
"objects",
"exist",
"and",
"creates",
"them",
"if",
"they",
"don",
"t",
"exist",
"yet",
"."
] |
3fa0eb4439e97aa292e744bcbd88a9faa36661d8
|
https://github.com/youseries/urule/blob/3fa0eb4439e97aa292e744bcbd88a9faa36661d8/urule-console/src/main/java/com/bstek/urule/console/repository/database/journal/DatabaseJournal.java#L483-L506
|
21,945
|
youseries/urule
|
urule-console/src/main/java/com/bstek/urule/console/repository/database/DbPersistenceManager.java
|
DbPersistenceManager.getNameIndex
|
public StringIndex getNameIndex() {
try {
if (nameIndex == null) {
FileSystemResource res = new FileSystemResource(context.getFileSystem(), RES_NAME_INDEX);
if (res.exists()) {
nameIndex = super.getNameIndex();
} else {
// create db nameindex
nameIndex = createDbNameIndex();
}
}
return nameIndex;
} catch (Exception e) {
IllegalStateException exception =
new IllegalStateException("Unable to create nsIndex");
exception.initCause(e);
throw exception;
}
}
|
java
|
public StringIndex getNameIndex() {
try {
if (nameIndex == null) {
FileSystemResource res = new FileSystemResource(context.getFileSystem(), RES_NAME_INDEX);
if (res.exists()) {
nameIndex = super.getNameIndex();
} else {
// create db nameindex
nameIndex = createDbNameIndex();
}
}
return nameIndex;
} catch (Exception e) {
IllegalStateException exception =
new IllegalStateException("Unable to create nsIndex");
exception.initCause(e);
throw exception;
}
}
|
[
"public",
"StringIndex",
"getNameIndex",
"(",
")",
"{",
"try",
"{",
"if",
"(",
"nameIndex",
"==",
"null",
")",
"{",
"FileSystemResource",
"res",
"=",
"new",
"FileSystemResource",
"(",
"context",
".",
"getFileSystem",
"(",
")",
",",
"RES_NAME_INDEX",
")",
";",
"if",
"(",
"res",
".",
"exists",
"(",
")",
")",
"{",
"nameIndex",
"=",
"super",
".",
"getNameIndex",
"(",
")",
";",
"}",
"else",
"{",
"// create db nameindex",
"nameIndex",
"=",
"createDbNameIndex",
"(",
")",
";",
"}",
"}",
"return",
"nameIndex",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"IllegalStateException",
"exception",
"=",
"new",
"IllegalStateException",
"(",
"\"Unable to create nsIndex\"",
")",
";",
"exception",
".",
"initCause",
"(",
"e",
")",
";",
"throw",
"exception",
";",
"}",
"}"
] |
Returns the local name index
@return the local name index
@throws IllegalStateException if an error occurs.
|
[
"Returns",
"the",
"local",
"name",
"index"
] |
3fa0eb4439e97aa292e744bcbd88a9faa36661d8
|
https://github.com/youseries/urule/blob/3fa0eb4439e97aa292e744bcbd88a9faa36661d8/urule-console/src/main/java/com/bstek/urule/console/repository/database/DbPersistenceManager.java#L611-L629
|
21,946
|
youseries/urule
|
urule-console/src/main/java/com/bstek/urule/console/repository/database/DbPersistenceManager.java
|
DbPersistenceManager.getKey
|
protected Object[] getKey(NodeId id) {
if (getStorageModel() == SM_BINARY_KEYS) {
return new Object[] { id.getRawBytes() };
} else {
return new Object[] {
id.getMostSignificantBits(), id.getLeastSignificantBits() };
}
}
|
java
|
protected Object[] getKey(NodeId id) {
if (getStorageModel() == SM_BINARY_KEYS) {
return new Object[] { id.getRawBytes() };
} else {
return new Object[] {
id.getMostSignificantBits(), id.getLeastSignificantBits() };
}
}
|
[
"protected",
"Object",
"[",
"]",
"getKey",
"(",
"NodeId",
"id",
")",
"{",
"if",
"(",
"getStorageModel",
"(",
")",
"==",
"SM_BINARY_KEYS",
")",
"{",
"return",
"new",
"Object",
"[",
"]",
"{",
"id",
".",
"getRawBytes",
"(",
")",
"}",
";",
"}",
"else",
"{",
"return",
"new",
"Object",
"[",
"]",
"{",
"id",
".",
"getMostSignificantBits",
"(",
")",
",",
"id",
".",
"getLeastSignificantBits",
"(",
")",
"}",
";",
"}",
"}"
] |
Constructs a parameter list for a PreparedStatement
for the given node identifier.
@param id the node id
@return a list of Objects
|
[
"Constructs",
"a",
"parameter",
"list",
"for",
"a",
"PreparedStatement",
"for",
"the",
"given",
"node",
"identifier",
"."
] |
3fa0eb4439e97aa292e744bcbd88a9faa36661d8
|
https://github.com/youseries/urule/blob/3fa0eb4439e97aa292e744bcbd88a9faa36661d8/urule-console/src/main/java/com/bstek/urule/console/repository/database/DbPersistenceManager.java#L710-L717
|
21,947
|
youseries/urule
|
urule-console/src/main/java/com/bstek/urule/console/repository/database/DbPersistenceManager.java
|
DbPersistenceManager.readBundle
|
private NodePropBundle readBundle(NodeId id, ResultSet rs, int column)
throws SQLException {
try {
InputStream in;
if (rs.getMetaData().getColumnType(column) == Types.BLOB) {
in = rs.getBlob(column).getBinaryStream();
} else {
in = rs.getBinaryStream(column);
}
try {
return binding.readBundle(in, id);
} finally {
in.close();
}
} catch (IOException e) {
SQLException exception =
new SQLException("Failed to parse bundle " + id);
exception.initCause(e);
throw exception;
}
}
|
java
|
private NodePropBundle readBundle(NodeId id, ResultSet rs, int column)
throws SQLException {
try {
InputStream in;
if (rs.getMetaData().getColumnType(column) == Types.BLOB) {
in = rs.getBlob(column).getBinaryStream();
} else {
in = rs.getBinaryStream(column);
}
try {
return binding.readBundle(in, id);
} finally {
in.close();
}
} catch (IOException e) {
SQLException exception =
new SQLException("Failed to parse bundle " + id);
exception.initCause(e);
throw exception;
}
}
|
[
"private",
"NodePropBundle",
"readBundle",
"(",
"NodeId",
"id",
",",
"ResultSet",
"rs",
",",
"int",
"column",
")",
"throws",
"SQLException",
"{",
"try",
"{",
"InputStream",
"in",
";",
"if",
"(",
"rs",
".",
"getMetaData",
"(",
")",
".",
"getColumnType",
"(",
"column",
")",
"==",
"Types",
".",
"BLOB",
")",
"{",
"in",
"=",
"rs",
".",
"getBlob",
"(",
"column",
")",
".",
"getBinaryStream",
"(",
")",
";",
"}",
"else",
"{",
"in",
"=",
"rs",
".",
"getBinaryStream",
"(",
"column",
")",
";",
"}",
"try",
"{",
"return",
"binding",
".",
"readBundle",
"(",
"in",
",",
"id",
")",
";",
"}",
"finally",
"{",
"in",
".",
"close",
"(",
")",
";",
"}",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"SQLException",
"exception",
"=",
"new",
"SQLException",
"(",
"\"Failed to parse bundle \"",
"+",
"id",
")",
";",
"exception",
".",
"initCause",
"(",
"e",
")",
";",
"throw",
"exception",
";",
"}",
"}"
] |
Reads and parses a bundle from the BLOB in the given column of the
current row of the given result set. This is a helper method to
circumvent issues JCR-1039 and JCR-1474.
@param id bundle identifier
@param rs result set
@param column BLOB column
@return parsed bundle
@throws SQLException if the bundle can not be read or parsed
|
[
"Reads",
"and",
"parses",
"a",
"bundle",
"from",
"the",
"BLOB",
"in",
"the",
"given",
"column",
"of",
"the",
"current",
"row",
"of",
"the",
"given",
"result",
"set",
".",
"This",
"is",
"a",
"helper",
"method",
"to",
"circumvent",
"issues",
"JCR",
"-",
"1039",
"and",
"JCR",
"-",
"1474",
"."
] |
3fa0eb4439e97aa292e744bcbd88a9faa36661d8
|
https://github.com/youseries/urule/blob/3fa0eb4439e97aa292e744bcbd88a9faa36661d8/urule-console/src/main/java/com/bstek/urule/console/repository/database/DbPersistenceManager.java#L895-L915
|
21,948
|
youseries/urule
|
urule-console/src/main/java/com/bstek/urule/console/repository/database/DbPersistenceManager.java
|
DbPersistenceManager.buildSQLStatements
|
protected void buildSQLStatements() {
// prepare statements
if (getStorageModel() == SM_BINARY_KEYS) {
bundleInsertSQL = "insert into " + schemaObjectPrefix + "BUNDLE (BUNDLE_DATA, NODE_ID) values (?, ?)";
bundleUpdateSQL = "update " + schemaObjectPrefix + "BUNDLE set BUNDLE_DATA = ? where NODE_ID = ?";
bundleSelectSQL = "select BUNDLE_DATA from " + schemaObjectPrefix + "BUNDLE where NODE_ID = ?";
bundleDeleteSQL = "delete from " + schemaObjectPrefix + "BUNDLE where NODE_ID = ?";
nodeReferenceInsertSQL = "insert into " + schemaObjectPrefix + "REFS (REFS_DATA, NODE_ID) values (?, ?)";
nodeReferenceUpdateSQL = "update " + schemaObjectPrefix + "REFS set REFS_DATA = ? where NODE_ID = ?";
nodeReferenceSelectSQL = "select REFS_DATA from " + schemaObjectPrefix + "REFS where NODE_ID = ?";
nodeReferenceDeleteSQL = "delete from " + schemaObjectPrefix + "REFS where NODE_ID = ?";
bundleSelectAllIdsSQL = "select NODE_ID from " + schemaObjectPrefix + "BUNDLE ORDER BY NODE_ID";
bundleSelectAllIdsFromSQL = "select NODE_ID from " + schemaObjectPrefix + "BUNDLE WHERE NODE_ID > ? ORDER BY NODE_ID";
bundleSelectAllBundlesSQL = "select NODE_ID, BUNDLE_DATA from " + schemaObjectPrefix + "BUNDLE ORDER BY NODE_ID";
bundleSelectAllBundlesFromSQL = "select NODE_ID, BUNDLE_DATA from " + schemaObjectPrefix + "BUNDLE WHERE NODE_ID > ? ORDER BY NODE_ID";
} else {
bundleInsertSQL = "insert into " + schemaObjectPrefix + "BUNDLE (BUNDLE_DATA, NODE_ID_HI, NODE_ID_LO) values (?, ?, ?)";
bundleUpdateSQL = "update " + schemaObjectPrefix + "BUNDLE set BUNDLE_DATA = ? where NODE_ID_HI = ? and NODE_ID_LO = ?";
bundleSelectSQL = "select BUNDLE_DATA from " + schemaObjectPrefix + "BUNDLE where NODE_ID_HI = ? and NODE_ID_LO = ?";
bundleDeleteSQL = "delete from " + schemaObjectPrefix + "BUNDLE where NODE_ID_HI = ? and NODE_ID_LO = ?";
nodeReferenceInsertSQL =
"insert into " + schemaObjectPrefix + "REFS"
+ " (REFS_DATA, NODE_ID_HI, NODE_ID_LO) values (?, ?, ?)";
nodeReferenceUpdateSQL =
"update " + schemaObjectPrefix + "REFS"
+ " set REFS_DATA = ? where NODE_ID_HI = ? and NODE_ID_LO = ?";
nodeReferenceSelectSQL = "select REFS_DATA from " + schemaObjectPrefix + "REFS where NODE_ID_HI = ? and NODE_ID_LO = ?";
nodeReferenceDeleteSQL = "delete from " + schemaObjectPrefix + "REFS where NODE_ID_HI = ? and NODE_ID_LO = ?";
bundleSelectAllIdsSQL = "select NODE_ID_HI, NODE_ID_LO from " + schemaObjectPrefix
+ "BUNDLE ORDER BY NODE_ID_HI, NODE_ID_LO";
// need to use HI and LO parameters
// this is not the exact statement, but not all databases support WHERE (NODE_ID_HI, NODE_ID_LOW) >= (?, ?)
bundleSelectAllIdsFromSQL =
"select NODE_ID_HI, NODE_ID_LO from " + schemaObjectPrefix + "BUNDLE"
+ " WHERE (NODE_ID_HI >= ?) AND (? IS NOT NULL)"
+ " ORDER BY NODE_ID_HI, NODE_ID_LO";
bundleSelectAllBundlesSQL = "select NODE_ID_HI, NODE_ID_LO, BUNDLE_DATA from " + schemaObjectPrefix
+ "BUNDLE ORDER BY NODE_ID_HI, NODE_ID_LO";
// need to use HI and LO parameters
// this is not the exact statement, but not all databases support WHERE (NODE_ID_HI, NODE_ID_LOW) >= (?, ?)
bundleSelectAllBundlesFromSQL =
"select NODE_ID_HI, NODE_ID_LO, BUNDLE_DATA from " + schemaObjectPrefix + "BUNDLE"
+ " WHERE (NODE_ID_HI >= ?) AND (? IS NOT NULL)"
+ " ORDER BY NODE_ID_HI, NODE_ID_LO";
}
}
|
java
|
protected void buildSQLStatements() {
// prepare statements
if (getStorageModel() == SM_BINARY_KEYS) {
bundleInsertSQL = "insert into " + schemaObjectPrefix + "BUNDLE (BUNDLE_DATA, NODE_ID) values (?, ?)";
bundleUpdateSQL = "update " + schemaObjectPrefix + "BUNDLE set BUNDLE_DATA = ? where NODE_ID = ?";
bundleSelectSQL = "select BUNDLE_DATA from " + schemaObjectPrefix + "BUNDLE where NODE_ID = ?";
bundleDeleteSQL = "delete from " + schemaObjectPrefix + "BUNDLE where NODE_ID = ?";
nodeReferenceInsertSQL = "insert into " + schemaObjectPrefix + "REFS (REFS_DATA, NODE_ID) values (?, ?)";
nodeReferenceUpdateSQL = "update " + schemaObjectPrefix + "REFS set REFS_DATA = ? where NODE_ID = ?";
nodeReferenceSelectSQL = "select REFS_DATA from " + schemaObjectPrefix + "REFS where NODE_ID = ?";
nodeReferenceDeleteSQL = "delete from " + schemaObjectPrefix + "REFS where NODE_ID = ?";
bundleSelectAllIdsSQL = "select NODE_ID from " + schemaObjectPrefix + "BUNDLE ORDER BY NODE_ID";
bundleSelectAllIdsFromSQL = "select NODE_ID from " + schemaObjectPrefix + "BUNDLE WHERE NODE_ID > ? ORDER BY NODE_ID";
bundleSelectAllBundlesSQL = "select NODE_ID, BUNDLE_DATA from " + schemaObjectPrefix + "BUNDLE ORDER BY NODE_ID";
bundleSelectAllBundlesFromSQL = "select NODE_ID, BUNDLE_DATA from " + schemaObjectPrefix + "BUNDLE WHERE NODE_ID > ? ORDER BY NODE_ID";
} else {
bundleInsertSQL = "insert into " + schemaObjectPrefix + "BUNDLE (BUNDLE_DATA, NODE_ID_HI, NODE_ID_LO) values (?, ?, ?)";
bundleUpdateSQL = "update " + schemaObjectPrefix + "BUNDLE set BUNDLE_DATA = ? where NODE_ID_HI = ? and NODE_ID_LO = ?";
bundleSelectSQL = "select BUNDLE_DATA from " + schemaObjectPrefix + "BUNDLE where NODE_ID_HI = ? and NODE_ID_LO = ?";
bundleDeleteSQL = "delete from " + schemaObjectPrefix + "BUNDLE where NODE_ID_HI = ? and NODE_ID_LO = ?";
nodeReferenceInsertSQL =
"insert into " + schemaObjectPrefix + "REFS"
+ " (REFS_DATA, NODE_ID_HI, NODE_ID_LO) values (?, ?, ?)";
nodeReferenceUpdateSQL =
"update " + schemaObjectPrefix + "REFS"
+ " set REFS_DATA = ? where NODE_ID_HI = ? and NODE_ID_LO = ?";
nodeReferenceSelectSQL = "select REFS_DATA from " + schemaObjectPrefix + "REFS where NODE_ID_HI = ? and NODE_ID_LO = ?";
nodeReferenceDeleteSQL = "delete from " + schemaObjectPrefix + "REFS where NODE_ID_HI = ? and NODE_ID_LO = ?";
bundleSelectAllIdsSQL = "select NODE_ID_HI, NODE_ID_LO from " + schemaObjectPrefix
+ "BUNDLE ORDER BY NODE_ID_HI, NODE_ID_LO";
// need to use HI and LO parameters
// this is not the exact statement, but not all databases support WHERE (NODE_ID_HI, NODE_ID_LOW) >= (?, ?)
bundleSelectAllIdsFromSQL =
"select NODE_ID_HI, NODE_ID_LO from " + schemaObjectPrefix + "BUNDLE"
+ " WHERE (NODE_ID_HI >= ?) AND (? IS NOT NULL)"
+ " ORDER BY NODE_ID_HI, NODE_ID_LO";
bundleSelectAllBundlesSQL = "select NODE_ID_HI, NODE_ID_LO, BUNDLE_DATA from " + schemaObjectPrefix
+ "BUNDLE ORDER BY NODE_ID_HI, NODE_ID_LO";
// need to use HI and LO parameters
// this is not the exact statement, but not all databases support WHERE (NODE_ID_HI, NODE_ID_LOW) >= (?, ?)
bundleSelectAllBundlesFromSQL =
"select NODE_ID_HI, NODE_ID_LO, BUNDLE_DATA from " + schemaObjectPrefix + "BUNDLE"
+ " WHERE (NODE_ID_HI >= ?) AND (? IS NOT NULL)"
+ " ORDER BY NODE_ID_HI, NODE_ID_LO";
}
}
|
[
"protected",
"void",
"buildSQLStatements",
"(",
")",
"{",
"// prepare statements",
"if",
"(",
"getStorageModel",
"(",
")",
"==",
"SM_BINARY_KEYS",
")",
"{",
"bundleInsertSQL",
"=",
"\"insert into \"",
"+",
"schemaObjectPrefix",
"+",
"\"BUNDLE (BUNDLE_DATA, NODE_ID) values (?, ?)\"",
";",
"bundleUpdateSQL",
"=",
"\"update \"",
"+",
"schemaObjectPrefix",
"+",
"\"BUNDLE set BUNDLE_DATA = ? where NODE_ID = ?\"",
";",
"bundleSelectSQL",
"=",
"\"select BUNDLE_DATA from \"",
"+",
"schemaObjectPrefix",
"+",
"\"BUNDLE where NODE_ID = ?\"",
";",
"bundleDeleteSQL",
"=",
"\"delete from \"",
"+",
"schemaObjectPrefix",
"+",
"\"BUNDLE where NODE_ID = ?\"",
";",
"nodeReferenceInsertSQL",
"=",
"\"insert into \"",
"+",
"schemaObjectPrefix",
"+",
"\"REFS (REFS_DATA, NODE_ID) values (?, ?)\"",
";",
"nodeReferenceUpdateSQL",
"=",
"\"update \"",
"+",
"schemaObjectPrefix",
"+",
"\"REFS set REFS_DATA = ? where NODE_ID = ?\"",
";",
"nodeReferenceSelectSQL",
"=",
"\"select REFS_DATA from \"",
"+",
"schemaObjectPrefix",
"+",
"\"REFS where NODE_ID = ?\"",
";",
"nodeReferenceDeleteSQL",
"=",
"\"delete from \"",
"+",
"schemaObjectPrefix",
"+",
"\"REFS where NODE_ID = ?\"",
";",
"bundleSelectAllIdsSQL",
"=",
"\"select NODE_ID from \"",
"+",
"schemaObjectPrefix",
"+",
"\"BUNDLE ORDER BY NODE_ID\"",
";",
"bundleSelectAllIdsFromSQL",
"=",
"\"select NODE_ID from \"",
"+",
"schemaObjectPrefix",
"+",
"\"BUNDLE WHERE NODE_ID > ? ORDER BY NODE_ID\"",
";",
"bundleSelectAllBundlesSQL",
"=",
"\"select NODE_ID, BUNDLE_DATA from \"",
"+",
"schemaObjectPrefix",
"+",
"\"BUNDLE ORDER BY NODE_ID\"",
";",
"bundleSelectAllBundlesFromSQL",
"=",
"\"select NODE_ID, BUNDLE_DATA from \"",
"+",
"schemaObjectPrefix",
"+",
"\"BUNDLE WHERE NODE_ID > ? ORDER BY NODE_ID\"",
";",
"}",
"else",
"{",
"bundleInsertSQL",
"=",
"\"insert into \"",
"+",
"schemaObjectPrefix",
"+",
"\"BUNDLE (BUNDLE_DATA, NODE_ID_HI, NODE_ID_LO) values (?, ?, ?)\"",
";",
"bundleUpdateSQL",
"=",
"\"update \"",
"+",
"schemaObjectPrefix",
"+",
"\"BUNDLE set BUNDLE_DATA = ? where NODE_ID_HI = ? and NODE_ID_LO = ?\"",
";",
"bundleSelectSQL",
"=",
"\"select BUNDLE_DATA from \"",
"+",
"schemaObjectPrefix",
"+",
"\"BUNDLE where NODE_ID_HI = ? and NODE_ID_LO = ?\"",
";",
"bundleDeleteSQL",
"=",
"\"delete from \"",
"+",
"schemaObjectPrefix",
"+",
"\"BUNDLE where NODE_ID_HI = ? and NODE_ID_LO = ?\"",
";",
"nodeReferenceInsertSQL",
"=",
"\"insert into \"",
"+",
"schemaObjectPrefix",
"+",
"\"REFS\"",
"+",
"\" (REFS_DATA, NODE_ID_HI, NODE_ID_LO) values (?, ?, ?)\"",
";",
"nodeReferenceUpdateSQL",
"=",
"\"update \"",
"+",
"schemaObjectPrefix",
"+",
"\"REFS\"",
"+",
"\" set REFS_DATA = ? where NODE_ID_HI = ? and NODE_ID_LO = ?\"",
";",
"nodeReferenceSelectSQL",
"=",
"\"select REFS_DATA from \"",
"+",
"schemaObjectPrefix",
"+",
"\"REFS where NODE_ID_HI = ? and NODE_ID_LO = ?\"",
";",
"nodeReferenceDeleteSQL",
"=",
"\"delete from \"",
"+",
"schemaObjectPrefix",
"+",
"\"REFS where NODE_ID_HI = ? and NODE_ID_LO = ?\"",
";",
"bundleSelectAllIdsSQL",
"=",
"\"select NODE_ID_HI, NODE_ID_LO from \"",
"+",
"schemaObjectPrefix",
"+",
"\"BUNDLE ORDER BY NODE_ID_HI, NODE_ID_LO\"",
";",
"// need to use HI and LO parameters",
"// this is not the exact statement, but not all databases support WHERE (NODE_ID_HI, NODE_ID_LOW) >= (?, ?)",
"bundleSelectAllIdsFromSQL",
"=",
"\"select NODE_ID_HI, NODE_ID_LO from \"",
"+",
"schemaObjectPrefix",
"+",
"\"BUNDLE\"",
"+",
"\" WHERE (NODE_ID_HI >= ?) AND (? IS NOT NULL)\"",
"+",
"\" ORDER BY NODE_ID_HI, NODE_ID_LO\"",
";",
"bundleSelectAllBundlesSQL",
"=",
"\"select NODE_ID_HI, NODE_ID_LO, BUNDLE_DATA from \"",
"+",
"schemaObjectPrefix",
"+",
"\"BUNDLE ORDER BY NODE_ID_HI, NODE_ID_LO\"",
";",
"// need to use HI and LO parameters",
"// this is not the exact statement, but not all databases support WHERE (NODE_ID_HI, NODE_ID_LOW) >= (?, ?)",
"bundleSelectAllBundlesFromSQL",
"=",
"\"select NODE_ID_HI, NODE_ID_LO, BUNDLE_DATA from \"",
"+",
"schemaObjectPrefix",
"+",
"\"BUNDLE\"",
"+",
"\" WHERE (NODE_ID_HI >= ?) AND (? IS NOT NULL)\"",
"+",
"\" ORDER BY NODE_ID_HI, NODE_ID_LO\"",
";",
"}",
"}"
] |
Initializes the SQL strings.
|
[
"Initializes",
"the",
"SQL",
"strings",
"."
] |
3fa0eb4439e97aa292e744bcbd88a9faa36661d8
|
https://github.com/youseries/urule/blob/3fa0eb4439e97aa292e744bcbd88a9faa36661d8/urule-console/src/main/java/com/bstek/urule/console/repository/database/DbPersistenceManager.java#L1084-L1136
|
21,949
|
youseries/urule
|
urule-console/src/main/java/com/bstek/urule/console/repository/database/journal/DatabaseRecordIterator.java
|
DatabaseRecordIterator.fetchRecord
|
private void fetchRecord() throws SQLException {
if (rs.next()) {
long revision = rs.getLong(1);
String journalId = rs.getString(2);
String producerId = rs.getString(3);
DataInputStream dataIn = new DataInputStream(rs.getBinaryStream(4));
record = new ReadRecord(journalId, producerId, revision, dataIn, 0, resolver, npResolver);
} else {
isEOF = true;
}
}
|
java
|
private void fetchRecord() throws SQLException {
if (rs.next()) {
long revision = rs.getLong(1);
String journalId = rs.getString(2);
String producerId = rs.getString(3);
DataInputStream dataIn = new DataInputStream(rs.getBinaryStream(4));
record = new ReadRecord(journalId, producerId, revision, dataIn, 0, resolver, npResolver);
} else {
isEOF = true;
}
}
|
[
"private",
"void",
"fetchRecord",
"(",
")",
"throws",
"SQLException",
"{",
"if",
"(",
"rs",
".",
"next",
"(",
")",
")",
"{",
"long",
"revision",
"=",
"rs",
".",
"getLong",
"(",
"1",
")",
";",
"String",
"journalId",
"=",
"rs",
".",
"getString",
"(",
"2",
")",
";",
"String",
"producerId",
"=",
"rs",
".",
"getString",
"(",
"3",
")",
";",
"DataInputStream",
"dataIn",
"=",
"new",
"DataInputStream",
"(",
"rs",
".",
"getBinaryStream",
"(",
"4",
")",
")",
";",
"record",
"=",
"new",
"ReadRecord",
"(",
"journalId",
",",
"producerId",
",",
"revision",
",",
"dataIn",
",",
"0",
",",
"resolver",
",",
"npResolver",
")",
";",
"}",
"else",
"{",
"isEOF",
"=",
"true",
";",
"}",
"}"
] |
Fetch the next record.
|
[
"Fetch",
"the",
"next",
"record",
"."
] |
3fa0eb4439e97aa292e744bcbd88a9faa36661d8
|
https://github.com/youseries/urule/blob/3fa0eb4439e97aa292e744bcbd88a9faa36661d8/urule-console/src/main/java/com/bstek/urule/console/repository/database/journal/DatabaseRecordIterator.java#L128-L138
|
21,950
|
youseries/urule
|
urule-console/src/main/java/com/bstek/urule/console/repository/database/journal/DatabaseRecordIterator.java
|
DatabaseRecordIterator.close
|
private static void close(ReadRecord record) {
if (record != null) {
try {
record.close();
} catch (IOException e) {
String msg = "Error while closing record.";
log.warn(msg, e);
}
}
}
|
java
|
private static void close(ReadRecord record) {
if (record != null) {
try {
record.close();
} catch (IOException e) {
String msg = "Error while closing record.";
log.warn(msg, e);
}
}
}
|
[
"private",
"static",
"void",
"close",
"(",
"ReadRecord",
"record",
")",
"{",
"if",
"(",
"record",
"!=",
"null",
")",
"{",
"try",
"{",
"record",
".",
"close",
"(",
")",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"String",
"msg",
"=",
"\"Error while closing record.\"",
";",
"log",
".",
"warn",
"(",
"msg",
",",
"e",
")",
";",
"}",
"}",
"}"
] |
Close a record.
@param record record
|
[
"Close",
"a",
"record",
"."
] |
3fa0eb4439e97aa292e744bcbd88a9faa36661d8
|
https://github.com/youseries/urule/blob/3fa0eb4439e97aa292e744bcbd88a9faa36661d8/urule-console/src/main/java/com/bstek/urule/console/repository/database/journal/DatabaseRecordIterator.java#L145-L154
|
21,951
|
youseries/urule
|
urule-console/src/main/java/com/bstek/urule/console/repository/database/journal/MSSqlDatabaseJournal.java
|
MSSqlDatabaseJournal.setTableSpace
|
public void setTableSpace(String tableSpace) {
if (tableSpace != null && tableSpace.length() > 0) {
this.tableSpace = "on " + tableSpace.trim();
} else {
this.tableSpace = "";
}
}
|
java
|
public void setTableSpace(String tableSpace) {
if (tableSpace != null && tableSpace.length() > 0) {
this.tableSpace = "on " + tableSpace.trim();
} else {
this.tableSpace = "";
}
}
|
[
"public",
"void",
"setTableSpace",
"(",
"String",
"tableSpace",
")",
"{",
"if",
"(",
"tableSpace",
"!=",
"null",
"&&",
"tableSpace",
".",
"length",
"(",
")",
">",
"0",
")",
"{",
"this",
".",
"tableSpace",
"=",
"\"on \"",
"+",
"tableSpace",
".",
"trim",
"(",
")",
";",
"}",
"else",
"{",
"this",
".",
"tableSpace",
"=",
"\"\"",
";",
"}",
"}"
] |
Sets the MS SQL table space.
@param tableSpace the MS SQL table space.
|
[
"Sets",
"the",
"MS",
"SQL",
"table",
"space",
"."
] |
3fa0eb4439e97aa292e744bcbd88a9faa36661d8
|
https://github.com/youseries/urule/blob/3fa0eb4439e97aa292e744bcbd88a9faa36661d8/urule-console/src/main/java/com/bstek/urule/console/repository/database/journal/MSSqlDatabaseJournal.java#L59-L65
|
21,952
|
hyperledger/fabric-sdk-java
|
src/main/java/org/hyperledger/fabric_ca/sdk/EnrollmentRequest.java
|
EnrollmentRequest.addAttrReq
|
public AttrReq addAttrReq(String name) throws InvalidArgumentException {
if (name == null || name.isEmpty()) {
throw new InvalidArgumentException("name may not be null or empty.");
}
return new AttrReq(name);
}
|
java
|
public AttrReq addAttrReq(String name) throws InvalidArgumentException {
if (name == null || name.isEmpty()) {
throw new InvalidArgumentException("name may not be null or empty.");
}
return new AttrReq(name);
}
|
[
"public",
"AttrReq",
"addAttrReq",
"(",
"String",
"name",
")",
"throws",
"InvalidArgumentException",
"{",
"if",
"(",
"name",
"==",
"null",
"||",
"name",
".",
"isEmpty",
"(",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"name may not be null or empty.\"",
")",
";",
"}",
"return",
"new",
"AttrReq",
"(",
"name",
")",
";",
"}"
] |
Add attribute to certificate.
@param name Name of attribute.
@return Attribute added.
@throws InvalidArgumentException
|
[
"Add",
"attribute",
"to",
"certificate",
"."
] |
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
|
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric_ca/sdk/EnrollmentRequest.java#L199-L205
|
21,953
|
hyperledger/fabric-sdk-java
|
src/main/java/org/hyperledger/fabric_ca/sdk/helper/Util.java
|
Util.dateToString
|
public static String dateToString(Date date) {
final TimeZone utc = TimeZone.getTimeZone("UTC");
SimpleDateFormat tformat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
tformat.setTimeZone(utc);
return tformat.format(date);
}
|
java
|
public static String dateToString(Date date) {
final TimeZone utc = TimeZone.getTimeZone("UTC");
SimpleDateFormat tformat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
tformat.setTimeZone(utc);
return tformat.format(date);
}
|
[
"public",
"static",
"String",
"dateToString",
"(",
"Date",
"date",
")",
"{",
"final",
"TimeZone",
"utc",
"=",
"TimeZone",
".",
"getTimeZone",
"(",
"\"UTC\"",
")",
";",
"SimpleDateFormat",
"tformat",
"=",
"new",
"SimpleDateFormat",
"(",
"\"yyyy-MM-dd'T'HH:mm:ss.SSSXXX\"",
")",
";",
"tformat",
".",
"setTimeZone",
"(",
"utc",
")",
";",
"return",
"tformat",
".",
"format",
"(",
"date",
")",
";",
"}"
] |
Converts Date type to String based on RFC3339 formatting
@param date
@return String
|
[
"Converts",
"Date",
"type",
"to",
"String",
"based",
"on",
"RFC3339",
"formatting"
] |
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
|
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric_ca/sdk/helper/Util.java#L15-L21
|
21,954
|
hyperledger/fabric-sdk-java
|
src/main/java/org/hyperledger/fabric/sdk/idemix/WeakBB.java
|
WeakBB.weakBBSign
|
public static ECP weakBBSign(BIG sk, BIG m) {
BIG exp = IdemixUtils.modAdd(sk, m, IdemixUtils.GROUP_ORDER);
exp.invmodp(IdemixUtils.GROUP_ORDER);
return IdemixUtils.genG1.mul(exp);
}
|
java
|
public static ECP weakBBSign(BIG sk, BIG m) {
BIG exp = IdemixUtils.modAdd(sk, m, IdemixUtils.GROUP_ORDER);
exp.invmodp(IdemixUtils.GROUP_ORDER);
return IdemixUtils.genG1.mul(exp);
}
|
[
"public",
"static",
"ECP",
"weakBBSign",
"(",
"BIG",
"sk",
",",
"BIG",
"m",
")",
"{",
"BIG",
"exp",
"=",
"IdemixUtils",
".",
"modAdd",
"(",
"sk",
",",
"m",
",",
"IdemixUtils",
".",
"GROUP_ORDER",
")",
";",
"exp",
".",
"invmodp",
"(",
"IdemixUtils",
".",
"GROUP_ORDER",
")",
";",
"return",
"IdemixUtils",
".",
"genG1",
".",
"mul",
"(",
"exp",
")",
";",
"}"
] |
Produces a WBB signature for a give message
@param sk Secret key
@param m Message
@return Signature
|
[
"Produces",
"a",
"WBB",
"signature",
"for",
"a",
"give",
"message"
] |
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
|
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/idemix/WeakBB.java#L71-L76
|
21,955
|
hyperledger/fabric-sdk-java
|
src/main/java/org/hyperledger/fabric/sdk/idemix/WeakBB.java
|
WeakBB.weakBBVerify
|
public static boolean weakBBVerify(ECP2 pk, ECP sig, BIG m) {
ECP2 p = new ECP2();
p.copy(pk);
p.add(IdemixUtils.genG2.mul(m));
p.affine();
return PAIR.fexp(PAIR.ate(p, sig)).equals(IdemixUtils.genGT);
}
|
java
|
public static boolean weakBBVerify(ECP2 pk, ECP sig, BIG m) {
ECP2 p = new ECP2();
p.copy(pk);
p.add(IdemixUtils.genG2.mul(m));
p.affine();
return PAIR.fexp(PAIR.ate(p, sig)).equals(IdemixUtils.genGT);
}
|
[
"public",
"static",
"boolean",
"weakBBVerify",
"(",
"ECP2",
"pk",
",",
"ECP",
"sig",
",",
"BIG",
"m",
")",
"{",
"ECP2",
"p",
"=",
"new",
"ECP2",
"(",
")",
";",
"p",
".",
"copy",
"(",
"pk",
")",
";",
"p",
".",
"add",
"(",
"IdemixUtils",
".",
"genG2",
".",
"mul",
"(",
"m",
")",
")",
";",
"p",
".",
"affine",
"(",
")",
";",
"return",
"PAIR",
".",
"fexp",
"(",
"PAIR",
".",
"ate",
"(",
"p",
",",
"sig",
")",
")",
".",
"equals",
"(",
"IdemixUtils",
".",
"genGT",
")",
";",
"}"
] |
Verify a WBB signature for a certain message
@param pk Public key
@param sig Signature
@param m Message
@return True iff valid
|
[
"Verify",
"a",
"WBB",
"signature",
"for",
"a",
"certain",
"message"
] |
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
|
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/idemix/WeakBB.java#L86-L93
|
21,956
|
hyperledger/fabric-sdk-java
|
src/main/java/org/hyperledger/fabric/sdk/idemix/IdemixCredRequest.java
|
IdemixCredRequest.check
|
boolean check(IdemixIssuerPublicKey ipk) {
if (nym == null ||
issuerNonce == null ||
proofC == null ||
proofS == null ||
ipk == null) {
return false;
}
ECP t = ipk.getHsk().mul(proofS);
t.sub(nym.mul(proofC));
byte[] proofData = new byte[0];
proofData = IdemixUtils.append(proofData, CREDREQUEST_LABEL.getBytes());
proofData = IdemixUtils.append(proofData, IdemixUtils.ecpToBytes(t));
proofData = IdemixUtils.append(proofData, IdemixUtils.ecpToBytes(ipk.getHsk()));
proofData = IdemixUtils.append(proofData, IdemixUtils.ecpToBytes(nym));
proofData = IdemixUtils.append(proofData, IdemixUtils.bigToBytes(issuerNonce));
proofData = IdemixUtils.append(proofData, ipk.getHash());
// Hash proofData to hproofdata
byte[] hproofdata = IdemixUtils.bigToBytes(IdemixUtils.hashModOrder(proofData));
return Arrays.equals(IdemixUtils.bigToBytes(proofC), hproofdata);
}
|
java
|
boolean check(IdemixIssuerPublicKey ipk) {
if (nym == null ||
issuerNonce == null ||
proofC == null ||
proofS == null ||
ipk == null) {
return false;
}
ECP t = ipk.getHsk().mul(proofS);
t.sub(nym.mul(proofC));
byte[] proofData = new byte[0];
proofData = IdemixUtils.append(proofData, CREDREQUEST_LABEL.getBytes());
proofData = IdemixUtils.append(proofData, IdemixUtils.ecpToBytes(t));
proofData = IdemixUtils.append(proofData, IdemixUtils.ecpToBytes(ipk.getHsk()));
proofData = IdemixUtils.append(proofData, IdemixUtils.ecpToBytes(nym));
proofData = IdemixUtils.append(proofData, IdemixUtils.bigToBytes(issuerNonce));
proofData = IdemixUtils.append(proofData, ipk.getHash());
// Hash proofData to hproofdata
byte[] hproofdata = IdemixUtils.bigToBytes(IdemixUtils.hashModOrder(proofData));
return Arrays.equals(IdemixUtils.bigToBytes(proofC), hproofdata);
}
|
[
"boolean",
"check",
"(",
"IdemixIssuerPublicKey",
"ipk",
")",
"{",
"if",
"(",
"nym",
"==",
"null",
"||",
"issuerNonce",
"==",
"null",
"||",
"proofC",
"==",
"null",
"||",
"proofS",
"==",
"null",
"||",
"ipk",
"==",
"null",
")",
"{",
"return",
"false",
";",
"}",
"ECP",
"t",
"=",
"ipk",
".",
"getHsk",
"(",
")",
".",
"mul",
"(",
"proofS",
")",
";",
"t",
".",
"sub",
"(",
"nym",
".",
"mul",
"(",
"proofC",
")",
")",
";",
"byte",
"[",
"]",
"proofData",
"=",
"new",
"byte",
"[",
"0",
"]",
";",
"proofData",
"=",
"IdemixUtils",
".",
"append",
"(",
"proofData",
",",
"CREDREQUEST_LABEL",
".",
"getBytes",
"(",
")",
")",
";",
"proofData",
"=",
"IdemixUtils",
".",
"append",
"(",
"proofData",
",",
"IdemixUtils",
".",
"ecpToBytes",
"(",
"t",
")",
")",
";",
"proofData",
"=",
"IdemixUtils",
".",
"append",
"(",
"proofData",
",",
"IdemixUtils",
".",
"ecpToBytes",
"(",
"ipk",
".",
"getHsk",
"(",
")",
")",
")",
";",
"proofData",
"=",
"IdemixUtils",
".",
"append",
"(",
"proofData",
",",
"IdemixUtils",
".",
"ecpToBytes",
"(",
"nym",
")",
")",
";",
"proofData",
"=",
"IdemixUtils",
".",
"append",
"(",
"proofData",
",",
"IdemixUtils",
".",
"bigToBytes",
"(",
"issuerNonce",
")",
")",
";",
"proofData",
"=",
"IdemixUtils",
".",
"append",
"(",
"proofData",
",",
"ipk",
".",
"getHash",
"(",
")",
")",
";",
"// Hash proofData to hproofdata",
"byte",
"[",
"]",
"hproofdata",
"=",
"IdemixUtils",
".",
"bigToBytes",
"(",
"IdemixUtils",
".",
"hashModOrder",
"(",
"proofData",
")",
")",
";",
"return",
"Arrays",
".",
"equals",
"(",
"IdemixUtils",
".",
"bigToBytes",
"(",
"proofC",
")",
",",
"hproofdata",
")",
";",
"}"
] |
Cryptographically verify the IdemixCredRequest
@param ipk the issuer public key
@return true iff valid
|
[
"Cryptographically",
"verify",
"the",
"IdemixCredRequest"
] |
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
|
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/idemix/IdemixCredRequest.java#L137-L163
|
21,957
|
hyperledger/fabric-sdk-java
|
src/main/java/org/hyperledger/fabric/sdk/idemix/IdemixCredRequest.java
|
IdemixCredRequest.toJson
|
public String toJson() {
StringWriter stringWriter = new StringWriter();
JsonWriter jsonWriter = Json.createWriter(new PrintWriter(stringWriter));
jsonWriter.writeObject(toJsonObject());
jsonWriter.close();
return stringWriter.toString();
}
|
java
|
public String toJson() {
StringWriter stringWriter = new StringWriter();
JsonWriter jsonWriter = Json.createWriter(new PrintWriter(stringWriter));
jsonWriter.writeObject(toJsonObject());
jsonWriter.close();
return stringWriter.toString();
}
|
[
"public",
"String",
"toJson",
"(",
")",
"{",
"StringWriter",
"stringWriter",
"=",
"new",
"StringWriter",
"(",
")",
";",
"JsonWriter",
"jsonWriter",
"=",
"Json",
".",
"createWriter",
"(",
"new",
"PrintWriter",
"(",
"stringWriter",
")",
")",
";",
"jsonWriter",
".",
"writeObject",
"(",
"toJsonObject",
"(",
")",
")",
";",
"jsonWriter",
".",
"close",
"(",
")",
";",
"return",
"stringWriter",
".",
"toString",
"(",
")",
";",
"}"
] |
Convert the enrollment request to a JSON string
|
[
"Convert",
"the",
"enrollment",
"request",
"to",
"a",
"JSON",
"string"
] |
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
|
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/idemix/IdemixCredRequest.java#L166-L172
|
21,958
|
hyperledger/fabric-sdk-java
|
src/main/java/org/hyperledger/fabric/sdk/LifecycleInstallChaincodeProposalResponse.java
|
LifecycleInstallChaincodeProposalResponse.getPackageId
|
public String getPackageId() throws ProposalException {
if (Status.SUCCESS != getStatus()) {
throw new ProposalException(format("Status of install proposal did not ret ok for %s, %s ", getPeer(), getStatus()));
}
ByteString payload = getProposalResponse().getResponse().getPayload();
Lifecycle.InstallChaincodeResult installChaincodeResult = null;
try {
installChaincodeResult = Lifecycle.InstallChaincodeResult.parseFrom(payload);
} catch (InvalidProtocolBufferException e) {
throw new ProposalException(format("Bad protobuf received for install proposal %s", getPeer()));
}
return installChaincodeResult.getPackageId();
}
|
java
|
public String getPackageId() throws ProposalException {
if (Status.SUCCESS != getStatus()) {
throw new ProposalException(format("Status of install proposal did not ret ok for %s, %s ", getPeer(), getStatus()));
}
ByteString payload = getProposalResponse().getResponse().getPayload();
Lifecycle.InstallChaincodeResult installChaincodeResult = null;
try {
installChaincodeResult = Lifecycle.InstallChaincodeResult.parseFrom(payload);
} catch (InvalidProtocolBufferException e) {
throw new ProposalException(format("Bad protobuf received for install proposal %s", getPeer()));
}
return installChaincodeResult.getPackageId();
}
|
[
"public",
"String",
"getPackageId",
"(",
")",
"throws",
"ProposalException",
"{",
"if",
"(",
"Status",
".",
"SUCCESS",
"!=",
"getStatus",
"(",
")",
")",
"{",
"throw",
"new",
"ProposalException",
"(",
"format",
"(",
"\"Status of install proposal did not ret ok for %s, %s \"",
",",
"getPeer",
"(",
")",
",",
"getStatus",
"(",
")",
")",
")",
";",
"}",
"ByteString",
"payload",
"=",
"getProposalResponse",
"(",
")",
".",
"getResponse",
"(",
")",
".",
"getPayload",
"(",
")",
";",
"Lifecycle",
".",
"InstallChaincodeResult",
"installChaincodeResult",
"=",
"null",
";",
"try",
"{",
"installChaincodeResult",
"=",
"Lifecycle",
".",
"InstallChaincodeResult",
".",
"parseFrom",
"(",
"payload",
")",
";",
"}",
"catch",
"(",
"InvalidProtocolBufferException",
"e",
")",
"{",
"throw",
"new",
"ProposalException",
"(",
"format",
"(",
"\"Bad protobuf received for install proposal %s\"",
",",
"getPeer",
"(",
")",
")",
")",
";",
"}",
"return",
"installChaincodeResult",
".",
"getPackageId",
"(",
")",
";",
"}"
] |
The packageId the identifies this chaincode change.
@return the package id.
@throws ProposalException
|
[
"The",
"packageId",
"the",
"identifies",
"this",
"chaincode",
"change",
"."
] |
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
|
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/LifecycleInstallChaincodeProposalResponse.java#L34-L46
|
21,959
|
hyperledger/fabric-sdk-java
|
src/main/java/org/hyperledger/fabric/sdk/idemix/IdemixIssuerPublicKey.java
|
IdemixIssuerPublicKey.check
|
public boolean check() {
// check formalities of IdemixIssuerPublicKey
if (AttributeNames == null || Hsk == null || HRand == null || HAttrs == null
|| BarG1 == null || BarG1.is_infinity() || BarG2 == null
|| HAttrs.length < AttributeNames.length) {
return false;
}
for (int i = 0; i < AttributeNames.length; i++) {
if (HAttrs[i] == null) {
return false;
}
}
// check proofs
ECP2 t1 = IdemixUtils.genG2.mul(ProofS);
ECP t2 = BarG1.mul(ProofS);
t1.add(W.mul(BIG.modneg(ProofC, IdemixUtils.GROUP_ORDER)));
t2.add(BarG2.mul(BIG.modneg(ProofC, IdemixUtils.GROUP_ORDER)));
// Generating proofData that will contain 3 elements in G1 (of size 2*FIELD_BYTES+1)and 3 elements in G2 (of size 4 * FIELD_BYTES)
byte[] proofData = new byte[0];
proofData = IdemixUtils.append(proofData, IdemixUtils.ecpToBytes(t1));
proofData = IdemixUtils.append(proofData, IdemixUtils.ecpToBytes(t2));
proofData = IdemixUtils.append(proofData, IdemixUtils.ecpToBytes(IdemixUtils.genG2));
proofData = IdemixUtils.append(proofData, IdemixUtils.ecpToBytes(BarG1));
proofData = IdemixUtils.append(proofData, IdemixUtils.ecpToBytes(W));
proofData = IdemixUtils.append(proofData, IdemixUtils.ecpToBytes(BarG2));
// Hash proofData to hproofdata and compare with proofC
return Arrays.equals(IdemixUtils.bigToBytes(IdemixUtils.hashModOrder(proofData)), IdemixUtils.bigToBytes(ProofC));
}
|
java
|
public boolean check() {
// check formalities of IdemixIssuerPublicKey
if (AttributeNames == null || Hsk == null || HRand == null || HAttrs == null
|| BarG1 == null || BarG1.is_infinity() || BarG2 == null
|| HAttrs.length < AttributeNames.length) {
return false;
}
for (int i = 0; i < AttributeNames.length; i++) {
if (HAttrs[i] == null) {
return false;
}
}
// check proofs
ECP2 t1 = IdemixUtils.genG2.mul(ProofS);
ECP t2 = BarG1.mul(ProofS);
t1.add(W.mul(BIG.modneg(ProofC, IdemixUtils.GROUP_ORDER)));
t2.add(BarG2.mul(BIG.modneg(ProofC, IdemixUtils.GROUP_ORDER)));
// Generating proofData that will contain 3 elements in G1 (of size 2*FIELD_BYTES+1)and 3 elements in G2 (of size 4 * FIELD_BYTES)
byte[] proofData = new byte[0];
proofData = IdemixUtils.append(proofData, IdemixUtils.ecpToBytes(t1));
proofData = IdemixUtils.append(proofData, IdemixUtils.ecpToBytes(t2));
proofData = IdemixUtils.append(proofData, IdemixUtils.ecpToBytes(IdemixUtils.genG2));
proofData = IdemixUtils.append(proofData, IdemixUtils.ecpToBytes(BarG1));
proofData = IdemixUtils.append(proofData, IdemixUtils.ecpToBytes(W));
proofData = IdemixUtils.append(proofData, IdemixUtils.ecpToBytes(BarG2));
// Hash proofData to hproofdata and compare with proofC
return Arrays.equals(IdemixUtils.bigToBytes(IdemixUtils.hashModOrder(proofData)), IdemixUtils.bigToBytes(ProofC));
}
|
[
"public",
"boolean",
"check",
"(",
")",
"{",
"// check formalities of IdemixIssuerPublicKey",
"if",
"(",
"AttributeNames",
"==",
"null",
"||",
"Hsk",
"==",
"null",
"||",
"HRand",
"==",
"null",
"||",
"HAttrs",
"==",
"null",
"||",
"BarG1",
"==",
"null",
"||",
"BarG1",
".",
"is_infinity",
"(",
")",
"||",
"BarG2",
"==",
"null",
"||",
"HAttrs",
".",
"length",
"<",
"AttributeNames",
".",
"length",
")",
"{",
"return",
"false",
";",
"}",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"AttributeNames",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"HAttrs",
"[",
"i",
"]",
"==",
"null",
")",
"{",
"return",
"false",
";",
"}",
"}",
"// check proofs",
"ECP2",
"t1",
"=",
"IdemixUtils",
".",
"genG2",
".",
"mul",
"(",
"ProofS",
")",
";",
"ECP",
"t2",
"=",
"BarG1",
".",
"mul",
"(",
"ProofS",
")",
";",
"t1",
".",
"add",
"(",
"W",
".",
"mul",
"(",
"BIG",
".",
"modneg",
"(",
"ProofC",
",",
"IdemixUtils",
".",
"GROUP_ORDER",
")",
")",
")",
";",
"t2",
".",
"add",
"(",
"BarG2",
".",
"mul",
"(",
"BIG",
".",
"modneg",
"(",
"ProofC",
",",
"IdemixUtils",
".",
"GROUP_ORDER",
")",
")",
")",
";",
"// Generating proofData that will contain 3 elements in G1 (of size 2*FIELD_BYTES+1)and 3 elements in G2 (of size 4 * FIELD_BYTES)",
"byte",
"[",
"]",
"proofData",
"=",
"new",
"byte",
"[",
"0",
"]",
";",
"proofData",
"=",
"IdemixUtils",
".",
"append",
"(",
"proofData",
",",
"IdemixUtils",
".",
"ecpToBytes",
"(",
"t1",
")",
")",
";",
"proofData",
"=",
"IdemixUtils",
".",
"append",
"(",
"proofData",
",",
"IdemixUtils",
".",
"ecpToBytes",
"(",
"t2",
")",
")",
";",
"proofData",
"=",
"IdemixUtils",
".",
"append",
"(",
"proofData",
",",
"IdemixUtils",
".",
"ecpToBytes",
"(",
"IdemixUtils",
".",
"genG2",
")",
")",
";",
"proofData",
"=",
"IdemixUtils",
".",
"append",
"(",
"proofData",
",",
"IdemixUtils",
".",
"ecpToBytes",
"(",
"BarG1",
")",
")",
";",
"proofData",
"=",
"IdemixUtils",
".",
"append",
"(",
"proofData",
",",
"IdemixUtils",
".",
"ecpToBytes",
"(",
"W",
")",
")",
";",
"proofData",
"=",
"IdemixUtils",
".",
"append",
"(",
"proofData",
",",
"IdemixUtils",
".",
"ecpToBytes",
"(",
"BarG2",
")",
")",
";",
"// Hash proofData to hproofdata and compare with proofC",
"return",
"Arrays",
".",
"equals",
"(",
"IdemixUtils",
".",
"bigToBytes",
"(",
"IdemixUtils",
".",
"hashModOrder",
"(",
"proofData",
")",
")",
",",
"IdemixUtils",
".",
"bigToBytes",
"(",
"ProofC",
")",
")",
";",
"}"
] |
check whether the issuer public key is correct
@return true iff valid
|
[
"check",
"whether",
"the",
"issuer",
"public",
"key",
"is",
"correct"
] |
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
|
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/idemix/IdemixIssuerPublicKey.java#L163-L195
|
21,960
|
hyperledger/fabric-sdk-java
|
src/main/java/org/hyperledger/fabric/sdk/LifecycleQueryApprovalStatusProposalResponse.java
|
LifecycleQueryApprovalStatusProposalResponse.getApprovalMap
|
public Map<String, Boolean> getApprovalMap() throws ProposalException {
Lifecycle.QueryApprovalStatusResults rs = getApprovalStatusResults();
if (rs == null) {
return Collections.emptyMap();
}
return rs.getApprovedMap();
}
|
java
|
public Map<String, Boolean> getApprovalMap() throws ProposalException {
Lifecycle.QueryApprovalStatusResults rs = getApprovalStatusResults();
if (rs == null) {
return Collections.emptyMap();
}
return rs.getApprovedMap();
}
|
[
"public",
"Map",
"<",
"String",
",",
"Boolean",
">",
"getApprovalMap",
"(",
")",
"throws",
"ProposalException",
"{",
"Lifecycle",
".",
"QueryApprovalStatusResults",
"rs",
"=",
"getApprovalStatusResults",
"(",
")",
";",
"if",
"(",
"rs",
"==",
"null",
")",
"{",
"return",
"Collections",
".",
"emptyMap",
"(",
")",
";",
"}",
"return",
"rs",
".",
"getApprovedMap",
"(",
")",
";",
"}"
] |
A map of approved and not approved. The key contains name of org the value a Boolean if approved.
@return
@throws ProposalException
|
[
"A",
"map",
"of",
"approved",
"and",
"not",
"approved",
".",
"The",
"key",
"contains",
"name",
"of",
"org",
"the",
"value",
"a",
"Boolean",
"if",
"approved",
"."
] |
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
|
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/LifecycleQueryApprovalStatusProposalResponse.java#L101-L108
|
21,961
|
hyperledger/fabric-sdk-java
|
src/main/java/org/hyperledger/fabric/sdk/NetworkConfig.java
|
NetworkConfig.getPeerNames
|
public Collection<String> getPeerNames() {
if (peers == null) {
return Collections.EMPTY_SET;
} else {
return new HashSet<>(peers.keySet());
}
}
|
java
|
public Collection<String> getPeerNames() {
if (peers == null) {
return Collections.EMPTY_SET;
} else {
return new HashSet<>(peers.keySet());
}
}
|
[
"public",
"Collection",
"<",
"String",
">",
"getPeerNames",
"(",
")",
"{",
"if",
"(",
"peers",
"==",
"null",
")",
"{",
"return",
"Collections",
".",
"EMPTY_SET",
";",
"}",
"else",
"{",
"return",
"new",
"HashSet",
"<>",
"(",
"peers",
".",
"keySet",
"(",
")",
")",
";",
"}",
"}"
] |
Names of Peers found
@return Collection of peer names found.
|
[
"Names",
"of",
"Peers",
"found"
] |
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
|
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/NetworkConfig.java#L85-L91
|
21,962
|
hyperledger/fabric-sdk-java
|
src/main/java/org/hyperledger/fabric/sdk/NetworkConfig.java
|
NetworkConfig.getOrdererNames
|
public Collection<String> getOrdererNames() {
if (orderers == null) {
return Collections.EMPTY_SET;
} else {
return new HashSet<>(orderers.keySet());
}
}
|
java
|
public Collection<String> getOrdererNames() {
if (orderers == null) {
return Collections.EMPTY_SET;
} else {
return new HashSet<>(orderers.keySet());
}
}
|
[
"public",
"Collection",
"<",
"String",
">",
"getOrdererNames",
"(",
")",
"{",
"if",
"(",
"orderers",
"==",
"null",
")",
"{",
"return",
"Collections",
".",
"EMPTY_SET",
";",
"}",
"else",
"{",
"return",
"new",
"HashSet",
"<>",
"(",
"orderers",
".",
"keySet",
"(",
")",
")",
";",
"}",
"}"
] |
Names of Orderers found
@return Collection of peer names found.
|
[
"Names",
"of",
"Orderers",
"found"
] |
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
|
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/NetworkConfig.java#L98-L104
|
21,963
|
hyperledger/fabric-sdk-java
|
src/main/java/org/hyperledger/fabric/sdk/NetworkConfig.java
|
NetworkConfig.setPeerProperties
|
public void setPeerProperties(String name, Properties properties) throws InvalidArgumentException {
setNodeProperties("Peer", name, peers, properties);
}
|
java
|
public void setPeerProperties(String name, Properties properties) throws InvalidArgumentException {
setNodeProperties("Peer", name, peers, properties);
}
|
[
"public",
"void",
"setPeerProperties",
"(",
"String",
"name",
",",
"Properties",
"properties",
")",
"throws",
"InvalidArgumentException",
"{",
"setNodeProperties",
"(",
"\"Peer\"",
",",
"name",
",",
"peers",
",",
"properties",
")",
";",
"}"
] |
Set a specific peer's properties.
@param name The name of the peer's property to set.
@param properties The properties to set.
@throws InvalidArgumentException
|
[
"Set",
"a",
"specific",
"peer",
"s",
"properties",
"."
] |
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
|
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/NetworkConfig.java#L176-L178
|
21,964
|
hyperledger/fabric-sdk-java
|
src/main/java/org/hyperledger/fabric/sdk/NetworkConfig.java
|
NetworkConfig.setOrdererProperties
|
public void setOrdererProperties(String name, Properties properties) throws InvalidArgumentException {
setNodeProperties("Orderer", name, orderers, properties);
}
|
java
|
public void setOrdererProperties(String name, Properties properties) throws InvalidArgumentException {
setNodeProperties("Orderer", name, orderers, properties);
}
|
[
"public",
"void",
"setOrdererProperties",
"(",
"String",
"name",
",",
"Properties",
"properties",
")",
"throws",
"InvalidArgumentException",
"{",
"setNodeProperties",
"(",
"\"Orderer\"",
",",
"name",
",",
"orderers",
",",
"properties",
")",
";",
"}"
] |
Set a specific orderer's properties.
@param name The name of the orderer's property to set.
@param properties The properties to set.
@throws InvalidArgumentException
|
[
"Set",
"a",
"specific",
"orderer",
"s",
"properties",
"."
] |
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
|
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/NetworkConfig.java#L187-L189
|
21,965
|
hyperledger/fabric-sdk-java
|
src/main/java/org/hyperledger/fabric/sdk/NetworkConfig.java
|
NetworkConfig.fromYamlFile
|
public static NetworkConfig fromYamlFile(File configFile) throws InvalidArgumentException, IOException, NetworkConfigurationException {
return fromFile(configFile, false);
}
|
java
|
public static NetworkConfig fromYamlFile(File configFile) throws InvalidArgumentException, IOException, NetworkConfigurationException {
return fromFile(configFile, false);
}
|
[
"public",
"static",
"NetworkConfig",
"fromYamlFile",
"(",
"File",
"configFile",
")",
"throws",
"InvalidArgumentException",
",",
"IOException",
",",
"NetworkConfigurationException",
"{",
"return",
"fromFile",
"(",
"configFile",
",",
"false",
")",
";",
"}"
] |
Creates a new NetworkConfig instance configured with details supplied in a YAML file.
@param configFile The file containing the network configuration
@return A new NetworkConfig instance
@throws InvalidArgumentException
@throws IOException
|
[
"Creates",
"a",
"new",
"NetworkConfig",
"instance",
"configured",
"with",
"details",
"supplied",
"in",
"a",
"YAML",
"file",
"."
] |
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
|
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/NetworkConfig.java#L242-L244
|
21,966
|
hyperledger/fabric-sdk-java
|
src/main/java/org/hyperledger/fabric/sdk/NetworkConfig.java
|
NetworkConfig.fromJsonFile
|
public static NetworkConfig fromJsonFile(File configFile) throws InvalidArgumentException, IOException, NetworkConfigurationException {
return fromFile(configFile, true);
}
|
java
|
public static NetworkConfig fromJsonFile(File configFile) throws InvalidArgumentException, IOException, NetworkConfigurationException {
return fromFile(configFile, true);
}
|
[
"public",
"static",
"NetworkConfig",
"fromJsonFile",
"(",
"File",
"configFile",
")",
"throws",
"InvalidArgumentException",
",",
"IOException",
",",
"NetworkConfigurationException",
"{",
"return",
"fromFile",
"(",
"configFile",
",",
"true",
")",
";",
"}"
] |
Creates a new NetworkConfig instance configured with details supplied in a JSON file.
@param configFile The file containing the network configuration
@return A new NetworkConfig instance
@throws InvalidArgumentException
@throws IOException
|
[
"Creates",
"a",
"new",
"NetworkConfig",
"instance",
"configured",
"with",
"details",
"supplied",
"in",
"a",
"JSON",
"file",
"."
] |
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
|
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/NetworkConfig.java#L254-L256
|
21,967
|
hyperledger/fabric-sdk-java
|
src/main/java/org/hyperledger/fabric/sdk/NetworkConfig.java
|
NetworkConfig.fromYamlStream
|
public static NetworkConfig fromYamlStream(InputStream configStream) throws InvalidArgumentException, NetworkConfigurationException {
logger.trace("NetworkConfig.fromYamlStream...");
// Sanity check
if (configStream == null) {
throw new InvalidArgumentException("configStream must be specified");
}
Yaml yaml = new Yaml();
@SuppressWarnings ("unchecked")
Map<String, Object> map = yaml.load(configStream);
JsonObjectBuilder builder = Json.createObjectBuilder(map);
JsonObject jsonConfig = builder.build();
return fromJsonObject(jsonConfig);
}
|
java
|
public static NetworkConfig fromYamlStream(InputStream configStream) throws InvalidArgumentException, NetworkConfigurationException {
logger.trace("NetworkConfig.fromYamlStream...");
// Sanity check
if (configStream == null) {
throw new InvalidArgumentException("configStream must be specified");
}
Yaml yaml = new Yaml();
@SuppressWarnings ("unchecked")
Map<String, Object> map = yaml.load(configStream);
JsonObjectBuilder builder = Json.createObjectBuilder(map);
JsonObject jsonConfig = builder.build();
return fromJsonObject(jsonConfig);
}
|
[
"public",
"static",
"NetworkConfig",
"fromYamlStream",
"(",
"InputStream",
"configStream",
")",
"throws",
"InvalidArgumentException",
",",
"NetworkConfigurationException",
"{",
"logger",
".",
"trace",
"(",
"\"NetworkConfig.fromYamlStream...\"",
")",
";",
"// Sanity check",
"if",
"(",
"configStream",
"==",
"null",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"configStream must be specified\"",
")",
";",
"}",
"Yaml",
"yaml",
"=",
"new",
"Yaml",
"(",
")",
";",
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"Map",
"<",
"String",
",",
"Object",
">",
"map",
"=",
"yaml",
".",
"load",
"(",
"configStream",
")",
";",
"JsonObjectBuilder",
"builder",
"=",
"Json",
".",
"createObjectBuilder",
"(",
"map",
")",
";",
"JsonObject",
"jsonConfig",
"=",
"builder",
".",
"build",
"(",
")",
";",
"return",
"fromJsonObject",
"(",
"jsonConfig",
")",
";",
"}"
] |
Creates a new NetworkConfig instance configured with details supplied in YAML format
@param configStream A stream opened on a YAML document containing network configuration details
@return A new NetworkConfig instance
@throws InvalidArgumentException
|
[
"Creates",
"a",
"new",
"NetworkConfig",
"instance",
"configured",
"with",
"details",
"supplied",
"in",
"YAML",
"format"
] |
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
|
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/NetworkConfig.java#L265-L283
|
21,968
|
hyperledger/fabric-sdk-java
|
src/main/java/org/hyperledger/fabric/sdk/NetworkConfig.java
|
NetworkConfig.fromJsonStream
|
public static NetworkConfig fromJsonStream(InputStream configStream) throws InvalidArgumentException, NetworkConfigurationException {
logger.trace("NetworkConfig.fromJsonStream...");
// Sanity check
if (configStream == null) {
throw new InvalidArgumentException("configStream must be specified");
}
// Read the input stream and convert to JSON
try (JsonReader reader = Json.createReader(configStream)) {
JsonObject jsonConfig = (JsonObject) reader.read();
return fromJsonObject(jsonConfig);
}
}
|
java
|
public static NetworkConfig fromJsonStream(InputStream configStream) throws InvalidArgumentException, NetworkConfigurationException {
logger.trace("NetworkConfig.fromJsonStream...");
// Sanity check
if (configStream == null) {
throw new InvalidArgumentException("configStream must be specified");
}
// Read the input stream and convert to JSON
try (JsonReader reader = Json.createReader(configStream)) {
JsonObject jsonConfig = (JsonObject) reader.read();
return fromJsonObject(jsonConfig);
}
}
|
[
"public",
"static",
"NetworkConfig",
"fromJsonStream",
"(",
"InputStream",
"configStream",
")",
"throws",
"InvalidArgumentException",
",",
"NetworkConfigurationException",
"{",
"logger",
".",
"trace",
"(",
"\"NetworkConfig.fromJsonStream...\"",
")",
";",
"// Sanity check",
"if",
"(",
"configStream",
"==",
"null",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"configStream must be specified\"",
")",
";",
"}",
"// Read the input stream and convert to JSON",
"try",
"(",
"JsonReader",
"reader",
"=",
"Json",
".",
"createReader",
"(",
"configStream",
")",
")",
"{",
"JsonObject",
"jsonConfig",
"=",
"(",
"JsonObject",
")",
"reader",
".",
"read",
"(",
")",
";",
"return",
"fromJsonObject",
"(",
"jsonConfig",
")",
";",
"}",
"}"
] |
Creates a new NetworkConfig instance configured with details supplied in JSON format
@param configStream A stream opened on a JSON document containing network configuration details
@return A new NetworkConfig instance
@throws InvalidArgumentException
|
[
"Creates",
"a",
"new",
"NetworkConfig",
"instance",
"configured",
"with",
"details",
"supplied",
"in",
"JSON",
"format"
] |
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
|
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/NetworkConfig.java#L292-L308
|
21,969
|
hyperledger/fabric-sdk-java
|
src/main/java/org/hyperledger/fabric/sdk/NetworkConfig.java
|
NetworkConfig.fromJsonObject
|
public static NetworkConfig fromJsonObject(JsonObject jsonConfig) throws InvalidArgumentException, NetworkConfigurationException {
// Sanity check
if (jsonConfig == null) {
throw new InvalidArgumentException("jsonConfig must be specified");
}
if (logger.isTraceEnabled()) {
logger.trace(format("NetworkConfig.fromJsonObject: %s", jsonConfig.toString()));
}
return NetworkConfig.load(jsonConfig);
}
|
java
|
public static NetworkConfig fromJsonObject(JsonObject jsonConfig) throws InvalidArgumentException, NetworkConfigurationException {
// Sanity check
if (jsonConfig == null) {
throw new InvalidArgumentException("jsonConfig must be specified");
}
if (logger.isTraceEnabled()) {
logger.trace(format("NetworkConfig.fromJsonObject: %s", jsonConfig.toString()));
}
return NetworkConfig.load(jsonConfig);
}
|
[
"public",
"static",
"NetworkConfig",
"fromJsonObject",
"(",
"JsonObject",
"jsonConfig",
")",
"throws",
"InvalidArgumentException",
",",
"NetworkConfigurationException",
"{",
"// Sanity check",
"if",
"(",
"jsonConfig",
"==",
"null",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"jsonConfig must be specified\"",
")",
";",
"}",
"if",
"(",
"logger",
".",
"isTraceEnabled",
"(",
")",
")",
"{",
"logger",
".",
"trace",
"(",
"format",
"(",
"\"NetworkConfig.fromJsonObject: %s\"",
",",
"jsonConfig",
".",
"toString",
"(",
")",
")",
")",
";",
"}",
"return",
"NetworkConfig",
".",
"load",
"(",
"jsonConfig",
")",
";",
"}"
] |
Creates a new NetworkConfig instance configured with details supplied in a JSON object
@param jsonConfig JSON object containing network configuration details
@return A new NetworkConfig instance
@throws InvalidArgumentException
|
[
"Creates",
"a",
"new",
"NetworkConfig",
"instance",
"configured",
"with",
"details",
"supplied",
"in",
"a",
"JSON",
"object"
] |
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
|
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/NetworkConfig.java#L317-L329
|
21,970
|
hyperledger/fabric-sdk-java
|
src/main/java/org/hyperledger/fabric/sdk/NetworkConfig.java
|
NetworkConfig.fromFile
|
private static NetworkConfig fromFile(File configFile, boolean isJson) throws InvalidArgumentException, IOException, NetworkConfigurationException {
// Sanity check
if (configFile == null) {
throw new InvalidArgumentException("configFile must be specified");
}
if (logger.isTraceEnabled()) {
logger.trace(format("NetworkConfig.fromFile: %s isJson = %b", configFile.getAbsolutePath(), isJson));
}
NetworkConfig config;
// Json file
try (InputStream stream = new FileInputStream(configFile)) {
config = isJson ? fromJsonStream(stream) : fromYamlStream(stream);
}
return config;
}
|
java
|
private static NetworkConfig fromFile(File configFile, boolean isJson) throws InvalidArgumentException, IOException, NetworkConfigurationException {
// Sanity check
if (configFile == null) {
throw new InvalidArgumentException("configFile must be specified");
}
if (logger.isTraceEnabled()) {
logger.trace(format("NetworkConfig.fromFile: %s isJson = %b", configFile.getAbsolutePath(), isJson));
}
NetworkConfig config;
// Json file
try (InputStream stream = new FileInputStream(configFile)) {
config = isJson ? fromJsonStream(stream) : fromYamlStream(stream);
}
return config;
}
|
[
"private",
"static",
"NetworkConfig",
"fromFile",
"(",
"File",
"configFile",
",",
"boolean",
"isJson",
")",
"throws",
"InvalidArgumentException",
",",
"IOException",
",",
"NetworkConfigurationException",
"{",
"// Sanity check",
"if",
"(",
"configFile",
"==",
"null",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"configFile must be specified\"",
")",
";",
"}",
"if",
"(",
"logger",
".",
"isTraceEnabled",
"(",
")",
")",
"{",
"logger",
".",
"trace",
"(",
"format",
"(",
"\"NetworkConfig.fromFile: %s isJson = %b\"",
",",
"configFile",
".",
"getAbsolutePath",
"(",
")",
",",
"isJson",
")",
")",
";",
"}",
"NetworkConfig",
"config",
";",
"// Json file",
"try",
"(",
"InputStream",
"stream",
"=",
"new",
"FileInputStream",
"(",
"configFile",
")",
")",
"{",
"config",
"=",
"isJson",
"?",
"fromJsonStream",
"(",
"stream",
")",
":",
"fromYamlStream",
"(",
"stream",
")",
";",
"}",
"return",
"config",
";",
"}"
] |
Loads a NetworkConfig object from a Json or Yaml file
|
[
"Loads",
"a",
"NetworkConfig",
"object",
"from",
"a",
"Json",
"or",
"Yaml",
"file"
] |
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
|
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/NetworkConfig.java#L332-L351
|
21,971
|
hyperledger/fabric-sdk-java
|
src/main/java/org/hyperledger/fabric/sdk/NetworkConfig.java
|
NetworkConfig.load
|
private static NetworkConfig load(JsonObject jsonConfig) throws InvalidArgumentException, NetworkConfigurationException {
// Sanity check
if (jsonConfig == null) {
throw new InvalidArgumentException("config must be specified");
}
return new NetworkConfig(jsonConfig);
}
|
java
|
private static NetworkConfig load(JsonObject jsonConfig) throws InvalidArgumentException, NetworkConfigurationException {
// Sanity check
if (jsonConfig == null) {
throw new InvalidArgumentException("config must be specified");
}
return new NetworkConfig(jsonConfig);
}
|
[
"private",
"static",
"NetworkConfig",
"load",
"(",
"JsonObject",
"jsonConfig",
")",
"throws",
"InvalidArgumentException",
",",
"NetworkConfigurationException",
"{",
"// Sanity check",
"if",
"(",
"jsonConfig",
"==",
"null",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"config must be specified\"",
")",
";",
"}",
"return",
"new",
"NetworkConfig",
"(",
"jsonConfig",
")",
";",
"}"
] |
Returns a new NetworkConfig instance and populates it from the specified JSON object
@param jsonConfig The JSON object containing the config details
@return A populated NetworkConfig instance
@throws InvalidArgumentException
|
[
"Returns",
"a",
"new",
"NetworkConfig",
"instance",
"and",
"populates",
"it",
"from",
"the",
"specified",
"JSON",
"object"
] |
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
|
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/NetworkConfig.java#L360-L368
|
21,972
|
hyperledger/fabric-sdk-java
|
src/main/java/org/hyperledger/fabric/sdk/NetworkConfig.java
|
NetworkConfig.getPeerOrgInfos
|
public Map<String, OrgInfo> getPeerOrgInfos(final String peerName) throws InvalidArgumentException {
if (Utils.isNullOrEmpty(peerName)) {
throw new InvalidArgumentException("peerName can not be null or empty.");
}
if (organizations == null || organizations.isEmpty()) {
return new HashMap<>();
}
Map<String, OrgInfo> ret = new HashMap<>(16);
organizations.forEach((name, orgInfo) -> {
if (orgInfo.getPeerNames().contains(peerName)) {
ret.put(name, orgInfo);
}
});
return ret;
}
|
java
|
public Map<String, OrgInfo> getPeerOrgInfos(final String peerName) throws InvalidArgumentException {
if (Utils.isNullOrEmpty(peerName)) {
throw new InvalidArgumentException("peerName can not be null or empty.");
}
if (organizations == null || organizations.isEmpty()) {
return new HashMap<>();
}
Map<String, OrgInfo> ret = new HashMap<>(16);
organizations.forEach((name, orgInfo) -> {
if (orgInfo.getPeerNames().contains(peerName)) {
ret.put(name, orgInfo);
}
});
return ret;
}
|
[
"public",
"Map",
"<",
"String",
",",
"OrgInfo",
">",
"getPeerOrgInfos",
"(",
"final",
"String",
"peerName",
")",
"throws",
"InvalidArgumentException",
"{",
"if",
"(",
"Utils",
".",
"isNullOrEmpty",
"(",
"peerName",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"peerName can not be null or empty.\"",
")",
";",
"}",
"if",
"(",
"organizations",
"==",
"null",
"||",
"organizations",
".",
"isEmpty",
"(",
")",
")",
"{",
"return",
"new",
"HashMap",
"<>",
"(",
")",
";",
"}",
"Map",
"<",
"String",
",",
"OrgInfo",
">",
"ret",
"=",
"new",
"HashMap",
"<>",
"(",
"16",
")",
";",
"organizations",
".",
"forEach",
"(",
"(",
"name",
",",
"orgInfo",
")",
"->",
"{",
"if",
"(",
"orgInfo",
".",
"getPeerNames",
"(",
")",
".",
"contains",
"(",
"peerName",
")",
")",
"{",
"ret",
".",
"put",
"(",
"name",
",",
"orgInfo",
")",
";",
"}",
"}",
")",
";",
"return",
"ret",
";",
"}"
] |
Find organizations for a peer.
@param peerName name of peer
@return returns map of orgName to {@link OrgInfo} that the peer belongs to.
@throws InvalidArgumentException
|
[
"Find",
"organizations",
"for",
"a",
"peer",
"."
] |
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
|
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/NetworkConfig.java#L389-L407
|
21,973
|
hyperledger/fabric-sdk-java
|
src/main/java/org/hyperledger/fabric/sdk/NetworkConfig.java
|
NetworkConfig.getPeerAdmin
|
public UserInfo getPeerAdmin(String orgName) throws NetworkConfigurationException {
OrgInfo org = getOrganizationInfo(orgName);
if (org == null) {
throw new NetworkConfigurationException(format("Organization %s is not defined", orgName));
}
return org.getPeerAdmin();
}
|
java
|
public UserInfo getPeerAdmin(String orgName) throws NetworkConfigurationException {
OrgInfo org = getOrganizationInfo(orgName);
if (org == null) {
throw new NetworkConfigurationException(format("Organization %s is not defined", orgName));
}
return org.getPeerAdmin();
}
|
[
"public",
"UserInfo",
"getPeerAdmin",
"(",
"String",
"orgName",
")",
"throws",
"NetworkConfigurationException",
"{",
"OrgInfo",
"org",
"=",
"getOrganizationInfo",
"(",
"orgName",
")",
";",
"if",
"(",
"org",
"==",
"null",
")",
"{",
"throw",
"new",
"NetworkConfigurationException",
"(",
"format",
"(",
"\"Organization %s is not defined\"",
",",
"orgName",
")",
")",
";",
"}",
"return",
"org",
".",
"getPeerAdmin",
"(",
")",
";",
"}"
] |
Returns the admin user associated with the specified organization
@param orgName The name of the organization
@return The admin user details
@throws NetworkConfigurationException
|
[
"Returns",
"the",
"admin",
"user",
"associated",
"with",
"the",
"specified",
"organization"
] |
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
|
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/NetworkConfig.java#L427-L435
|
21,974
|
hyperledger/fabric-sdk-java
|
src/main/java/org/hyperledger/fabric/sdk/NetworkConfig.java
|
NetworkConfig.createAllOrderers
|
private void createAllOrderers() throws NetworkConfigurationException {
// Sanity check
if (orderers != null) {
throw new NetworkConfigurationException("INTERNAL ERROR: orderers has already been initialized!");
}
orderers = new HashMap<>();
// orderers is a JSON object containing a nested object for each orderers
JsonObject jsonOrderers = getJsonObject(jsonConfig, "orderers");
if (jsonOrderers != null) {
for (Entry<String, JsonValue> entry : jsonOrderers.entrySet()) {
String ordererName = entry.getKey();
JsonObject jsonOrderer = getJsonValueAsObject(entry.getValue());
if (jsonOrderer == null) {
throw new NetworkConfigurationException(format("Error loading config. Invalid orderer entry: %s", ordererName));
}
Node orderer = createNode(ordererName, jsonOrderer, "url");
if (orderer == null) {
throw new NetworkConfigurationException(format("Error loading config. Invalid orderer entry: %s", ordererName));
}
orderers.put(ordererName, orderer);
}
}
}
|
java
|
private void createAllOrderers() throws NetworkConfigurationException {
// Sanity check
if (orderers != null) {
throw new NetworkConfigurationException("INTERNAL ERROR: orderers has already been initialized!");
}
orderers = new HashMap<>();
// orderers is a JSON object containing a nested object for each orderers
JsonObject jsonOrderers = getJsonObject(jsonConfig, "orderers");
if (jsonOrderers != null) {
for (Entry<String, JsonValue> entry : jsonOrderers.entrySet()) {
String ordererName = entry.getKey();
JsonObject jsonOrderer = getJsonValueAsObject(entry.getValue());
if (jsonOrderer == null) {
throw new NetworkConfigurationException(format("Error loading config. Invalid orderer entry: %s", ordererName));
}
Node orderer = createNode(ordererName, jsonOrderer, "url");
if (orderer == null) {
throw new NetworkConfigurationException(format("Error loading config. Invalid orderer entry: %s", ordererName));
}
orderers.put(ordererName, orderer);
}
}
}
|
[
"private",
"void",
"createAllOrderers",
"(",
")",
"throws",
"NetworkConfigurationException",
"{",
"// Sanity check",
"if",
"(",
"orderers",
"!=",
"null",
")",
"{",
"throw",
"new",
"NetworkConfigurationException",
"(",
"\"INTERNAL ERROR: orderers has already been initialized!\"",
")",
";",
"}",
"orderers",
"=",
"new",
"HashMap",
"<>",
"(",
")",
";",
"// orderers is a JSON object containing a nested object for each orderers",
"JsonObject",
"jsonOrderers",
"=",
"getJsonObject",
"(",
"jsonConfig",
",",
"\"orderers\"",
")",
";",
"if",
"(",
"jsonOrderers",
"!=",
"null",
")",
"{",
"for",
"(",
"Entry",
"<",
"String",
",",
"JsonValue",
">",
"entry",
":",
"jsonOrderers",
".",
"entrySet",
"(",
")",
")",
"{",
"String",
"ordererName",
"=",
"entry",
".",
"getKey",
"(",
")",
";",
"JsonObject",
"jsonOrderer",
"=",
"getJsonValueAsObject",
"(",
"entry",
".",
"getValue",
"(",
")",
")",
";",
"if",
"(",
"jsonOrderer",
"==",
"null",
")",
"{",
"throw",
"new",
"NetworkConfigurationException",
"(",
"format",
"(",
"\"Error loading config. Invalid orderer entry: %s\"",
",",
"ordererName",
")",
")",
";",
"}",
"Node",
"orderer",
"=",
"createNode",
"(",
"ordererName",
",",
"jsonOrderer",
",",
"\"url\"",
")",
";",
"if",
"(",
"orderer",
"==",
"null",
")",
"{",
"throw",
"new",
"NetworkConfigurationException",
"(",
"format",
"(",
"\"Error loading config. Invalid orderer entry: %s\"",
",",
"ordererName",
")",
")",
";",
"}",
"orderers",
".",
"put",
"(",
"ordererName",
",",
"orderer",
")",
";",
"}",
"}",
"}"
] |
Creates Node instances representing all the orderers defined in the config file
|
[
"Creates",
"Node",
"instances",
"representing",
"all",
"the",
"orderers",
"defined",
"in",
"the",
"config",
"file"
] |
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
|
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/NetworkConfig.java#L501-L531
|
21,975
|
hyperledger/fabric-sdk-java
|
src/main/java/org/hyperledger/fabric/sdk/NetworkConfig.java
|
NetworkConfig.createAllPeers
|
private void createAllPeers() throws NetworkConfigurationException {
// Sanity checks
if (peers != null) {
throw new NetworkConfigurationException("INTERNAL ERROR: peers has already been initialized!");
}
peers = new HashMap<>();
// peers is a JSON object containing a nested object for each peer
JsonObject jsonPeers = getJsonObject(jsonConfig, "peers");
//out("Peers: " + (jsonPeers == null ? "null" : jsonPeers.toString()));
if (jsonPeers != null) {
for (Entry<String, JsonValue> entry : jsonPeers.entrySet()) {
String peerName = entry.getKey();
JsonObject jsonPeer = getJsonValueAsObject(entry.getValue());
if (jsonPeer == null) {
throw new NetworkConfigurationException(format("Error loading config. Invalid peer entry: %s", peerName));
}
Node peer = createNode(peerName, jsonPeer, "url");
if (peer == null) {
throw new NetworkConfigurationException(format("Error loading config. Invalid peer entry: %s", peerName));
}
peers.put(peerName, peer);
}
}
}
|
java
|
private void createAllPeers() throws NetworkConfigurationException {
// Sanity checks
if (peers != null) {
throw new NetworkConfigurationException("INTERNAL ERROR: peers has already been initialized!");
}
peers = new HashMap<>();
// peers is a JSON object containing a nested object for each peer
JsonObject jsonPeers = getJsonObject(jsonConfig, "peers");
//out("Peers: " + (jsonPeers == null ? "null" : jsonPeers.toString()));
if (jsonPeers != null) {
for (Entry<String, JsonValue> entry : jsonPeers.entrySet()) {
String peerName = entry.getKey();
JsonObject jsonPeer = getJsonValueAsObject(entry.getValue());
if (jsonPeer == null) {
throw new NetworkConfigurationException(format("Error loading config. Invalid peer entry: %s", peerName));
}
Node peer = createNode(peerName, jsonPeer, "url");
if (peer == null) {
throw new NetworkConfigurationException(format("Error loading config. Invalid peer entry: %s", peerName));
}
peers.put(peerName, peer);
}
}
}
|
[
"private",
"void",
"createAllPeers",
"(",
")",
"throws",
"NetworkConfigurationException",
"{",
"// Sanity checks",
"if",
"(",
"peers",
"!=",
"null",
")",
"{",
"throw",
"new",
"NetworkConfigurationException",
"(",
"\"INTERNAL ERROR: peers has already been initialized!\"",
")",
";",
"}",
"peers",
"=",
"new",
"HashMap",
"<>",
"(",
")",
";",
"// peers is a JSON object containing a nested object for each peer",
"JsonObject",
"jsonPeers",
"=",
"getJsonObject",
"(",
"jsonConfig",
",",
"\"peers\"",
")",
";",
"//out(\"Peers: \" + (jsonPeers == null ? \"null\" : jsonPeers.toString()));",
"if",
"(",
"jsonPeers",
"!=",
"null",
")",
"{",
"for",
"(",
"Entry",
"<",
"String",
",",
"JsonValue",
">",
"entry",
":",
"jsonPeers",
".",
"entrySet",
"(",
")",
")",
"{",
"String",
"peerName",
"=",
"entry",
".",
"getKey",
"(",
")",
";",
"JsonObject",
"jsonPeer",
"=",
"getJsonValueAsObject",
"(",
"entry",
".",
"getValue",
"(",
")",
")",
";",
"if",
"(",
"jsonPeer",
"==",
"null",
")",
"{",
"throw",
"new",
"NetworkConfigurationException",
"(",
"format",
"(",
"\"Error loading config. Invalid peer entry: %s\"",
",",
"peerName",
")",
")",
";",
"}",
"Node",
"peer",
"=",
"createNode",
"(",
"peerName",
",",
"jsonPeer",
",",
"\"url\"",
")",
";",
"if",
"(",
"peer",
"==",
"null",
")",
"{",
"throw",
"new",
"NetworkConfigurationException",
"(",
"format",
"(",
"\"Error loading config. Invalid peer entry: %s\"",
",",
"peerName",
")",
")",
";",
"}",
"peers",
".",
"put",
"(",
"peerName",
",",
"peer",
")",
";",
"}",
"}",
"}"
] |
Creates Node instances representing all the peers defined in the config file
|
[
"Creates",
"Node",
"instances",
"representing",
"all",
"the",
"peers",
"defined",
"in",
"the",
"config",
"file"
] |
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
|
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/NetworkConfig.java#L534-L566
|
21,976
|
hyperledger/fabric-sdk-java
|
src/main/java/org/hyperledger/fabric/sdk/NetworkConfig.java
|
NetworkConfig.findCertificateAuthorities
|
private Map<String, JsonObject> findCertificateAuthorities() throws NetworkConfigurationException {
Map<String, JsonObject> ret = new HashMap<>();
JsonObject jsonCertificateAuthorities = getJsonObject(jsonConfig, "certificateAuthorities");
if (null != jsonCertificateAuthorities) {
for (Entry<String, JsonValue> entry : jsonCertificateAuthorities.entrySet()) {
String name = entry.getKey();
JsonObject jsonCA = getJsonValueAsObject(entry.getValue());
if (jsonCA == null) {
throw new NetworkConfigurationException(format("Error loading config. Invalid CA entry: %s", name));
}
ret.put(name, jsonCA);
}
}
return ret;
}
|
java
|
private Map<String, JsonObject> findCertificateAuthorities() throws NetworkConfigurationException {
Map<String, JsonObject> ret = new HashMap<>();
JsonObject jsonCertificateAuthorities = getJsonObject(jsonConfig, "certificateAuthorities");
if (null != jsonCertificateAuthorities) {
for (Entry<String, JsonValue> entry : jsonCertificateAuthorities.entrySet()) {
String name = entry.getKey();
JsonObject jsonCA = getJsonValueAsObject(entry.getValue());
if (jsonCA == null) {
throw new NetworkConfigurationException(format("Error loading config. Invalid CA entry: %s", name));
}
ret.put(name, jsonCA);
}
}
return ret;
}
|
[
"private",
"Map",
"<",
"String",
",",
"JsonObject",
">",
"findCertificateAuthorities",
"(",
")",
"throws",
"NetworkConfigurationException",
"{",
"Map",
"<",
"String",
",",
"JsonObject",
">",
"ret",
"=",
"new",
"HashMap",
"<>",
"(",
")",
";",
"JsonObject",
"jsonCertificateAuthorities",
"=",
"getJsonObject",
"(",
"jsonConfig",
",",
"\"certificateAuthorities\"",
")",
";",
"if",
"(",
"null",
"!=",
"jsonCertificateAuthorities",
")",
"{",
"for",
"(",
"Entry",
"<",
"String",
",",
"JsonValue",
">",
"entry",
":",
"jsonCertificateAuthorities",
".",
"entrySet",
"(",
")",
")",
"{",
"String",
"name",
"=",
"entry",
".",
"getKey",
"(",
")",
";",
"JsonObject",
"jsonCA",
"=",
"getJsonValueAsObject",
"(",
"entry",
".",
"getValue",
"(",
")",
")",
";",
"if",
"(",
"jsonCA",
"==",
"null",
")",
"{",
"throw",
"new",
"NetworkConfigurationException",
"(",
"format",
"(",
"\"Error loading config. Invalid CA entry: %s\"",
",",
"name",
")",
")",
";",
"}",
"ret",
".",
"put",
"(",
"name",
",",
"jsonCA",
")",
";",
"}",
"}",
"return",
"ret",
";",
"}"
] |
Produce a map from tag to jsonobject for the CA
|
[
"Produce",
"a",
"map",
"from",
"tag",
"to",
"jsonobject",
"for",
"the",
"CA"
] |
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
|
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/NetworkConfig.java#L569-L588
|
21,977
|
hyperledger/fabric-sdk-java
|
src/main/java/org/hyperledger/fabric/sdk/NetworkConfig.java
|
NetworkConfig.createAllOrganizations
|
private void createAllOrganizations(Map<String, JsonObject> foundCertificateAuthorities) throws NetworkConfigurationException {
// Sanity check
if (organizations != null) {
throw new NetworkConfigurationException("INTERNAL ERROR: organizations has already been initialized!");
}
organizations = new HashMap<>();
// organizations is a JSON object containing a nested object for each Org
JsonObject jsonOrganizations = getJsonObject(jsonConfig, "organizations");
if (jsonOrganizations != null) {
for (Entry<String, JsonValue> entry : jsonOrganizations.entrySet()) {
String orgName = entry.getKey();
JsonObject jsonOrg = getJsonValueAsObject(entry.getValue());
if (jsonOrg == null) {
throw new NetworkConfigurationException(format("Error loading config. Invalid Organization entry: %s", orgName));
}
OrgInfo org = createOrg(orgName, jsonOrg, foundCertificateAuthorities);
organizations.put(orgName, org);
}
}
}
|
java
|
private void createAllOrganizations(Map<String, JsonObject> foundCertificateAuthorities) throws NetworkConfigurationException {
// Sanity check
if (organizations != null) {
throw new NetworkConfigurationException("INTERNAL ERROR: organizations has already been initialized!");
}
organizations = new HashMap<>();
// organizations is a JSON object containing a nested object for each Org
JsonObject jsonOrganizations = getJsonObject(jsonConfig, "organizations");
if (jsonOrganizations != null) {
for (Entry<String, JsonValue> entry : jsonOrganizations.entrySet()) {
String orgName = entry.getKey();
JsonObject jsonOrg = getJsonValueAsObject(entry.getValue());
if (jsonOrg == null) {
throw new NetworkConfigurationException(format("Error loading config. Invalid Organization entry: %s", orgName));
}
OrgInfo org = createOrg(orgName, jsonOrg, foundCertificateAuthorities);
organizations.put(orgName, org);
}
}
}
|
[
"private",
"void",
"createAllOrganizations",
"(",
"Map",
"<",
"String",
",",
"JsonObject",
">",
"foundCertificateAuthorities",
")",
"throws",
"NetworkConfigurationException",
"{",
"// Sanity check",
"if",
"(",
"organizations",
"!=",
"null",
")",
"{",
"throw",
"new",
"NetworkConfigurationException",
"(",
"\"INTERNAL ERROR: organizations has already been initialized!\"",
")",
";",
"}",
"organizations",
"=",
"new",
"HashMap",
"<>",
"(",
")",
";",
"// organizations is a JSON object containing a nested object for each Org",
"JsonObject",
"jsonOrganizations",
"=",
"getJsonObject",
"(",
"jsonConfig",
",",
"\"organizations\"",
")",
";",
"if",
"(",
"jsonOrganizations",
"!=",
"null",
")",
"{",
"for",
"(",
"Entry",
"<",
"String",
",",
"JsonValue",
">",
"entry",
":",
"jsonOrganizations",
".",
"entrySet",
"(",
")",
")",
"{",
"String",
"orgName",
"=",
"entry",
".",
"getKey",
"(",
")",
";",
"JsonObject",
"jsonOrg",
"=",
"getJsonValueAsObject",
"(",
"entry",
".",
"getValue",
"(",
")",
")",
";",
"if",
"(",
"jsonOrg",
"==",
"null",
")",
"{",
"throw",
"new",
"NetworkConfigurationException",
"(",
"format",
"(",
"\"Error loading config. Invalid Organization entry: %s\"",
",",
"orgName",
")",
")",
";",
"}",
"OrgInfo",
"org",
"=",
"createOrg",
"(",
"orgName",
",",
"jsonOrg",
",",
"foundCertificateAuthorities",
")",
";",
"organizations",
".",
"put",
"(",
"orgName",
",",
"org",
")",
";",
"}",
"}",
"}"
] |
Creates JsonObjects representing all the Organizations defined in the config file
|
[
"Creates",
"JsonObjects",
"representing",
"all",
"the",
"Organizations",
"defined",
"in",
"the",
"config",
"file"
] |
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
|
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/NetworkConfig.java#L591-L618
|
21,978
|
hyperledger/fabric-sdk-java
|
src/main/java/org/hyperledger/fabric/sdk/NetworkConfig.java
|
NetworkConfig.getOrderer
|
private Orderer getOrderer(HFClient client, String ordererName) throws InvalidArgumentException {
Orderer orderer = null;
Node o = orderers.get(ordererName);
if (o != null) {
orderer = client.newOrderer(o.getName(), o.getUrl(), o.getProperties());
}
return orderer;
}
|
java
|
private Orderer getOrderer(HFClient client, String ordererName) throws InvalidArgumentException {
Orderer orderer = null;
Node o = orderers.get(ordererName);
if (o != null) {
orderer = client.newOrderer(o.getName(), o.getUrl(), o.getProperties());
}
return orderer;
}
|
[
"private",
"Orderer",
"getOrderer",
"(",
"HFClient",
"client",
",",
"String",
"ordererName",
")",
"throws",
"InvalidArgumentException",
"{",
"Orderer",
"orderer",
"=",
"null",
";",
"Node",
"o",
"=",
"orderers",
".",
"get",
"(",
"ordererName",
")",
";",
"if",
"(",
"o",
"!=",
"null",
")",
"{",
"orderer",
"=",
"client",
".",
"newOrderer",
"(",
"o",
".",
"getName",
"(",
")",
",",
"o",
".",
"getUrl",
"(",
")",
",",
"o",
".",
"getProperties",
"(",
")",
")",
";",
"}",
"return",
"orderer",
";",
"}"
] |
Returns a new Orderer instance for the specified orderer name
|
[
"Returns",
"a",
"new",
"Orderer",
"instance",
"for",
"the",
"specified",
"orderer",
"name"
] |
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
|
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/NetworkConfig.java#L793-L800
|
21,979
|
hyperledger/fabric-sdk-java
|
src/main/java/org/hyperledger/fabric/sdk/NetworkConfig.java
|
NetworkConfig.createNode
|
private Node createNode(String nodeName, JsonObject jsonNode, String urlPropName) throws NetworkConfigurationException {
// jsonNode.
// if (jsonNode.isNull(urlPropName)) {
// return null;
// }
String url = jsonNode.getString(urlPropName, null);
if (url == null) {
return null;
}
Properties props = extractProperties(jsonNode, "grpcOptions");
if (null != props) {
String value = props.getProperty("grpc.keepalive_time_ms");
if (null != value) {
props.remove("grpc.keepalive_time_ms");
props.put("grpc.NettyChannelBuilderOption.keepAliveTime", new Object[] {new Long(value), TimeUnit.MILLISECONDS});
}
value = props.getProperty("grpc.keepalive_timeout_ms");
if (null != value) {
props.remove("grpc.keepalive_timeout_ms");
props.put("grpc.NettyChannelBuilderOption.keepAliveTimeout", new Object[] {new Long(value), TimeUnit.MILLISECONDS});
}
}
// Extract the pem details
getTLSCerts(nodeName, jsonNode, props);
return new Node(nodeName, url, props, jsonNode);
}
|
java
|
private Node createNode(String nodeName, JsonObject jsonNode, String urlPropName) throws NetworkConfigurationException {
// jsonNode.
// if (jsonNode.isNull(urlPropName)) {
// return null;
// }
String url = jsonNode.getString(urlPropName, null);
if (url == null) {
return null;
}
Properties props = extractProperties(jsonNode, "grpcOptions");
if (null != props) {
String value = props.getProperty("grpc.keepalive_time_ms");
if (null != value) {
props.remove("grpc.keepalive_time_ms");
props.put("grpc.NettyChannelBuilderOption.keepAliveTime", new Object[] {new Long(value), TimeUnit.MILLISECONDS});
}
value = props.getProperty("grpc.keepalive_timeout_ms");
if (null != value) {
props.remove("grpc.keepalive_timeout_ms");
props.put("grpc.NettyChannelBuilderOption.keepAliveTimeout", new Object[] {new Long(value), TimeUnit.MILLISECONDS});
}
}
// Extract the pem details
getTLSCerts(nodeName, jsonNode, props);
return new Node(nodeName, url, props, jsonNode);
}
|
[
"private",
"Node",
"createNode",
"(",
"String",
"nodeName",
",",
"JsonObject",
"jsonNode",
",",
"String",
"urlPropName",
")",
"throws",
"NetworkConfigurationException",
"{",
"// jsonNode.",
"// if (jsonNode.isNull(urlPropName)) {",
"// return null;",
"// }",
"String",
"url",
"=",
"jsonNode",
".",
"getString",
"(",
"urlPropName",
",",
"null",
")",
";",
"if",
"(",
"url",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"Properties",
"props",
"=",
"extractProperties",
"(",
"jsonNode",
",",
"\"grpcOptions\"",
")",
";",
"if",
"(",
"null",
"!=",
"props",
")",
"{",
"String",
"value",
"=",
"props",
".",
"getProperty",
"(",
"\"grpc.keepalive_time_ms\"",
")",
";",
"if",
"(",
"null",
"!=",
"value",
")",
"{",
"props",
".",
"remove",
"(",
"\"grpc.keepalive_time_ms\"",
")",
";",
"props",
".",
"put",
"(",
"\"grpc.NettyChannelBuilderOption.keepAliveTime\"",
",",
"new",
"Object",
"[",
"]",
"{",
"new",
"Long",
"(",
"value",
")",
",",
"TimeUnit",
".",
"MILLISECONDS",
"}",
")",
";",
"}",
"value",
"=",
"props",
".",
"getProperty",
"(",
"\"grpc.keepalive_timeout_ms\"",
")",
";",
"if",
"(",
"null",
"!=",
"value",
")",
"{",
"props",
".",
"remove",
"(",
"\"grpc.keepalive_timeout_ms\"",
")",
";",
"props",
".",
"put",
"(",
"\"grpc.NettyChannelBuilderOption.keepAliveTimeout\"",
",",
"new",
"Object",
"[",
"]",
"{",
"new",
"Long",
"(",
"value",
")",
",",
"TimeUnit",
".",
"MILLISECONDS",
"}",
")",
";",
"}",
"}",
"// Extract the pem details",
"getTLSCerts",
"(",
"nodeName",
",",
"jsonNode",
",",
"props",
")",
";",
"return",
"new",
"Node",
"(",
"nodeName",
",",
"url",
",",
"props",
",",
"jsonNode",
")",
";",
"}"
] |
Creates a new Node instance from a JSON object
|
[
"Creates",
"a",
"new",
"Node",
"instance",
"from",
"a",
"JSON",
"object"
] |
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
|
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/NetworkConfig.java#L803-L835
|
21,980
|
hyperledger/fabric-sdk-java
|
src/main/java/org/hyperledger/fabric/sdk/NetworkConfig.java
|
NetworkConfig.createOrg
|
private OrgInfo createOrg(String orgName, JsonObject jsonOrg, Map<String, JsonObject> foundCertificateAuthorities) throws NetworkConfigurationException {
String msgPrefix = format("Organization %s", orgName);
String mspId = getJsonValueAsString(jsonOrg.get("mspid"));
OrgInfo org = new OrgInfo(orgName, mspId);
// Peers
JsonArray jsonPeers = getJsonValueAsArray(jsonOrg.get("peers"));
if (jsonPeers != null) {
for (JsonValue peer : jsonPeers) {
String peerName = getJsonValueAsString(peer);
if (peerName != null) {
org.addPeerName(peerName);
}
}
}
// CAs
JsonArray jsonCertificateAuthorities = getJsonValueAsArray(jsonOrg.get("certificateAuthorities"));
if (jsonCertificateAuthorities != null) {
for (JsonValue jsonCA : jsonCertificateAuthorities) {
String caName = getJsonValueAsString(jsonCA);
if (caName != null) {
JsonObject jsonObject = foundCertificateAuthorities.get(caName);
if (jsonObject != null) {
org.addCertificateAuthority(createCA(caName, jsonObject, org));
} else {
throw new NetworkConfigurationException(format("%s: Certificate Authority %s is not defined", msgPrefix, caName));
}
}
}
}
String adminPrivateKeyString = extractPemString(jsonOrg, "adminPrivateKey", msgPrefix);
String signedCert = extractPemString(jsonOrg, "signedCert", msgPrefix);
if (!isNullOrEmpty(adminPrivateKeyString) && !isNullOrEmpty(signedCert)) {
PrivateKey privateKey = null;
try {
privateKey = getPrivateKeyFromString(adminPrivateKeyString);
} catch (IOException ioe) {
throw new NetworkConfigurationException(format("%s: Invalid private key", msgPrefix), ioe);
}
final PrivateKey privateKeyFinal = privateKey;
try {
org.peerAdmin = new UserInfo(CryptoSuite.Factory.getCryptoSuite(), mspId, "PeerAdmin_" + mspId + "_" + orgName, null);
} catch (Exception e) {
throw new NetworkConfigurationException(e.getMessage(), e);
}
org.peerAdmin.setEnrollment(new X509Enrollment(privateKeyFinal, signedCert));
}
return org;
}
|
java
|
private OrgInfo createOrg(String orgName, JsonObject jsonOrg, Map<String, JsonObject> foundCertificateAuthorities) throws NetworkConfigurationException {
String msgPrefix = format("Organization %s", orgName);
String mspId = getJsonValueAsString(jsonOrg.get("mspid"));
OrgInfo org = new OrgInfo(orgName, mspId);
// Peers
JsonArray jsonPeers = getJsonValueAsArray(jsonOrg.get("peers"));
if (jsonPeers != null) {
for (JsonValue peer : jsonPeers) {
String peerName = getJsonValueAsString(peer);
if (peerName != null) {
org.addPeerName(peerName);
}
}
}
// CAs
JsonArray jsonCertificateAuthorities = getJsonValueAsArray(jsonOrg.get("certificateAuthorities"));
if (jsonCertificateAuthorities != null) {
for (JsonValue jsonCA : jsonCertificateAuthorities) {
String caName = getJsonValueAsString(jsonCA);
if (caName != null) {
JsonObject jsonObject = foundCertificateAuthorities.get(caName);
if (jsonObject != null) {
org.addCertificateAuthority(createCA(caName, jsonObject, org));
} else {
throw new NetworkConfigurationException(format("%s: Certificate Authority %s is not defined", msgPrefix, caName));
}
}
}
}
String adminPrivateKeyString = extractPemString(jsonOrg, "adminPrivateKey", msgPrefix);
String signedCert = extractPemString(jsonOrg, "signedCert", msgPrefix);
if (!isNullOrEmpty(adminPrivateKeyString) && !isNullOrEmpty(signedCert)) {
PrivateKey privateKey = null;
try {
privateKey = getPrivateKeyFromString(adminPrivateKeyString);
} catch (IOException ioe) {
throw new NetworkConfigurationException(format("%s: Invalid private key", msgPrefix), ioe);
}
final PrivateKey privateKeyFinal = privateKey;
try {
org.peerAdmin = new UserInfo(CryptoSuite.Factory.getCryptoSuite(), mspId, "PeerAdmin_" + mspId + "_" + orgName, null);
} catch (Exception e) {
throw new NetworkConfigurationException(e.getMessage(), e);
}
org.peerAdmin.setEnrollment(new X509Enrollment(privateKeyFinal, signedCert));
}
return org;
}
|
[
"private",
"OrgInfo",
"createOrg",
"(",
"String",
"orgName",
",",
"JsonObject",
"jsonOrg",
",",
"Map",
"<",
"String",
",",
"JsonObject",
">",
"foundCertificateAuthorities",
")",
"throws",
"NetworkConfigurationException",
"{",
"String",
"msgPrefix",
"=",
"format",
"(",
"\"Organization %s\"",
",",
"orgName",
")",
";",
"String",
"mspId",
"=",
"getJsonValueAsString",
"(",
"jsonOrg",
".",
"get",
"(",
"\"mspid\"",
")",
")",
";",
"OrgInfo",
"org",
"=",
"new",
"OrgInfo",
"(",
"orgName",
",",
"mspId",
")",
";",
"// Peers",
"JsonArray",
"jsonPeers",
"=",
"getJsonValueAsArray",
"(",
"jsonOrg",
".",
"get",
"(",
"\"peers\"",
")",
")",
";",
"if",
"(",
"jsonPeers",
"!=",
"null",
")",
"{",
"for",
"(",
"JsonValue",
"peer",
":",
"jsonPeers",
")",
"{",
"String",
"peerName",
"=",
"getJsonValueAsString",
"(",
"peer",
")",
";",
"if",
"(",
"peerName",
"!=",
"null",
")",
"{",
"org",
".",
"addPeerName",
"(",
"peerName",
")",
";",
"}",
"}",
"}",
"// CAs",
"JsonArray",
"jsonCertificateAuthorities",
"=",
"getJsonValueAsArray",
"(",
"jsonOrg",
".",
"get",
"(",
"\"certificateAuthorities\"",
")",
")",
";",
"if",
"(",
"jsonCertificateAuthorities",
"!=",
"null",
")",
"{",
"for",
"(",
"JsonValue",
"jsonCA",
":",
"jsonCertificateAuthorities",
")",
"{",
"String",
"caName",
"=",
"getJsonValueAsString",
"(",
"jsonCA",
")",
";",
"if",
"(",
"caName",
"!=",
"null",
")",
"{",
"JsonObject",
"jsonObject",
"=",
"foundCertificateAuthorities",
".",
"get",
"(",
"caName",
")",
";",
"if",
"(",
"jsonObject",
"!=",
"null",
")",
"{",
"org",
".",
"addCertificateAuthority",
"(",
"createCA",
"(",
"caName",
",",
"jsonObject",
",",
"org",
")",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"NetworkConfigurationException",
"(",
"format",
"(",
"\"%s: Certificate Authority %s is not defined\"",
",",
"msgPrefix",
",",
"caName",
")",
")",
";",
"}",
"}",
"}",
"}",
"String",
"adminPrivateKeyString",
"=",
"extractPemString",
"(",
"jsonOrg",
",",
"\"adminPrivateKey\"",
",",
"msgPrefix",
")",
";",
"String",
"signedCert",
"=",
"extractPemString",
"(",
"jsonOrg",
",",
"\"signedCert\"",
",",
"msgPrefix",
")",
";",
"if",
"(",
"!",
"isNullOrEmpty",
"(",
"adminPrivateKeyString",
")",
"&&",
"!",
"isNullOrEmpty",
"(",
"signedCert",
")",
")",
"{",
"PrivateKey",
"privateKey",
"=",
"null",
";",
"try",
"{",
"privateKey",
"=",
"getPrivateKeyFromString",
"(",
"adminPrivateKeyString",
")",
";",
"}",
"catch",
"(",
"IOException",
"ioe",
")",
"{",
"throw",
"new",
"NetworkConfigurationException",
"(",
"format",
"(",
"\"%s: Invalid private key\"",
",",
"msgPrefix",
")",
",",
"ioe",
")",
";",
"}",
"final",
"PrivateKey",
"privateKeyFinal",
"=",
"privateKey",
";",
"try",
"{",
"org",
".",
"peerAdmin",
"=",
"new",
"UserInfo",
"(",
"CryptoSuite",
".",
"Factory",
".",
"getCryptoSuite",
"(",
")",
",",
"mspId",
",",
"\"PeerAdmin_\"",
"+",
"mspId",
"+",
"\"_\"",
"+",
"orgName",
",",
"null",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"throw",
"new",
"NetworkConfigurationException",
"(",
"e",
".",
"getMessage",
"(",
")",
",",
"e",
")",
";",
"}",
"org",
".",
"peerAdmin",
".",
"setEnrollment",
"(",
"new",
"X509Enrollment",
"(",
"privateKeyFinal",
",",
"signedCert",
")",
")",
";",
"}",
"return",
"org",
";",
"}"
] |
Creates a new OrgInfo instance from a JSON object
|
[
"Creates",
"a",
"new",
"OrgInfo",
"instance",
"from",
"a",
"JSON",
"object"
] |
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
|
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/NetworkConfig.java#L855-L917
|
21,981
|
hyperledger/fabric-sdk-java
|
src/main/java/org/hyperledger/fabric/sdk/NetworkConfig.java
|
NetworkConfig.createCA
|
private CAInfo createCA(String name, JsonObject jsonCA, OrgInfo org) throws NetworkConfigurationException {
String url = getJsonValueAsString(jsonCA.get("url"));
Properties httpOptions = extractProperties(jsonCA, "httpOptions");
String enrollId = null;
String enrollSecret = null;
List<JsonObject> registrars = getJsonValueAsList(jsonCA.get("registrar"));
List<UserInfo> regUsers = new LinkedList<>();
if (registrars != null) {
for (JsonObject reg : registrars) {
enrollId = getJsonValueAsString(reg.get("enrollId"));
enrollSecret = getJsonValueAsString(reg.get("enrollSecret"));
try {
regUsers.add(new UserInfo(CryptoSuite.Factory.getCryptoSuite(), org.mspId, enrollId, enrollSecret));
} catch (Exception e) {
throw new NetworkConfigurationException(e.getMessage(), e);
}
}
}
CAInfo caInfo = new CAInfo(name, org.mspId, url, regUsers, httpOptions);
String caName = getJsonValueAsString(jsonCA.get("caName"));
if (caName != null) {
caInfo.setCaName(caName);
}
Properties properties = new Properties();
if (null != httpOptions && "false".equals(httpOptions.getProperty("verify"))) {
properties.setProperty("allowAllHostNames", "true");
}
getTLSCerts(name, jsonCA, properties);
caInfo.setProperties(properties);
return caInfo;
}
|
java
|
private CAInfo createCA(String name, JsonObject jsonCA, OrgInfo org) throws NetworkConfigurationException {
String url = getJsonValueAsString(jsonCA.get("url"));
Properties httpOptions = extractProperties(jsonCA, "httpOptions");
String enrollId = null;
String enrollSecret = null;
List<JsonObject> registrars = getJsonValueAsList(jsonCA.get("registrar"));
List<UserInfo> regUsers = new LinkedList<>();
if (registrars != null) {
for (JsonObject reg : registrars) {
enrollId = getJsonValueAsString(reg.get("enrollId"));
enrollSecret = getJsonValueAsString(reg.get("enrollSecret"));
try {
regUsers.add(new UserInfo(CryptoSuite.Factory.getCryptoSuite(), org.mspId, enrollId, enrollSecret));
} catch (Exception e) {
throw new NetworkConfigurationException(e.getMessage(), e);
}
}
}
CAInfo caInfo = new CAInfo(name, org.mspId, url, regUsers, httpOptions);
String caName = getJsonValueAsString(jsonCA.get("caName"));
if (caName != null) {
caInfo.setCaName(caName);
}
Properties properties = new Properties();
if (null != httpOptions && "false".equals(httpOptions.getProperty("verify"))) {
properties.setProperty("allowAllHostNames", "true");
}
getTLSCerts(name, jsonCA, properties);
caInfo.setProperties(properties);
return caInfo;
}
|
[
"private",
"CAInfo",
"createCA",
"(",
"String",
"name",
",",
"JsonObject",
"jsonCA",
",",
"OrgInfo",
"org",
")",
"throws",
"NetworkConfigurationException",
"{",
"String",
"url",
"=",
"getJsonValueAsString",
"(",
"jsonCA",
".",
"get",
"(",
"\"url\"",
")",
")",
";",
"Properties",
"httpOptions",
"=",
"extractProperties",
"(",
"jsonCA",
",",
"\"httpOptions\"",
")",
";",
"String",
"enrollId",
"=",
"null",
";",
"String",
"enrollSecret",
"=",
"null",
";",
"List",
"<",
"JsonObject",
">",
"registrars",
"=",
"getJsonValueAsList",
"(",
"jsonCA",
".",
"get",
"(",
"\"registrar\"",
")",
")",
";",
"List",
"<",
"UserInfo",
">",
"regUsers",
"=",
"new",
"LinkedList",
"<>",
"(",
")",
";",
"if",
"(",
"registrars",
"!=",
"null",
")",
"{",
"for",
"(",
"JsonObject",
"reg",
":",
"registrars",
")",
"{",
"enrollId",
"=",
"getJsonValueAsString",
"(",
"reg",
".",
"get",
"(",
"\"enrollId\"",
")",
")",
";",
"enrollSecret",
"=",
"getJsonValueAsString",
"(",
"reg",
".",
"get",
"(",
"\"enrollSecret\"",
")",
")",
";",
"try",
"{",
"regUsers",
".",
"add",
"(",
"new",
"UserInfo",
"(",
"CryptoSuite",
".",
"Factory",
".",
"getCryptoSuite",
"(",
")",
",",
"org",
".",
"mspId",
",",
"enrollId",
",",
"enrollSecret",
")",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"throw",
"new",
"NetworkConfigurationException",
"(",
"e",
".",
"getMessage",
"(",
")",
",",
"e",
")",
";",
"}",
"}",
"}",
"CAInfo",
"caInfo",
"=",
"new",
"CAInfo",
"(",
"name",
",",
"org",
".",
"mspId",
",",
"url",
",",
"regUsers",
",",
"httpOptions",
")",
";",
"String",
"caName",
"=",
"getJsonValueAsString",
"(",
"jsonCA",
".",
"get",
"(",
"\"caName\"",
")",
")",
";",
"if",
"(",
"caName",
"!=",
"null",
")",
"{",
"caInfo",
".",
"setCaName",
"(",
"caName",
")",
";",
"}",
"Properties",
"properties",
"=",
"new",
"Properties",
"(",
")",
";",
"if",
"(",
"null",
"!=",
"httpOptions",
"&&",
"\"false\"",
".",
"equals",
"(",
"httpOptions",
".",
"getProperty",
"(",
"\"verify\"",
")",
")",
")",
"{",
"properties",
".",
"setProperty",
"(",
"\"allowAllHostNames\"",
",",
"\"true\"",
")",
";",
"}",
"getTLSCerts",
"(",
"name",
",",
"jsonCA",
",",
"properties",
")",
";",
"caInfo",
".",
"setProperties",
"(",
"properties",
")",
";",
"return",
"caInfo",
";",
"}"
] |
Creates a new CAInfo instance from a JSON object
|
[
"Creates",
"a",
"new",
"CAInfo",
"instance",
"from",
"a",
"JSON",
"object"
] |
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
|
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/NetworkConfig.java#L967-L1005
|
21,982
|
hyperledger/fabric-sdk-java
|
src/main/java/org/hyperledger/fabric/sdk/NetworkConfig.java
|
NetworkConfig.extractProperties
|
private static Properties extractProperties(JsonObject json, String fieldName) {
Properties props = new Properties();
// Extract any other grpc options
JsonObject options = getJsonObject(json, fieldName);
if (options != null) {
for (Entry<String, JsonValue> entry : options.entrySet()) {
String key = entry.getKey();
JsonValue value = entry.getValue();
props.setProperty(key, getJsonValue(value));
}
}
return props;
}
|
java
|
private static Properties extractProperties(JsonObject json, String fieldName) {
Properties props = new Properties();
// Extract any other grpc options
JsonObject options = getJsonObject(json, fieldName);
if (options != null) {
for (Entry<String, JsonValue> entry : options.entrySet()) {
String key = entry.getKey();
JsonValue value = entry.getValue();
props.setProperty(key, getJsonValue(value));
}
}
return props;
}
|
[
"private",
"static",
"Properties",
"extractProperties",
"(",
"JsonObject",
"json",
",",
"String",
"fieldName",
")",
"{",
"Properties",
"props",
"=",
"new",
"Properties",
"(",
")",
";",
"// Extract any other grpc options",
"JsonObject",
"options",
"=",
"getJsonObject",
"(",
"json",
",",
"fieldName",
")",
";",
"if",
"(",
"options",
"!=",
"null",
")",
"{",
"for",
"(",
"Entry",
"<",
"String",
",",
"JsonValue",
">",
"entry",
":",
"options",
".",
"entrySet",
"(",
")",
")",
"{",
"String",
"key",
"=",
"entry",
".",
"getKey",
"(",
")",
";",
"JsonValue",
"value",
"=",
"entry",
".",
"getValue",
"(",
")",
";",
"props",
".",
"setProperty",
"(",
"key",
",",
"getJsonValue",
"(",
"value",
")",
")",
";",
"}",
"}",
"return",
"props",
";",
"}"
] |
Extracts all defined properties of the specified field and returns a Properties object
|
[
"Extracts",
"all",
"defined",
"properties",
"of",
"the",
"specified",
"field",
"and",
"returns",
"a",
"Properties",
"object"
] |
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
|
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/NetworkConfig.java#L1008-L1022
|
21,983
|
hyperledger/fabric-sdk-java
|
src/main/java/org/hyperledger/fabric/sdk/NetworkConfig.java
|
NetworkConfig.getPeer
|
private Peer getPeer(HFClient client, String peerName) throws InvalidArgumentException {
Peer peer = null;
Node p = peers.get(peerName);
if (p != null) {
peer = client.newPeer(p.getName(), p.getUrl(), p.getProperties());
}
return peer;
}
|
java
|
private Peer getPeer(HFClient client, String peerName) throws InvalidArgumentException {
Peer peer = null;
Node p = peers.get(peerName);
if (p != null) {
peer = client.newPeer(p.getName(), p.getUrl(), p.getProperties());
}
return peer;
}
|
[
"private",
"Peer",
"getPeer",
"(",
"HFClient",
"client",
",",
"String",
"peerName",
")",
"throws",
"InvalidArgumentException",
"{",
"Peer",
"peer",
"=",
"null",
";",
"Node",
"p",
"=",
"peers",
".",
"get",
"(",
"peerName",
")",
";",
"if",
"(",
"p",
"!=",
"null",
")",
"{",
"peer",
"=",
"client",
".",
"newPeer",
"(",
"p",
".",
"getName",
"(",
")",
",",
"p",
".",
"getUrl",
"(",
")",
",",
"p",
".",
"getProperties",
"(",
")",
")",
";",
"}",
"return",
"peer",
";",
"}"
] |
Returns a new Peer instance for the specified peer name
|
[
"Returns",
"a",
"new",
"Peer",
"instance",
"for",
"the",
"specified",
"peer",
"name"
] |
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
|
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/NetworkConfig.java#L1025-L1032
|
21,984
|
hyperledger/fabric-sdk-java
|
src/main/java/org/hyperledger/fabric/sdk/NetworkConfig.java
|
NetworkConfig.getJsonValue
|
private static String getJsonValue(JsonValue value) {
String s = null;
if (value != null) {
s = getJsonValueAsString(value);
if (s == null) {
s = getJsonValueAsNumberString(value);
}
if (s == null) {
Boolean b = getJsonValueAsBoolean(value);
if (b != null) {
s = b ? "true" : "false";
}
}
}
return s;
}
|
java
|
private static String getJsonValue(JsonValue value) {
String s = null;
if (value != null) {
s = getJsonValueAsString(value);
if (s == null) {
s = getJsonValueAsNumberString(value);
}
if (s == null) {
Boolean b = getJsonValueAsBoolean(value);
if (b != null) {
s = b ? "true" : "false";
}
}
}
return s;
}
|
[
"private",
"static",
"String",
"getJsonValue",
"(",
"JsonValue",
"value",
")",
"{",
"String",
"s",
"=",
"null",
";",
"if",
"(",
"value",
"!=",
"null",
")",
"{",
"s",
"=",
"getJsonValueAsString",
"(",
"value",
")",
";",
"if",
"(",
"s",
"==",
"null",
")",
"{",
"s",
"=",
"getJsonValueAsNumberString",
"(",
"value",
")",
";",
"}",
"if",
"(",
"s",
"==",
"null",
")",
"{",
"Boolean",
"b",
"=",
"getJsonValueAsBoolean",
"(",
"value",
")",
";",
"if",
"(",
"b",
"!=",
"null",
")",
"{",
"s",
"=",
"b",
"?",
"\"true\"",
":",
"\"false\"",
";",
"}",
"}",
"}",
"return",
"s",
";",
"}"
] |
If it's anything else it returns null
|
[
"If",
"it",
"s",
"anything",
"else",
"it",
"returns",
"null"
] |
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
|
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/NetworkConfig.java#L1039-L1054
|
21,985
|
hyperledger/fabric-sdk-java
|
src/main/java/org/hyperledger/fabric/sdk/NetworkConfig.java
|
NetworkConfig.getJsonValueAsObject
|
private static JsonObject getJsonValueAsObject(JsonValue value) {
return (value != null && value.getValueType() == ValueType.OBJECT) ? value.asJsonObject() : null;
}
|
java
|
private static JsonObject getJsonValueAsObject(JsonValue value) {
return (value != null && value.getValueType() == ValueType.OBJECT) ? value.asJsonObject() : null;
}
|
[
"private",
"static",
"JsonObject",
"getJsonValueAsObject",
"(",
"JsonValue",
"value",
")",
"{",
"return",
"(",
"value",
"!=",
"null",
"&&",
"value",
".",
"getValueType",
"(",
")",
"==",
"ValueType",
".",
"OBJECT",
")",
"?",
"value",
".",
"asJsonObject",
"(",
")",
":",
"null",
";",
"}"
] |
Returns the specified JsonValue as a JsonObject, or null if it's not an object
|
[
"Returns",
"the",
"specified",
"JsonValue",
"as",
"a",
"JsonObject",
"or",
"null",
"if",
"it",
"s",
"not",
"an",
"object"
] |
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
|
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/NetworkConfig.java#L1057-L1059
|
21,986
|
hyperledger/fabric-sdk-java
|
src/main/java/org/hyperledger/fabric/sdk/NetworkConfig.java
|
NetworkConfig.getJsonValueAsArray
|
private static JsonArray getJsonValueAsArray(JsonValue value) {
return (value != null && value.getValueType() == ValueType.ARRAY) ? value.asJsonArray() : null;
}
|
java
|
private static JsonArray getJsonValueAsArray(JsonValue value) {
return (value != null && value.getValueType() == ValueType.ARRAY) ? value.asJsonArray() : null;
}
|
[
"private",
"static",
"JsonArray",
"getJsonValueAsArray",
"(",
"JsonValue",
"value",
")",
"{",
"return",
"(",
"value",
"!=",
"null",
"&&",
"value",
".",
"getValueType",
"(",
")",
"==",
"ValueType",
".",
"ARRAY",
")",
"?",
"value",
".",
"asJsonArray",
"(",
")",
":",
"null",
";",
"}"
] |
Returns the specified JsonValue as a JsonArray, or null if it's not an array
|
[
"Returns",
"the",
"specified",
"JsonValue",
"as",
"a",
"JsonArray",
"or",
"null",
"if",
"it",
"s",
"not",
"an",
"array"
] |
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
|
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/NetworkConfig.java#L1062-L1064
|
21,987
|
hyperledger/fabric-sdk-java
|
src/main/java/org/hyperledger/fabric/sdk/NetworkConfig.java
|
NetworkConfig.getJsonValueAsList
|
private static List<JsonObject> getJsonValueAsList(JsonValue value) {
if (value != null) {
if (value.getValueType() == ValueType.ARRAY) {
return value.asJsonArray().getValuesAs(JsonObject.class);
} else if (value.getValueType() == ValueType.OBJECT) {
List<JsonObject> ret = new ArrayList<>();
ret.add(value.asJsonObject());
return ret;
}
}
return null;
}
|
java
|
private static List<JsonObject> getJsonValueAsList(JsonValue value) {
if (value != null) {
if (value.getValueType() == ValueType.ARRAY) {
return value.asJsonArray().getValuesAs(JsonObject.class);
} else if (value.getValueType() == ValueType.OBJECT) {
List<JsonObject> ret = new ArrayList<>();
ret.add(value.asJsonObject());
return ret;
}
}
return null;
}
|
[
"private",
"static",
"List",
"<",
"JsonObject",
">",
"getJsonValueAsList",
"(",
"JsonValue",
"value",
")",
"{",
"if",
"(",
"value",
"!=",
"null",
")",
"{",
"if",
"(",
"value",
".",
"getValueType",
"(",
")",
"==",
"ValueType",
".",
"ARRAY",
")",
"{",
"return",
"value",
".",
"asJsonArray",
"(",
")",
".",
"getValuesAs",
"(",
"JsonObject",
".",
"class",
")",
";",
"}",
"else",
"if",
"(",
"value",
".",
"getValueType",
"(",
")",
"==",
"ValueType",
".",
"OBJECT",
")",
"{",
"List",
"<",
"JsonObject",
">",
"ret",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"ret",
".",
"add",
"(",
"value",
".",
"asJsonObject",
"(",
")",
")",
";",
"return",
"ret",
";",
"}",
"}",
"return",
"null",
";",
"}"
] |
Returns the specified JsonValue as a List. Allows single or array
|
[
"Returns",
"the",
"specified",
"JsonValue",
"as",
"a",
"List",
".",
"Allows",
"single",
"or",
"array"
] |
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
|
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/NetworkConfig.java#L1067-L1080
|
21,988
|
hyperledger/fabric-sdk-java
|
src/main/java/org/hyperledger/fabric/sdk/NetworkConfig.java
|
NetworkConfig.getJsonValueAsBoolean
|
private static Boolean getJsonValueAsBoolean(JsonValue value) {
if (value != null) {
if (value.getValueType() == ValueType.TRUE) {
return true;
} else if (value.getValueType() == ValueType.FALSE) {
return false;
}
}
return null;
}
|
java
|
private static Boolean getJsonValueAsBoolean(JsonValue value) {
if (value != null) {
if (value.getValueType() == ValueType.TRUE) {
return true;
} else if (value.getValueType() == ValueType.FALSE) {
return false;
}
}
return null;
}
|
[
"private",
"static",
"Boolean",
"getJsonValueAsBoolean",
"(",
"JsonValue",
"value",
")",
"{",
"if",
"(",
"value",
"!=",
"null",
")",
"{",
"if",
"(",
"value",
".",
"getValueType",
"(",
")",
"==",
"ValueType",
".",
"TRUE",
")",
"{",
"return",
"true",
";",
"}",
"else",
"if",
"(",
"value",
".",
"getValueType",
"(",
")",
"==",
"ValueType",
".",
"FALSE",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"null",
";",
"}"
] |
Returns the specified JsonValue as a Boolean, or null if it's not a boolean
|
[
"Returns",
"the",
"specified",
"JsonValue",
"as",
"a",
"Boolean",
"or",
"null",
"if",
"it",
"s",
"not",
"a",
"boolean"
] |
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
|
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/NetworkConfig.java#L1093-L1102
|
21,989
|
hyperledger/fabric-sdk-java
|
src/main/java/org/hyperledger/fabric/sdk/NetworkConfig.java
|
NetworkConfig.getJsonObject
|
private static JsonObject getJsonObject(JsonObject object, String propName) {
JsonObject obj = null;
JsonValue val = object.get(propName);
if (val != null && val.getValueType() == ValueType.OBJECT) {
obj = val.asJsonObject();
}
return obj;
}
|
java
|
private static JsonObject getJsonObject(JsonObject object, String propName) {
JsonObject obj = null;
JsonValue val = object.get(propName);
if (val != null && val.getValueType() == ValueType.OBJECT) {
obj = val.asJsonObject();
}
return obj;
}
|
[
"private",
"static",
"JsonObject",
"getJsonObject",
"(",
"JsonObject",
"object",
",",
"String",
"propName",
")",
"{",
"JsonObject",
"obj",
"=",
"null",
";",
"JsonValue",
"val",
"=",
"object",
".",
"get",
"(",
"propName",
")",
";",
"if",
"(",
"val",
"!=",
"null",
"&&",
"val",
".",
"getValueType",
"(",
")",
"==",
"ValueType",
".",
"OBJECT",
")",
"{",
"obj",
"=",
"val",
".",
"asJsonObject",
"(",
")",
";",
"}",
"return",
"obj",
";",
"}"
] |
Returns the specified property as a JsonObject
|
[
"Returns",
"the",
"specified",
"property",
"as",
"a",
"JsonObject"
] |
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
|
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/NetworkConfig.java#L1105-L1112
|
21,990
|
hyperledger/fabric-sdk-java
|
src/main/java/org/hyperledger/fabric/sdk/NetworkConfig.java
|
NetworkConfig.getChannelNames
|
public Set<String> getChannelNames() {
Set<String> ret = Collections.EMPTY_SET;
JsonObject channels = getJsonObject(jsonConfig, "channels");
if (channels != null) {
final Set<String> channelNames = channels.keySet();
if (channelNames != null && !channelNames.isEmpty()) {
ret = new HashSet<>(channelNames);
}
}
return ret;
}
|
java
|
public Set<String> getChannelNames() {
Set<String> ret = Collections.EMPTY_SET;
JsonObject channels = getJsonObject(jsonConfig, "channels");
if (channels != null) {
final Set<String> channelNames = channels.keySet();
if (channelNames != null && !channelNames.isEmpty()) {
ret = new HashSet<>(channelNames);
}
}
return ret;
}
|
[
"public",
"Set",
"<",
"String",
">",
"getChannelNames",
"(",
")",
"{",
"Set",
"<",
"String",
">",
"ret",
"=",
"Collections",
".",
"EMPTY_SET",
";",
"JsonObject",
"channels",
"=",
"getJsonObject",
"(",
"jsonConfig",
",",
"\"channels\"",
")",
";",
"if",
"(",
"channels",
"!=",
"null",
")",
"{",
"final",
"Set",
"<",
"String",
">",
"channelNames",
"=",
"channels",
".",
"keySet",
"(",
")",
";",
"if",
"(",
"channelNames",
"!=",
"null",
"&&",
"!",
"channelNames",
".",
"isEmpty",
"(",
")",
")",
"{",
"ret",
"=",
"new",
"HashSet",
"<>",
"(",
"channelNames",
")",
";",
"}",
"}",
"return",
"ret",
";",
"}"
] |
Get the channel names found.
@return A set of the channel names found in the configuration file or empty set if none found.
|
[
"Get",
"the",
"channel",
"names",
"found",
"."
] |
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
|
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/NetworkConfig.java#L1120-L1131
|
21,991
|
hyperledger/fabric-sdk-java
|
src/main/java/org/hyperledger/fabric/sdk/UpgradeProposalRequest.java
|
UpgradeProposalRequest.setTransientMap
|
public void setTransientMap(Map<String, byte[]> transientMap) throws InvalidArgumentException {
if (null == transientMap) {
throw new InvalidArgumentException("Transient map may not be set to null");
}
this.transientMap = transientMap;
}
|
java
|
public void setTransientMap(Map<String, byte[]> transientMap) throws InvalidArgumentException {
if (null == transientMap) {
throw new InvalidArgumentException("Transient map may not be set to null");
}
this.transientMap = transientMap;
}
|
[
"public",
"void",
"setTransientMap",
"(",
"Map",
"<",
"String",
",",
"byte",
"[",
"]",
">",
"transientMap",
")",
"throws",
"InvalidArgumentException",
"{",
"if",
"(",
"null",
"==",
"transientMap",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"Transient map may not be set to null\"",
")",
";",
"}",
"this",
".",
"transientMap",
"=",
"transientMap",
";",
"}"
] |
Transient data added to the proposal that is not added to the ledger.
@param transientMap Map of strings to bytes that's added to the proposal
@throws InvalidArgumentException if the argument is null.
|
[
"Transient",
"data",
"added",
"to",
"the",
"proposal",
"that",
"is",
"not",
"added",
"to",
"the",
"ledger",
"."
] |
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
|
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/UpgradeProposalRequest.java#L37-L44
|
21,992
|
hyperledger/fabric-sdk-java
|
src/main/java/org/hyperledger/fabric/sdk/LifecycleChaincodeEndorsementPolicy.java
|
LifecycleChaincodeEndorsementPolicy.fromStream
|
public static LifecycleChaincodeEndorsementPolicy fromStream(InputStream inputStream) throws IOException {
return new LifecycleChaincodeEndorsementPolicy(ByteString.copyFrom(IOUtils.toByteArray(inputStream)));
}
|
java
|
public static LifecycleChaincodeEndorsementPolicy fromStream(InputStream inputStream) throws IOException {
return new LifecycleChaincodeEndorsementPolicy(ByteString.copyFrom(IOUtils.toByteArray(inputStream)));
}
|
[
"public",
"static",
"LifecycleChaincodeEndorsementPolicy",
"fromStream",
"(",
"InputStream",
"inputStream",
")",
"throws",
"IOException",
"{",
"return",
"new",
"LifecycleChaincodeEndorsementPolicy",
"(",
"ByteString",
".",
"copyFrom",
"(",
"IOUtils",
".",
"toByteArray",
"(",
"inputStream",
")",
")",
")",
";",
"}"
] |
Construct a chaincode endorsement policy from a stream.
@param inputStream
@throws IOException
|
[
"Construct",
"a",
"chaincode",
"endorsement",
"policy",
"from",
"a",
"stream",
"."
] |
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
|
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/LifecycleChaincodeEndorsementPolicy.java#L262-L264
|
21,993
|
hyperledger/fabric-sdk-java
|
src/main/java/org/hyperledger/fabric/sdk/LifecycleApproveChaincodeDefinitionForMyOrgRequest.java
|
LifecycleApproveChaincodeDefinitionForMyOrgRequest.setChaincodeName
|
public void setChaincodeName(String chaincodeName) throws InvalidArgumentException {
if (Utils.isNullOrEmpty(chaincodeName)) {
throw new InvalidArgumentException("The chaincodeName parameter can not be null or empty.");
}
this.chaincodeName = chaincodeName;
}
|
java
|
public void setChaincodeName(String chaincodeName) throws InvalidArgumentException {
if (Utils.isNullOrEmpty(chaincodeName)) {
throw new InvalidArgumentException("The chaincodeName parameter can not be null or empty.");
}
this.chaincodeName = chaincodeName;
}
|
[
"public",
"void",
"setChaincodeName",
"(",
"String",
"chaincodeName",
")",
"throws",
"InvalidArgumentException",
"{",
"if",
"(",
"Utils",
".",
"isNullOrEmpty",
"(",
"chaincodeName",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"The chaincodeName parameter can not be null or empty.\"",
")",
";",
"}",
"this",
".",
"chaincodeName",
"=",
"chaincodeName",
";",
"}"
] |
The name of the chaincode to approve.
@param chaincodeName
|
[
"The",
"name",
"of",
"the",
"chaincode",
"to",
"approve",
"."
] |
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
|
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/LifecycleApproveChaincodeDefinitionForMyOrgRequest.java#L109-L114
|
21,994
|
hyperledger/fabric-sdk-java
|
src/main/java/org/hyperledger/fabric/sdk/LifecycleApproveChaincodeDefinitionForMyOrgRequest.java
|
LifecycleApproveChaincodeDefinitionForMyOrgRequest.setChaincodeVersion
|
public void setChaincodeVersion(String chaincodeVersion) throws InvalidArgumentException {
if (Utils.isNullOrEmpty(chaincodeVersion)) {
throw new InvalidArgumentException("The chaincodeVersion parameter can not be null or empty.");
}
this.chaincodeVersion = chaincodeVersion;
}
|
java
|
public void setChaincodeVersion(String chaincodeVersion) throws InvalidArgumentException {
if (Utils.isNullOrEmpty(chaincodeVersion)) {
throw new InvalidArgumentException("The chaincodeVersion parameter can not be null or empty.");
}
this.chaincodeVersion = chaincodeVersion;
}
|
[
"public",
"void",
"setChaincodeVersion",
"(",
"String",
"chaincodeVersion",
")",
"throws",
"InvalidArgumentException",
"{",
"if",
"(",
"Utils",
".",
"isNullOrEmpty",
"(",
"chaincodeVersion",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"The chaincodeVersion parameter can not be null or empty.\"",
")",
";",
"}",
"this",
".",
"chaincodeVersion",
"=",
"chaincodeVersion",
";",
"}"
] |
The version of the chaincode to approve.
@param chaincodeVersion the version.
|
[
"The",
"version",
"of",
"the",
"chaincode",
"to",
"approve",
"."
] |
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
|
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/LifecycleApproveChaincodeDefinitionForMyOrgRequest.java#L127-L133
|
21,995
|
hyperledger/fabric-sdk-java
|
src/main/java/org/hyperledger/fabric/sdk/LifecycleApproveChaincodeDefinitionForMyOrgRequest.java
|
LifecycleApproveChaincodeDefinitionForMyOrgRequest.setChaincodeEndorsementPlugin
|
public void setChaincodeEndorsementPlugin(String chaincodeEndorsementPlugin) throws InvalidArgumentException {
if (Utils.isNullOrEmpty(chaincodeEndorsementPlugin)) {
throw new InvalidArgumentException("The getChaincodeEndorsementPlugin parameter can not be null or empty.");
}
this.chaincodeEndorsementPlugin = chaincodeEndorsementPlugin;
}
|
java
|
public void setChaincodeEndorsementPlugin(String chaincodeEndorsementPlugin) throws InvalidArgumentException {
if (Utils.isNullOrEmpty(chaincodeEndorsementPlugin)) {
throw new InvalidArgumentException("The getChaincodeEndorsementPlugin parameter can not be null or empty.");
}
this.chaincodeEndorsementPlugin = chaincodeEndorsementPlugin;
}
|
[
"public",
"void",
"setChaincodeEndorsementPlugin",
"(",
"String",
"chaincodeEndorsementPlugin",
")",
"throws",
"InvalidArgumentException",
"{",
"if",
"(",
"Utils",
".",
"isNullOrEmpty",
"(",
"chaincodeEndorsementPlugin",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"The getChaincodeEndorsementPlugin parameter can not be null or empty.\"",
")",
";",
"}",
"this",
".",
"chaincodeEndorsementPlugin",
"=",
"chaincodeEndorsementPlugin",
";",
"}"
] |
This is the chaincode endorsement plugin. Should default, not needing set. ONLY set if there is a specific endorsement is set for your organization
@param chaincodeEndorsementPlugin
@throws InvalidArgumentException
|
[
"This",
"is",
"the",
"chaincode",
"endorsement",
"plugin",
".",
"Should",
"default",
"not",
"needing",
"set",
".",
"ONLY",
"set",
"if",
"there",
"is",
"a",
"specific",
"endorsement",
"is",
"set",
"for",
"your",
"organization"
] |
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
|
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/LifecycleApproveChaincodeDefinitionForMyOrgRequest.java#L207-L212
|
21,996
|
hyperledger/fabric-sdk-java
|
src/main/java/org/hyperledger/fabric/sdk/LifecycleApproveChaincodeDefinitionForMyOrgRequest.java
|
LifecycleApproveChaincodeDefinitionForMyOrgRequest.setChaincodeValidationPlugin
|
public void setChaincodeValidationPlugin(String chaincodeValidationPlugin) throws InvalidArgumentException {
if (Utils.isNullOrEmpty(chaincodeValidationPlugin)) {
throw new InvalidArgumentException("The getChaincodeValidationPlugin parameter can not be null or empty.");
}
this.chaincodeValidationPlugin = chaincodeValidationPlugin;
}
|
java
|
public void setChaincodeValidationPlugin(String chaincodeValidationPlugin) throws InvalidArgumentException {
if (Utils.isNullOrEmpty(chaincodeValidationPlugin)) {
throw new InvalidArgumentException("The getChaincodeValidationPlugin parameter can not be null or empty.");
}
this.chaincodeValidationPlugin = chaincodeValidationPlugin;
}
|
[
"public",
"void",
"setChaincodeValidationPlugin",
"(",
"String",
"chaincodeValidationPlugin",
")",
"throws",
"InvalidArgumentException",
"{",
"if",
"(",
"Utils",
".",
"isNullOrEmpty",
"(",
"chaincodeValidationPlugin",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"The getChaincodeValidationPlugin parameter can not be null or empty.\"",
")",
";",
"}",
"this",
".",
"chaincodeValidationPlugin",
"=",
"chaincodeValidationPlugin",
";",
"}"
] |
This is the chaincode validation plugin. Should default, not needing set. ONLY set if there is a specific validation is set for your organization
@param chaincodeValidationPlugin
@throws InvalidArgumentException
|
[
"This",
"is",
"the",
"chaincode",
"validation",
"plugin",
".",
"Should",
"default",
"not",
"needing",
"set",
".",
"ONLY",
"set",
"if",
"there",
"is",
"a",
"specific",
"validation",
"is",
"set",
"for",
"your",
"organization"
] |
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
|
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/LifecycleApproveChaincodeDefinitionForMyOrgRequest.java#L220-L225
|
21,997
|
hyperledger/fabric-sdk-java
|
src/main/java/org/hyperledger/fabric/sdk/UpdateChannelConfiguration.java
|
UpdateChannelConfiguration.setUpdateChannelConfiguration
|
public void setUpdateChannelConfiguration(byte[] updateChannelConfigurationAsBytes) throws InvalidArgumentException {
if (updateChannelConfigurationAsBytes == null) {
throw new InvalidArgumentException("UpdateChannelConfiguration updateChannelConfigurationAsBytes must be non-null");
}
logger.trace("Creating setUpdateChannelConfiguration from bytes");
configBytes = updateChannelConfigurationAsBytes;
}
|
java
|
public void setUpdateChannelConfiguration(byte[] updateChannelConfigurationAsBytes) throws InvalidArgumentException {
if (updateChannelConfigurationAsBytes == null) {
throw new InvalidArgumentException("UpdateChannelConfiguration updateChannelConfigurationAsBytes must be non-null");
}
logger.trace("Creating setUpdateChannelConfiguration from bytes");
configBytes = updateChannelConfigurationAsBytes;
}
|
[
"public",
"void",
"setUpdateChannelConfiguration",
"(",
"byte",
"[",
"]",
"updateChannelConfigurationAsBytes",
")",
"throws",
"InvalidArgumentException",
"{",
"if",
"(",
"updateChannelConfigurationAsBytes",
"==",
"null",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"UpdateChannelConfiguration updateChannelConfigurationAsBytes must be non-null\"",
")",
";",
"}",
"logger",
".",
"trace",
"(",
"\"Creating setUpdateChannelConfiguration from bytes\"",
")",
";",
"configBytes",
"=",
"updateChannelConfigurationAsBytes",
";",
"}"
] |
sets the UpdateChannelConfiguration from a byte array
@param updateChannelConfigurationAsBytes the byte array containing the serialized channel configuration
|
[
"sets",
"the",
"UpdateChannelConfiguration",
"from",
"a",
"byte",
"array"
] |
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
|
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/UpdateChannelConfiguration.java#L84-L90
|
21,998
|
hyperledger/fabric-sdk-java
|
src/main/java/org/hyperledger/fabric/sdk/Peer.java
|
Peer.setChannel
|
void setChannel(Channel channel) throws InvalidArgumentException {
if (null != this.channel) {
throw new InvalidArgumentException(format("Can not add peer %s to channel %s because it already belongs to channel %s.",
name, channel.getName(), this.channel.getName()));
}
logger.debug(format("%s setting channel to %s, from %s", toString(), "" + channel, "" + this.channel));
this.channel = channel;
this.channelName = channel.getName();
}
|
java
|
void setChannel(Channel channel) throws InvalidArgumentException {
if (null != this.channel) {
throw new InvalidArgumentException(format("Can not add peer %s to channel %s because it already belongs to channel %s.",
name, channel.getName(), this.channel.getName()));
}
logger.debug(format("%s setting channel to %s, from %s", toString(), "" + channel, "" + this.channel));
this.channel = channel;
this.channelName = channel.getName();
}
|
[
"void",
"setChannel",
"(",
"Channel",
"channel",
")",
"throws",
"InvalidArgumentException",
"{",
"if",
"(",
"null",
"!=",
"this",
".",
"channel",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"format",
"(",
"\"Can not add peer %s to channel %s because it already belongs to channel %s.\"",
",",
"name",
",",
"channel",
".",
"getName",
"(",
")",
",",
"this",
".",
"channel",
".",
"getName",
"(",
")",
")",
")",
";",
"}",
"logger",
".",
"debug",
"(",
"format",
"(",
"\"%s setting channel to %s, from %s\"",
",",
"toString",
"(",
")",
",",
"\"\"",
"+",
"channel",
",",
"\"\"",
"+",
"this",
".",
"channel",
")",
")",
";",
"this",
".",
"channel",
"=",
"channel",
";",
"this",
".",
"channelName",
"=",
"channel",
".",
"getName",
"(",
")",
";",
"}"
] |
Set the channel the peer is on.
@param channel
|
[
"Set",
"the",
"channel",
"the",
"peer",
"is",
"on",
"."
] |
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
|
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/Peer.java#L175-L186
|
21,999
|
hyperledger/fabric-sdk-java
|
src/main/java/org/hyperledger/fabric/sdk/Peer.java
|
Peer.setPeerEventingServiceDisconnected
|
public PeerEventingServiceDisconnected setPeerEventingServiceDisconnected(PeerEventingServiceDisconnected newPeerEventingServiceDisconnectedHandler) {
PeerEventingServiceDisconnected ret = disconnectedHandler;
disconnectedHandler = newPeerEventingServiceDisconnectedHandler;
return ret;
}
|
java
|
public PeerEventingServiceDisconnected setPeerEventingServiceDisconnected(PeerEventingServiceDisconnected newPeerEventingServiceDisconnectedHandler) {
PeerEventingServiceDisconnected ret = disconnectedHandler;
disconnectedHandler = newPeerEventingServiceDisconnectedHandler;
return ret;
}
|
[
"public",
"PeerEventingServiceDisconnected",
"setPeerEventingServiceDisconnected",
"(",
"PeerEventingServiceDisconnected",
"newPeerEventingServiceDisconnectedHandler",
")",
"{",
"PeerEventingServiceDisconnected",
"ret",
"=",
"disconnectedHandler",
";",
"disconnectedHandler",
"=",
"newPeerEventingServiceDisconnectedHandler",
";",
"return",
"ret",
";",
"}"
] |
Set class to handle peer eventing service disconnects
@param newPeerEventingServiceDisconnectedHandler New handler to replace. If set to null no retry will take place.
@return the old handler.
|
[
"Set",
"class",
"to",
"handle",
"peer",
"eventing",
"service",
"disconnects"
] |
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
|
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/Peer.java#L588-L592
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.