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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
138,500 | QSFT/Doradus | doradus-server/src/main/java/com/dell/doradus/service/schema/SchemaService.java | SchemaService.checkTenants | private void checkTenants() {
m_logger.info("The following tenants and applications are defined:");
Collection<Tenant> tenantList = TenantService.instance().getTenants();
for (Tenant tenant : tenantList) {
checkTenantApps(tenant);
}
if (tenantList.size() == 0) {
m_logger.info(" <no tenants>");
}
} | java | private void checkTenants() {
m_logger.info("The following tenants and applications are defined:");
Collection<Tenant> tenantList = TenantService.instance().getTenants();
for (Tenant tenant : tenantList) {
checkTenantApps(tenant);
}
if (tenantList.size() == 0) {
m_logger.info(" <no tenants>");
}
} | [
"private",
"void",
"checkTenants",
"(",
")",
"{",
"m_logger",
".",
"info",
"(",
"\"The following tenants and applications are defined:\"",
")",
";",
"Collection",
"<",
"Tenant",
">",
"tenantList",
"=",
"TenantService",
".",
"instance",
"(",
")",
".",
"getTenants",
"(",
")",
";",
"for",
"(",
"Tenant",
"tenant",
":",
"tenantList",
")",
"{",
"checkTenantApps",
"(",
"tenant",
")",
";",
"}",
"if",
"(",
"tenantList",
".",
"size",
"(",
")",
"==",
"0",
")",
"{",
"m_logger",
".",
"info",
"(",
"\" <no tenants>\"",
")",
";",
"}",
"}"
] | Check to the applications for this tenant. | [
"Check",
"to",
"the",
"applications",
"for",
"this",
"tenant",
"."
] | ad64d3c37922eefda68ec8869ef089c1ca604b70 | https://github.com/QSFT/Doradus/blob/ad64d3c37922eefda68ec8869ef089c1ca604b70/doradus-server/src/main/java/com/dell/doradus/service/schema/SchemaService.java#L286-L295 |
138,501 | QSFT/Doradus | doradus-server/src/main/java/com/dell/doradus/service/schema/SchemaService.java | SchemaService.checkTenantApps | private void checkTenantApps(Tenant tenant) {
m_logger.info(" Tenant: {}", tenant.getName());
try {
Iterator<DRow> rowIter =
DBService.instance(tenant).getAllRows(SchemaService.APPS_STORE_NAME).iterator();
if (!rowIter.hasNext()) {
m_logger.info(" <no applications>");
}
while (rowIter.hasNext()) {
DRow row = rowIter.next();
ApplicationDefinition appDef = loadAppRow(tenant, getColumnMap(row.getAllColumns(1024).iterator()));
if (appDef != null) {
String appName = appDef.getAppName();
String ssName = getStorageServiceOption(appDef);
m_logger.info(" Application '{}': StorageService={}; keyspace={}",
new Object[]{appName, ssName, tenant.getName()});
if (DoradusServer.instance().findStorageService(ssName) == null) {
m_logger.warn(" >>>Application '{}' uses storage service '{}' which has not been " +
"initialized; application will not be accessible via this server",
appDef.getAppName(), ssName);
}
}
}
} catch (Exception e) {
m_logger.warn("Could not check tenant '" + tenant.getName() +
"'. Applications may be unavailable.", e);
}
} | java | private void checkTenantApps(Tenant tenant) {
m_logger.info(" Tenant: {}", tenant.getName());
try {
Iterator<DRow> rowIter =
DBService.instance(tenant).getAllRows(SchemaService.APPS_STORE_NAME).iterator();
if (!rowIter.hasNext()) {
m_logger.info(" <no applications>");
}
while (rowIter.hasNext()) {
DRow row = rowIter.next();
ApplicationDefinition appDef = loadAppRow(tenant, getColumnMap(row.getAllColumns(1024).iterator()));
if (appDef != null) {
String appName = appDef.getAppName();
String ssName = getStorageServiceOption(appDef);
m_logger.info(" Application '{}': StorageService={}; keyspace={}",
new Object[]{appName, ssName, tenant.getName()});
if (DoradusServer.instance().findStorageService(ssName) == null) {
m_logger.warn(" >>>Application '{}' uses storage service '{}' which has not been " +
"initialized; application will not be accessible via this server",
appDef.getAppName(), ssName);
}
}
}
} catch (Exception e) {
m_logger.warn("Could not check tenant '" + tenant.getName() +
"'. Applications may be unavailable.", e);
}
} | [
"private",
"void",
"checkTenantApps",
"(",
"Tenant",
"tenant",
")",
"{",
"m_logger",
".",
"info",
"(",
"\" Tenant: {}\"",
",",
"tenant",
".",
"getName",
"(",
")",
")",
";",
"try",
"{",
"Iterator",
"<",
"DRow",
">",
"rowIter",
"=",
"DBService",
".",
"instance",
"(",
"tenant",
")",
".",
"getAllRows",
"(",
"SchemaService",
".",
"APPS_STORE_NAME",
")",
".",
"iterator",
"(",
")",
";",
"if",
"(",
"!",
"rowIter",
".",
"hasNext",
"(",
")",
")",
"{",
"m_logger",
".",
"info",
"(",
"\" <no applications>\"",
")",
";",
"}",
"while",
"(",
"rowIter",
".",
"hasNext",
"(",
")",
")",
"{",
"DRow",
"row",
"=",
"rowIter",
".",
"next",
"(",
")",
";",
"ApplicationDefinition",
"appDef",
"=",
"loadAppRow",
"(",
"tenant",
",",
"getColumnMap",
"(",
"row",
".",
"getAllColumns",
"(",
"1024",
")",
".",
"iterator",
"(",
")",
")",
")",
";",
"if",
"(",
"appDef",
"!=",
"null",
")",
"{",
"String",
"appName",
"=",
"appDef",
".",
"getAppName",
"(",
")",
";",
"String",
"ssName",
"=",
"getStorageServiceOption",
"(",
"appDef",
")",
";",
"m_logger",
".",
"info",
"(",
"\" Application '{}': StorageService={}; keyspace={}\"",
",",
"new",
"Object",
"[",
"]",
"{",
"appName",
",",
"ssName",
",",
"tenant",
".",
"getName",
"(",
")",
"}",
")",
";",
"if",
"(",
"DoradusServer",
".",
"instance",
"(",
")",
".",
"findStorageService",
"(",
"ssName",
")",
"==",
"null",
")",
"{",
"m_logger",
".",
"warn",
"(",
"\" >>>Application '{}' uses storage service '{}' which has not been \"",
"+",
"\"initialized; application will not be accessible via this server\"",
",",
"appDef",
".",
"getAppName",
"(",
")",
",",
"ssName",
")",
";",
"}",
"}",
"}",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"m_logger",
".",
"warn",
"(",
"\"Could not check tenant '\"",
"+",
"tenant",
".",
"getName",
"(",
")",
"+",
"\"'. Applications may be unavailable.\"",
",",
"e",
")",
";",
"}",
"}"
] | Check that this tenant, its applications, and storage managers are available. | [
"Check",
"that",
"this",
"tenant",
"its",
"applications",
"and",
"storage",
"managers",
"are",
"available",
"."
] | ad64d3c37922eefda68ec8869ef089c1ca604b70 | https://github.com/QSFT/Doradus/blob/ad64d3c37922eefda68ec8869ef089c1ca604b70/doradus-server/src/main/java/com/dell/doradus/service/schema/SchemaService.java#L298-L325 |
138,502 | QSFT/Doradus | doradus-server/src/main/java/com/dell/doradus/service/schema/SchemaService.java | SchemaService.deleteAppProperties | private void deleteAppProperties(ApplicationDefinition appDef) {
Tenant tenant = Tenant.getTenant(appDef);
DBTransaction dbTran = DBService.instance(tenant).startTransaction();
dbTran.deleteRow(SchemaService.APPS_STORE_NAME, appDef.getAppName());
DBService.instance(tenant).commit(dbTran);
} | java | private void deleteAppProperties(ApplicationDefinition appDef) {
Tenant tenant = Tenant.getTenant(appDef);
DBTransaction dbTran = DBService.instance(tenant).startTransaction();
dbTran.deleteRow(SchemaService.APPS_STORE_NAME, appDef.getAppName());
DBService.instance(tenant).commit(dbTran);
} | [
"private",
"void",
"deleteAppProperties",
"(",
"ApplicationDefinition",
"appDef",
")",
"{",
"Tenant",
"tenant",
"=",
"Tenant",
".",
"getTenant",
"(",
"appDef",
")",
";",
"DBTransaction",
"dbTran",
"=",
"DBService",
".",
"instance",
"(",
"tenant",
")",
".",
"startTransaction",
"(",
")",
";",
"dbTran",
".",
"deleteRow",
"(",
"SchemaService",
".",
"APPS_STORE_NAME",
",",
"appDef",
".",
"getAppName",
"(",
")",
")",
";",
"DBService",
".",
"instance",
"(",
"tenant",
")",
".",
"commit",
"(",
"dbTran",
")",
";",
"}"
] | Delete the given application's schema row from the Applications CF. | [
"Delete",
"the",
"given",
"application",
"s",
"schema",
"row",
"from",
"the",
"Applications",
"CF",
"."
] | ad64d3c37922eefda68ec8869ef089c1ca604b70 | https://github.com/QSFT/Doradus/blob/ad64d3c37922eefda68ec8869ef089c1ca604b70/doradus-server/src/main/java/com/dell/doradus/service/schema/SchemaService.java#L328-L333 |
138,503 | QSFT/Doradus | doradus-server/src/main/java/com/dell/doradus/service/schema/SchemaService.java | SchemaService.initializeApplication | private void initializeApplication(ApplicationDefinition currAppDef, ApplicationDefinition appDef) {
getStorageService(appDef).initializeApplication(currAppDef, appDef);
storeApplicationSchema(appDef);
} | java | private void initializeApplication(ApplicationDefinition currAppDef, ApplicationDefinition appDef) {
getStorageService(appDef).initializeApplication(currAppDef, appDef);
storeApplicationSchema(appDef);
} | [
"private",
"void",
"initializeApplication",
"(",
"ApplicationDefinition",
"currAppDef",
",",
"ApplicationDefinition",
"appDef",
")",
"{",
"getStorageService",
"(",
"appDef",
")",
".",
"initializeApplication",
"(",
"currAppDef",
",",
"appDef",
")",
";",
"storeApplicationSchema",
"(",
"appDef",
")",
";",
"}"
] | Initialize storage and store the given schema for the given new or updated application. | [
"Initialize",
"storage",
"and",
"store",
"the",
"given",
"schema",
"for",
"the",
"given",
"new",
"or",
"updated",
"application",
"."
] | ad64d3c37922eefda68ec8869ef089c1ca604b70 | https://github.com/QSFT/Doradus/blob/ad64d3c37922eefda68ec8869ef089c1ca604b70/doradus-server/src/main/java/com/dell/doradus/service/schema/SchemaService.java#L336-L339 |
138,504 | QSFT/Doradus | doradus-server/src/main/java/com/dell/doradus/service/schema/SchemaService.java | SchemaService.storeApplicationSchema | private void storeApplicationSchema(ApplicationDefinition appDef) {
String appName = appDef.getAppName();
Tenant tenant = Tenant.getTenant(appDef);
DBTransaction dbTran = DBService.instance(tenant).startTransaction();
dbTran.addColumn(SchemaService.APPS_STORE_NAME, appName, COLNAME_APP_SCHEMA, appDef.toDoc().toJSON());
dbTran.addColumn(SchemaService.APPS_STORE_NAME, appName, COLNAME_APP_SCHEMA_FORMAT, ContentType.APPLICATION_JSON.toString());
dbTran.addColumn(SchemaService.APPS_STORE_NAME, appName, COLNAME_APP_SCHEMA_VERSION, Integer.toString(CURRENT_SCHEMA_LEVEL));
DBService.instance(tenant).commit(dbTran);
} | java | private void storeApplicationSchema(ApplicationDefinition appDef) {
String appName = appDef.getAppName();
Tenant tenant = Tenant.getTenant(appDef);
DBTransaction dbTran = DBService.instance(tenant).startTransaction();
dbTran.addColumn(SchemaService.APPS_STORE_NAME, appName, COLNAME_APP_SCHEMA, appDef.toDoc().toJSON());
dbTran.addColumn(SchemaService.APPS_STORE_NAME, appName, COLNAME_APP_SCHEMA_FORMAT, ContentType.APPLICATION_JSON.toString());
dbTran.addColumn(SchemaService.APPS_STORE_NAME, appName, COLNAME_APP_SCHEMA_VERSION, Integer.toString(CURRENT_SCHEMA_LEVEL));
DBService.instance(tenant).commit(dbTran);
} | [
"private",
"void",
"storeApplicationSchema",
"(",
"ApplicationDefinition",
"appDef",
")",
"{",
"String",
"appName",
"=",
"appDef",
".",
"getAppName",
"(",
")",
";",
"Tenant",
"tenant",
"=",
"Tenant",
".",
"getTenant",
"(",
"appDef",
")",
";",
"DBTransaction",
"dbTran",
"=",
"DBService",
".",
"instance",
"(",
"tenant",
")",
".",
"startTransaction",
"(",
")",
";",
"dbTran",
".",
"addColumn",
"(",
"SchemaService",
".",
"APPS_STORE_NAME",
",",
"appName",
",",
"COLNAME_APP_SCHEMA",
",",
"appDef",
".",
"toDoc",
"(",
")",
".",
"toJSON",
"(",
")",
")",
";",
"dbTran",
".",
"addColumn",
"(",
"SchemaService",
".",
"APPS_STORE_NAME",
",",
"appName",
",",
"COLNAME_APP_SCHEMA_FORMAT",
",",
"ContentType",
".",
"APPLICATION_JSON",
".",
"toString",
"(",
")",
")",
";",
"dbTran",
".",
"addColumn",
"(",
"SchemaService",
".",
"APPS_STORE_NAME",
",",
"appName",
",",
"COLNAME_APP_SCHEMA_VERSION",
",",
"Integer",
".",
"toString",
"(",
"CURRENT_SCHEMA_LEVEL",
")",
")",
";",
"DBService",
".",
"instance",
"(",
"tenant",
")",
".",
"commit",
"(",
"dbTran",
")",
";",
"}"
] | Store the application row with schema, version, and format. | [
"Store",
"the",
"application",
"row",
"with",
"schema",
"version",
"and",
"format",
"."
] | ad64d3c37922eefda68ec8869ef089c1ca604b70 | https://github.com/QSFT/Doradus/blob/ad64d3c37922eefda68ec8869ef089c1ca604b70/doradus-server/src/main/java/com/dell/doradus/service/schema/SchemaService.java#L342-L350 |
138,505 | QSFT/Doradus | doradus-server/src/main/java/com/dell/doradus/service/schema/SchemaService.java | SchemaService.checkApplicationKey | private ApplicationDefinition checkApplicationKey(ApplicationDefinition appDef) {
Tenant tenant = Tenant.getTenant(appDef);
ApplicationDefinition currAppDef = getApplication(tenant, appDef.getAppName());
if (currAppDef == null) {
m_logger.info("Defining application: {}", appDef.getAppName());
} else {
m_logger.info("Updating application: {}", appDef.getAppName());
String appKey = currAppDef.getKey();
Utils.require(Utils.isEmpty(appKey) || appKey.equals(appDef.getKey()),
"Application key cannot be changed: %s", appDef.getKey());
}
return currAppDef;
} | java | private ApplicationDefinition checkApplicationKey(ApplicationDefinition appDef) {
Tenant tenant = Tenant.getTenant(appDef);
ApplicationDefinition currAppDef = getApplication(tenant, appDef.getAppName());
if (currAppDef == null) {
m_logger.info("Defining application: {}", appDef.getAppName());
} else {
m_logger.info("Updating application: {}", appDef.getAppName());
String appKey = currAppDef.getKey();
Utils.require(Utils.isEmpty(appKey) || appKey.equals(appDef.getKey()),
"Application key cannot be changed: %s", appDef.getKey());
}
return currAppDef;
} | [
"private",
"ApplicationDefinition",
"checkApplicationKey",
"(",
"ApplicationDefinition",
"appDef",
")",
"{",
"Tenant",
"tenant",
"=",
"Tenant",
".",
"getTenant",
"(",
"appDef",
")",
";",
"ApplicationDefinition",
"currAppDef",
"=",
"getApplication",
"(",
"tenant",
",",
"appDef",
".",
"getAppName",
"(",
")",
")",
";",
"if",
"(",
"currAppDef",
"==",
"null",
")",
"{",
"m_logger",
".",
"info",
"(",
"\"Defining application: {}\"",
",",
"appDef",
".",
"getAppName",
"(",
")",
")",
";",
"}",
"else",
"{",
"m_logger",
".",
"info",
"(",
"\"Updating application: {}\"",
",",
"appDef",
".",
"getAppName",
"(",
")",
")",
";",
"String",
"appKey",
"=",
"currAppDef",
".",
"getKey",
"(",
")",
";",
"Utils",
".",
"require",
"(",
"Utils",
".",
"isEmpty",
"(",
"appKey",
")",
"||",
"appKey",
".",
"equals",
"(",
"appDef",
".",
"getKey",
"(",
")",
")",
",",
"\"Application key cannot be changed: %s\"",
",",
"appDef",
".",
"getKey",
"(",
")",
")",
";",
"}",
"return",
"currAppDef",
";",
"}"
] | Verify key match of an existing application, if any, and return it's definition. | [
"Verify",
"key",
"match",
"of",
"an",
"existing",
"application",
"if",
"any",
"and",
"return",
"it",
"s",
"definition",
"."
] | ad64d3c37922eefda68ec8869ef089c1ca604b70 | https://github.com/QSFT/Doradus/blob/ad64d3c37922eefda68ec8869ef089c1ca604b70/doradus-server/src/main/java/com/dell/doradus/service/schema/SchemaService.java#L353-L365 |
138,506 | QSFT/Doradus | doradus-server/src/main/java/com/dell/doradus/service/schema/SchemaService.java | SchemaService.verifyStorageServiceOption | private StorageService verifyStorageServiceOption(ApplicationDefinition currAppDef, ApplicationDefinition appDef) {
// Verify or assign StorageService
String ssName = getStorageServiceOption(appDef);
StorageService storageService = getStorageService(appDef);
Utils.require(storageService != null, "StorageService is unknown or hasn't been initialized: %s", ssName);
// Currently, StorageService can't be changed.
if (currAppDef != null) {
String currSSName = getStorageServiceOption(currAppDef);
Utils.require(currSSName.equals(ssName), "'StorageService' cannot be changed for application: %s", appDef.getAppName());
}
return storageService;
} | java | private StorageService verifyStorageServiceOption(ApplicationDefinition currAppDef, ApplicationDefinition appDef) {
// Verify or assign StorageService
String ssName = getStorageServiceOption(appDef);
StorageService storageService = getStorageService(appDef);
Utils.require(storageService != null, "StorageService is unknown or hasn't been initialized: %s", ssName);
// Currently, StorageService can't be changed.
if (currAppDef != null) {
String currSSName = getStorageServiceOption(currAppDef);
Utils.require(currSSName.equals(ssName), "'StorageService' cannot be changed for application: %s", appDef.getAppName());
}
return storageService;
} | [
"private",
"StorageService",
"verifyStorageServiceOption",
"(",
"ApplicationDefinition",
"currAppDef",
",",
"ApplicationDefinition",
"appDef",
")",
"{",
"// Verify or assign StorageService\r",
"String",
"ssName",
"=",
"getStorageServiceOption",
"(",
"appDef",
")",
";",
"StorageService",
"storageService",
"=",
"getStorageService",
"(",
"appDef",
")",
";",
"Utils",
".",
"require",
"(",
"storageService",
"!=",
"null",
",",
"\"StorageService is unknown or hasn't been initialized: %s\"",
",",
"ssName",
")",
";",
"// Currently, StorageService can't be changed.\r",
"if",
"(",
"currAppDef",
"!=",
"null",
")",
"{",
"String",
"currSSName",
"=",
"getStorageServiceOption",
"(",
"currAppDef",
")",
";",
"Utils",
".",
"require",
"(",
"currSSName",
".",
"equals",
"(",
"ssName",
")",
",",
"\"'StorageService' cannot be changed for application: %s\"",
",",
"appDef",
".",
"getAppName",
"(",
")",
")",
";",
"}",
"return",
"storageService",
";",
"}"
] | change, ensure it hasn't changed. Return the application's StorageService object. | [
"change",
"ensure",
"it",
"hasn",
"t",
"changed",
".",
"Return",
"the",
"application",
"s",
"StorageService",
"object",
"."
] | ad64d3c37922eefda68ec8869ef089c1ca604b70 | https://github.com/QSFT/Doradus/blob/ad64d3c37922eefda68ec8869ef089c1ca604b70/doradus-server/src/main/java/com/dell/doradus/service/schema/SchemaService.java#L369-L381 |
138,507 | QSFT/Doradus | doradus-server/src/main/java/com/dell/doradus/service/schema/SchemaService.java | SchemaService.loadAppRow | private ApplicationDefinition loadAppRow(Tenant tenant, Map<String, String> colMap) {
ApplicationDefinition appDef = new ApplicationDefinition();
String appSchema = colMap.get(COLNAME_APP_SCHEMA);
if (appSchema == null) {
return null; // Not a real application definition row
}
String format = colMap.get(COLNAME_APP_SCHEMA_FORMAT);
ContentType contentType = Utils.isEmpty(format) ? ContentType.TEXT_XML : new ContentType(format);
String versionStr = colMap.get(COLNAME_APP_SCHEMA_VERSION);
int schemaVersion = Utils.isEmpty(versionStr) ? CURRENT_SCHEMA_LEVEL : Integer.parseInt(versionStr);
if (schemaVersion > CURRENT_SCHEMA_LEVEL) {
m_logger.warn("Skipping schema with advanced version: {}", schemaVersion);
return null;
}
try {
appDef.parse(UNode.parse(appSchema, contentType));
} catch (Exception e) {
m_logger.warn("Error parsing schema for application '" + appDef.getAppName() + "'; skipped", e);
return null;
}
appDef.setTenantName(tenant.getName());
return appDef;
} | java | private ApplicationDefinition loadAppRow(Tenant tenant, Map<String, String> colMap) {
ApplicationDefinition appDef = new ApplicationDefinition();
String appSchema = colMap.get(COLNAME_APP_SCHEMA);
if (appSchema == null) {
return null; // Not a real application definition row
}
String format = colMap.get(COLNAME_APP_SCHEMA_FORMAT);
ContentType contentType = Utils.isEmpty(format) ? ContentType.TEXT_XML : new ContentType(format);
String versionStr = colMap.get(COLNAME_APP_SCHEMA_VERSION);
int schemaVersion = Utils.isEmpty(versionStr) ? CURRENT_SCHEMA_LEVEL : Integer.parseInt(versionStr);
if (schemaVersion > CURRENT_SCHEMA_LEVEL) {
m_logger.warn("Skipping schema with advanced version: {}", schemaVersion);
return null;
}
try {
appDef.parse(UNode.parse(appSchema, contentType));
} catch (Exception e) {
m_logger.warn("Error parsing schema for application '" + appDef.getAppName() + "'; skipped", e);
return null;
}
appDef.setTenantName(tenant.getName());
return appDef;
} | [
"private",
"ApplicationDefinition",
"loadAppRow",
"(",
"Tenant",
"tenant",
",",
"Map",
"<",
"String",
",",
"String",
">",
"colMap",
")",
"{",
"ApplicationDefinition",
"appDef",
"=",
"new",
"ApplicationDefinition",
"(",
")",
";",
"String",
"appSchema",
"=",
"colMap",
".",
"get",
"(",
"COLNAME_APP_SCHEMA",
")",
";",
"if",
"(",
"appSchema",
"==",
"null",
")",
"{",
"return",
"null",
";",
"// Not a real application definition row\r",
"}",
"String",
"format",
"=",
"colMap",
".",
"get",
"(",
"COLNAME_APP_SCHEMA_FORMAT",
")",
";",
"ContentType",
"contentType",
"=",
"Utils",
".",
"isEmpty",
"(",
"format",
")",
"?",
"ContentType",
".",
"TEXT_XML",
":",
"new",
"ContentType",
"(",
"format",
")",
";",
"String",
"versionStr",
"=",
"colMap",
".",
"get",
"(",
"COLNAME_APP_SCHEMA_VERSION",
")",
";",
"int",
"schemaVersion",
"=",
"Utils",
".",
"isEmpty",
"(",
"versionStr",
")",
"?",
"CURRENT_SCHEMA_LEVEL",
":",
"Integer",
".",
"parseInt",
"(",
"versionStr",
")",
";",
"if",
"(",
"schemaVersion",
">",
"CURRENT_SCHEMA_LEVEL",
")",
"{",
"m_logger",
".",
"warn",
"(",
"\"Skipping schema with advanced version: {}\"",
",",
"schemaVersion",
")",
";",
"return",
"null",
";",
"}",
"try",
"{",
"appDef",
".",
"parse",
"(",
"UNode",
".",
"parse",
"(",
"appSchema",
",",
"contentType",
")",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"m_logger",
".",
"warn",
"(",
"\"Error parsing schema for application '\"",
"+",
"appDef",
".",
"getAppName",
"(",
")",
"+",
"\"'; skipped\"",
",",
"e",
")",
";",
"return",
"null",
";",
"}",
"appDef",
".",
"setTenantName",
"(",
"tenant",
".",
"getName",
"(",
")",
")",
";",
"return",
"appDef",
";",
"}"
] | Parse the application schema from the given application row. | [
"Parse",
"the",
"application",
"schema",
"from",
"the",
"given",
"application",
"row",
"."
] | ad64d3c37922eefda68ec8869ef089c1ca604b70 | https://github.com/QSFT/Doradus/blob/ad64d3c37922eefda68ec8869ef089c1ca604b70/doradus-server/src/main/java/com/dell/doradus/service/schema/SchemaService.java#L393-L415 |
138,508 | QSFT/Doradus | doradus-server/src/main/java/com/dell/doradus/service/schema/SchemaService.java | SchemaService.getApplicationDefinition | private ApplicationDefinition getApplicationDefinition(Tenant tenant, String appName) {
Iterator<DColumn> colIter =
DBService.instance(tenant).getAllColumns(SchemaService.APPS_STORE_NAME, appName).iterator();
if (!colIter.hasNext()) {
return null;
}
return loadAppRow(tenant, getColumnMap(colIter));
} | java | private ApplicationDefinition getApplicationDefinition(Tenant tenant, String appName) {
Iterator<DColumn> colIter =
DBService.instance(tenant).getAllColumns(SchemaService.APPS_STORE_NAME, appName).iterator();
if (!colIter.hasNext()) {
return null;
}
return loadAppRow(tenant, getColumnMap(colIter));
} | [
"private",
"ApplicationDefinition",
"getApplicationDefinition",
"(",
"Tenant",
"tenant",
",",
"String",
"appName",
")",
"{",
"Iterator",
"<",
"DColumn",
">",
"colIter",
"=",
"DBService",
".",
"instance",
"(",
"tenant",
")",
".",
"getAllColumns",
"(",
"SchemaService",
".",
"APPS_STORE_NAME",
",",
"appName",
")",
".",
"iterator",
"(",
")",
";",
"if",
"(",
"!",
"colIter",
".",
"hasNext",
"(",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"loadAppRow",
"(",
"tenant",
",",
"getColumnMap",
"(",
"colIter",
")",
")",
";",
"}"
] | Get the given application's application. | [
"Get",
"the",
"given",
"application",
"s",
"application",
"."
] | ad64d3c37922eefda68ec8869ef089c1ca604b70 | https://github.com/QSFT/Doradus/blob/ad64d3c37922eefda68ec8869ef089c1ca604b70/doradus-server/src/main/java/com/dell/doradus/service/schema/SchemaService.java#L418-L425 |
138,509 | QSFT/Doradus | doradus-server/src/main/java/com/dell/doradus/service/schema/SchemaService.java | SchemaService.findAllApplications | private Collection<ApplicationDefinition> findAllApplications(Tenant tenant) {
List<ApplicationDefinition> result = new ArrayList<>();
Iterator<DRow> rowIter =
DBService.instance(tenant).getAllRows(SchemaService.APPS_STORE_NAME).iterator();
while (rowIter.hasNext()) {
DRow row = rowIter.next();
ApplicationDefinition appDef = loadAppRow(tenant, getColumnMap(row.getAllColumns(1024).iterator()));
if (appDef != null) {
result.add(appDef);
}
}
return result;
} | java | private Collection<ApplicationDefinition> findAllApplications(Tenant tenant) {
List<ApplicationDefinition> result = new ArrayList<>();
Iterator<DRow> rowIter =
DBService.instance(tenant).getAllRows(SchemaService.APPS_STORE_NAME).iterator();
while (rowIter.hasNext()) {
DRow row = rowIter.next();
ApplicationDefinition appDef = loadAppRow(tenant, getColumnMap(row.getAllColumns(1024).iterator()));
if (appDef != null) {
result.add(appDef);
}
}
return result;
} | [
"private",
"Collection",
"<",
"ApplicationDefinition",
">",
"findAllApplications",
"(",
"Tenant",
"tenant",
")",
"{",
"List",
"<",
"ApplicationDefinition",
">",
"result",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"Iterator",
"<",
"DRow",
">",
"rowIter",
"=",
"DBService",
".",
"instance",
"(",
"tenant",
")",
".",
"getAllRows",
"(",
"SchemaService",
".",
"APPS_STORE_NAME",
")",
".",
"iterator",
"(",
")",
";",
"while",
"(",
"rowIter",
".",
"hasNext",
"(",
")",
")",
"{",
"DRow",
"row",
"=",
"rowIter",
".",
"next",
"(",
")",
";",
"ApplicationDefinition",
"appDef",
"=",
"loadAppRow",
"(",
"tenant",
",",
"getColumnMap",
"(",
"row",
".",
"getAllColumns",
"(",
"1024",
")",
".",
"iterator",
"(",
")",
")",
")",
";",
"if",
"(",
"appDef",
"!=",
"null",
")",
"{",
"result",
".",
"add",
"(",
"appDef",
")",
";",
"}",
"}",
"return",
"result",
";",
"}"
] | Get all application definitions for the given Tenant. | [
"Get",
"all",
"application",
"definitions",
"for",
"the",
"given",
"Tenant",
"."
] | ad64d3c37922eefda68ec8869ef089c1ca604b70 | https://github.com/QSFT/Doradus/blob/ad64d3c37922eefda68ec8869ef089c1ca604b70/doradus-server/src/main/java/com/dell/doradus/service/schema/SchemaService.java#L428-L440 |
138,510 | QSFT/Doradus | doradus-server/src/main/java/com/dell/doradus/service/olap/OLAPService.java | OLAPService.objectQuery | public SearchResultList objectQuery(TableDefinition tableDef, OlapQuery olapQuery) {
checkServiceState();
return m_olap.search(tableDef.getAppDef(), tableDef.getTableName(), olapQuery);
} | java | public SearchResultList objectQuery(TableDefinition tableDef, OlapQuery olapQuery) {
checkServiceState();
return m_olap.search(tableDef.getAppDef(), tableDef.getTableName(), olapQuery);
} | [
"public",
"SearchResultList",
"objectQuery",
"(",
"TableDefinition",
"tableDef",
",",
"OlapQuery",
"olapQuery",
")",
"{",
"checkServiceState",
"(",
")",
";",
"return",
"m_olap",
".",
"search",
"(",
"tableDef",
".",
"getAppDef",
"(",
")",
",",
"tableDef",
".",
"getTableName",
"(",
")",
",",
"olapQuery",
")",
";",
"}"
] | Perform an object query on the given table using the given query parameters.
@param tableDef {@link TableDefinition} of table to query.
@param olapQuery {@link OlapQuery} containing query parameters.
@return {@link SearchResultList} containing search results. | [
"Perform",
"an",
"object",
"query",
"on",
"the",
"given",
"table",
"using",
"the",
"given",
"query",
"parameters",
"."
] | ad64d3c37922eefda68ec8869ef089c1ca604b70 | https://github.com/QSFT/Doradus/blob/ad64d3c37922eefda68ec8869ef089c1ca604b70/doradus-server/src/main/java/com/dell/doradus/service/olap/OLAPService.java#L169-L172 |
138,511 | QSFT/Doradus | doradus-server/src/main/java/com/dell/doradus/service/olap/OLAPService.java | OLAPService.aggregateQuery | public AggregateResult aggregateQuery(TableDefinition tableDef, OlapAggregate request) {
checkServiceState();
AggregationResult result = m_olap.aggregate(tableDef.getAppDef(), tableDef.getTableName(), request);
return AggregateResultConverter.create(result, request);
} | java | public AggregateResult aggregateQuery(TableDefinition tableDef, OlapAggregate request) {
checkServiceState();
AggregationResult result = m_olap.aggregate(tableDef.getAppDef(), tableDef.getTableName(), request);
return AggregateResultConverter.create(result, request);
} | [
"public",
"AggregateResult",
"aggregateQuery",
"(",
"TableDefinition",
"tableDef",
",",
"OlapAggregate",
"request",
")",
"{",
"checkServiceState",
"(",
")",
";",
"AggregationResult",
"result",
"=",
"m_olap",
".",
"aggregate",
"(",
"tableDef",
".",
"getAppDef",
"(",
")",
",",
"tableDef",
".",
"getTableName",
"(",
")",
",",
"request",
")",
";",
"return",
"AggregateResultConverter",
".",
"create",
"(",
"result",
",",
"request",
")",
";",
"}"
] | Perform an aggregate query on the given table using the given request.
@param tableDef {@link TableDefinition} of table to query.
@param request {@link OlapAggregate} that defines query parameters.
@return {@link AggregateResult} containing search results. | [
"Perform",
"an",
"aggregate",
"query",
"on",
"the",
"given",
"table",
"using",
"the",
"given",
"request",
"."
] | ad64d3c37922eefda68ec8869ef089c1ca604b70 | https://github.com/QSFT/Doradus/blob/ad64d3c37922eefda68ec8869ef089c1ca604b70/doradus-server/src/main/java/com/dell/doradus/service/olap/OLAPService.java#L181-L185 |
138,512 | QSFT/Doradus | doradus-server/src/main/java/com/dell/doradus/service/olap/OLAPService.java | OLAPService.addBatch | public BatchResult addBatch(ApplicationDefinition appDef, String shardName, OlapBatch batch) {
return addBatch(appDef, shardName, batch, null);
} | java | public BatchResult addBatch(ApplicationDefinition appDef, String shardName, OlapBatch batch) {
return addBatch(appDef, shardName, batch, null);
} | [
"public",
"BatchResult",
"addBatch",
"(",
"ApplicationDefinition",
"appDef",
",",
"String",
"shardName",
",",
"OlapBatch",
"batch",
")",
"{",
"return",
"addBatch",
"(",
"appDef",
",",
"shardName",
",",
"batch",
",",
"null",
")",
";",
"}"
] | Add a batch of updates for the given application to the given shard. Objects can
new, updated, or deleted.
@param appDef {@link ApplicationDefinition} of application to update.
@param shardName Shard to add batch to.
@param batch {@link OlapBatch} containing object updates.
@return {@link BatchResult} indicating results of update. | [
"Add",
"a",
"batch",
"of",
"updates",
"for",
"the",
"given",
"application",
"to",
"the",
"given",
"shard",
".",
"Objects",
"can",
"new",
"updated",
"or",
"deleted",
"."
] | ad64d3c37922eefda68ec8869ef089c1ca604b70 | https://github.com/QSFT/Doradus/blob/ad64d3c37922eefda68ec8869ef089c1ca604b70/doradus-server/src/main/java/com/dell/doradus/service/olap/OLAPService.java#L198-L200 |
138,513 | QSFT/Doradus | doradus-server/src/main/java/com/dell/doradus/service/olap/OLAPService.java | OLAPService.deleteShard | public void deleteShard(ApplicationDefinition appDef, String shard) {
checkServiceState();
m_olap.deleteShard(appDef, shard);
} | java | public void deleteShard(ApplicationDefinition appDef, String shard) {
checkServiceState();
m_olap.deleteShard(appDef, shard);
} | [
"public",
"void",
"deleteShard",
"(",
"ApplicationDefinition",
"appDef",
",",
"String",
"shard",
")",
"{",
"checkServiceState",
"(",
")",
";",
"m_olap",
".",
"deleteShard",
"(",
"appDef",
",",
"shard",
")",
";",
"}"
] | Delete the shard for the given application, including all of its data. This method
is a no-op if the given shard does not exist or has no data.
@param appDef {@link ApplicationDefinition} of application.
@param shard Shard name. | [
"Delete",
"the",
"shard",
"for",
"the",
"given",
"application",
"including",
"all",
"of",
"its",
"data",
".",
"This",
"method",
"is",
"a",
"no",
"-",
"op",
"if",
"the",
"given",
"shard",
"does",
"not",
"exist",
"or",
"has",
"no",
"data",
"."
] | ad64d3c37922eefda68ec8869ef089c1ca604b70 | https://github.com/QSFT/Doradus/blob/ad64d3c37922eefda68ec8869ef089c1ca604b70/doradus-server/src/main/java/com/dell/doradus/service/olap/OLAPService.java#L249-L252 |
138,514 | QSFT/Doradus | doradus-server/src/main/java/com/dell/doradus/service/olap/OLAPService.java | OLAPService.getStatistics | public UNode getStatistics(ApplicationDefinition appDef, String shard, Map<String, String> paramMap) {
checkServiceState();
CubeSearcher searcher = m_olap.getSearcher(appDef, shard);
String file = paramMap.get("file");
if(file != null) {
return OlapStatistics.getFileData(searcher, file);
}
String sort = paramMap.get("sort");
boolean memStats = !"false".equals(paramMap.get("mem"));
return OlapStatistics.getStatistics(searcher, sort, memStats);
} | java | public UNode getStatistics(ApplicationDefinition appDef, String shard, Map<String, String> paramMap) {
checkServiceState();
CubeSearcher searcher = m_olap.getSearcher(appDef, shard);
String file = paramMap.get("file");
if(file != null) {
return OlapStatistics.getFileData(searcher, file);
}
String sort = paramMap.get("sort");
boolean memStats = !"false".equals(paramMap.get("mem"));
return OlapStatistics.getStatistics(searcher, sort, memStats);
} | [
"public",
"UNode",
"getStatistics",
"(",
"ApplicationDefinition",
"appDef",
",",
"String",
"shard",
",",
"Map",
"<",
"String",
",",
"String",
">",
"paramMap",
")",
"{",
"checkServiceState",
"(",
")",
";",
"CubeSearcher",
"searcher",
"=",
"m_olap",
".",
"getSearcher",
"(",
"appDef",
",",
"shard",
")",
";",
"String",
"file",
"=",
"paramMap",
".",
"get",
"(",
"\"file\"",
")",
";",
"if",
"(",
"file",
"!=",
"null",
")",
"{",
"return",
"OlapStatistics",
".",
"getFileData",
"(",
"searcher",
",",
"file",
")",
";",
"}",
"String",
"sort",
"=",
"paramMap",
".",
"get",
"(",
"\"sort\"",
")",
";",
"boolean",
"memStats",
"=",
"!",
"\"false\"",
".",
"equals",
"(",
"paramMap",
".",
"get",
"(",
"\"mem\"",
")",
")",
";",
"return",
"OlapStatistics",
".",
"getStatistics",
"(",
"searcher",
",",
"sort",
",",
"memStats",
")",
";",
"}"
] | Get detailed shard statistics for the given shard. This command is mostly used for
development and diagnostics.
@param appDef {@link ApplicationDefinition} of application to query.
@param shard Name of shard to query.
@param paramMap Map of statistic option key/value pairs.
@return Root of statistics information as a {@link UNode} tree. | [
"Get",
"detailed",
"shard",
"statistics",
"for",
"the",
"given",
"shard",
".",
"This",
"command",
"is",
"mostly",
"used",
"for",
"development",
"and",
"diagnostics",
"."
] | ad64d3c37922eefda68ec8869ef089c1ca604b70 | https://github.com/QSFT/Doradus/blob/ad64d3c37922eefda68ec8869ef089c1ca604b70/doradus-server/src/main/java/com/dell/doradus/service/olap/OLAPService.java#L306-L316 |
138,515 | QSFT/Doradus | doradus-server/src/main/java/com/dell/doradus/service/olap/OLAPService.java | OLAPService.getExpirationDate | public Date getExpirationDate(ApplicationDefinition appDef, String shard) {
checkServiceState();
return m_olap.getExpirationDate(appDef, shard);
} | java | public Date getExpirationDate(ApplicationDefinition appDef, String shard) {
checkServiceState();
return m_olap.getExpirationDate(appDef, shard);
} | [
"public",
"Date",
"getExpirationDate",
"(",
"ApplicationDefinition",
"appDef",
",",
"String",
"shard",
")",
"{",
"checkServiceState",
"(",
")",
";",
"return",
"m_olap",
".",
"getExpirationDate",
"(",
"appDef",
",",
"shard",
")",
";",
"}"
] | Get the expire-date for the given shard name and OLAP application. Null is returned
if the shard does not exist or has no expire-date.
@param appDef OLAP application definition.
@param shard Shard name.
@return Shard's expire-date or null if it doesn't exist or has no
expire-date. | [
"Get",
"the",
"expire",
"-",
"date",
"for",
"the",
"given",
"shard",
"name",
"and",
"OLAP",
"application",
".",
"Null",
"is",
"returned",
"if",
"the",
"shard",
"does",
"not",
"exist",
"or",
"has",
"no",
"expire",
"-",
"date",
"."
] | ad64d3c37922eefda68ec8869ef089c1ca604b70 | https://github.com/QSFT/Doradus/blob/ad64d3c37922eefda68ec8869ef089c1ca604b70/doradus-server/src/main/java/com/dell/doradus/service/olap/OLAPService.java#L360-L363 |
138,516 | QSFT/Doradus | doradus-server/src/main/java/com/dell/doradus/service/olap/OLAPService.java | OLAPService.getOverwriteOption | private boolean getOverwriteOption(Map<String, String> options) {
boolean bOverwrite = true;
if (options != null) {
for (String name : options.keySet()) {
if ("overwrite".equals(name.toLowerCase())) {
bOverwrite = Boolean.parseBoolean(options.get(name));
} else {
Utils.require(false, "Unknown OLAP batch option: " + name);
}
}
}
return bOverwrite;
} | java | private boolean getOverwriteOption(Map<String, String> options) {
boolean bOverwrite = true;
if (options != null) {
for (String name : options.keySet()) {
if ("overwrite".equals(name.toLowerCase())) {
bOverwrite = Boolean.parseBoolean(options.get(name));
} else {
Utils.require(false, "Unknown OLAP batch option: " + name);
}
}
}
return bOverwrite;
} | [
"private",
"boolean",
"getOverwriteOption",
"(",
"Map",
"<",
"String",
",",
"String",
">",
"options",
")",
"{",
"boolean",
"bOverwrite",
"=",
"true",
";",
"if",
"(",
"options",
"!=",
"null",
")",
"{",
"for",
"(",
"String",
"name",
":",
"options",
".",
"keySet",
"(",
")",
")",
"{",
"if",
"(",
"\"overwrite\"",
".",
"equals",
"(",
"name",
".",
"toLowerCase",
"(",
")",
")",
")",
"{",
"bOverwrite",
"=",
"Boolean",
".",
"parseBoolean",
"(",
"options",
".",
"get",
"(",
"name",
")",
")",
";",
"}",
"else",
"{",
"Utils",
".",
"require",
"(",
"false",
",",
"\"Unknown OLAP batch option: \"",
"+",
"name",
")",
";",
"}",
"}",
"}",
"return",
"bOverwrite",
";",
"}"
] | Get case-insensitive "overwrite" option. Default to "true". | [
"Get",
"case",
"-",
"insensitive",
"overwrite",
"option",
".",
"Default",
"to",
"true",
"."
] | ad64d3c37922eefda68ec8869ef089c1ca604b70 | https://github.com/QSFT/Doradus/blob/ad64d3c37922eefda68ec8869ef089c1ca604b70/doradus-server/src/main/java/com/dell/doradus/service/olap/OLAPService.java#L392-L404 |
138,517 | QSFT/Doradus | doradus-server/src/main/java/com/dell/doradus/service/olap/OLAPService.java | OLAPService.validateApplication | private void validateApplication(ApplicationDefinition appDef) {
boolean bSawAgingFreq = false;
for (String optName : appDef.getOptionNames()) {
String optValue = appDef.getOption(optName);
switch (optName) {
case CommonDefs.OPT_STORAGE_SERVICE:
assert optValue.equals(this.getClass().getSimpleName());
break;
case CommonDefs.OPT_AGING_CHECK_FREQ:
new TaskFrequency(optValue);
bSawAgingFreq = true;
break;
case "auto-merge":
new TaskFrequency(optValue);
break;
default:
throw new IllegalArgumentException("Unknown option for OLAPService application: " + optName);
}
}
for (TableDefinition tableDef : appDef.getTableDefinitions().values()) {
validateTable(tableDef);
}
if (!bSawAgingFreq) {
appDef.setOption(CommonDefs.OPT_AGING_CHECK_FREQ, "1 DAY");
}
} | java | private void validateApplication(ApplicationDefinition appDef) {
boolean bSawAgingFreq = false;
for (String optName : appDef.getOptionNames()) {
String optValue = appDef.getOption(optName);
switch (optName) {
case CommonDefs.OPT_STORAGE_SERVICE:
assert optValue.equals(this.getClass().getSimpleName());
break;
case CommonDefs.OPT_AGING_CHECK_FREQ:
new TaskFrequency(optValue);
bSawAgingFreq = true;
break;
case "auto-merge":
new TaskFrequency(optValue);
break;
default:
throw new IllegalArgumentException("Unknown option for OLAPService application: " + optName);
}
}
for (TableDefinition tableDef : appDef.getTableDefinitions().values()) {
validateTable(tableDef);
}
if (!bSawAgingFreq) {
appDef.setOption(CommonDefs.OPT_AGING_CHECK_FREQ, "1 DAY");
}
} | [
"private",
"void",
"validateApplication",
"(",
"ApplicationDefinition",
"appDef",
")",
"{",
"boolean",
"bSawAgingFreq",
"=",
"false",
";",
"for",
"(",
"String",
"optName",
":",
"appDef",
".",
"getOptionNames",
"(",
")",
")",
"{",
"String",
"optValue",
"=",
"appDef",
".",
"getOption",
"(",
"optName",
")",
";",
"switch",
"(",
"optName",
")",
"{",
"case",
"CommonDefs",
".",
"OPT_STORAGE_SERVICE",
":",
"assert",
"optValue",
".",
"equals",
"(",
"this",
".",
"getClass",
"(",
")",
".",
"getSimpleName",
"(",
")",
")",
";",
"break",
";",
"case",
"CommonDefs",
".",
"OPT_AGING_CHECK_FREQ",
":",
"new",
"TaskFrequency",
"(",
"optValue",
")",
";",
"bSawAgingFreq",
"=",
"true",
";",
"break",
";",
"case",
"\"auto-merge\"",
":",
"new",
"TaskFrequency",
"(",
"optValue",
")",
";",
"break",
";",
"default",
":",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Unknown option for OLAPService application: \"",
"+",
"optName",
")",
";",
"}",
"}",
"for",
"(",
"TableDefinition",
"tableDef",
":",
"appDef",
".",
"getTableDefinitions",
"(",
")",
".",
"values",
"(",
")",
")",
"{",
"validateTable",
"(",
"tableDef",
")",
";",
"}",
"if",
"(",
"!",
"bSawAgingFreq",
")",
"{",
"appDef",
".",
"setOption",
"(",
"CommonDefs",
".",
"OPT_AGING_CHECK_FREQ",
",",
"\"1 DAY\"",
")",
";",
"}",
"}"
] | Validate the given application for OLAP constraints. | [
"Validate",
"the",
"given",
"application",
"for",
"OLAP",
"constraints",
"."
] | ad64d3c37922eefda68ec8869ef089c1ca604b70 | https://github.com/QSFT/Doradus/blob/ad64d3c37922eefda68ec8869ef089c1ca604b70/doradus-server/src/main/java/com/dell/doradus/service/olap/OLAPService.java#L407-L437 |
138,518 | QSFT/Doradus | doradus-server/src/main/java/com/dell/doradus/service/olap/OLAPService.java | OLAPService.validateTable | private void validateTable(TableDefinition tableDef) {
// No options are currently allowed:
for (String optName : tableDef.getOptionNames()) {
Utils.require(false, "Unknown option for OLAPService table: " + optName);
}
for (FieldDefinition fieldDef : tableDef.getFieldDefinitions()) {
validateField(fieldDef);
}
} | java | private void validateTable(TableDefinition tableDef) {
// No options are currently allowed:
for (String optName : tableDef.getOptionNames()) {
Utils.require(false, "Unknown option for OLAPService table: " + optName);
}
for (FieldDefinition fieldDef : tableDef.getFieldDefinitions()) {
validateField(fieldDef);
}
} | [
"private",
"void",
"validateTable",
"(",
"TableDefinition",
"tableDef",
")",
"{",
"// No options are currently allowed:\r",
"for",
"(",
"String",
"optName",
":",
"tableDef",
".",
"getOptionNames",
"(",
")",
")",
"{",
"Utils",
".",
"require",
"(",
"false",
",",
"\"Unknown option for OLAPService table: \"",
"+",
"optName",
")",
";",
"}",
"for",
"(",
"FieldDefinition",
"fieldDef",
":",
"tableDef",
".",
"getFieldDefinitions",
"(",
")",
")",
"{",
"validateField",
"(",
"fieldDef",
")",
";",
"}",
"}"
] | Validate the given table for OLAP constraints. | [
"Validate",
"the",
"given",
"table",
"for",
"OLAP",
"constraints",
"."
] | ad64d3c37922eefda68ec8869ef089c1ca604b70 | https://github.com/QSFT/Doradus/blob/ad64d3c37922eefda68ec8869ef089c1ca604b70/doradus-server/src/main/java/com/dell/doradus/service/olap/OLAPService.java#L440-L449 |
138,519 | QSFT/Doradus | doradus-server/src/main/java/com/dell/doradus/service/db/thrift/CassandraSchemaMgr.java | CassandraSchemaMgr.getKeyspaces | public Collection<String> getKeyspaces(DBConn dbConn) {
List<String> result = new ArrayList<>();
try {
for (KsDef ksDef : dbConn.getClientSession().describe_keyspaces()) {
result.add(ksDef.getName());
}
} catch (Exception e) {
String errMsg = "Failed to get keyspace description";
m_logger.error(errMsg, e);
throw new RuntimeException(errMsg, e);
}
return result;
} | java | public Collection<String> getKeyspaces(DBConn dbConn) {
List<String> result = new ArrayList<>();
try {
for (KsDef ksDef : dbConn.getClientSession().describe_keyspaces()) {
result.add(ksDef.getName());
}
} catch (Exception e) {
String errMsg = "Failed to get keyspace description";
m_logger.error(errMsg, e);
throw new RuntimeException(errMsg, e);
}
return result;
} | [
"public",
"Collection",
"<",
"String",
">",
"getKeyspaces",
"(",
"DBConn",
"dbConn",
")",
"{",
"List",
"<",
"String",
">",
"result",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"try",
"{",
"for",
"(",
"KsDef",
"ksDef",
":",
"dbConn",
".",
"getClientSession",
"(",
")",
".",
"describe_keyspaces",
"(",
")",
")",
"{",
"result",
".",
"add",
"(",
"ksDef",
".",
"getName",
"(",
")",
")",
";",
"}",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"String",
"errMsg",
"=",
"\"Failed to get keyspace description\"",
";",
"m_logger",
".",
"error",
"(",
"errMsg",
",",
"e",
")",
";",
"throw",
"new",
"RuntimeException",
"(",
"errMsg",
",",
"e",
")",
";",
"}",
"return",
"result",
";",
"}"
] | Get a list of all known keyspaces. This method can be used with any DB connection.
@param dbConn Database connection to use.
@return List of all known keyspaces, empty if none. | [
"Get",
"a",
"list",
"of",
"all",
"known",
"keyspaces",
".",
"This",
"method",
"can",
"be",
"used",
"with",
"any",
"DB",
"connection",
"."
] | ad64d3c37922eefda68ec8869ef089c1ca604b70 | https://github.com/QSFT/Doradus/blob/ad64d3c37922eefda68ec8869ef089c1ca604b70/doradus-server/src/main/java/com/dell/doradus/service/db/thrift/CassandraSchemaMgr.java#L58-L70 |
138,520 | QSFT/Doradus | doradus-server/src/main/java/com/dell/doradus/service/db/thrift/CassandraSchemaMgr.java | CassandraSchemaMgr.createKeyspace | public void createKeyspace(DBConn dbConn, String keyspace) {
m_logger.info("Creating Keyspace '{}'", keyspace);
try {
KsDef ksDef = setKeySpaceOptions(keyspace);
dbConn.getClientSession().system_add_keyspace(ksDef);
waitForSchemaPropagation(dbConn);
Thread.sleep(1000); // wait for gossip to other Cassandra nodes
} catch (Exception ex) {
String errMsg = "Failed to create Keyspace '" + keyspace + "'";
m_logger.error(errMsg, ex);
throw new RuntimeException(errMsg, ex);
}
} | java | public void createKeyspace(DBConn dbConn, String keyspace) {
m_logger.info("Creating Keyspace '{}'", keyspace);
try {
KsDef ksDef = setKeySpaceOptions(keyspace);
dbConn.getClientSession().system_add_keyspace(ksDef);
waitForSchemaPropagation(dbConn);
Thread.sleep(1000); // wait for gossip to other Cassandra nodes
} catch (Exception ex) {
String errMsg = "Failed to create Keyspace '" + keyspace + "'";
m_logger.error(errMsg, ex);
throw new RuntimeException(errMsg, ex);
}
} | [
"public",
"void",
"createKeyspace",
"(",
"DBConn",
"dbConn",
",",
"String",
"keyspace",
")",
"{",
"m_logger",
".",
"info",
"(",
"\"Creating Keyspace '{}'\"",
",",
"keyspace",
")",
";",
"try",
"{",
"KsDef",
"ksDef",
"=",
"setKeySpaceOptions",
"(",
"keyspace",
")",
";",
"dbConn",
".",
"getClientSession",
"(",
")",
".",
"system_add_keyspace",
"(",
"ksDef",
")",
";",
"waitForSchemaPropagation",
"(",
"dbConn",
")",
";",
"Thread",
".",
"sleep",
"(",
"1000",
")",
";",
"// wait for gossip to other Cassandra nodes\r",
"}",
"catch",
"(",
"Exception",
"ex",
")",
"{",
"String",
"errMsg",
"=",
"\"Failed to create Keyspace '\"",
"+",
"keyspace",
"+",
"\"'\"",
";",
"m_logger",
".",
"error",
"(",
"errMsg",
",",
"ex",
")",
";",
"throw",
"new",
"RuntimeException",
"(",
"errMsg",
",",
"ex",
")",
";",
"}",
"}"
] | Create a new keyspace with the given name. The keyspace is created with parameters
defined for our DBService instance, if any. This method should be used with a
no-keyspace DB connection.
@param dbConn Database connection to use.
@param keyspace Name of new keyspace. | [
"Create",
"a",
"new",
"keyspace",
"with",
"the",
"given",
"name",
".",
"The",
"keyspace",
"is",
"created",
"with",
"parameters",
"defined",
"for",
"our",
"DBService",
"instance",
"if",
"any",
".",
"This",
"method",
"should",
"be",
"used",
"with",
"a",
"no",
"-",
"keyspace",
"DB",
"connection",
"."
] | ad64d3c37922eefda68ec8869ef089c1ca604b70 | https://github.com/QSFT/Doradus/blob/ad64d3c37922eefda68ec8869ef089c1ca604b70/doradus-server/src/main/java/com/dell/doradus/service/db/thrift/CassandraSchemaMgr.java#L80-L92 |
138,521 | QSFT/Doradus | doradus-server/src/main/java/com/dell/doradus/service/db/thrift/CassandraSchemaMgr.java | CassandraSchemaMgr.keyspaceExists | public boolean keyspaceExists(DBConn dbConn, String keyspace) {
try {
dbConn.getClientSession().describe_keyspace(keyspace);
return true;
} catch (Exception e) {
return false; // Notfound
}
} | java | public boolean keyspaceExists(DBConn dbConn, String keyspace) {
try {
dbConn.getClientSession().describe_keyspace(keyspace);
return true;
} catch (Exception e) {
return false; // Notfound
}
} | [
"public",
"boolean",
"keyspaceExists",
"(",
"DBConn",
"dbConn",
",",
"String",
"keyspace",
")",
"{",
"try",
"{",
"dbConn",
".",
"getClientSession",
"(",
")",
".",
"describe_keyspace",
"(",
"keyspace",
")",
";",
"return",
"true",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"return",
"false",
";",
"// Notfound\r",
"}",
"}"
] | Return true if a keyspace with the given name exists. This method can be used with
any DB connection.
@param dbConn Database connection to use.
@param keyspace Keyspace name.
@return True if it exists. | [
"Return",
"true",
"if",
"a",
"keyspace",
"with",
"the",
"given",
"name",
"exists",
".",
"This",
"method",
"can",
"be",
"used",
"with",
"any",
"DB",
"connection",
"."
] | ad64d3c37922eefda68ec8869ef089c1ca604b70 | https://github.com/QSFT/Doradus/blob/ad64d3c37922eefda68ec8869ef089c1ca604b70/doradus-server/src/main/java/com/dell/doradus/service/db/thrift/CassandraSchemaMgr.java#L103-L110 |
138,522 | QSFT/Doradus | doradus-server/src/main/java/com/dell/doradus/service/db/thrift/CassandraSchemaMgr.java | CassandraSchemaMgr.dropKeyspace | public void dropKeyspace(DBConn dbConn, String keyspace) {
m_logger.info("Deleting Keyspace '{}'", keyspace);
try {
dbConn.getClientSession().system_drop_keyspace(keyspace);
waitForSchemaPropagation(dbConn);
} catch (Exception ex) {
String errMsg = "Failed to delete Keyspace '" + keyspace + "'";
m_logger.error(errMsg, ex);
throw new RuntimeException(errMsg, ex);
}
} | java | public void dropKeyspace(DBConn dbConn, String keyspace) {
m_logger.info("Deleting Keyspace '{}'", keyspace);
try {
dbConn.getClientSession().system_drop_keyspace(keyspace);
waitForSchemaPropagation(dbConn);
} catch (Exception ex) {
String errMsg = "Failed to delete Keyspace '" + keyspace + "'";
m_logger.error(errMsg, ex);
throw new RuntimeException(errMsg, ex);
}
} | [
"public",
"void",
"dropKeyspace",
"(",
"DBConn",
"dbConn",
",",
"String",
"keyspace",
")",
"{",
"m_logger",
".",
"info",
"(",
"\"Deleting Keyspace '{}'\"",
",",
"keyspace",
")",
";",
"try",
"{",
"dbConn",
".",
"getClientSession",
"(",
")",
".",
"system_drop_keyspace",
"(",
"keyspace",
")",
";",
"waitForSchemaPropagation",
"(",
"dbConn",
")",
";",
"}",
"catch",
"(",
"Exception",
"ex",
")",
"{",
"String",
"errMsg",
"=",
"\"Failed to delete Keyspace '\"",
"+",
"keyspace",
"+",
"\"'\"",
";",
"m_logger",
".",
"error",
"(",
"errMsg",
",",
"ex",
")",
";",
"throw",
"new",
"RuntimeException",
"(",
"errMsg",
",",
"ex",
")",
";",
"}",
"}"
] | Delete the keyspace with the given name. This method can use any DB connection.
@param dbConn Database connection to use.
@param keyspace Name of keyspace to drop. | [
"Delete",
"the",
"keyspace",
"with",
"the",
"given",
"name",
".",
"This",
"method",
"can",
"use",
"any",
"DB",
"connection",
"."
] | ad64d3c37922eefda68ec8869ef089c1ca604b70 | https://github.com/QSFT/Doradus/blob/ad64d3c37922eefda68ec8869ef089c1ca604b70/doradus-server/src/main/java/com/dell/doradus/service/db/thrift/CassandraSchemaMgr.java#L118-L128 |
138,523 | QSFT/Doradus | doradus-server/src/main/java/com/dell/doradus/service/db/thrift/CassandraSchemaMgr.java | CassandraSchemaMgr.createColumnFamily | public void createColumnFamily(DBConn dbConn, String keyspace, String cfName, boolean bBinaryValues) {
m_logger.info("Creating ColumnFamily: {}:{}", keyspace, cfName);
CfDef cfDef = new CfDef();
cfDef.setKeyspace(keyspace);
cfDef.setName(cfName);
cfDef.setColumn_type("Standard");
cfDef.setComparator_type("UTF8Type");
cfDef.setKey_validation_class("UTF8Type");
if (bBinaryValues) {
cfDef.setDefault_validation_class("BytesType");
} else {
cfDef.setDefault_validation_class("UTF8Type");
}
Map<String, Object> cfOptions = m_service.getParamMap("cf_defaults");
if (cfOptions != null) {
for (String optName : cfOptions.keySet()) {
Object optValue = cfOptions.get(optName);
CfDef._Fields fieldEnum = CfDef._Fields.findByName(optName);
if (fieldEnum == null) {
m_logger.warn("Unknown ColumnFamily option: {}", optName);
continue;
}
try {
cfDef.setFieldValue(fieldEnum, optValue);
} catch (Exception e) {
m_logger.warn("Error setting ColumnFamily option '" + optName +
"' to '" + optValue + "' -- ignoring", e);
}
}
}
// In a multi-node startup, multiple nodes may be trying to create the same CF.
for (int attempt = 1; !columnFamilyExists(dbConn, keyspace, cfName); attempt++) {
try {
dbConn.getClientSession().system_add_column_family(cfDef);
waitForSchemaPropagation(dbConn);
} catch (Exception ex) {
if (attempt > m_service.getParamInt("max_commit_attempts", 10)) {
String msg = String.format("%d attempts to create ColumnFamily %s:%s failed",
attempt, keyspace, cfName);
throw new RuntimeException(msg, ex);
}
try { Thread.sleep(1000); } catch (InterruptedException e) { }
}
}
} | java | public void createColumnFamily(DBConn dbConn, String keyspace, String cfName, boolean bBinaryValues) {
m_logger.info("Creating ColumnFamily: {}:{}", keyspace, cfName);
CfDef cfDef = new CfDef();
cfDef.setKeyspace(keyspace);
cfDef.setName(cfName);
cfDef.setColumn_type("Standard");
cfDef.setComparator_type("UTF8Type");
cfDef.setKey_validation_class("UTF8Type");
if (bBinaryValues) {
cfDef.setDefault_validation_class("BytesType");
} else {
cfDef.setDefault_validation_class("UTF8Type");
}
Map<String, Object> cfOptions = m_service.getParamMap("cf_defaults");
if (cfOptions != null) {
for (String optName : cfOptions.keySet()) {
Object optValue = cfOptions.get(optName);
CfDef._Fields fieldEnum = CfDef._Fields.findByName(optName);
if (fieldEnum == null) {
m_logger.warn("Unknown ColumnFamily option: {}", optName);
continue;
}
try {
cfDef.setFieldValue(fieldEnum, optValue);
} catch (Exception e) {
m_logger.warn("Error setting ColumnFamily option '" + optName +
"' to '" + optValue + "' -- ignoring", e);
}
}
}
// In a multi-node startup, multiple nodes may be trying to create the same CF.
for (int attempt = 1; !columnFamilyExists(dbConn, keyspace, cfName); attempt++) {
try {
dbConn.getClientSession().system_add_column_family(cfDef);
waitForSchemaPropagation(dbConn);
} catch (Exception ex) {
if (attempt > m_service.getParamInt("max_commit_attempts", 10)) {
String msg = String.format("%d attempts to create ColumnFamily %s:%s failed",
attempt, keyspace, cfName);
throw new RuntimeException(msg, ex);
}
try { Thread.sleep(1000); } catch (InterruptedException e) { }
}
}
} | [
"public",
"void",
"createColumnFamily",
"(",
"DBConn",
"dbConn",
",",
"String",
"keyspace",
",",
"String",
"cfName",
",",
"boolean",
"bBinaryValues",
")",
"{",
"m_logger",
".",
"info",
"(",
"\"Creating ColumnFamily: {}:{}\"",
",",
"keyspace",
",",
"cfName",
")",
";",
"CfDef",
"cfDef",
"=",
"new",
"CfDef",
"(",
")",
";",
"cfDef",
".",
"setKeyspace",
"(",
"keyspace",
")",
";",
"cfDef",
".",
"setName",
"(",
"cfName",
")",
";",
"cfDef",
".",
"setColumn_type",
"(",
"\"Standard\"",
")",
";",
"cfDef",
".",
"setComparator_type",
"(",
"\"UTF8Type\"",
")",
";",
"cfDef",
".",
"setKey_validation_class",
"(",
"\"UTF8Type\"",
")",
";",
"if",
"(",
"bBinaryValues",
")",
"{",
"cfDef",
".",
"setDefault_validation_class",
"(",
"\"BytesType\"",
")",
";",
"}",
"else",
"{",
"cfDef",
".",
"setDefault_validation_class",
"(",
"\"UTF8Type\"",
")",
";",
"}",
"Map",
"<",
"String",
",",
"Object",
">",
"cfOptions",
"=",
"m_service",
".",
"getParamMap",
"(",
"\"cf_defaults\"",
")",
";",
"if",
"(",
"cfOptions",
"!=",
"null",
")",
"{",
"for",
"(",
"String",
"optName",
":",
"cfOptions",
".",
"keySet",
"(",
")",
")",
"{",
"Object",
"optValue",
"=",
"cfOptions",
".",
"get",
"(",
"optName",
")",
";",
"CfDef",
".",
"_Fields",
"fieldEnum",
"=",
"CfDef",
".",
"_Fields",
".",
"findByName",
"(",
"optName",
")",
";",
"if",
"(",
"fieldEnum",
"==",
"null",
")",
"{",
"m_logger",
".",
"warn",
"(",
"\"Unknown ColumnFamily option: {}\"",
",",
"optName",
")",
";",
"continue",
";",
"}",
"try",
"{",
"cfDef",
".",
"setFieldValue",
"(",
"fieldEnum",
",",
"optValue",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"m_logger",
".",
"warn",
"(",
"\"Error setting ColumnFamily option '\"",
"+",
"optName",
"+",
"\"' to '\"",
"+",
"optValue",
"+",
"\"' -- ignoring\"",
",",
"e",
")",
";",
"}",
"}",
"}",
"// In a multi-node startup, multiple nodes may be trying to create the same CF.\r",
"for",
"(",
"int",
"attempt",
"=",
"1",
";",
"!",
"columnFamilyExists",
"(",
"dbConn",
",",
"keyspace",
",",
"cfName",
")",
";",
"attempt",
"++",
")",
"{",
"try",
"{",
"dbConn",
".",
"getClientSession",
"(",
")",
".",
"system_add_column_family",
"(",
"cfDef",
")",
";",
"waitForSchemaPropagation",
"(",
"dbConn",
")",
";",
"}",
"catch",
"(",
"Exception",
"ex",
")",
"{",
"if",
"(",
"attempt",
">",
"m_service",
".",
"getParamInt",
"(",
"\"max_commit_attempts\"",
",",
"10",
")",
")",
"{",
"String",
"msg",
"=",
"String",
".",
"format",
"(",
"\"%d attempts to create ColumnFamily %s:%s failed\"",
",",
"attempt",
",",
"keyspace",
",",
"cfName",
")",
";",
"throw",
"new",
"RuntimeException",
"(",
"msg",
",",
"ex",
")",
";",
"}",
"try",
"{",
"Thread",
".",
"sleep",
"(",
"1000",
")",
";",
"}",
"catch",
"(",
"InterruptedException",
"e",
")",
"{",
"}",
"}",
"}",
"}"
] | Create a new ColumnFamily with the given parameters. If the new CF is
created successfully, wait for all nodes in the cluster to receive the schema
change before returning. An exception is thrown if the CF create fails. The
current DB connection can be connected to any keyspace.
@param dbConn Database connection to use.
@param keyspace Keyspace that owns new CF.
@param cfName name of new CF.
@param bBinaryValues True if column values shoud be binary. | [
"Create",
"a",
"new",
"ColumnFamily",
"with",
"the",
"given",
"parameters",
".",
"If",
"the",
"new",
"CF",
"is",
"created",
"successfully",
"wait",
"for",
"all",
"nodes",
"in",
"the",
"cluster",
"to",
"receive",
"the",
"schema",
"change",
"before",
"returning",
".",
"An",
"exception",
"is",
"thrown",
"if",
"the",
"CF",
"create",
"fails",
".",
"The",
"current",
"DB",
"connection",
"can",
"be",
"connected",
"to",
"any",
"keyspace",
"."
] | ad64d3c37922eefda68ec8869ef089c1ca604b70 | https://github.com/QSFT/Doradus/blob/ad64d3c37922eefda68ec8869ef089c1ca604b70/doradus-server/src/main/java/com/dell/doradus/service/db/thrift/CassandraSchemaMgr.java#L143-L190 |
138,524 | QSFT/Doradus | doradus-server/src/main/java/com/dell/doradus/service/db/thrift/CassandraSchemaMgr.java | CassandraSchemaMgr.columnFamilyExists | public boolean columnFamilyExists(DBConn dbConn, String keyspace, String cfName) {
KsDef ksDef = null;
try {
ksDef = dbConn.getClientSession().describe_keyspace(keyspace);
} catch (Exception ex) {
throw new RuntimeException("Failed to get keyspace definition for '" + keyspace + "'", ex);
}
List<CfDef> cfDefList = ksDef.getCf_defs();
for (CfDef cfDef : cfDefList) {
if (cfDef.getName().equals(cfName)) {
return true;
}
}
return false;
} | java | public boolean columnFamilyExists(DBConn dbConn, String keyspace, String cfName) {
KsDef ksDef = null;
try {
ksDef = dbConn.getClientSession().describe_keyspace(keyspace);
} catch (Exception ex) {
throw new RuntimeException("Failed to get keyspace definition for '" + keyspace + "'", ex);
}
List<CfDef> cfDefList = ksDef.getCf_defs();
for (CfDef cfDef : cfDefList) {
if (cfDef.getName().equals(cfName)) {
return true;
}
}
return false;
} | [
"public",
"boolean",
"columnFamilyExists",
"(",
"DBConn",
"dbConn",
",",
"String",
"keyspace",
",",
"String",
"cfName",
")",
"{",
"KsDef",
"ksDef",
"=",
"null",
";",
"try",
"{",
"ksDef",
"=",
"dbConn",
".",
"getClientSession",
"(",
")",
".",
"describe_keyspace",
"(",
"keyspace",
")",
";",
"}",
"catch",
"(",
"Exception",
"ex",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"Failed to get keyspace definition for '\"",
"+",
"keyspace",
"+",
"\"'\"",
",",
"ex",
")",
";",
"}",
"List",
"<",
"CfDef",
">",
"cfDefList",
"=",
"ksDef",
".",
"getCf_defs",
"(",
")",
";",
"for",
"(",
"CfDef",
"cfDef",
":",
"cfDefList",
")",
"{",
"if",
"(",
"cfDef",
".",
"getName",
"(",
")",
".",
"equals",
"(",
"cfName",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Return true if the given store name currently exists in the given keyspace. This
method can be used with a connection connected to any keyspace.
@param dbConn Database connection to use.
@param cfName Candidate ColumnFamily name.
@return True if the CF exists in the database. | [
"Return",
"true",
"if",
"the",
"given",
"store",
"name",
"currently",
"exists",
"in",
"the",
"given",
"keyspace",
".",
"This",
"method",
"can",
"be",
"used",
"with",
"a",
"connection",
"connected",
"to",
"any",
"keyspace",
"."
] | ad64d3c37922eefda68ec8869ef089c1ca604b70 | https://github.com/QSFT/Doradus/blob/ad64d3c37922eefda68ec8869ef089c1ca604b70/doradus-server/src/main/java/com/dell/doradus/service/db/thrift/CassandraSchemaMgr.java#L200-L215 |
138,525 | QSFT/Doradus | doradus-server/src/main/java/com/dell/doradus/service/db/thrift/CassandraSchemaMgr.java | CassandraSchemaMgr.deleteColumnFamily | public void deleteColumnFamily(DBConn dbConn, String cfName) {
m_logger.info("Deleting ColumnFamily: {}", cfName);
try {
dbConn.getClientSession().system_drop_column_family(cfName);
waitForSchemaPropagation(dbConn);
} catch (Exception ex) {
throw new RuntimeException("drop_column_family failed", ex);
}
} | java | public void deleteColumnFamily(DBConn dbConn, String cfName) {
m_logger.info("Deleting ColumnFamily: {}", cfName);
try {
dbConn.getClientSession().system_drop_column_family(cfName);
waitForSchemaPropagation(dbConn);
} catch (Exception ex) {
throw new RuntimeException("drop_column_family failed", ex);
}
} | [
"public",
"void",
"deleteColumnFamily",
"(",
"DBConn",
"dbConn",
",",
"String",
"cfName",
")",
"{",
"m_logger",
".",
"info",
"(",
"\"Deleting ColumnFamily: {}\"",
",",
"cfName",
")",
";",
"try",
"{",
"dbConn",
".",
"getClientSession",
"(",
")",
".",
"system_drop_column_family",
"(",
"cfName",
")",
";",
"waitForSchemaPropagation",
"(",
"dbConn",
")",
";",
"}",
"catch",
"(",
"Exception",
"ex",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"drop_column_family failed\"",
",",
"ex",
")",
";",
"}",
"}"
] | Delete the column family with the given name. The given DB connection must be
connected to the keyspace in which the CF is to be deleted.
@param dbConn Database connection to use.
@param cfName Name of CF to delete. | [
"Delete",
"the",
"column",
"family",
"with",
"the",
"given",
"name",
".",
"The",
"given",
"DB",
"connection",
"must",
"be",
"connected",
"to",
"the",
"keyspace",
"in",
"which",
"the",
"CF",
"is",
"to",
"be",
"deleted",
"."
] | ad64d3c37922eefda68ec8869ef089c1ca604b70 | https://github.com/QSFT/Doradus/blob/ad64d3c37922eefda68ec8869ef089c1ca604b70/doradus-server/src/main/java/com/dell/doradus/service/db/thrift/CassandraSchemaMgr.java#L224-L232 |
138,526 | QSFT/Doradus | doradus-server/src/main/java/com/dell/doradus/service/db/thrift/CassandraSchemaMgr.java | CassandraSchemaMgr.setKeySpaceOptions | private KsDef setKeySpaceOptions(String keyspace) {
KsDef ksDef = new KsDef();
ksDef.setName(keyspace);
Map<String, Object> ksDefs = m_service.getParamMap("ks_defaults");
if (ksDefs != null) {
for (String name : ksDefs.keySet()) {
Object value = ksDefs.get(name);
try {
KsDef._Fields field = KsDef._Fields.findByName(name);
if (field == null) {
m_logger.warn("Unknown KeySpace option: {} -- ignoring", name);
} else {
ksDef.setFieldValue(field, value);
}
} catch (Exception e) {
m_logger.warn("Error setting Keyspace option '" + name + "' to '" + value + "' -- ignoring", e);
}
}
}
// Legacy support: ReplicationFactor -> replication_factor
if (m_service.getParam("ReplicationFactor") != null) {
Map<String, String> stratOpts = new HashMap<>();
stratOpts.put("replication_factor", m_service.getParamString("ReplicationFactor"));
ksDef.setStrategy_options(stratOpts);
}
// required: strategy_class, strategy_options, replication_factor, cf_defs, durable_writes
if (!ksDef.isSetStrategy_class()) {
ksDef.setStrategy_class(DEFAULT_KS_STRATEGY_CLASS);
}
if (!ksDef.isSetStrategy_options()) {
Map<String, String> stratOpts = new HashMap<>();
stratOpts.put("replication_factor", DEFAULT_KS_REPLICATION_FACTOR);
ksDef.setStrategy_options(stratOpts);
}
if (!ksDef.isSetCf_defs()) {
ksDef.setCf_defs(DEFAULT_KS_CF_DEFS);
}
if (!ksDef.isSetDurable_writes()) {
ksDef.setDurable_writes(DEFAULT_KS_DURABLE_WRITES);
}
return ksDef;
} | java | private KsDef setKeySpaceOptions(String keyspace) {
KsDef ksDef = new KsDef();
ksDef.setName(keyspace);
Map<String, Object> ksDefs = m_service.getParamMap("ks_defaults");
if (ksDefs != null) {
for (String name : ksDefs.keySet()) {
Object value = ksDefs.get(name);
try {
KsDef._Fields field = KsDef._Fields.findByName(name);
if (field == null) {
m_logger.warn("Unknown KeySpace option: {} -- ignoring", name);
} else {
ksDef.setFieldValue(field, value);
}
} catch (Exception e) {
m_logger.warn("Error setting Keyspace option '" + name + "' to '" + value + "' -- ignoring", e);
}
}
}
// Legacy support: ReplicationFactor -> replication_factor
if (m_service.getParam("ReplicationFactor") != null) {
Map<String, String> stratOpts = new HashMap<>();
stratOpts.put("replication_factor", m_service.getParamString("ReplicationFactor"));
ksDef.setStrategy_options(stratOpts);
}
// required: strategy_class, strategy_options, replication_factor, cf_defs, durable_writes
if (!ksDef.isSetStrategy_class()) {
ksDef.setStrategy_class(DEFAULT_KS_STRATEGY_CLASS);
}
if (!ksDef.isSetStrategy_options()) {
Map<String, String> stratOpts = new HashMap<>();
stratOpts.put("replication_factor", DEFAULT_KS_REPLICATION_FACTOR);
ksDef.setStrategy_options(stratOpts);
}
if (!ksDef.isSetCf_defs()) {
ksDef.setCf_defs(DEFAULT_KS_CF_DEFS);
}
if (!ksDef.isSetDurable_writes()) {
ksDef.setDurable_writes(DEFAULT_KS_DURABLE_WRITES);
}
return ksDef;
} | [
"private",
"KsDef",
"setKeySpaceOptions",
"(",
"String",
"keyspace",
")",
"{",
"KsDef",
"ksDef",
"=",
"new",
"KsDef",
"(",
")",
";",
"ksDef",
".",
"setName",
"(",
"keyspace",
")",
";",
"Map",
"<",
"String",
",",
"Object",
">",
"ksDefs",
"=",
"m_service",
".",
"getParamMap",
"(",
"\"ks_defaults\"",
")",
";",
"if",
"(",
"ksDefs",
"!=",
"null",
")",
"{",
"for",
"(",
"String",
"name",
":",
"ksDefs",
".",
"keySet",
"(",
")",
")",
"{",
"Object",
"value",
"=",
"ksDefs",
".",
"get",
"(",
"name",
")",
";",
"try",
"{",
"KsDef",
".",
"_Fields",
"field",
"=",
"KsDef",
".",
"_Fields",
".",
"findByName",
"(",
"name",
")",
";",
"if",
"(",
"field",
"==",
"null",
")",
"{",
"m_logger",
".",
"warn",
"(",
"\"Unknown KeySpace option: {} -- ignoring\"",
",",
"name",
")",
";",
"}",
"else",
"{",
"ksDef",
".",
"setFieldValue",
"(",
"field",
",",
"value",
")",
";",
"}",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"m_logger",
".",
"warn",
"(",
"\"Error setting Keyspace option '\"",
"+",
"name",
"+",
"\"' to '\"",
"+",
"value",
"+",
"\"' -- ignoring\"",
",",
"e",
")",
";",
"}",
"}",
"}",
"// Legacy support: ReplicationFactor -> replication_factor\r",
"if",
"(",
"m_service",
".",
"getParam",
"(",
"\"ReplicationFactor\"",
")",
"!=",
"null",
")",
"{",
"Map",
"<",
"String",
",",
"String",
">",
"stratOpts",
"=",
"new",
"HashMap",
"<>",
"(",
")",
";",
"stratOpts",
".",
"put",
"(",
"\"replication_factor\"",
",",
"m_service",
".",
"getParamString",
"(",
"\"ReplicationFactor\"",
")",
")",
";",
"ksDef",
".",
"setStrategy_options",
"(",
"stratOpts",
")",
";",
"}",
"// required: strategy_class, strategy_options, replication_factor, cf_defs, durable_writes\r",
"if",
"(",
"!",
"ksDef",
".",
"isSetStrategy_class",
"(",
")",
")",
"{",
"ksDef",
".",
"setStrategy_class",
"(",
"DEFAULT_KS_STRATEGY_CLASS",
")",
";",
"}",
"if",
"(",
"!",
"ksDef",
".",
"isSetStrategy_options",
"(",
")",
")",
"{",
"Map",
"<",
"String",
",",
"String",
">",
"stratOpts",
"=",
"new",
"HashMap",
"<>",
"(",
")",
";",
"stratOpts",
".",
"put",
"(",
"\"replication_factor\"",
",",
"DEFAULT_KS_REPLICATION_FACTOR",
")",
";",
"ksDef",
".",
"setStrategy_options",
"(",
"stratOpts",
")",
";",
"}",
"if",
"(",
"!",
"ksDef",
".",
"isSetCf_defs",
"(",
")",
")",
"{",
"ksDef",
".",
"setCf_defs",
"(",
"DEFAULT_KS_CF_DEFS",
")",
";",
"}",
"if",
"(",
"!",
"ksDef",
".",
"isSetDurable_writes",
"(",
")",
")",
"{",
"ksDef",
".",
"setDurable_writes",
"(",
"DEFAULT_KS_DURABLE_WRITES",
")",
";",
"}",
"return",
"ksDef",
";",
"}"
] | Build KsDef from doradus.yaml and DBService-specific options. | [
"Build",
"KsDef",
"from",
"doradus",
".",
"yaml",
"and",
"DBService",
"-",
"specific",
"options",
"."
] | ad64d3c37922eefda68ec8869ef089c1ca604b70 | https://github.com/QSFT/Doradus/blob/ad64d3c37922eefda68ec8869ef089c1ca604b70/doradus-server/src/main/java/com/dell/doradus/service/db/thrift/CassandraSchemaMgr.java#L237-L280 |
138,527 | QSFT/Doradus | doradus-server/src/main/java/com/dell/doradus/service/db/thrift/CassandraSchemaMgr.java | CassandraSchemaMgr.waitForSchemaPropagation | private void waitForSchemaPropagation(DBConn dbConn) {
for(int i = 0; i < 5; i++) {
try {
Map<String, List<String>> versions = dbConn.getClientSession().describe_schema_versions();
if(versions.size() <= 1) return;
m_logger.info("Schema versions are not synchronized yet. Retrying");
Thread.sleep(500 + 1000 * i);
}catch(Exception ex) {
m_logger.warn("Error waiting for schema propagation: {}", ex.getMessage());
}
m_logger.error("Schema versions have not been synchronized");
}
} | java | private void waitForSchemaPropagation(DBConn dbConn) {
for(int i = 0; i < 5; i++) {
try {
Map<String, List<String>> versions = dbConn.getClientSession().describe_schema_versions();
if(versions.size() <= 1) return;
m_logger.info("Schema versions are not synchronized yet. Retrying");
Thread.sleep(500 + 1000 * i);
}catch(Exception ex) {
m_logger.warn("Error waiting for schema propagation: {}", ex.getMessage());
}
m_logger.error("Schema versions have not been synchronized");
}
} | [
"private",
"void",
"waitForSchemaPropagation",
"(",
"DBConn",
"dbConn",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"5",
";",
"i",
"++",
")",
"{",
"try",
"{",
"Map",
"<",
"String",
",",
"List",
"<",
"String",
">",
">",
"versions",
"=",
"dbConn",
".",
"getClientSession",
"(",
")",
".",
"describe_schema_versions",
"(",
")",
";",
"if",
"(",
"versions",
".",
"size",
"(",
")",
"<=",
"1",
")",
"return",
";",
"m_logger",
".",
"info",
"(",
"\"Schema versions are not synchronized yet. Retrying\"",
")",
";",
"Thread",
".",
"sleep",
"(",
"500",
"+",
"1000",
"*",
"i",
")",
";",
"}",
"catch",
"(",
"Exception",
"ex",
")",
"{",
"m_logger",
".",
"warn",
"(",
"\"Error waiting for schema propagation: {}\"",
",",
"ex",
".",
"getMessage",
"(",
")",
")",
";",
"}",
"m_logger",
".",
"error",
"(",
"\"Schema versions have not been synchronized\"",
")",
";",
"}",
"}"
] | This method waits until all the nodes have the same schema | [
"This",
"method",
"waits",
"until",
"all",
"the",
"nodes",
"have",
"the",
"same",
"schema"
] | ad64d3c37922eefda68ec8869ef089c1ca604b70 | https://github.com/QSFT/Doradus/blob/ad64d3c37922eefda68ec8869ef089c1ca604b70/doradus-server/src/main/java/com/dell/doradus/service/db/thrift/CassandraSchemaMgr.java#L285-L297 |
138,528 | osglworks/java-tool | src/main/java/org/osgl/util/IO.java | IO.outputStream | public static OutputStream outputStream(File file) {
try {
return new FileOutputStream(file);
} catch (FileNotFoundException e) {
throw E.ioException(e);
}
} | java | public static OutputStream outputStream(File file) {
try {
return new FileOutputStream(file);
} catch (FileNotFoundException e) {
throw E.ioException(e);
}
} | [
"public",
"static",
"OutputStream",
"outputStream",
"(",
"File",
"file",
")",
"{",
"try",
"{",
"return",
"new",
"FileOutputStream",
"(",
"file",
")",
";",
"}",
"catch",
"(",
"FileNotFoundException",
"e",
")",
"{",
"throw",
"E",
".",
"ioException",
"(",
"e",
")",
";",
"}",
"}"
] | Returns a file output stream
@param file
the file to which the returned output stream can be used to write to
@return an output stream that can be used to write to file specified | [
"Returns",
"a",
"file",
"output",
"stream"
] | 8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b | https://github.com/osglworks/java-tool/blob/8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b/src/main/java/org/osgl/util/IO.java#L1064-L1070 |
138,529 | osglworks/java-tool | src/main/java/org/osgl/util/IO.java | IO.writer | public static Writer writer(File file) {
try {
return new FileWriter(file);
} catch (IOException e) {
throw E.ioException(e);
}
} | java | public static Writer writer(File file) {
try {
return new FileWriter(file);
} catch (IOException e) {
throw E.ioException(e);
}
} | [
"public",
"static",
"Writer",
"writer",
"(",
"File",
"file",
")",
"{",
"try",
"{",
"return",
"new",
"FileWriter",
"(",
"file",
")",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"throw",
"E",
".",
"ioException",
"(",
"e",
")",
";",
"}",
"}"
] | Returns a file writer
@param file
the file to be written
@return a writer | [
"Returns",
"a",
"file",
"writer"
] | 8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b | https://github.com/osglworks/java-tool/blob/8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b/src/main/java/org/osgl/util/IO.java#L1102-L1108 |
138,530 | osglworks/java-tool | src/main/java/org/osgl/util/IO.java | IO.inputStream | public static InputStream inputStream(File file) {
// workaround http://stackoverflow.com/questions/36880692/java-file-does-not-exists-but-file-getabsolutefile-exists
if (!file.exists()) {
file = file.getAbsoluteFile();
}
if (!file.exists()) {
throw E.ioException("File does not exists: %s", file.getPath());
}
try {
return new FileInputStream(file);
} catch (FileNotFoundException e) {
throw E.ioException(e);
}
} | java | public static InputStream inputStream(File file) {
// workaround http://stackoverflow.com/questions/36880692/java-file-does-not-exists-but-file-getabsolutefile-exists
if (!file.exists()) {
file = file.getAbsoluteFile();
}
if (!file.exists()) {
throw E.ioException("File does not exists: %s", file.getPath());
}
try {
return new FileInputStream(file);
} catch (FileNotFoundException e) {
throw E.ioException(e);
}
} | [
"public",
"static",
"InputStream",
"inputStream",
"(",
"File",
"file",
")",
"{",
"// workaround http://stackoverflow.com/questions/36880692/java-file-does-not-exists-but-file-getabsolutefile-exists",
"if",
"(",
"!",
"file",
".",
"exists",
"(",
")",
")",
"{",
"file",
"=",
"file",
".",
"getAbsoluteFile",
"(",
")",
";",
"}",
"if",
"(",
"!",
"file",
".",
"exists",
"(",
")",
")",
"{",
"throw",
"E",
".",
"ioException",
"(",
"\"File does not exists: %s\"",
",",
"file",
".",
"getPath",
"(",
")",
")",
";",
"}",
"try",
"{",
"return",
"new",
"FileInputStream",
"(",
"file",
")",
";",
"}",
"catch",
"(",
"FileNotFoundException",
"e",
")",
"{",
"throw",
"E",
".",
"ioException",
"(",
"e",
")",
";",
"}",
"}"
] | Returns a file input stream
@param file
the file to be read
@return inputstream that read the file | [
"Returns",
"a",
"file",
"input",
"stream"
] | 8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b | https://github.com/osglworks/java-tool/blob/8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b/src/main/java/org/osgl/util/IO.java#L1139-L1152 |
138,531 | osglworks/java-tool | src/main/java/org/osgl/util/IO.java | IO.inputStream | public static InputStream inputStream(URL url) {
try {
return url.openStream();
} catch (IOException e) {
throw E.ioException(e);
}
} | java | public static InputStream inputStream(URL url) {
try {
return url.openStream();
} catch (IOException e) {
throw E.ioException(e);
}
} | [
"public",
"static",
"InputStream",
"inputStream",
"(",
"URL",
"url",
")",
"{",
"try",
"{",
"return",
"url",
".",
"openStream",
"(",
")",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"throw",
"E",
".",
"ioException",
"(",
"e",
")",
";",
"}",
"}"
] | Create an input stream from a URL.
@param url
the URL.
@return the new inputstream. | [
"Create",
"an",
"input",
"stream",
"from",
"a",
"URL",
"."
] | 8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b | https://github.com/osglworks/java-tool/blob/8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b/src/main/java/org/osgl/util/IO.java#L1224-L1230 |
138,532 | osglworks/java-tool | src/main/java/org/osgl/util/IO.java | IO.reader | public static Reader reader(File file) {
E.illegalArgumentIfNot(file.canRead(), "file not readable: " + file.getPath());
try {
return new FileReader(file);
} catch (IOException e) {
throw E.ioException(e);
}
} | java | public static Reader reader(File file) {
E.illegalArgumentIfNot(file.canRead(), "file not readable: " + file.getPath());
try {
return new FileReader(file);
} catch (IOException e) {
throw E.ioException(e);
}
} | [
"public",
"static",
"Reader",
"reader",
"(",
"File",
"file",
")",
"{",
"E",
".",
"illegalArgumentIfNot",
"(",
"file",
".",
"canRead",
"(",
")",
",",
"\"file not readable: \"",
"+",
"file",
".",
"getPath",
"(",
")",
")",
";",
"try",
"{",
"return",
"new",
"FileReader",
"(",
"file",
")",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"throw",
"E",
".",
"ioException",
"(",
"e",
")",
";",
"}",
"}"
] | Returns a file reader
@param file
the file to be read
@return a reader that reads the file specified | [
"Returns",
"a",
"file",
"reader"
] | 8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b | https://github.com/osglworks/java-tool/blob/8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b/src/main/java/org/osgl/util/IO.java#L1256-L1263 |
138,533 | osglworks/java-tool | src/main/java/org/osgl/util/IO.java | IO.checksum | public static String checksum(InputStream is) {
try {
MessageDigest md = MessageDigest.getInstance("SHA1");
byte[] dataBytes = new byte[1024];
int nread;
while ((nread = is.read(dataBytes)) != -1) {
md.update(dataBytes, 0, nread);
}
byte[] mdbytes = md.digest();
S.Buffer sb = S.buffer();
for (int i = 0; i < mdbytes.length; i++) {
sb.append(Integer.toString((mdbytes[i] & 0xff) + 0x100, 16).substring(1));
}
return sb.toString();
} catch (NoSuchAlgorithmException e) {
throw E.unexpected("SHA1 algorithm not found");
} catch (IOException e) {
throw E.ioException(e);
}
} | java | public static String checksum(InputStream is) {
try {
MessageDigest md = MessageDigest.getInstance("SHA1");
byte[] dataBytes = new byte[1024];
int nread;
while ((nread = is.read(dataBytes)) != -1) {
md.update(dataBytes, 0, nread);
}
byte[] mdbytes = md.digest();
S.Buffer sb = S.buffer();
for (int i = 0; i < mdbytes.length; i++) {
sb.append(Integer.toString((mdbytes[i] & 0xff) + 0x100, 16).substring(1));
}
return sb.toString();
} catch (NoSuchAlgorithmException e) {
throw E.unexpected("SHA1 algorithm not found");
} catch (IOException e) {
throw E.ioException(e);
}
} | [
"public",
"static",
"String",
"checksum",
"(",
"InputStream",
"is",
")",
"{",
"try",
"{",
"MessageDigest",
"md",
"=",
"MessageDigest",
".",
"getInstance",
"(",
"\"SHA1\"",
")",
";",
"byte",
"[",
"]",
"dataBytes",
"=",
"new",
"byte",
"[",
"1024",
"]",
";",
"int",
"nread",
";",
"while",
"(",
"(",
"nread",
"=",
"is",
".",
"read",
"(",
"dataBytes",
")",
")",
"!=",
"-",
"1",
")",
"{",
"md",
".",
"update",
"(",
"dataBytes",
",",
"0",
",",
"nread",
")",
";",
"}",
"byte",
"[",
"]",
"mdbytes",
"=",
"md",
".",
"digest",
"(",
")",
";",
"S",
".",
"Buffer",
"sb",
"=",
"S",
".",
"buffer",
"(",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"mdbytes",
".",
"length",
";",
"i",
"++",
")",
"{",
"sb",
".",
"append",
"(",
"Integer",
".",
"toString",
"(",
"(",
"mdbytes",
"[",
"i",
"]",
"&",
"0xff",
")",
"+",
"0x100",
",",
"16",
")",
".",
"substring",
"(",
"1",
")",
")",
";",
"}",
"return",
"sb",
".",
"toString",
"(",
")",
";",
"}",
"catch",
"(",
"NoSuchAlgorithmException",
"e",
")",
"{",
"throw",
"E",
".",
"unexpected",
"(",
"\"SHA1 algorithm not found\"",
")",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"throw",
"E",
".",
"ioException",
"(",
"e",
")",
";",
"}",
"}"
] | Returns checksum from an input stream.
@param is
the inputstream
@return the checksum of the content from the inputstream | [
"Returns",
"checksum",
"from",
"an",
"input",
"stream",
"."
] | 8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b | https://github.com/osglworks/java-tool/blob/8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b/src/main/java/org/osgl/util/IO.java#L1342-L1365 |
138,534 | osglworks/java-tool | src/main/java/org/osgl/util/IO.java | IO.loadProperties | public static Properties loadProperties(URL url) {
if (null == url) {
return new Properties();
}
return loadProperties(inputStream(url));
} | java | public static Properties loadProperties(URL url) {
if (null == url) {
return new Properties();
}
return loadProperties(inputStream(url));
} | [
"public",
"static",
"Properties",
"loadProperties",
"(",
"URL",
"url",
")",
"{",
"if",
"(",
"null",
"==",
"url",
")",
"{",
"return",
"new",
"Properties",
"(",
")",
";",
"}",
"return",
"loadProperties",
"(",
"inputStream",
"(",
"url",
")",
")",
";",
"}"
] | Load properties from a URL
@param url the URL of the properties file
@return
the properties contains the content of the URL or an empty properties
if the URL is invalid or null | [
"Load",
"properties",
"from",
"a",
"URL"
] | 8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b | https://github.com/osglworks/java-tool/blob/8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b/src/main/java/org/osgl/util/IO.java#L1415-L1420 |
138,535 | osglworks/java-tool | src/main/java/org/osgl/util/IO.java | IO.writeContent | @Deprecated
public static void writeContent(CharSequence content, File file, String encoding) {
write(content, file, encoding);
} | java | @Deprecated
public static void writeContent(CharSequence content, File file, String encoding) {
write(content, file, encoding);
} | [
"@",
"Deprecated",
"public",
"static",
"void",
"writeContent",
"(",
"CharSequence",
"content",
",",
"File",
"file",
",",
"String",
"encoding",
")",
"{",
"write",
"(",
"content",
",",
"file",
",",
"encoding",
")",
";",
"}"
] | Write string content to a file with encoding specified.
This is deprecated. Please use {@link #write(CharSequence, File, String)} instead | [
"Write",
"string",
"content",
"to",
"a",
"file",
"with",
"encoding",
"specified",
"."
] | 8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b | https://github.com/osglworks/java-tool/blob/8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b/src/main/java/org/osgl/util/IO.java#L1702-L1705 |
138,536 | osglworks/java-tool | src/main/java/org/osgl/util/IO.java | IO.write | public static void write(CharSequence content, File file, String encoding) {
OutputStream os = null;
try {
os = new FileOutputStream(file);
PrintWriter printWriter = new PrintWriter(new OutputStreamWriter(os, encoding));
printWriter.print(content);
printWriter.flush();
os.flush();
} catch (IOException e) {
throw E.unexpected(e);
} finally {
close(os);
}
} | java | public static void write(CharSequence content, File file, String encoding) {
OutputStream os = null;
try {
os = new FileOutputStream(file);
PrintWriter printWriter = new PrintWriter(new OutputStreamWriter(os, encoding));
printWriter.print(content);
printWriter.flush();
os.flush();
} catch (IOException e) {
throw E.unexpected(e);
} finally {
close(os);
}
} | [
"public",
"static",
"void",
"write",
"(",
"CharSequence",
"content",
",",
"File",
"file",
",",
"String",
"encoding",
")",
"{",
"OutputStream",
"os",
"=",
"null",
";",
"try",
"{",
"os",
"=",
"new",
"FileOutputStream",
"(",
"file",
")",
";",
"PrintWriter",
"printWriter",
"=",
"new",
"PrintWriter",
"(",
"new",
"OutputStreamWriter",
"(",
"os",
",",
"encoding",
")",
")",
";",
"printWriter",
".",
"print",
"(",
"content",
")",
";",
"printWriter",
".",
"flush",
"(",
")",
";",
"os",
".",
"flush",
"(",
")",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"throw",
"E",
".",
"unexpected",
"(",
"e",
")",
";",
"}",
"finally",
"{",
"close",
"(",
"os",
")",
";",
"}",
"}"
] | Write String content to a file with encoding specified
@param content
The content to write
@param file
The file to write
@param encoding
encoding used to write the content to file | [
"Write",
"String",
"content",
"to",
"a",
"file",
"with",
"encoding",
"specified"
] | 8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b | https://github.com/osglworks/java-tool/blob/8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b/src/main/java/org/osgl/util/IO.java#L1739-L1752 |
138,537 | osglworks/java-tool | src/main/java/org/osgl/util/IO.java | IO.write | public static void write(CharSequence content, Writer writer, boolean closeOs) {
try {
writer.write(content.toString());
} catch (IOException e) {
throw E.ioException(e);
} finally {
if (closeOs) {
close(writer);
}
}
} | java | public static void write(CharSequence content, Writer writer, boolean closeOs) {
try {
writer.write(content.toString());
} catch (IOException e) {
throw E.ioException(e);
} finally {
if (closeOs) {
close(writer);
}
}
} | [
"public",
"static",
"void",
"write",
"(",
"CharSequence",
"content",
",",
"Writer",
"writer",
",",
"boolean",
"closeOs",
")",
"{",
"try",
"{",
"writer",
".",
"write",
"(",
"content",
".",
"toString",
"(",
")",
")",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"throw",
"E",
".",
"ioException",
"(",
"e",
")",
";",
"}",
"finally",
"{",
"if",
"(",
"closeOs",
")",
"{",
"close",
"(",
"writer",
")",
";",
"}",
"}",
"}"
] | Write content into a writer.
@param content
the content to be written to the writer
@param writer
to where the content be written | [
"Write",
"content",
"into",
"a",
"writer",
"."
] | 8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b | https://github.com/osglworks/java-tool/blob/8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b/src/main/java/org/osgl/util/IO.java#L1811-L1821 |
138,538 | osglworks/java-tool | src/main/java/org/osgl/util/IO.java | IO.copy | public static int copy(InputStream is, OutputStream os, boolean closeOs) {
if (closeOs) {
return write(is).ensureCloseSink().to(os);
} else {
return write(is).to(os);
}
} | java | public static int copy(InputStream is, OutputStream os, boolean closeOs) {
if (closeOs) {
return write(is).ensureCloseSink().to(os);
} else {
return write(is).to(os);
}
} | [
"public",
"static",
"int",
"copy",
"(",
"InputStream",
"is",
",",
"OutputStream",
"os",
",",
"boolean",
"closeOs",
")",
"{",
"if",
"(",
"closeOs",
")",
"{",
"return",
"write",
"(",
"is",
")",
".",
"ensureCloseSink",
"(",
")",
".",
"to",
"(",
"os",
")",
";",
"}",
"else",
"{",
"return",
"write",
"(",
"is",
")",
".",
"to",
"(",
"os",
")",
";",
"}",
"}"
] | Copy an stream to another one. It close the input stream anyway.
If the param closeOs is true then close the output stream.
@param is
input stream
@param os
output stream
@param closeOs
specify whether it shall close output stream after operation
@return number of bytes copied | [
"Copy",
"an",
"stream",
"to",
"another",
"one",
".",
"It",
"close",
"the",
"input",
"stream",
"anyway",
"."
] | 8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b | https://github.com/osglworks/java-tool/blob/8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b/src/main/java/org/osgl/util/IO.java#L1874-L1880 |
138,539 | osglworks/java-tool | src/main/java/org/osgl/util/IO.java | IO.write | public static int write(InputStream is, File f) {
try {
return copy(is, new BufferedOutputStream(new FileOutputStream(f)));
} catch (FileNotFoundException e) {
throw E.ioException(e);
}
} | java | public static int write(InputStream is, File f) {
try {
return copy(is, new BufferedOutputStream(new FileOutputStream(f)));
} catch (FileNotFoundException e) {
throw E.ioException(e);
}
} | [
"public",
"static",
"int",
"write",
"(",
"InputStream",
"is",
",",
"File",
"f",
")",
"{",
"try",
"{",
"return",
"copy",
"(",
"is",
",",
"new",
"BufferedOutputStream",
"(",
"new",
"FileOutputStream",
"(",
"f",
")",
")",
")",
";",
"}",
"catch",
"(",
"FileNotFoundException",
"e",
")",
"{",
"throw",
"E",
".",
"ioException",
"(",
"e",
")",
";",
"}",
"}"
] | Read from inputstream and write into file.
@param is
the inputstream
@param f
the file
@return
the number of bytes written to the file | [
"Read",
"from",
"inputstream",
"and",
"write",
"into",
"file",
"."
] | 8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b | https://github.com/osglworks/java-tool/blob/8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b/src/main/java/org/osgl/util/IO.java#L1898-L1904 |
138,540 | osglworks/java-tool | src/main/java/org/osgl/util/IO.java | IO.copy | public static int copy(Reader reader, Writer writer, boolean closeWriter) {
if (closeWriter) {
return write(reader).ensureCloseSink().to(writer);
} else {
return write(reader).to(writer);
}
} | java | public static int copy(Reader reader, Writer writer, boolean closeWriter) {
if (closeWriter) {
return write(reader).ensureCloseSink().to(writer);
} else {
return write(reader).to(writer);
}
} | [
"public",
"static",
"int",
"copy",
"(",
"Reader",
"reader",
",",
"Writer",
"writer",
",",
"boolean",
"closeWriter",
")",
"{",
"if",
"(",
"closeWriter",
")",
"{",
"return",
"write",
"(",
"reader",
")",
".",
"ensureCloseSink",
"(",
")",
".",
"to",
"(",
"writer",
")",
";",
"}",
"else",
"{",
"return",
"write",
"(",
"reader",
")",
".",
"to",
"(",
"writer",
")",
";",
"}",
"}"
] | Copy from a `Reader` into a `Writer`.
@param reader
A reader - the source
@param writer
a writer - the target
@param closeWriter
indicate if it shall close the writer after operation
@return the number of chars copied | [
"Copy",
"from",
"a",
"Reader",
"into",
"a",
"Writer",
"."
] | 8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b | https://github.com/osglworks/java-tool/blob/8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b/src/main/java/org/osgl/util/IO.java#L1932-L1938 |
138,541 | osglworks/java-tool | src/main/java/org/osgl/util/IO.java | IO.write | public static void write(byte b, OutputStream os) {
try {
os.write(b);
} catch (IOException e) {
throw E.ioException(e);
}
} | java | public static void write(byte b, OutputStream os) {
try {
os.write(b);
} catch (IOException e) {
throw E.ioException(e);
}
} | [
"public",
"static",
"void",
"write",
"(",
"byte",
"b",
",",
"OutputStream",
"os",
")",
"{",
"try",
"{",
"os",
".",
"write",
"(",
"b",
")",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"throw",
"E",
".",
"ioException",
"(",
"e",
")",
";",
"}",
"}"
] | Write a byte into outputstream.
The outputstream is not closed after written.
@param b
the byte to be written
@param os
the output stream into which the byte is written | [
"Write",
"a",
"byte",
"into",
"outputstream",
"."
] | 8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b | https://github.com/osglworks/java-tool/blob/8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b/src/main/java/org/osgl/util/IO.java#L1950-L1956 |
138,542 | osglworks/java-tool | src/main/java/org/osgl/util/IO.java | IO.write | public static void write(byte[] data, File file) {
try {
write(new ByteArrayInputStream(data), new BufferedOutputStream(new FileOutputStream(file)));
} catch (FileNotFoundException e) {
throw E.ioException(e);
}
} | java | public static void write(byte[] data, File file) {
try {
write(new ByteArrayInputStream(data), new BufferedOutputStream(new FileOutputStream(file)));
} catch (FileNotFoundException e) {
throw E.ioException(e);
}
} | [
"public",
"static",
"void",
"write",
"(",
"byte",
"[",
"]",
"data",
",",
"File",
"file",
")",
"{",
"try",
"{",
"write",
"(",
"new",
"ByteArrayInputStream",
"(",
"data",
")",
",",
"new",
"BufferedOutputStream",
"(",
"new",
"FileOutputStream",
"(",
"file",
")",
")",
")",
";",
"}",
"catch",
"(",
"FileNotFoundException",
"e",
")",
"{",
"throw",
"E",
".",
"ioException",
"(",
"e",
")",
";",
"}",
"}"
] | Write binary data to a file
@param data
The binary data to write
@param file
The file to write | [
"Write",
"binary",
"data",
"to",
"a",
"file"
] | 8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b | https://github.com/osglworks/java-tool/blob/8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b/src/main/java/org/osgl/util/IO.java#L1973-L1979 |
138,543 | osglworks/java-tool | src/main/java/org/osgl/util/IO.java | IO.write | public static void write(byte[] data, OutputStream os, boolean closeSink) {
try {
os.write(data);
} catch (IOException e) {
throw E.ioException(e);
} finally {
if (closeSink) {
close(os);
}
}
} | java | public static void write(byte[] data, OutputStream os, boolean closeSink) {
try {
os.write(data);
} catch (IOException e) {
throw E.ioException(e);
} finally {
if (closeSink) {
close(os);
}
}
} | [
"public",
"static",
"void",
"write",
"(",
"byte",
"[",
"]",
"data",
",",
"OutputStream",
"os",
",",
"boolean",
"closeSink",
")",
"{",
"try",
"{",
"os",
".",
"write",
"(",
"data",
")",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"throw",
"E",
".",
"ioException",
"(",
"e",
")",
";",
"}",
"finally",
"{",
"if",
"(",
"closeSink",
")",
"{",
"close",
"(",
"os",
")",
";",
"}",
"}",
"}"
] | Write binary data to an outputstream.
@param data
the binary data to write
@param os
the output stream
@param closeSink
if `true` then close the output stream once finished writing | [
"Write",
"binary",
"data",
"to",
"an",
"outputstream",
"."
] | 8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b | https://github.com/osglworks/java-tool/blob/8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b/src/main/java/org/osgl/util/IO.java#L2015-L2025 |
138,544 | osglworks/java-tool | src/main/java/org/osgl/util/IO.java | IO.copyDirectory | public static void copyDirectory(File source, File target) {
if (source.isDirectory()) {
if (!target.exists()) {
target.mkdir();
}
for (String child : source.list()) {
copyDirectory(new File(source, child), new File(target, child));
}
} else {
try {
write(new FileInputStream(source), new FileOutputStream(target));
} catch (IOException e) {
if (target.isDirectory()) {
if (!target.exists()) {
if (!target.mkdirs()) {
throw E.ioException("cannot copy [%s] to [%s]", source, target);
}
}
target = new File(target, source.getName());
} else {
File targetFolder = target.getParentFile();
if (!targetFolder.exists()) {
if (!targetFolder.mkdirs()) {
throw E.ioException("cannot copy [%s] to [%s]", source, target);
}
}
}
try {
write(new FileInputStream(source), new FileOutputStream(target));
} catch (IOException e0) {
throw E.ioException(e0);
}
}
}
} | java | public static void copyDirectory(File source, File target) {
if (source.isDirectory()) {
if (!target.exists()) {
target.mkdir();
}
for (String child : source.list()) {
copyDirectory(new File(source, child), new File(target, child));
}
} else {
try {
write(new FileInputStream(source), new FileOutputStream(target));
} catch (IOException e) {
if (target.isDirectory()) {
if (!target.exists()) {
if (!target.mkdirs()) {
throw E.ioException("cannot copy [%s] to [%s]", source, target);
}
}
target = new File(target, source.getName());
} else {
File targetFolder = target.getParentFile();
if (!targetFolder.exists()) {
if (!targetFolder.mkdirs()) {
throw E.ioException("cannot copy [%s] to [%s]", source, target);
}
}
}
try {
write(new FileInputStream(source), new FileOutputStream(target));
} catch (IOException e0) {
throw E.ioException(e0);
}
}
}
} | [
"public",
"static",
"void",
"copyDirectory",
"(",
"File",
"source",
",",
"File",
"target",
")",
"{",
"if",
"(",
"source",
".",
"isDirectory",
"(",
")",
")",
"{",
"if",
"(",
"!",
"target",
".",
"exists",
"(",
")",
")",
"{",
"target",
".",
"mkdir",
"(",
")",
";",
"}",
"for",
"(",
"String",
"child",
":",
"source",
".",
"list",
"(",
")",
")",
"{",
"copyDirectory",
"(",
"new",
"File",
"(",
"source",
",",
"child",
")",
",",
"new",
"File",
"(",
"target",
",",
"child",
")",
")",
";",
"}",
"}",
"else",
"{",
"try",
"{",
"write",
"(",
"new",
"FileInputStream",
"(",
"source",
")",
",",
"new",
"FileOutputStream",
"(",
"target",
")",
")",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"if",
"(",
"target",
".",
"isDirectory",
"(",
")",
")",
"{",
"if",
"(",
"!",
"target",
".",
"exists",
"(",
")",
")",
"{",
"if",
"(",
"!",
"target",
".",
"mkdirs",
"(",
")",
")",
"{",
"throw",
"E",
".",
"ioException",
"(",
"\"cannot copy [%s] to [%s]\"",
",",
"source",
",",
"target",
")",
";",
"}",
"}",
"target",
"=",
"new",
"File",
"(",
"target",
",",
"source",
".",
"getName",
"(",
")",
")",
";",
"}",
"else",
"{",
"File",
"targetFolder",
"=",
"target",
".",
"getParentFile",
"(",
")",
";",
"if",
"(",
"!",
"targetFolder",
".",
"exists",
"(",
")",
")",
"{",
"if",
"(",
"!",
"targetFolder",
".",
"mkdirs",
"(",
")",
")",
"{",
"throw",
"E",
".",
"ioException",
"(",
"\"cannot copy [%s] to [%s]\"",
",",
"source",
",",
"target",
")",
";",
"}",
"}",
"}",
"try",
"{",
"write",
"(",
"new",
"FileInputStream",
"(",
"source",
")",
",",
"new",
"FileOutputStream",
"(",
"target",
")",
")",
";",
"}",
"catch",
"(",
"IOException",
"e0",
")",
"{",
"throw",
"E",
".",
"ioException",
"(",
"e0",
")",
";",
"}",
"}",
"}",
"}"
] | If target does not exist, it will be created. | [
"If",
"target",
"does",
"not",
"exist",
"it",
"will",
"be",
"created",
"."
] | 8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b | https://github.com/osglworks/java-tool/blob/8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b/src/main/java/org/osgl/util/IO.java#L2043-L2077 |
138,545 | osglworks/java-tool | src/main/java/org/osgl/util/IO.java | IO.zip | public static ISObject zip(ISObject... objects) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ZipOutputStream zos = new ZipOutputStream(baos);
try {
for (ISObject obj : objects) {
ZipEntry entry = new ZipEntry(obj.getAttribute(SObject.ATTR_FILE_NAME));
InputStream is = obj.asInputStream();
zos.putNextEntry(entry);
copy(is, zos, false);
zos.closeEntry();
}
} catch (IOException e) {
throw E.ioException(e);
} finally {
close(zos);
}
return SObject.of(Codec.encodeUrl(S.random()), baos.toByteArray());
} | java | public static ISObject zip(ISObject... objects) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ZipOutputStream zos = new ZipOutputStream(baos);
try {
for (ISObject obj : objects) {
ZipEntry entry = new ZipEntry(obj.getAttribute(SObject.ATTR_FILE_NAME));
InputStream is = obj.asInputStream();
zos.putNextEntry(entry);
copy(is, zos, false);
zos.closeEntry();
}
} catch (IOException e) {
throw E.ioException(e);
} finally {
close(zos);
}
return SObject.of(Codec.encodeUrl(S.random()), baos.toByteArray());
} | [
"public",
"static",
"ISObject",
"zip",
"(",
"ISObject",
"...",
"objects",
")",
"{",
"ByteArrayOutputStream",
"baos",
"=",
"new",
"ByteArrayOutputStream",
"(",
")",
";",
"ZipOutputStream",
"zos",
"=",
"new",
"ZipOutputStream",
"(",
"baos",
")",
";",
"try",
"{",
"for",
"(",
"ISObject",
"obj",
":",
"objects",
")",
"{",
"ZipEntry",
"entry",
"=",
"new",
"ZipEntry",
"(",
"obj",
".",
"getAttribute",
"(",
"SObject",
".",
"ATTR_FILE_NAME",
")",
")",
";",
"InputStream",
"is",
"=",
"obj",
".",
"asInputStream",
"(",
")",
";",
"zos",
".",
"putNextEntry",
"(",
"entry",
")",
";",
"copy",
"(",
"is",
",",
"zos",
",",
"false",
")",
";",
"zos",
".",
"closeEntry",
"(",
")",
";",
"}",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"throw",
"E",
".",
"ioException",
"(",
"e",
")",
";",
"}",
"finally",
"{",
"close",
"(",
"zos",
")",
";",
"}",
"return",
"SObject",
".",
"of",
"(",
"Codec",
".",
"encodeUrl",
"(",
"S",
".",
"random",
"(",
")",
")",
",",
"baos",
".",
"toByteArray",
"(",
")",
")",
";",
"}"
] | Zip a list of sobject into a single sobject.
@param objects
the sobjects to be zipped.
@return an sobject that is a zip package of `objects`. | [
"Zip",
"a",
"list",
"of",
"sobject",
"into",
"a",
"single",
"sobject",
"."
] | 8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b | https://github.com/osglworks/java-tool/blob/8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b/src/main/java/org/osgl/util/IO.java#L2086-L2103 |
138,546 | osglworks/java-tool | src/main/java/org/osgl/util/IO.java | IO.zip | public static File zip(File... files) {
try {
File temp = File.createTempFile("osgl", ".zip");
zipInto(temp, files);
return temp;
} catch (IOException e) {
throw E.ioException(e);
}
} | java | public static File zip(File... files) {
try {
File temp = File.createTempFile("osgl", ".zip");
zipInto(temp, files);
return temp;
} catch (IOException e) {
throw E.ioException(e);
}
} | [
"public",
"static",
"File",
"zip",
"(",
"File",
"...",
"files",
")",
"{",
"try",
"{",
"File",
"temp",
"=",
"File",
".",
"createTempFile",
"(",
"\"osgl\"",
",",
"\".zip\"",
")",
";",
"zipInto",
"(",
"temp",
",",
"files",
")",
";",
"return",
"temp",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"throw",
"E",
".",
"ioException",
"(",
"e",
")",
";",
"}",
"}"
] | Zip a list of files into a single file. The name of the zip file
is randomly picked up in the temp dir.
@param files
the files to be zipped.
@return a file that is a zip package of the `files` | [
"Zip",
"a",
"list",
"of",
"files",
"into",
"a",
"single",
"file",
".",
"The",
"name",
"of",
"the",
"zip",
"file",
"is",
"randomly",
"picked",
"up",
"in",
"the",
"temp",
"dir",
"."
] | 8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b | https://github.com/osglworks/java-tool/blob/8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b/src/main/java/org/osgl/util/IO.java#L2113-L2121 |
138,547 | osglworks/java-tool | src/main/java/org/osgl/util/IO.java | IO.zipInto | public static void zipInto(File target, File... files) {
ZipOutputStream zos = null;
try {
zos = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(target)));
byte[] buffer = new byte[128];
for (File f : files) {
ZipEntry entry = new ZipEntry(f.getName());
InputStream is = new BufferedInputStream(new FileInputStream(f));
zos.putNextEntry(entry);
int read = 0;
while ((read = is.read(buffer)) != -1) {
zos.write(buffer, 0, read);
}
zos.closeEntry();
IO.close(is);
}
} catch (IOException e) {
throw E.ioException(e);
} finally {
IO.close(zos);
}
} | java | public static void zipInto(File target, File... files) {
ZipOutputStream zos = null;
try {
zos = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(target)));
byte[] buffer = new byte[128];
for (File f : files) {
ZipEntry entry = new ZipEntry(f.getName());
InputStream is = new BufferedInputStream(new FileInputStream(f));
zos.putNextEntry(entry);
int read = 0;
while ((read = is.read(buffer)) != -1) {
zos.write(buffer, 0, read);
}
zos.closeEntry();
IO.close(is);
}
} catch (IOException e) {
throw E.ioException(e);
} finally {
IO.close(zos);
}
} | [
"public",
"static",
"void",
"zipInto",
"(",
"File",
"target",
",",
"File",
"...",
"files",
")",
"{",
"ZipOutputStream",
"zos",
"=",
"null",
";",
"try",
"{",
"zos",
"=",
"new",
"ZipOutputStream",
"(",
"new",
"BufferedOutputStream",
"(",
"new",
"FileOutputStream",
"(",
"target",
")",
")",
")",
";",
"byte",
"[",
"]",
"buffer",
"=",
"new",
"byte",
"[",
"128",
"]",
";",
"for",
"(",
"File",
"f",
":",
"files",
")",
"{",
"ZipEntry",
"entry",
"=",
"new",
"ZipEntry",
"(",
"f",
".",
"getName",
"(",
")",
")",
";",
"InputStream",
"is",
"=",
"new",
"BufferedInputStream",
"(",
"new",
"FileInputStream",
"(",
"f",
")",
")",
";",
"zos",
".",
"putNextEntry",
"(",
"entry",
")",
";",
"int",
"read",
"=",
"0",
";",
"while",
"(",
"(",
"read",
"=",
"is",
".",
"read",
"(",
"buffer",
")",
")",
"!=",
"-",
"1",
")",
"{",
"zos",
".",
"write",
"(",
"buffer",
",",
"0",
",",
"read",
")",
";",
"}",
"zos",
".",
"closeEntry",
"(",
")",
";",
"IO",
".",
"close",
"(",
"is",
")",
";",
"}",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"throw",
"E",
".",
"ioException",
"(",
"e",
")",
";",
"}",
"finally",
"{",
"IO",
".",
"close",
"(",
"zos",
")",
";",
"}",
"}"
] | Zip a list of files into specified target file.
@param target
the target file as the zip package
@param files
the files to be zipped. | [
"Zip",
"a",
"list",
"of",
"files",
"into",
"specified",
"target",
"file",
"."
] | 8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b | https://github.com/osglworks/java-tool/blob/8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b/src/main/java/org/osgl/util/IO.java#L2131-L2152 |
138,548 | osglworks/java-tool | src/main/java/org/osgl/util/ValueObject.java | ValueObject.decode | public static <T> T decode(String string, Class<T> targetType) {
Type type = typeOf(targetType);
return type.decode(string, targetType);
} | java | public static <T> T decode(String string, Class<T> targetType) {
Type type = typeOf(targetType);
return type.decode(string, targetType);
} | [
"public",
"static",
"<",
"T",
">",
"T",
"decode",
"(",
"String",
"string",
",",
"Class",
"<",
"T",
">",
"targetType",
")",
"{",
"Type",
"type",
"=",
"typeOf",
"(",
"targetType",
")",
";",
"return",
"type",
".",
"decode",
"(",
"string",
",",
"targetType",
")",
";",
"}"
] | Decode a object instance from a string with given target object type
@param string the string encoded the value of the instance
@param targetType the class of the instance decoded from the string
@param <T> the generic type of the instance
@return the instance decoded | [
"Decode",
"a",
"object",
"instance",
"from",
"a",
"string",
"with",
"given",
"target",
"object",
"type"
] | 8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b | https://github.com/osglworks/java-tool/blob/8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b/src/main/java/org/osgl/util/ValueObject.java#L554-L557 |
138,549 | osglworks/java-tool | src/main/java/org/osgl/util/ValueObject.java | ValueObject.encode | public static String encode(Object o) {
Type type = typeOf(o);
return type.encode(o);
} | java | public static String encode(Object o) {
Type type = typeOf(o);
return type.encode(o);
} | [
"public",
"static",
"String",
"encode",
"(",
"Object",
"o",
")",
"{",
"Type",
"type",
"=",
"typeOf",
"(",
"o",
")",
";",
"return",
"type",
".",
"encode",
"(",
"o",
")",
";",
"}"
] | Encode a object into a String
@param o the object to be encoded
@return the encoded string representation of the object
@throws IllegalArgumentException when object is a UDF type and Codec is not registered | [
"Encode",
"a",
"object",
"into",
"a",
"String"
] | 8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b | https://github.com/osglworks/java-tool/blob/8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b/src/main/java/org/osgl/util/ValueObject.java#L566-L569 |
138,550 | osglworks/java-tool | src/main/java/org/osgl/util/StrBase.java | StrBase.lastIndexOf | public int lastIndexOf(java.util.List<Character> list) {
return lastIndexOf((CharSequence) FastStr.of(list));
} | java | public int lastIndexOf(java.util.List<Character> list) {
return lastIndexOf((CharSequence) FastStr.of(list));
} | [
"public",
"int",
"lastIndexOf",
"(",
"java",
".",
"util",
".",
"List",
"<",
"Character",
">",
"list",
")",
"{",
"return",
"lastIndexOf",
"(",
"(",
"CharSequence",
")",
"FastStr",
".",
"of",
"(",
"list",
")",
")",
";",
"}"
] | Returns the index within this str of the last occurrence of the
specified character list
@param list the list of chars to search for
@return the index of the last occurrence of the specified char list | [
"Returns",
"the",
"index",
"within",
"this",
"str",
"of",
"the",
"last",
"occurrence",
"of",
"the",
"specified",
"character",
"list"
] | 8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b | https://github.com/osglworks/java-tool/blob/8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b/src/main/java/org/osgl/util/StrBase.java#L595-L597 |
138,551 | osglworks/java-tool | src/main/java/org/osgl/OsglConfig.java | OsglConfig.addGlobalMappingFilters | public static void addGlobalMappingFilters(String filterSpec, String ... filterSpecs) {
addGlobalMappingFilter(filterSpec);
for (String s : filterSpecs) {
addGlobalMappingFilter(s);
}
} | java | public static void addGlobalMappingFilters(String filterSpec, String ... filterSpecs) {
addGlobalMappingFilter(filterSpec);
for (String s : filterSpecs) {
addGlobalMappingFilter(s);
}
} | [
"public",
"static",
"void",
"addGlobalMappingFilters",
"(",
"String",
"filterSpec",
",",
"String",
"...",
"filterSpecs",
")",
"{",
"addGlobalMappingFilter",
"(",
"filterSpec",
")",
";",
"for",
"(",
"String",
"s",
":",
"filterSpecs",
")",
"{",
"addGlobalMappingFilter",
"(",
"s",
")",
";",
"}",
"}"
] | Register global mapping filters.
@param filterSpec
the first filter spec
@param filterSpecs
other filter specs
@see #addGlobalMappingFilter(String) | [
"Register",
"global",
"mapping",
"filters",
"."
] | 8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b | https://github.com/osglworks/java-tool/blob/8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b/src/main/java/org/osgl/OsglConfig.java#L158-L163 |
138,552 | osglworks/java-tool | src/main/java/org/osgl/OsglConfig.java | OsglConfig.addGlobalMappingFilter | public static void addGlobalMappingFilter(String filterSpec) {
List<String> list = S.fastSplit(filterSpec, ",");
for (String s : list) {
if (S.blank(s)) {
continue;
}
addSingleGlobalMappingFilter(s.trim());
}
} | java | public static void addGlobalMappingFilter(String filterSpec) {
List<String> list = S.fastSplit(filterSpec, ",");
for (String s : list) {
if (S.blank(s)) {
continue;
}
addSingleGlobalMappingFilter(s.trim());
}
} | [
"public",
"static",
"void",
"addGlobalMappingFilter",
"(",
"String",
"filterSpec",
")",
"{",
"List",
"<",
"String",
">",
"list",
"=",
"S",
".",
"fastSplit",
"(",
"filterSpec",
",",
"\",\"",
")",
";",
"for",
"(",
"String",
"s",
":",
"list",
")",
"{",
"if",
"(",
"S",
".",
"blank",
"(",
"s",
")",
")",
"{",
"continue",
";",
"}",
"addSingleGlobalMappingFilter",
"(",
"s",
".",
"trim",
"(",
")",
")",
";",
"}",
"}"
] | Register a global mapping filter. Unlike normal mapping filter, global mapping filter spec
* checks only immediate level field name or map key
* it is always a black list filter
* it supports different matching verb:
- `contains:<payload>` - if test string contains `payload` then it shall be ignored
- `starts:<payload>` - if test string starts with `payload` then it shall be ignored
- `ends:<payload>` - if test string ends with `payload` then it shall be ignored
- `reg:<payload>` - if test string matches reg exp pattern `payload` then it shall be ignored
* if the filter spec dose not fall in the above category, then it is added into a set, and
if any test string exactly matches any item in that set, it shall be ignored.
@param filterSpec
the filter spec. It can contains multiple filter specs separated by `,` | [
"Register",
"a",
"global",
"mapping",
"filter",
".",
"Unlike",
"normal",
"mapping",
"filter",
"global",
"mapping",
"filter",
"spec"
] | 8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b | https://github.com/osglworks/java-tool/blob/8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b/src/main/java/org/osgl/OsglConfig.java#L194-L202 |
138,553 | osglworks/java-tool | src/main/java/org/osgl/util/FastStr.java | FastStr.of | public static FastStr of(char[] ca) {
if (ca.length == 0) return EMPTY_STR;
char[] newArray = new char[ca.length];
System.arraycopy(ca, 0, newArray, 0, ca.length);
return new FastStr(ca);
} | java | public static FastStr of(char[] ca) {
if (ca.length == 0) return EMPTY_STR;
char[] newArray = new char[ca.length];
System.arraycopy(ca, 0, newArray, 0, ca.length);
return new FastStr(ca);
} | [
"public",
"static",
"FastStr",
"of",
"(",
"char",
"[",
"]",
"ca",
")",
"{",
"if",
"(",
"ca",
".",
"length",
"==",
"0",
")",
"return",
"EMPTY_STR",
";",
"char",
"[",
"]",
"newArray",
"=",
"new",
"char",
"[",
"ca",
".",
"length",
"]",
";",
"System",
".",
"arraycopy",
"(",
"ca",
",",
"0",
",",
"newArray",
",",
"0",
",",
"ca",
".",
"length",
")",
";",
"return",
"new",
"FastStr",
"(",
"ca",
")",
";",
"}"
] | Construct a FastStr from a char array
@param ca the char array
@return a FastStr | [
"Construct",
"a",
"FastStr",
"from",
"a",
"char",
"array"
] | 8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b | https://github.com/osglworks/java-tool/blob/8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b/src/main/java/org/osgl/util/FastStr.java#L1542-L1547 |
138,554 | osglworks/java-tool | src/main/java/org/osgl/util/FastStr.java | FastStr.of | public static FastStr of(CharSequence cs) {
if (cs instanceof FastStr) {
return (FastStr)cs;
}
return of(cs.toString());
} | java | public static FastStr of(CharSequence cs) {
if (cs instanceof FastStr) {
return (FastStr)cs;
}
return of(cs.toString());
} | [
"public",
"static",
"FastStr",
"of",
"(",
"CharSequence",
"cs",
")",
"{",
"if",
"(",
"cs",
"instanceof",
"FastStr",
")",
"{",
"return",
"(",
"FastStr",
")",
"cs",
";",
"}",
"return",
"of",
"(",
"cs",
".",
"toString",
"(",
")",
")",
";",
"}"
] | Construct a FastStr from a CharSequence
@param cs the CharSequence instance
@return a FastStr | [
"Construct",
"a",
"FastStr",
"from",
"a",
"CharSequence"
] | 8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b | https://github.com/osglworks/java-tool/blob/8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b/src/main/java/org/osgl/util/FastStr.java#L1554-L1559 |
138,555 | osglworks/java-tool | src/main/java/org/osgl/util/FastStr.java | FastStr.of | public static FastStr of(String s) {
int sz = s.length();
if (sz == 0) return EMPTY_STR;
char[] buf = s.toCharArray();
return new FastStr(buf, 0, sz);
} | java | public static FastStr of(String s) {
int sz = s.length();
if (sz == 0) return EMPTY_STR;
char[] buf = s.toCharArray();
return new FastStr(buf, 0, sz);
} | [
"public",
"static",
"FastStr",
"of",
"(",
"String",
"s",
")",
"{",
"int",
"sz",
"=",
"s",
".",
"length",
"(",
")",
";",
"if",
"(",
"sz",
"==",
"0",
")",
"return",
"EMPTY_STR",
";",
"char",
"[",
"]",
"buf",
"=",
"s",
".",
"toCharArray",
"(",
")",
";",
"return",
"new",
"FastStr",
"(",
"buf",
",",
"0",
",",
"sz",
")",
";",
"}"
] | Construct a FastStr from a String
@param s the String
@return a FastStr | [
"Construct",
"a",
"FastStr",
"from",
"a",
"String"
] | 8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b | https://github.com/osglworks/java-tool/blob/8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b/src/main/java/org/osgl/util/FastStr.java#L1566-L1571 |
138,556 | osglworks/java-tool | src/main/java/org/osgl/util/FastStr.java | FastStr.of | public static FastStr of(StringBuilder sb) {
int sz = sb.length();
if (0 == sz) return EMPTY_STR;
char[] buf = new char[sz];
for (int i = 0; i < sz; ++i) {
buf[i] = sb.charAt(i);
}
return new FastStr(buf, 0, sz);
} | java | public static FastStr of(StringBuilder sb) {
int sz = sb.length();
if (0 == sz) return EMPTY_STR;
char[] buf = new char[sz];
for (int i = 0; i < sz; ++i) {
buf[i] = sb.charAt(i);
}
return new FastStr(buf, 0, sz);
} | [
"public",
"static",
"FastStr",
"of",
"(",
"StringBuilder",
"sb",
")",
"{",
"int",
"sz",
"=",
"sb",
".",
"length",
"(",
")",
";",
"if",
"(",
"0",
"==",
"sz",
")",
"return",
"EMPTY_STR",
";",
"char",
"[",
"]",
"buf",
"=",
"new",
"char",
"[",
"sz",
"]",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"sz",
";",
"++",
"i",
")",
"{",
"buf",
"[",
"i",
"]",
"=",
"sb",
".",
"charAt",
"(",
"i",
")",
";",
"}",
"return",
"new",
"FastStr",
"(",
"buf",
",",
"0",
",",
"sz",
")",
";",
"}"
] | Construct a FastStr from a StringBuilder
@param sb the string builder
@return a FastStr | [
"Construct",
"a",
"FastStr",
"from",
"a",
"StringBuilder"
] | 8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b | https://github.com/osglworks/java-tool/blob/8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b/src/main/java/org/osgl/util/FastStr.java#L1578-L1586 |
138,557 | osglworks/java-tool | src/main/java/org/osgl/util/FastStr.java | FastStr.of | public static FastStr of(Iterable<Character> itr) {
StringBuilder sb = new StringBuilder();
for (Character c : itr) {
sb.append(c);
}
return of(sb);
} | java | public static FastStr of(Iterable<Character> itr) {
StringBuilder sb = new StringBuilder();
for (Character c : itr) {
sb.append(c);
}
return of(sb);
} | [
"public",
"static",
"FastStr",
"of",
"(",
"Iterable",
"<",
"Character",
">",
"itr",
")",
"{",
"StringBuilder",
"sb",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"for",
"(",
"Character",
"c",
":",
"itr",
")",
"{",
"sb",
".",
"append",
"(",
"c",
")",
";",
"}",
"return",
"of",
"(",
"sb",
")",
";",
"}"
] | Construct a FastStr instance from an iterable of characters
@param itr the character iterable
@return the FastStr | [
"Construct",
"a",
"FastStr",
"instance",
"from",
"an",
"iterable",
"of",
"characters"
] | 8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b | https://github.com/osglworks/java-tool/blob/8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b/src/main/java/org/osgl/util/FastStr.java#L1608-L1614 |
138,558 | osglworks/java-tool | src/main/java/org/osgl/util/FastStr.java | FastStr.of | public static FastStr of(Collection<Character> col) {
int sz = col.size();
if (0 == sz) return EMPTY_STR;
char[] buf = new char[sz];
Iterator<Character> itr = col.iterator();
int i = 0;
while (itr.hasNext()) {
buf[i++] = itr.next();
}
return new FastStr(buf, 0, sz);
} | java | public static FastStr of(Collection<Character> col) {
int sz = col.size();
if (0 == sz) return EMPTY_STR;
char[] buf = new char[sz];
Iterator<Character> itr = col.iterator();
int i = 0;
while (itr.hasNext()) {
buf[i++] = itr.next();
}
return new FastStr(buf, 0, sz);
} | [
"public",
"static",
"FastStr",
"of",
"(",
"Collection",
"<",
"Character",
">",
"col",
")",
"{",
"int",
"sz",
"=",
"col",
".",
"size",
"(",
")",
";",
"if",
"(",
"0",
"==",
"sz",
")",
"return",
"EMPTY_STR",
";",
"char",
"[",
"]",
"buf",
"=",
"new",
"char",
"[",
"sz",
"]",
";",
"Iterator",
"<",
"Character",
">",
"itr",
"=",
"col",
".",
"iterator",
"(",
")",
";",
"int",
"i",
"=",
"0",
";",
"while",
"(",
"itr",
".",
"hasNext",
"(",
")",
")",
"{",
"buf",
"[",
"i",
"++",
"]",
"=",
"itr",
".",
"next",
"(",
")",
";",
"}",
"return",
"new",
"FastStr",
"(",
"buf",
",",
"0",
",",
"sz",
")",
";",
"}"
] | Construct a FastStr instance from a collection of characters
@param col the character collection
@return a FastStr instance | [
"Construct",
"a",
"FastStr",
"instance",
"from",
"a",
"collection",
"of",
"characters"
] | 8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b | https://github.com/osglworks/java-tool/blob/8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b/src/main/java/org/osgl/util/FastStr.java#L1621-L1631 |
138,559 | osglworks/java-tool | src/main/java/org/osgl/util/FastStr.java | FastStr.of | public static FastStr of(Iterator<Character> itr) {
StringBuilder sb = new StringBuilder();
while (itr.hasNext()) {
sb.append(itr.next());
}
return of(sb);
} | java | public static FastStr of(Iterator<Character> itr) {
StringBuilder sb = new StringBuilder();
while (itr.hasNext()) {
sb.append(itr.next());
}
return of(sb);
} | [
"public",
"static",
"FastStr",
"of",
"(",
"Iterator",
"<",
"Character",
">",
"itr",
")",
"{",
"StringBuilder",
"sb",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"while",
"(",
"itr",
".",
"hasNext",
"(",
")",
")",
"{",
"sb",
".",
"append",
"(",
"itr",
".",
"next",
"(",
")",
")",
";",
"}",
"return",
"of",
"(",
"sb",
")",
";",
"}"
] | Construct a FastStr instance from an iterator of characters
@param itr the character iterator
@return a FastStr instance consists of all chars in the iterator | [
"Construct",
"a",
"FastStr",
"instance",
"from",
"an",
"iterator",
"of",
"characters"
] | 8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b | https://github.com/osglworks/java-tool/blob/8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b/src/main/java/org/osgl/util/FastStr.java#L1638-L1644 |
138,560 | osglworks/java-tool | src/main/java/org/osgl/util/FastStr.java | FastStr.unsafeOf | public static FastStr unsafeOf(String s) {
int sz = s.length();
if (sz == 0) return EMPTY_STR;
char[] buf = bufOf(s);
return new FastStr(buf, 0, sz);
} | java | public static FastStr unsafeOf(String s) {
int sz = s.length();
if (sz == 0) return EMPTY_STR;
char[] buf = bufOf(s);
return new FastStr(buf, 0, sz);
} | [
"public",
"static",
"FastStr",
"unsafeOf",
"(",
"String",
"s",
")",
"{",
"int",
"sz",
"=",
"s",
".",
"length",
"(",
")",
";",
"if",
"(",
"sz",
"==",
"0",
")",
"return",
"EMPTY_STR",
";",
"char",
"[",
"]",
"buf",
"=",
"bufOf",
"(",
"s",
")",
";",
"return",
"new",
"FastStr",
"(",
"buf",
",",
"0",
",",
"sz",
")",
";",
"}"
] | Construct a FastStr instance from a String instance.
The FastStr instance will share the char array buf with
the String instance
@param s the string instance
@return A FastStr instance | [
"Construct",
"a",
"FastStr",
"instance",
"from",
"a",
"String",
"instance",
".",
"The",
"FastStr",
"instance",
"will",
"share",
"the",
"char",
"array",
"buf",
"with",
"the",
"String",
"instance"
] | 8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b | https://github.com/osglworks/java-tool/blob/8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b/src/main/java/org/osgl/util/FastStr.java#L1662-L1667 |
138,561 | osglworks/java-tool | src/main/java/org/osgl/util/FastStr.java | FastStr.unsafeOf | @SuppressWarnings("unused")
public static FastStr unsafeOf(char[] buf) {
E.NPE(buf);
return new FastStr(buf, 0, buf.length);
} | java | @SuppressWarnings("unused")
public static FastStr unsafeOf(char[] buf) {
E.NPE(buf);
return new FastStr(buf, 0, buf.length);
} | [
"@",
"SuppressWarnings",
"(",
"\"unused\"",
")",
"public",
"static",
"FastStr",
"unsafeOf",
"(",
"char",
"[",
"]",
"buf",
")",
"{",
"E",
".",
"NPE",
"(",
"buf",
")",
";",
"return",
"new",
"FastStr",
"(",
"buf",
",",
"0",
",",
"buf",
".",
"length",
")",
";",
"}"
] | Construct a FastStr instance from char array without array copying
@param buf the char array
@return a FastStr instance from the char array | [
"Construct",
"a",
"FastStr",
"instance",
"from",
"char",
"array",
"without",
"array",
"copying"
] | 8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b | https://github.com/osglworks/java-tool/blob/8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b/src/main/java/org/osgl/util/FastStr.java#L1674-L1678 |
138,562 | osglworks/java-tool | src/main/java/org/osgl/util/FastStr.java | FastStr.unsafeOf | public static FastStr unsafeOf(char[] buf, int start, int end) {
E.NPE(buf);
E.illegalArgumentIf(start < 0 || end > buf.length);
if (end < start) return EMPTY_STR;
return new FastStr(buf, start, end);
} | java | public static FastStr unsafeOf(char[] buf, int start, int end) {
E.NPE(buf);
E.illegalArgumentIf(start < 0 || end > buf.length);
if (end < start) return EMPTY_STR;
return new FastStr(buf, start, end);
} | [
"public",
"static",
"FastStr",
"unsafeOf",
"(",
"char",
"[",
"]",
"buf",
",",
"int",
"start",
",",
"int",
"end",
")",
"{",
"E",
".",
"NPE",
"(",
"buf",
")",
";",
"E",
".",
"illegalArgumentIf",
"(",
"start",
"<",
"0",
"||",
"end",
">",
"buf",
".",
"length",
")",
";",
"if",
"(",
"end",
"<",
"start",
")",
"return",
"EMPTY_STR",
";",
"return",
"new",
"FastStr",
"(",
"buf",
",",
"start",
",",
"end",
")",
";",
"}"
] | Construct a FastStr instance from char array, from the start position, finished at end position
without copying the array. This method might use the array directly instead of copying elements
from the array. Thus it is extremely important that the array buf passed in will NOT be updated
outside the FastStr instance.
@param buf the char array
@param start the start position (inclusive)
@param end the end position (exclusive)
@return a FastStr instance that consist of chars specified | [
"Construct",
"a",
"FastStr",
"instance",
"from",
"char",
"array",
"from",
"the",
"start",
"position",
"finished",
"at",
"end",
"position",
"without",
"copying",
"the",
"array",
".",
"This",
"method",
"might",
"use",
"the",
"array",
"directly",
"instead",
"of",
"copying",
"elements",
"from",
"the",
"array",
".",
"Thus",
"it",
"is",
"extremely",
"important",
"that",
"the",
"array",
"buf",
"passed",
"in",
"will",
"NOT",
"be",
"updated",
"outside",
"the",
"FastStr",
"instance",
"."
] | 8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b | https://github.com/osglworks/java-tool/blob/8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b/src/main/java/org/osgl/util/FastStr.java#L1690-L1695 |
138,563 | osglworks/java-tool | src/main/java/org/osgl/util/StringValueResolver.java | StringValueResolver.attributes | public StringValueResolver<T> attributes(Map<String, Object> attributes) {
this.attributes.putAll(attributes);
return this;
} | java | public StringValueResolver<T> attributes(Map<String, Object> attributes) {
this.attributes.putAll(attributes);
return this;
} | [
"public",
"StringValueResolver",
"<",
"T",
">",
"attributes",
"(",
"Map",
"<",
"String",
",",
"Object",
">",
"attributes",
")",
"{",
"this",
".",
"attributes",
".",
"putAll",
"(",
"attributes",
")",
";",
"return",
"this",
";",
"}"
] | Set attributes to this resolver
Note use this method only on new resolver instance instead of shared instance
@param attributes the attributes map
@return this resolver instance | [
"Set",
"attributes",
"to",
"this",
"resolver"
] | 8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b | https://github.com/osglworks/java-tool/blob/8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b/src/main/java/org/osgl/util/StringValueResolver.java#L102-L105 |
138,564 | osglworks/java-tool | src/main/java/org/osgl/storage/impl/SObject.java | SObject.of | public static SObject of(String key, File file) {
if (file.canRead() && file.isFile()) {
SObject sobj = new FileSObject(key, file);
String fileName = file.getName();
sobj.setAttribute(ATTR_FILE_NAME, file.getName());
String fileExtension = S.fileExtension(fileName);
MimeType mimeType = MimeType.findByFileExtension(fileExtension);
String type = null != mimeType ? mimeType.type() : null;
sobj.setAttribute(ATTR_CONTENT_TYPE, type);
sobj.setAttribute(ATTR_CONTENT_LENGTH, S.string(file.length()));
return sobj;
} else {
return getInvalidObject(key, new IOException("File is a directory or not readable"));
}
} | java | public static SObject of(String key, File file) {
if (file.canRead() && file.isFile()) {
SObject sobj = new FileSObject(key, file);
String fileName = file.getName();
sobj.setAttribute(ATTR_FILE_NAME, file.getName());
String fileExtension = S.fileExtension(fileName);
MimeType mimeType = MimeType.findByFileExtension(fileExtension);
String type = null != mimeType ? mimeType.type() : null;
sobj.setAttribute(ATTR_CONTENT_TYPE, type);
sobj.setAttribute(ATTR_CONTENT_LENGTH, S.string(file.length()));
return sobj;
} else {
return getInvalidObject(key, new IOException("File is a directory or not readable"));
}
} | [
"public",
"static",
"SObject",
"of",
"(",
"String",
"key",
",",
"File",
"file",
")",
"{",
"if",
"(",
"file",
".",
"canRead",
"(",
")",
"&&",
"file",
".",
"isFile",
"(",
")",
")",
"{",
"SObject",
"sobj",
"=",
"new",
"FileSObject",
"(",
"key",
",",
"file",
")",
";",
"String",
"fileName",
"=",
"file",
".",
"getName",
"(",
")",
";",
"sobj",
".",
"setAttribute",
"(",
"ATTR_FILE_NAME",
",",
"file",
".",
"getName",
"(",
")",
")",
";",
"String",
"fileExtension",
"=",
"S",
".",
"fileExtension",
"(",
"fileName",
")",
";",
"MimeType",
"mimeType",
"=",
"MimeType",
".",
"findByFileExtension",
"(",
"fileExtension",
")",
";",
"String",
"type",
"=",
"null",
"!=",
"mimeType",
"?",
"mimeType",
".",
"type",
"(",
")",
":",
"null",
";",
"sobj",
".",
"setAttribute",
"(",
"ATTR_CONTENT_TYPE",
",",
"type",
")",
";",
"sobj",
".",
"setAttribute",
"(",
"ATTR_CONTENT_LENGTH",
",",
"S",
".",
"string",
"(",
"file",
".",
"length",
"(",
")",
")",
")",
";",
"return",
"sobj",
";",
"}",
"else",
"{",
"return",
"getInvalidObject",
"(",
"key",
",",
"new",
"IOException",
"(",
"\"File is a directory or not readable\"",
")",
")",
";",
"}",
"}"
] | Construct an SObject with key and file specified
@see #of(String, File, Map) | [
"Construct",
"an",
"SObject",
"with",
"key",
"and",
"file",
"specified"
] | 8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b | https://github.com/osglworks/java-tool/blob/8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b/src/main/java/org/osgl/storage/impl/SObject.java#L205-L219 |
138,565 | osglworks/java-tool | src/main/java/org/osgl/storage/impl/SObject.java | SObject.loadResource | public static SObject loadResource(String url) {
InputStream is = SObject.class.getResourceAsStream(url);
if (null == is) {
return null;
}
String filename = S.afterLast(url, "/");
if (S.blank(filename)) {
filename = url;
}
return of(randomKey(), is, ATTR_FILE_NAME, filename);
} | java | public static SObject loadResource(String url) {
InputStream is = SObject.class.getResourceAsStream(url);
if (null == is) {
return null;
}
String filename = S.afterLast(url, "/");
if (S.blank(filename)) {
filename = url;
}
return of(randomKey(), is, ATTR_FILE_NAME, filename);
} | [
"public",
"static",
"SObject",
"loadResource",
"(",
"String",
"url",
")",
"{",
"InputStream",
"is",
"=",
"SObject",
".",
"class",
".",
"getResourceAsStream",
"(",
"url",
")",
";",
"if",
"(",
"null",
"==",
"is",
")",
"{",
"return",
"null",
";",
"}",
"String",
"filename",
"=",
"S",
".",
"afterLast",
"(",
"url",
",",
"\"/\"",
")",
";",
"if",
"(",
"S",
".",
"blank",
"(",
"filename",
")",
")",
"{",
"filename",
"=",
"url",
";",
"}",
"return",
"of",
"(",
"randomKey",
"(",
")",
",",
"is",
",",
"ATTR_FILE_NAME",
",",
"filename",
")",
";",
"}"
] | Load an sobject from classpath by given url path
This method will call {@link Class#getResource(String)} method to open
an inputstream to the resource and then construct an SObject with the
inputstream
@param url the resource url path
@return the sobject instance if loaded successfully or `null` if cannot load resource from the url | [
"Load",
"an",
"sobject",
"from",
"classpath",
"by",
"given",
"url",
"path"
] | 8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b | https://github.com/osglworks/java-tool/blob/8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b/src/main/java/org/osgl/storage/impl/SObject.java#L298-L308 |
138,566 | osglworks/java-tool | src/main/java/org/osgl/storage/impl/SObject.java | SObject.of | public static SObject of(String key, String content, String... attrs) {
SObject sobj = of(key, content);
Map<String, String> map = C.Map(attrs);
sobj.setAttributes(map);
return sobj;
} | java | public static SObject of(String key, String content, String... attrs) {
SObject sobj = of(key, content);
Map<String, String> map = C.Map(attrs);
sobj.setAttributes(map);
return sobj;
} | [
"public",
"static",
"SObject",
"of",
"(",
"String",
"key",
",",
"String",
"content",
",",
"String",
"...",
"attrs",
")",
"{",
"SObject",
"sobj",
"=",
"of",
"(",
"key",
",",
"content",
")",
";",
"Map",
"<",
"String",
",",
"String",
">",
"map",
"=",
"C",
".",
"Map",
"(",
"attrs",
")",
";",
"sobj",
".",
"setAttributes",
"(",
"map",
")",
";",
"return",
"sobj",
";",
"}"
] | Construct an sobject with key, content and attributes specified in sequence
key1, val1, key2, val2, ...
@see #of(String, String, Map) | [
"Construct",
"an",
"sobject",
"with",
"key",
"content",
"and",
"attributes",
"specified",
"in",
"sequence",
"key1",
"val1",
"key2",
"val2",
"..."
] | 8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b | https://github.com/osglworks/java-tool/blob/8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b/src/main/java/org/osgl/storage/impl/SObject.java#L455-L460 |
138,567 | osglworks/java-tool | src/main/java/org/osgl/storage/impl/SObject.java | SObject.of | public static SObject of(String key, byte[] buf, int len) {
if (len <= 0) {
return of(key, new byte[0]);
}
if (len >= buf.length) {
return of(key, buf);
}
byte[] ba = new byte[len];
System.arraycopy(buf, 0, ba, 0, len);
return of(key, ba);
} | java | public static SObject of(String key, byte[] buf, int len) {
if (len <= 0) {
return of(key, new byte[0]);
}
if (len >= buf.length) {
return of(key, buf);
}
byte[] ba = new byte[len];
System.arraycopy(buf, 0, ba, 0, len);
return of(key, ba);
} | [
"public",
"static",
"SObject",
"of",
"(",
"String",
"key",
",",
"byte",
"[",
"]",
"buf",
",",
"int",
"len",
")",
"{",
"if",
"(",
"len",
"<=",
"0",
")",
"{",
"return",
"of",
"(",
"key",
",",
"new",
"byte",
"[",
"0",
"]",
")",
";",
"}",
"if",
"(",
"len",
">=",
"buf",
".",
"length",
")",
"{",
"return",
"of",
"(",
"key",
",",
"buf",
")",
";",
"}",
"byte",
"[",
"]",
"ba",
"=",
"new",
"byte",
"[",
"len",
"]",
";",
"System",
".",
"arraycopy",
"(",
"buf",
",",
"0",
",",
"ba",
",",
"0",
",",
"len",
")",
";",
"return",
"of",
"(",
"key",
",",
"ba",
")",
";",
"}"
] | Construct an SObject with specified key, byte array and number of bytes
@param key the key
@param buf the source byte array
@param len the number of bytes in the array should be stored in the returing object
@return an SObject as described above | [
"Construct",
"an",
"SObject",
"with",
"specified",
"key",
"byte",
"array",
"and",
"number",
"of",
"bytes"
] | 8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b | https://github.com/osglworks/java-tool/blob/8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b/src/main/java/org/osgl/storage/impl/SObject.java#L510-L520 |
138,568 | osglworks/java-tool | src/main/java/org/osgl/util/MimeType.java | MimeType.typeOfSuffix | public static String typeOfSuffix(String fileExtension) {
MimeType mimeType = indexByFileExtension.get(fileExtension);
return null == mimeType ? fileExtension : mimeType.type;
} | java | public static String typeOfSuffix(String fileExtension) {
MimeType mimeType = indexByFileExtension.get(fileExtension);
return null == mimeType ? fileExtension : mimeType.type;
} | [
"public",
"static",
"String",
"typeOfSuffix",
"(",
"String",
"fileExtension",
")",
"{",
"MimeType",
"mimeType",
"=",
"indexByFileExtension",
".",
"get",
"(",
"fileExtension",
")",
";",
"return",
"null",
"==",
"mimeType",
"?",
"fileExtension",
":",
"mimeType",
".",
"type",
";",
"}"
] | Return a content type string corresponding to a given file extension suffix.
If there is no MimeType corresponding to the file extension, then returns the file
extension string directly.
@param fileExtension
file extension suffix
@return
A content type string corresponding to the file extension suffix
or the file extension suffix itself if no corresponding mimetype found. | [
"Return",
"a",
"content",
"type",
"string",
"corresponding",
"to",
"a",
"given",
"file",
"extension",
"suffix",
"."
] | 8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b | https://github.com/osglworks/java-tool/blob/8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b/src/main/java/org/osgl/util/MimeType.java#L112-L115 |
138,569 | osglworks/java-tool | src/main/java/org/osgl/util/BigLines.java | BigLines.preview | public List<String> preview(int limit, boolean noHeaderLine) {
E.illegalArgumentIf(limit < 1, "limit must be positive integer");
return fetch(noHeaderLine ? 1 : 0, limit);
} | java | public List<String> preview(int limit, boolean noHeaderLine) {
E.illegalArgumentIf(limit < 1, "limit must be positive integer");
return fetch(noHeaderLine ? 1 : 0, limit);
} | [
"public",
"List",
"<",
"String",
">",
"preview",
"(",
"int",
"limit",
",",
"boolean",
"noHeaderLine",
")",
"{",
"E",
".",
"illegalArgumentIf",
"(",
"limit",
"<",
"1",
",",
"\"limit must be positive integer\"",
")",
";",
"return",
"fetch",
"(",
"noHeaderLine",
"?",
"1",
":",
"0",
",",
"limit",
")",
";",
"}"
] | Returns first `limit` lines.
@param limit
the number of lines to be returned
@param noHeaderLine
if `false` then header line will be excluded in the return list
@return the first `limit` lines. | [
"Returns",
"first",
"limit",
"lines",
"."
] | 8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b | https://github.com/osglworks/java-tool/blob/8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b/src/main/java/org/osgl/util/BigLines.java#L112-L115 |
138,570 | osglworks/java-tool | src/main/java/org/osgl/util/BigLines.java | BigLines.fetch | public String fetch(int lineNumber) {
E.illegalArgumentIf(lineNumber < 0, "line number must not be negative number: " + lineNumber);
E.illegalArgumentIf(lineNumber >= lines(), "line number is out of range: " + lineNumber);
List<String> list = fetch(lineNumber, 1);
return list.isEmpty() ? null : list.get(0);
} | java | public String fetch(int lineNumber) {
E.illegalArgumentIf(lineNumber < 0, "line number must not be negative number: " + lineNumber);
E.illegalArgumentIf(lineNumber >= lines(), "line number is out of range: " + lineNumber);
List<String> list = fetch(lineNumber, 1);
return list.isEmpty() ? null : list.get(0);
} | [
"public",
"String",
"fetch",
"(",
"int",
"lineNumber",
")",
"{",
"E",
".",
"illegalArgumentIf",
"(",
"lineNumber",
"<",
"0",
",",
"\"line number must not be negative number: \"",
"+",
"lineNumber",
")",
";",
"E",
".",
"illegalArgumentIf",
"(",
"lineNumber",
">=",
"lines",
"(",
")",
",",
"\"line number is out of range: \"",
"+",
"lineNumber",
")",
";",
"List",
"<",
"String",
">",
"list",
"=",
"fetch",
"(",
"lineNumber",
",",
"1",
")",
";",
"return",
"list",
".",
"isEmpty",
"(",
")",
"?",
"null",
":",
"list",
".",
"get",
"(",
"0",
")",
";",
"}"
] | Returns the line specified by `lineNumber`.
Note the `lineNumber` starts with `0`.
@param lineNumber
specify the line to be returned.
@return the line as described above. | [
"Returns",
"the",
"line",
"specified",
"by",
"lineNumber",
"."
] | 8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b | https://github.com/osglworks/java-tool/blob/8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b/src/main/java/org/osgl/util/BigLines.java#L126-L131 |
138,571 | osglworks/java-tool | src/main/java/org/osgl/util/BigLines.java | BigLines.fetch | public List<String> fetch(int offset, int limit) {
E.illegalArgumentIf(offset < 0, "offset must not be negative number");
E.illegalArgumentIf(offset >= lines(), "offset is out of range: " + offset);
E.illegalArgumentIf(limit < 1, "limit must be at least 1");
BufferedReader reader = IO.buffered(IO.reader(file));
try {
for (int i = 0; i < offset; ++i) {
if (null == reader.readLine()) {
break;
}
}
} catch (IOException e) {
throw E.ioException(e);
}
List<String> lines = new ArrayList<>();
try {
for (int i = 0; i < limit; ++i) {
String line = reader.readLine();
if (null == line) {
break;
}
lines.add(line);
}
} catch (IOException e) {
throw E.ioException(e);
}
return lines;
} | java | public List<String> fetch(int offset, int limit) {
E.illegalArgumentIf(offset < 0, "offset must not be negative number");
E.illegalArgumentIf(offset >= lines(), "offset is out of range: " + offset);
E.illegalArgumentIf(limit < 1, "limit must be at least 1");
BufferedReader reader = IO.buffered(IO.reader(file));
try {
for (int i = 0; i < offset; ++i) {
if (null == reader.readLine()) {
break;
}
}
} catch (IOException e) {
throw E.ioException(e);
}
List<String> lines = new ArrayList<>();
try {
for (int i = 0; i < limit; ++i) {
String line = reader.readLine();
if (null == line) {
break;
}
lines.add(line);
}
} catch (IOException e) {
throw E.ioException(e);
}
return lines;
} | [
"public",
"List",
"<",
"String",
">",
"fetch",
"(",
"int",
"offset",
",",
"int",
"limit",
")",
"{",
"E",
".",
"illegalArgumentIf",
"(",
"offset",
"<",
"0",
",",
"\"offset must not be negative number\"",
")",
";",
"E",
".",
"illegalArgumentIf",
"(",
"offset",
">=",
"lines",
"(",
")",
",",
"\"offset is out of range: \"",
"+",
"offset",
")",
";",
"E",
".",
"illegalArgumentIf",
"(",
"limit",
"<",
"1",
",",
"\"limit must be at least 1\"",
")",
";",
"BufferedReader",
"reader",
"=",
"IO",
".",
"buffered",
"(",
"IO",
".",
"reader",
"(",
"file",
")",
")",
";",
"try",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"offset",
";",
"++",
"i",
")",
"{",
"if",
"(",
"null",
"==",
"reader",
".",
"readLine",
"(",
")",
")",
"{",
"break",
";",
"}",
"}",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"throw",
"E",
".",
"ioException",
"(",
"e",
")",
";",
"}",
"List",
"<",
"String",
">",
"lines",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"try",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"limit",
";",
"++",
"i",
")",
"{",
"String",
"line",
"=",
"reader",
".",
"readLine",
"(",
")",
";",
"if",
"(",
"null",
"==",
"line",
")",
"{",
"break",
";",
"}",
"lines",
".",
"add",
"(",
"line",
")",
";",
"}",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"throw",
"E",
".",
"ioException",
"(",
"e",
")",
";",
"}",
"return",
"lines",
";",
"}"
] | Returns a number of lines specified by start position `offset` and `limit`.
@param offset
the start line number (`0` based)
@param limit
the number of lines to be returned.
@return a number of lines as specified. | [
"Returns",
"a",
"number",
"of",
"lines",
"specified",
"by",
"start",
"position",
"offset",
"and",
"limit",
"."
] | 8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b | https://github.com/osglworks/java-tool/blob/8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b/src/main/java/org/osgl/util/BigLines.java#L142-L169 |
138,572 | osglworks/java-tool | src/main/java/org/osgl/util/Generics.java | Generics.buildTypeParamImplLookup | public static Map<String, Class> buildTypeParamImplLookup(Class theClass) {
Map<String, Class> lookup = new HashMap<>();
buildTypeParamImplLookup(theClass, lookup);
return lookup;
} | java | public static Map<String, Class> buildTypeParamImplLookup(Class theClass) {
Map<String, Class> lookup = new HashMap<>();
buildTypeParamImplLookup(theClass, lookup);
return lookup;
} | [
"public",
"static",
"Map",
"<",
"String",
",",
"Class",
">",
"buildTypeParamImplLookup",
"(",
"Class",
"theClass",
")",
"{",
"Map",
"<",
"String",
",",
"Class",
">",
"lookup",
"=",
"new",
"HashMap",
"<>",
"(",
")",
";",
"buildTypeParamImplLookup",
"(",
"theClass",
",",
"lookup",
")",
";",
"return",
"lookup",
";",
"}"
] | Build class type variable name and type variable implementation lookup
@param theClass the class to build the lookup
@return the lookup | [
"Build",
"class",
"type",
"variable",
"name",
"and",
"type",
"variable",
"implementation",
"lookup"
] | 8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b | https://github.com/osglworks/java-tool/blob/8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b/src/main/java/org/osgl/util/Generics.java#L118-L122 |
138,573 | osglworks/java-tool | src/main/java/org/osgl/util/Codec.java | Codec.encodeUrlSafeBase64 | public static String encodeUrlSafeBase64(String value) {
return new String(UrlSafeBase64.encode(value.getBytes(Charsets.UTF_8)));
} | java | public static String encodeUrlSafeBase64(String value) {
return new String(UrlSafeBase64.encode(value.getBytes(Charsets.UTF_8)));
} | [
"public",
"static",
"String",
"encodeUrlSafeBase64",
"(",
"String",
"value",
")",
"{",
"return",
"new",
"String",
"(",
"UrlSafeBase64",
".",
"encode",
"(",
"value",
".",
"getBytes",
"(",
"Charsets",
".",
"UTF_8",
")",
")",
")",
";",
"}"
] | Encode a String to base64 using variant URL safe encode scheme
@param value the plain string
@return the base64 encoded String that is URL safe | [
"Encode",
"a",
"String",
"to",
"base64",
"using",
"variant",
"URL",
"safe",
"encode",
"scheme"
] | 8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b | https://github.com/osglworks/java-tool/blob/8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b/src/main/java/org/osgl/util/Codec.java#L102-L104 |
138,574 | osglworks/java-tool | src/main/java/org/osgl/util/Codec.java | Codec.hexMD5 | public static String hexMD5(String value) {
try {
MessageDigest messageDigest = MessageDigest.getInstance("MD5");
messageDigest.reset();
messageDigest.update(value.getBytes("utf-8"));
byte[] digest = messageDigest.digest();
return byteToHexString(digest);
} catch (Exception ex) {
throw new UnexpectedException(ex);
}
} | java | public static String hexMD5(String value) {
try {
MessageDigest messageDigest = MessageDigest.getInstance("MD5");
messageDigest.reset();
messageDigest.update(value.getBytes("utf-8"));
byte[] digest = messageDigest.digest();
return byteToHexString(digest);
} catch (Exception ex) {
throw new UnexpectedException(ex);
}
} | [
"public",
"static",
"String",
"hexMD5",
"(",
"String",
"value",
")",
"{",
"try",
"{",
"MessageDigest",
"messageDigest",
"=",
"MessageDigest",
".",
"getInstance",
"(",
"\"MD5\"",
")",
";",
"messageDigest",
".",
"reset",
"(",
")",
";",
"messageDigest",
".",
"update",
"(",
"value",
".",
"getBytes",
"(",
"\"utf-8\"",
")",
")",
";",
"byte",
"[",
"]",
"digest",
"=",
"messageDigest",
".",
"digest",
"(",
")",
";",
"return",
"byteToHexString",
"(",
"digest",
")",
";",
"}",
"catch",
"(",
"Exception",
"ex",
")",
"{",
"throw",
"new",
"UnexpectedException",
"(",
"ex",
")",
";",
"}",
"}"
] | Build an hexadecimal MD5 hash for a String
@param value The String to hash
@return An hexadecimal Hash | [
"Build",
"an",
"hexadecimal",
"MD5",
"hash",
"for",
"a",
"String"
] | 8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b | https://github.com/osglworks/java-tool/blob/8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b/src/main/java/org/osgl/util/Codec.java#L176-L186 |
138,575 | osglworks/java-tool | src/main/java/org/osgl/util/Codec.java | Codec.hexSHA1 | public static String hexSHA1(String value) {
try {
MessageDigest md;
md = MessageDigest.getInstance("SHA-1");
md.update(value.getBytes("utf-8"));
byte[] digest = md.digest();
return byteToHexString(digest);
} catch (Exception ex) {
throw new UnexpectedException(ex);
}
} | java | public static String hexSHA1(String value) {
try {
MessageDigest md;
md = MessageDigest.getInstance("SHA-1");
md.update(value.getBytes("utf-8"));
byte[] digest = md.digest();
return byteToHexString(digest);
} catch (Exception ex) {
throw new UnexpectedException(ex);
}
} | [
"public",
"static",
"String",
"hexSHA1",
"(",
"String",
"value",
")",
"{",
"try",
"{",
"MessageDigest",
"md",
";",
"md",
"=",
"MessageDigest",
".",
"getInstance",
"(",
"\"SHA-1\"",
")",
";",
"md",
".",
"update",
"(",
"value",
".",
"getBytes",
"(",
"\"utf-8\"",
")",
")",
";",
"byte",
"[",
"]",
"digest",
"=",
"md",
".",
"digest",
"(",
")",
";",
"return",
"byteToHexString",
"(",
"digest",
")",
";",
"}",
"catch",
"(",
"Exception",
"ex",
")",
"{",
"throw",
"new",
"UnexpectedException",
"(",
"ex",
")",
";",
"}",
"}"
] | Build an hexadecimal SHA1 hash for a String
@param value The String to hash
@return An hexadecimal Hash | [
"Build",
"an",
"hexadecimal",
"SHA1",
"hash",
"for",
"a",
"String"
] | 8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b | https://github.com/osglworks/java-tool/blob/8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b/src/main/java/org/osgl/util/Codec.java#L194-L204 |
138,576 | osglworks/java-tool | src/main/java/org/osgl/util/E.java | E.NPE | public static void NPE(Object o1, Object o2, Object o3, Object... objects) {
NPE(o1, o2, o3);
for (Object o : objects) {
if (null == o) {
throw new NullPointerException();
}
}
} | java | public static void NPE(Object o1, Object o2, Object o3, Object... objects) {
NPE(o1, o2, o3);
for (Object o : objects) {
if (null == o) {
throw new NullPointerException();
}
}
} | [
"public",
"static",
"void",
"NPE",
"(",
"Object",
"o1",
",",
"Object",
"o2",
",",
"Object",
"o3",
",",
"Object",
"...",
"objects",
")",
"{",
"NPE",
"(",
"o1",
",",
"o2",
",",
"o3",
")",
";",
"for",
"(",
"Object",
"o",
":",
"objects",
")",
"{",
"if",
"(",
"null",
"==",
"o",
")",
"{",
"throw",
"new",
"NullPointerException",
"(",
")",
";",
"}",
"}",
"}"
] | Throw out NullPointerException if any one of the passed objects is null.
@param o1
the first object to be evaluated
@param o2
the second object to be evaluated
@param o3
the third object to be evaluated
@param objects
other object instances to be evaluated | [
"Throw",
"out",
"NullPointerException",
"if",
"any",
"one",
"of",
"the",
"passed",
"objects",
"is",
"null",
"."
] | 8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b | https://github.com/osglworks/java-tool/blob/8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b/src/main/java/org/osgl/util/E.java#L150-L157 |
138,577 | osglworks/java-tool | src/main/java/org/osgl/util/E.java | E.asRuntimeException | public static RuntimeException asRuntimeException(Exception e) {
if (e instanceof RuntimeException) {
return (RuntimeException) e;
}
return UnexpectedMethodInvocationException.triage(e);
} | java | public static RuntimeException asRuntimeException(Exception e) {
if (e instanceof RuntimeException) {
return (RuntimeException) e;
}
return UnexpectedMethodInvocationException.triage(e);
} | [
"public",
"static",
"RuntimeException",
"asRuntimeException",
"(",
"Exception",
"e",
")",
"{",
"if",
"(",
"e",
"instanceof",
"RuntimeException",
")",
"{",
"return",
"(",
"RuntimeException",
")",
"e",
";",
"}",
"return",
"UnexpectedMethodInvocationException",
".",
"triage",
"(",
"e",
")",
";",
"}"
] | Convert an Exception to RuntimeException
@param e the Exception instance
@return a RuntimeException instance | [
"Convert",
"an",
"Exception",
"to",
"RuntimeException"
] | 8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b | https://github.com/osglworks/java-tool/blob/8b6eee2bccb067eb32e6a7bc4a4dfef7a7d9008b/src/main/java/org/osgl/util/E.java#L811-L816 |
138,578 | jillesvangurp/jsonj | src/main/java/com/github/jsonj/tools/JsonParser.java | JsonParser.parseJsonLines | public Stream<JsonObject> parseJsonLines(Reader r) {
return StreamSupport.stream(Spliterators.spliteratorUnknownSize(jsonLinesIterator(r), Spliterator.ORDERED), false);
} | java | public Stream<JsonObject> parseJsonLines(Reader r) {
return StreamSupport.stream(Spliterators.spliteratorUnknownSize(jsonLinesIterator(r), Spliterator.ORDERED), false);
} | [
"public",
"Stream",
"<",
"JsonObject",
">",
"parseJsonLines",
"(",
"Reader",
"r",
")",
"{",
"return",
"StreamSupport",
".",
"stream",
"(",
"Spliterators",
".",
"spliteratorUnknownSize",
"(",
"jsonLinesIterator",
"(",
"r",
")",
",",
"Spliterator",
".",
"ORDERED",
")",
",",
"false",
")",
";",
"}"
] | Use this to parse jsonlines.org style input. IMPORTANT, you have to close the reader yourself with a try ... finally.
@param r a reader
@return a Stream of the parsed jsonObjects. | [
"Use",
"this",
"to",
"parse",
"jsonlines",
".",
"org",
"style",
"input",
".",
"IMPORTANT",
"you",
"have",
"to",
"close",
"the",
"reader",
"yourself",
"with",
"a",
"try",
"...",
"finally",
"."
] | 1da0c44c5bdb60c0cd806c48d2da5a8a75bf84af | https://github.com/jillesvangurp/jsonj/blob/1da0c44c5bdb60c0cd806c48d2da5a8a75bf84af/src/main/java/com/github/jsonj/tools/JsonParser.java#L216-L218 |
138,579 | jillesvangurp/jsonj | src/main/java/com/github/jsonj/tools/JsonXmlConverter.java | JsonXmlConverter.getW3cDocument | public static org.w3c.dom.Document getW3cDocument(JsonElement value, String rootName) {
Element root = getElement(value, rootName);
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
DOMImplementation impl = builder.getDOMImplementation();
return DOMConverter.convert(new Document(root), impl);
} catch (ParserConfigurationException e) {
throw new IllegalStateException(e);
}
} | java | public static org.w3c.dom.Document getW3cDocument(JsonElement value, String rootName) {
Element root = getElement(value, rootName);
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
DOMImplementation impl = builder.getDOMImplementation();
return DOMConverter.convert(new Document(root), impl);
} catch (ParserConfigurationException e) {
throw new IllegalStateException(e);
}
} | [
"public",
"static",
"org",
".",
"w3c",
".",
"dom",
".",
"Document",
"getW3cDocument",
"(",
"JsonElement",
"value",
",",
"String",
"rootName",
")",
"{",
"Element",
"root",
"=",
"getElement",
"(",
"value",
",",
"rootName",
")",
";",
"try",
"{",
"DocumentBuilderFactory",
"factory",
"=",
"DocumentBuilderFactory",
".",
"newInstance",
"(",
")",
";",
"factory",
".",
"setNamespaceAware",
"(",
"true",
")",
";",
"DocumentBuilder",
"builder",
"=",
"factory",
".",
"newDocumentBuilder",
"(",
")",
";",
"DOMImplementation",
"impl",
"=",
"builder",
".",
"getDOMImplementation",
"(",
")",
";",
"return",
"DOMConverter",
".",
"convert",
"(",
"new",
"Document",
"(",
"root",
")",
",",
"impl",
")",
";",
"}",
"catch",
"(",
"ParserConfigurationException",
"e",
")",
"{",
"throw",
"new",
"IllegalStateException",
"(",
"e",
")",
";",
"}",
"}"
] | Convert any JsonElement into an w3c DOM tree.
@param value
a json element
@param rootName
the root name of the xml
@return a Document | [
"Convert",
"any",
"JsonElement",
"into",
"an",
"w3c",
"DOM",
"tree",
"."
] | 1da0c44c5bdb60c0cd806c48d2da5a8a75bf84af | https://github.com/jillesvangurp/jsonj/blob/1da0c44c5bdb60c0cd806c48d2da5a8a75bf84af/src/main/java/com/github/jsonj/tools/JsonXmlConverter.java#L120-L132 |
138,580 | jillesvangurp/jsonj | src/main/java/com/github/jsonj/tools/JsonBuilder.java | JsonBuilder.put | public @Nonnull JsonBuilder put(String key, String s) {
object.put(key, primitive(s));
return this;
} | java | public @Nonnull JsonBuilder put(String key, String s) {
object.put(key, primitive(s));
return this;
} | [
"public",
"@",
"Nonnull",
"JsonBuilder",
"put",
"(",
"String",
"key",
",",
"String",
"s",
")",
"{",
"object",
".",
"put",
"(",
"key",
",",
"primitive",
"(",
"s",
")",
")",
";",
"return",
"this",
";",
"}"
] | Add a string value to the object.
@param key key
@param s value
@return the builder | [
"Add",
"a",
"string",
"value",
"to",
"the",
"object",
"."
] | 1da0c44c5bdb60c0cd806c48d2da5a8a75bf84af | https://github.com/jillesvangurp/jsonj/blob/1da0c44c5bdb60c0cd806c48d2da5a8a75bf84af/src/main/java/com/github/jsonj/tools/JsonBuilder.java#L88-L91 |
138,581 | jillesvangurp/jsonj | src/main/java/com/github/jsonj/tools/JsonBuilder.java | JsonBuilder.put | public @Nonnull JsonBuilder put(String key, boolean b) {
object.put(key, primitive(b));
return this;
} | java | public @Nonnull JsonBuilder put(String key, boolean b) {
object.put(key, primitive(b));
return this;
} | [
"public",
"@",
"Nonnull",
"JsonBuilder",
"put",
"(",
"String",
"key",
",",
"boolean",
"b",
")",
"{",
"object",
".",
"put",
"(",
"key",
",",
"primitive",
"(",
"b",
")",
")",
";",
"return",
"this",
";",
"}"
] | Add a boolean value to the object.
@param key key
@param b value
@return the builder | [
"Add",
"a",
"boolean",
"value",
"to",
"the",
"object",
"."
] | 1da0c44c5bdb60c0cd806c48d2da5a8a75bf84af | https://github.com/jillesvangurp/jsonj/blob/1da0c44c5bdb60c0cd806c48d2da5a8a75bf84af/src/main/java/com/github/jsonj/tools/JsonBuilder.java#L100-L103 |
138,582 | jillesvangurp/jsonj | src/main/java/com/github/jsonj/tools/JsonBuilder.java | JsonBuilder.put | public @Nonnull JsonBuilder put(String key, Number n) {
object.put(key, primitive(n));
return this;
} | java | public @Nonnull JsonBuilder put(String key, Number n) {
object.put(key, primitive(n));
return this;
} | [
"public",
"@",
"Nonnull",
"JsonBuilder",
"put",
"(",
"String",
"key",
",",
"Number",
"n",
")",
"{",
"object",
".",
"put",
"(",
"key",
",",
"primitive",
"(",
"n",
")",
")",
";",
"return",
"this",
";",
"}"
] | Add a number to the object.
@param key key
@param n value
@return the builder | [
"Add",
"a",
"number",
"to",
"the",
"object",
"."
] | 1da0c44c5bdb60c0cd806c48d2da5a8a75bf84af | https://github.com/jillesvangurp/jsonj/blob/1da0c44c5bdb60c0cd806c48d2da5a8a75bf84af/src/main/java/com/github/jsonj/tools/JsonBuilder.java#L112-L115 |
138,583 | jillesvangurp/jsonj | src/main/java/com/github/jsonj/tools/JsonBuilder.java | JsonBuilder.putArray | public @Nonnull JsonBuilder putArray(String key, String... values) {
JsonArray jjArray = new JsonArray();
for (String string : values) {
jjArray.add(primitive(string));
}
object.put(key, jjArray);
return this;
} | java | public @Nonnull JsonBuilder putArray(String key, String... values) {
JsonArray jjArray = new JsonArray();
for (String string : values) {
jjArray.add(primitive(string));
}
object.put(key, jjArray);
return this;
} | [
"public",
"@",
"Nonnull",
"JsonBuilder",
"putArray",
"(",
"String",
"key",
",",
"String",
"...",
"values",
")",
"{",
"JsonArray",
"jjArray",
"=",
"new",
"JsonArray",
"(",
")",
";",
"for",
"(",
"String",
"string",
":",
"values",
")",
"{",
"jjArray",
".",
"add",
"(",
"primitive",
"(",
"string",
")",
")",
";",
"}",
"object",
".",
"put",
"(",
"key",
",",
"jjArray",
")",
";",
"return",
"this",
";",
"}"
] | Add a JsonArray to the object with the string values added.
@param key key
@param values one or more {@link String} values
values that go in the array
@return the builder | [
"Add",
"a",
"JsonArray",
"to",
"the",
"object",
"with",
"the",
"string",
"values",
"added",
"."
] | 1da0c44c5bdb60c0cd806c48d2da5a8a75bf84af | https://github.com/jillesvangurp/jsonj/blob/1da0c44c5bdb60c0cd806c48d2da5a8a75bf84af/src/main/java/com/github/jsonj/tools/JsonBuilder.java#L125-L132 |
138,584 | jillesvangurp/jsonj | src/main/java/com/github/jsonj/tools/JsonBuilder.java | JsonBuilder.field | public static @Nonnull Entry<String,JsonElement> field(String key, JsonElement value) {
Entry<String, JsonElement> entry = new Entry<String,JsonElement>() {
@Override
public String getKey() {
return key;
}
@Override
public JsonElement getValue() {
return value;
}
@Override
public JsonElement setValue(JsonElement value) {
throw new UnsupportedOperationException("entries are immutable");
}};
return entry;
} | java | public static @Nonnull Entry<String,JsonElement> field(String key, JsonElement value) {
Entry<String, JsonElement> entry = new Entry<String,JsonElement>() {
@Override
public String getKey() {
return key;
}
@Override
public JsonElement getValue() {
return value;
}
@Override
public JsonElement setValue(JsonElement value) {
throw new UnsupportedOperationException("entries are immutable");
}};
return entry;
} | [
"public",
"static",
"@",
"Nonnull",
"Entry",
"<",
"String",
",",
"JsonElement",
">",
"field",
"(",
"String",
"key",
",",
"JsonElement",
"value",
")",
"{",
"Entry",
"<",
"String",
",",
"JsonElement",
">",
"entry",
"=",
"new",
"Entry",
"<",
"String",
",",
"JsonElement",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"String",
"getKey",
"(",
")",
"{",
"return",
"key",
";",
"}",
"@",
"Override",
"public",
"JsonElement",
"getValue",
"(",
")",
"{",
"return",
"value",
";",
"}",
"@",
"Override",
"public",
"JsonElement",
"setValue",
"(",
"JsonElement",
"value",
")",
"{",
"throw",
"new",
"UnsupportedOperationException",
"(",
"\"entries are immutable\"",
")",
";",
"}",
"}",
";",
"return",
"entry",
";",
"}"
] | Create a new field that can be added to a JsonObject.
@param key key
@param value value
@return field entry implementation that can be added to a JsonObject | [
"Create",
"a",
"new",
"field",
"that",
"can",
"be",
"added",
"to",
"a",
"JsonObject",
"."
] | 1da0c44c5bdb60c0cd806c48d2da5a8a75bf84af | https://github.com/jillesvangurp/jsonj/blob/1da0c44c5bdb60c0cd806c48d2da5a8a75bf84af/src/main/java/com/github/jsonj/tools/JsonBuilder.java#L186-L204 |
138,585 | jillesvangurp/jsonj | src/main/java/com/github/jsonj/tools/JsonBuilder.java | JsonBuilder.field | public static @Nonnull Entry<String,JsonElement> field(String key, Object value) {
return field(key, fromObject(value));
} | java | public static @Nonnull Entry<String,JsonElement> field(String key, Object value) {
return field(key, fromObject(value));
} | [
"public",
"static",
"@",
"Nonnull",
"Entry",
"<",
"String",
",",
"JsonElement",
">",
"field",
"(",
"String",
"key",
",",
"Object",
"value",
")",
"{",
"return",
"field",
"(",
"key",
",",
"fromObject",
"(",
"value",
")",
")",
";",
"}"
] | Create a new field with the key and the result of fromObject on the value.
@param key key
@param value value
@return field entry implementation that can be added to a JsonObject | [
"Create",
"a",
"new",
"field",
"with",
"the",
"key",
"and",
"the",
"result",
"of",
"fromObject",
"on",
"the",
"value",
"."
] | 1da0c44c5bdb60c0cd806c48d2da5a8a75bf84af | https://github.com/jillesvangurp/jsonj/blob/1da0c44c5bdb60c0cd806c48d2da5a8a75bf84af/src/main/java/com/github/jsonj/tools/JsonBuilder.java#L212-L214 |
138,586 | jillesvangurp/jsonj | src/main/java/com/github/jsonj/JsonArray.java | JsonArray.get | public JsonElement get(String label) {
int i = 0;
try{
for (JsonElement e : this) {
if(e.isPrimitive() && e.asPrimitive().asString().equals(label)) {
return e;
} else if((e.isObject() || e.isArray()) && Integer.valueOf(label).equals(i)) {
return e;
}
i++;
}
} catch(NumberFormatException e) {
// fail gracefully
return null;
}
// the element was not found
return null;
} | java | public JsonElement get(String label) {
int i = 0;
try{
for (JsonElement e : this) {
if(e.isPrimitive() && e.asPrimitive().asString().equals(label)) {
return e;
} else if((e.isObject() || e.isArray()) && Integer.valueOf(label).equals(i)) {
return e;
}
i++;
}
} catch(NumberFormatException e) {
// fail gracefully
return null;
}
// the element was not found
return null;
} | [
"public",
"JsonElement",
"get",
"(",
"String",
"label",
")",
"{",
"int",
"i",
"=",
"0",
";",
"try",
"{",
"for",
"(",
"JsonElement",
"e",
":",
"this",
")",
"{",
"if",
"(",
"e",
".",
"isPrimitive",
"(",
")",
"&&",
"e",
".",
"asPrimitive",
"(",
")",
".",
"asString",
"(",
")",
".",
"equals",
"(",
"label",
")",
")",
"{",
"return",
"e",
";",
"}",
"else",
"if",
"(",
"(",
"e",
".",
"isObject",
"(",
")",
"||",
"e",
".",
"isArray",
"(",
")",
")",
"&&",
"Integer",
".",
"valueOf",
"(",
"label",
")",
".",
"equals",
"(",
"i",
")",
")",
"{",
"return",
"e",
";",
"}",
"i",
"++",
";",
"}",
"}",
"catch",
"(",
"NumberFormatException",
"e",
")",
"{",
"// fail gracefully",
"return",
"null",
";",
"}",
"// the element was not found",
"return",
"null",
";",
"}"
] | Convenient method providing a few alternate ways of extracting elements
from a JsonArray.
@param label label
@return the first element in the array matching the label or the n-th
element if the label is an integer and the element an object or
an array. | [
"Convenient",
"method",
"providing",
"a",
"few",
"alternate",
"ways",
"of",
"extracting",
"elements",
"from",
"a",
"JsonArray",
"."
] | 1da0c44c5bdb60c0cd806c48d2da5a8a75bf84af | https://github.com/jillesvangurp/jsonj/blob/1da0c44c5bdb60c0cd806c48d2da5a8a75bf84af/src/main/java/com/github/jsonj/JsonArray.java#L236-L253 |
138,587 | jillesvangurp/jsonj | src/main/java/com/github/jsonj/JsonArray.java | JsonArray.replace | public boolean replace(JsonElement e1, JsonElement e2) {
int index = indexOf(e1);
if(index>=0) {
set(index, e2);
return true;
} else {
return false;
}
} | java | public boolean replace(JsonElement e1, JsonElement e2) {
int index = indexOf(e1);
if(index>=0) {
set(index, e2);
return true;
} else {
return false;
}
} | [
"public",
"boolean",
"replace",
"(",
"JsonElement",
"e1",
",",
"JsonElement",
"e2",
")",
"{",
"int",
"index",
"=",
"indexOf",
"(",
"e1",
")",
";",
"if",
"(",
"index",
">=",
"0",
")",
"{",
"set",
"(",
"index",
",",
"e2",
")",
";",
"return",
"true",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] | Replaces the first matching element.
@param e1 original
@param e2 replacement
@return true if the element was replaced. | [
"Replaces",
"the",
"first",
"matching",
"element",
"."
] | 1da0c44c5bdb60c0cd806c48d2da5a8a75bf84af | https://github.com/jillesvangurp/jsonj/blob/1da0c44c5bdb60c0cd806c48d2da5a8a75bf84af/src/main/java/com/github/jsonj/JsonArray.java#L573-L581 |
138,588 | jillesvangurp/jsonj | src/main/java/com/github/jsonj/JsonArray.java | JsonArray.replace | public boolean replace(Object e1, Object e2) {
return replace(fromObject(e1),fromObject(e2));
} | java | public boolean replace(Object e1, Object e2) {
return replace(fromObject(e1),fromObject(e2));
} | [
"public",
"boolean",
"replace",
"(",
"Object",
"e1",
",",
"Object",
"e2",
")",
"{",
"return",
"replace",
"(",
"fromObject",
"(",
"e1",
")",
",",
"fromObject",
"(",
"e2",
")",
")",
";",
"}"
] | Replaces the element.
@param e1 original
@param e2 replacement
@return true if element was replaced | [
"Replaces",
"the",
"element",
"."
] | 1da0c44c5bdb60c0cd806c48d2da5a8a75bf84af | https://github.com/jillesvangurp/jsonj/blob/1da0c44c5bdb60c0cd806c48d2da5a8a75bf84af/src/main/java/com/github/jsonj/JsonArray.java#L589-L591 |
138,589 | jillesvangurp/jsonj | src/main/java/com/github/jsonj/JsonArray.java | JsonArray.replaceObject | public boolean replaceObject(JsonObject e1, JsonObject e2, String...path) {
JsonElement compareElement = e1.get(path);
if(compareElement == null) {
throw new IllegalArgumentException("specified path may not be null in object " + StringUtils.join(path));
}
int i=0;
for(JsonElement e: this) {
if(e.isObject()) {
JsonElement fieldValue = e.asObject().get(path);
if(compareElement.equals(fieldValue)) {
set(i,e2);
return true;
}
}
i++;
}
return false;
} | java | public boolean replaceObject(JsonObject e1, JsonObject e2, String...path) {
JsonElement compareElement = e1.get(path);
if(compareElement == null) {
throw new IllegalArgumentException("specified path may not be null in object " + StringUtils.join(path));
}
int i=0;
for(JsonElement e: this) {
if(e.isObject()) {
JsonElement fieldValue = e.asObject().get(path);
if(compareElement.equals(fieldValue)) {
set(i,e2);
return true;
}
}
i++;
}
return false;
} | [
"public",
"boolean",
"replaceObject",
"(",
"JsonObject",
"e1",
",",
"JsonObject",
"e2",
",",
"String",
"...",
"path",
")",
"{",
"JsonElement",
"compareElement",
"=",
"e1",
".",
"get",
"(",
"path",
")",
";",
"if",
"(",
"compareElement",
"==",
"null",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"specified path may not be null in object \"",
"+",
"StringUtils",
".",
"join",
"(",
"path",
")",
")",
";",
"}",
"int",
"i",
"=",
"0",
";",
"for",
"(",
"JsonElement",
"e",
":",
"this",
")",
"{",
"if",
"(",
"e",
".",
"isObject",
"(",
")",
")",
"{",
"JsonElement",
"fieldValue",
"=",
"e",
".",
"asObject",
"(",
")",
".",
"get",
"(",
"path",
")",
";",
"if",
"(",
"compareElement",
".",
"equals",
"(",
"fieldValue",
")",
")",
"{",
"set",
"(",
"i",
",",
"e2",
")",
";",
"return",
"true",
";",
"}",
"}",
"i",
"++",
";",
"}",
"return",
"false",
";",
"}"
] | Convenient replace method that allows you to replace an object based on field equality for a specified field.
Useful if you have an id field in your objects. Note, the array may contain non objects as well or objects
without the specified field. Those elements won't be replaced of course.
@param e1 object you want replaced; must have a value at the specified path
@param e2 replacement
@param path path
@return true if something was replaced. | [
"Convenient",
"replace",
"method",
"that",
"allows",
"you",
"to",
"replace",
"an",
"object",
"based",
"on",
"field",
"equality",
"for",
"a",
"specified",
"field",
".",
"Useful",
"if",
"you",
"have",
"an",
"id",
"field",
"in",
"your",
"objects",
".",
"Note",
"the",
"array",
"may",
"contain",
"non",
"objects",
"as",
"well",
"or",
"objects",
"without",
"the",
"specified",
"field",
".",
"Those",
"elements",
"won",
"t",
"be",
"replaced",
"of",
"course",
"."
] | 1da0c44c5bdb60c0cd806c48d2da5a8a75bf84af | https://github.com/jillesvangurp/jsonj/blob/1da0c44c5bdb60c0cd806c48d2da5a8a75bf84af/src/main/java/com/github/jsonj/JsonArray.java#L603-L620 |
138,590 | jillesvangurp/jsonj | src/main/java/com/github/jsonj/JsonArray.java | JsonArray.objects | public @Nonnull Iterable<JsonObject> objects() {
final JsonArray parent=this;
return () -> {
final Iterator<JsonElement> iterator = parent.iterator();
return new Iterator<JsonObject>() {
@Override
public boolean hasNext() {
return iterator.hasNext();
}
@Override
public JsonObject next() {
return iterator.next().asObject();
}
@Override
public void remove() {
iterator.remove();
}
};
};
} | java | public @Nonnull Iterable<JsonObject> objects() {
final JsonArray parent=this;
return () -> {
final Iterator<JsonElement> iterator = parent.iterator();
return new Iterator<JsonObject>() {
@Override
public boolean hasNext() {
return iterator.hasNext();
}
@Override
public JsonObject next() {
return iterator.next().asObject();
}
@Override
public void remove() {
iterator.remove();
}
};
};
} | [
"public",
"@",
"Nonnull",
"Iterable",
"<",
"JsonObject",
">",
"objects",
"(",
")",
"{",
"final",
"JsonArray",
"parent",
"=",
"this",
";",
"return",
"(",
")",
"->",
"{",
"final",
"Iterator",
"<",
"JsonElement",
">",
"iterator",
"=",
"parent",
".",
"iterator",
"(",
")",
";",
"return",
"new",
"Iterator",
"<",
"JsonObject",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"boolean",
"hasNext",
"(",
")",
"{",
"return",
"iterator",
".",
"hasNext",
"(",
")",
";",
"}",
"@",
"Override",
"public",
"JsonObject",
"next",
"(",
")",
"{",
"return",
"iterator",
".",
"next",
"(",
")",
".",
"asObject",
"(",
")",
";",
"}",
"@",
"Override",
"public",
"void",
"remove",
"(",
")",
"{",
"iterator",
".",
"remove",
"(",
")",
";",
"}",
"}",
";",
"}",
";",
"}"
] | Convenience method to prevent casting JsonElement to JsonObject when iterating in the common case that you have
an array of JsonObjects.
@return iterable that iterates over JsonObjects instead of JsonElements. | [
"Convenience",
"method",
"to",
"prevent",
"casting",
"JsonElement",
"to",
"JsonObject",
"when",
"iterating",
"in",
"the",
"common",
"case",
"that",
"you",
"have",
"an",
"array",
"of",
"JsonObjects",
"."
] | 1da0c44c5bdb60c0cd806c48d2da5a8a75bf84af | https://github.com/jillesvangurp/jsonj/blob/1da0c44c5bdb60c0cd806c48d2da5a8a75bf84af/src/main/java/com/github/jsonj/JsonArray.java#L734-L756 |
138,591 | jillesvangurp/jsonj | src/main/java/com/github/jsonj/JsonArray.java | JsonArray.arrays | public @Nonnull Iterable<JsonArray> arrays() {
final JsonArray parent=this;
return () -> {
final Iterator<JsonElement> iterator = parent.iterator();
return new Iterator<JsonArray>() {
@Override
public boolean hasNext() {
return iterator.hasNext();
}
@Override
public JsonArray next() {
return iterator.next().asArray();
}
@Override
public void remove() {
iterator.remove();
}
};
};
} | java | public @Nonnull Iterable<JsonArray> arrays() {
final JsonArray parent=this;
return () -> {
final Iterator<JsonElement> iterator = parent.iterator();
return new Iterator<JsonArray>() {
@Override
public boolean hasNext() {
return iterator.hasNext();
}
@Override
public JsonArray next() {
return iterator.next().asArray();
}
@Override
public void remove() {
iterator.remove();
}
};
};
} | [
"public",
"@",
"Nonnull",
"Iterable",
"<",
"JsonArray",
">",
"arrays",
"(",
")",
"{",
"final",
"JsonArray",
"parent",
"=",
"this",
";",
"return",
"(",
")",
"->",
"{",
"final",
"Iterator",
"<",
"JsonElement",
">",
"iterator",
"=",
"parent",
".",
"iterator",
"(",
")",
";",
"return",
"new",
"Iterator",
"<",
"JsonArray",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"boolean",
"hasNext",
"(",
")",
"{",
"return",
"iterator",
".",
"hasNext",
"(",
")",
";",
"}",
"@",
"Override",
"public",
"JsonArray",
"next",
"(",
")",
"{",
"return",
"iterator",
".",
"next",
"(",
")",
".",
"asArray",
"(",
")",
";",
"}",
"@",
"Override",
"public",
"void",
"remove",
"(",
")",
"{",
"iterator",
".",
"remove",
"(",
")",
";",
"}",
"}",
";",
"}",
";",
"}"
] | Convenience method to prevent casting JsonElement to JsonArray when iterating in the common case that you have
an array of JsonArrays.
@return iterable that iterates over JsonArrays instead of JsonElements. | [
"Convenience",
"method",
"to",
"prevent",
"casting",
"JsonElement",
"to",
"JsonArray",
"when",
"iterating",
"in",
"the",
"common",
"case",
"that",
"you",
"have",
"an",
"array",
"of",
"JsonArrays",
"."
] | 1da0c44c5bdb60c0cd806c48d2da5a8a75bf84af | https://github.com/jillesvangurp/jsonj/blob/1da0c44c5bdb60c0cd806c48d2da5a8a75bf84af/src/main/java/com/github/jsonj/JsonArray.java#L790-L812 |
138,592 | jillesvangurp/jsonj | src/main/java/com/github/jsonj/JsonArray.java | JsonArray.strings | public @Nonnull Iterable<String> strings() {
final JsonArray parent=this;
return () -> {
final Iterator<JsonElement> iterator = parent.iterator();
return new Iterator<String>() {
@Override
public boolean hasNext() {
return iterator.hasNext();
}
@Override
public String next() {
return iterator.next().asString();
}
@Override
public void remove() {
iterator.remove();
}
};
};
} | java | public @Nonnull Iterable<String> strings() {
final JsonArray parent=this;
return () -> {
final Iterator<JsonElement> iterator = parent.iterator();
return new Iterator<String>() {
@Override
public boolean hasNext() {
return iterator.hasNext();
}
@Override
public String next() {
return iterator.next().asString();
}
@Override
public void remove() {
iterator.remove();
}
};
};
} | [
"public",
"@",
"Nonnull",
"Iterable",
"<",
"String",
">",
"strings",
"(",
")",
"{",
"final",
"JsonArray",
"parent",
"=",
"this",
";",
"return",
"(",
")",
"->",
"{",
"final",
"Iterator",
"<",
"JsonElement",
">",
"iterator",
"=",
"parent",
".",
"iterator",
"(",
")",
";",
"return",
"new",
"Iterator",
"<",
"String",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"boolean",
"hasNext",
"(",
")",
"{",
"return",
"iterator",
".",
"hasNext",
"(",
")",
";",
"}",
"@",
"Override",
"public",
"String",
"next",
"(",
")",
"{",
"return",
"iterator",
".",
"next",
"(",
")",
".",
"asString",
"(",
")",
";",
"}",
"@",
"Override",
"public",
"void",
"remove",
"(",
")",
"{",
"iterator",
".",
"remove",
"(",
")",
";",
"}",
"}",
";",
"}",
";",
"}"
] | Convenience method to prevent casting JsonElement to String when iterating in the common case that you have
an array of strings.
@return iterable that iterates over Strings instead of JsonElements. | [
"Convenience",
"method",
"to",
"prevent",
"casting",
"JsonElement",
"to",
"String",
"when",
"iterating",
"in",
"the",
"common",
"case",
"that",
"you",
"have",
"an",
"array",
"of",
"strings",
"."
] | 1da0c44c5bdb60c0cd806c48d2da5a8a75bf84af | https://github.com/jillesvangurp/jsonj/blob/1da0c44c5bdb60c0cd806c48d2da5a8a75bf84af/src/main/java/com/github/jsonj/JsonArray.java#L820-L842 |
138,593 | jillesvangurp/jsonj | src/main/java/com/github/jsonj/JsonArray.java | JsonArray.doubles | public @Nonnull Iterable<Double> doubles() {
final JsonArray parent=this;
return () -> {
final Iterator<JsonElement> iterator = parent.iterator();
return new Iterator<Double>() {
@Override
public boolean hasNext() {
return iterator.hasNext();
}
@Override
public Double next() {
return iterator.next().asDouble();
}
@Override
public void remove() {
iterator.remove();
}
};
};
} | java | public @Nonnull Iterable<Double> doubles() {
final JsonArray parent=this;
return () -> {
final Iterator<JsonElement> iterator = parent.iterator();
return new Iterator<Double>() {
@Override
public boolean hasNext() {
return iterator.hasNext();
}
@Override
public Double next() {
return iterator.next().asDouble();
}
@Override
public void remove() {
iterator.remove();
}
};
};
} | [
"public",
"@",
"Nonnull",
"Iterable",
"<",
"Double",
">",
"doubles",
"(",
")",
"{",
"final",
"JsonArray",
"parent",
"=",
"this",
";",
"return",
"(",
")",
"->",
"{",
"final",
"Iterator",
"<",
"JsonElement",
">",
"iterator",
"=",
"parent",
".",
"iterator",
"(",
")",
";",
"return",
"new",
"Iterator",
"<",
"Double",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"boolean",
"hasNext",
"(",
")",
"{",
"return",
"iterator",
".",
"hasNext",
"(",
")",
";",
"}",
"@",
"Override",
"public",
"Double",
"next",
"(",
")",
"{",
"return",
"iterator",
".",
"next",
"(",
")",
".",
"asDouble",
"(",
")",
";",
"}",
"@",
"Override",
"public",
"void",
"remove",
"(",
")",
"{",
"iterator",
".",
"remove",
"(",
")",
";",
"}",
"}",
";",
"}",
";",
"}"
] | Convenience method to prevent casting JsonElement to Double when iterating in the common case that you have
an array of doubles.
@return iterable that iterates over Doubles instead of JsonElements. | [
"Convenience",
"method",
"to",
"prevent",
"casting",
"JsonElement",
"to",
"Double",
"when",
"iterating",
"in",
"the",
"common",
"case",
"that",
"you",
"have",
"an",
"array",
"of",
"doubles",
"."
] | 1da0c44c5bdb60c0cd806c48d2da5a8a75bf84af | https://github.com/jillesvangurp/jsonj/blob/1da0c44c5bdb60c0cd806c48d2da5a8a75bf84af/src/main/java/com/github/jsonj/JsonArray.java#L850-L872 |
138,594 | jillesvangurp/jsonj | src/main/java/com/github/jsonj/JsonSet.java | JsonSet.add | @Override
public void add(final String... elements) {
for (String s : elements) {
JsonPrimitive primitive = primitive(s);
if (!contains(primitive)) {
add(primitive);
}
}
} | java | @Override
public void add(final String... elements) {
for (String s : elements) {
JsonPrimitive primitive = primitive(s);
if (!contains(primitive)) {
add(primitive);
}
}
} | [
"@",
"Override",
"public",
"void",
"add",
"(",
"final",
"String",
"...",
"elements",
")",
"{",
"for",
"(",
"String",
"s",
":",
"elements",
")",
"{",
"JsonPrimitive",
"primitive",
"=",
"primitive",
"(",
"s",
")",
";",
"if",
"(",
"!",
"contains",
"(",
"primitive",
")",
")",
"{",
"add",
"(",
"primitive",
")",
";",
"}",
"}",
"}"
] | Variant of add that adds multiple strings.
@param elements
elements | [
"Variant",
"of",
"add",
"that",
"adds",
"multiple",
"strings",
"."
] | 1da0c44c5bdb60c0cd806c48d2da5a8a75bf84af | https://github.com/jillesvangurp/jsonj/blob/1da0c44c5bdb60c0cd806c48d2da5a8a75bf84af/src/main/java/com/github/jsonj/JsonSet.java#L89-L97 |
138,595 | jillesvangurp/jsonj | src/main/java/com/github/jsonj/JsonSet.java | JsonSet.add | @Override
public boolean add(final String s) {
JsonPrimitive primitive = primitive(s);
if (!contains(primitive)) {
return add(primitive);
} else {
return false;
}
} | java | @Override
public boolean add(final String s) {
JsonPrimitive primitive = primitive(s);
if (!contains(primitive)) {
return add(primitive);
} else {
return false;
}
} | [
"@",
"Override",
"public",
"boolean",
"add",
"(",
"final",
"String",
"s",
")",
"{",
"JsonPrimitive",
"primitive",
"=",
"primitive",
"(",
"s",
")",
";",
"if",
"(",
"!",
"contains",
"(",
"primitive",
")",
")",
"{",
"return",
"add",
"(",
"primitive",
")",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] | Variant of add that takes a string instead of a JsonElement. The inherited add only supports JsonElement.
@param s
element | [
"Variant",
"of",
"add",
"that",
"takes",
"a",
"string",
"instead",
"of",
"a",
"JsonElement",
".",
"The",
"inherited",
"add",
"only",
"supports",
"JsonElement",
"."
] | 1da0c44c5bdb60c0cd806c48d2da5a8a75bf84af | https://github.com/jillesvangurp/jsonj/blob/1da0c44c5bdb60c0cd806c48d2da5a8a75bf84af/src/main/java/com/github/jsonj/JsonSet.java#L105-L113 |
138,596 | jillesvangurp/jsonj | src/main/java/com/github/jsonj/JsonSet.java | JsonSet.withIdStrategy | public JsonSet withIdStrategy(IdStrategy strategy) {
this.strategy = strategy;
if(size()>0) {
JsonSet seen=new JsonSet().withIdStrategy(strategy);
Iterator<JsonElement> iterator = this.iterator();
while (iterator.hasNext()) {
JsonElement e = iterator.next();
if(seen.contains(e)) {
iterator.remove();
} else {
seen.add(e);
}
}
}
return this;
} | java | public JsonSet withIdStrategy(IdStrategy strategy) {
this.strategy = strategy;
if(size()>0) {
JsonSet seen=new JsonSet().withIdStrategy(strategy);
Iterator<JsonElement> iterator = this.iterator();
while (iterator.hasNext()) {
JsonElement e = iterator.next();
if(seen.contains(e)) {
iterator.remove();
} else {
seen.add(e);
}
}
}
return this;
} | [
"public",
"JsonSet",
"withIdStrategy",
"(",
"IdStrategy",
"strategy",
")",
"{",
"this",
".",
"strategy",
"=",
"strategy",
";",
"if",
"(",
"size",
"(",
")",
">",
"0",
")",
"{",
"JsonSet",
"seen",
"=",
"new",
"JsonSet",
"(",
")",
".",
"withIdStrategy",
"(",
"strategy",
")",
";",
"Iterator",
"<",
"JsonElement",
">",
"iterator",
"=",
"this",
".",
"iterator",
"(",
")",
";",
"while",
"(",
"iterator",
".",
"hasNext",
"(",
")",
")",
"{",
"JsonElement",
"e",
"=",
"iterator",
".",
"next",
"(",
")",
";",
"if",
"(",
"seen",
".",
"contains",
"(",
"e",
")",
")",
"{",
"iterator",
".",
"remove",
"(",
")",
";",
"}",
"else",
"{",
"seen",
".",
"add",
"(",
"e",
")",
";",
"}",
"}",
"}",
"return",
"this",
";",
"}"
] | Changes the strategy on the current set.
@param strategy id strategy
@return the current set. | [
"Changes",
"the",
"strategy",
"on",
"the",
"current",
"set",
"."
] | 1da0c44c5bdb60c0cd806c48d2da5a8a75bf84af | https://github.com/jillesvangurp/jsonj/blob/1da0c44c5bdb60c0cd806c48d2da5a8a75bf84af/src/main/java/com/github/jsonj/JsonSet.java#L221-L236 |
138,597 | otto-de/hmac-auth | hmac-auth-common/src/main/java/de/otto/hmac/authentication/WrappedRequest.java | WrappedRequest.wrap | public static WrappedRequest wrap(final HttpServletRequest request) throws IOException {
if (request instanceof WrappedRequest) {
return (WrappedRequest) request;
}
return new WrappedRequest(request);
} | java | public static WrappedRequest wrap(final HttpServletRequest request) throws IOException {
if (request instanceof WrappedRequest) {
return (WrappedRequest) request;
}
return new WrappedRequest(request);
} | [
"public",
"static",
"WrappedRequest",
"wrap",
"(",
"final",
"HttpServletRequest",
"request",
")",
"throws",
"IOException",
"{",
"if",
"(",
"request",
"instanceof",
"WrappedRequest",
")",
"{",
"return",
"(",
"WrappedRequest",
")",
"request",
";",
"}",
"return",
"new",
"WrappedRequest",
"(",
"request",
")",
";",
"}"
] | Factory method used to create a WrappedRequest, wrapping a HttpServletRequest.
@param request the HttServletRequest
@return WrappedRequest
@throws IOException if reading the request body fails. | [
"Factory",
"method",
"used",
"to",
"create",
"a",
"WrappedRequest",
"wrapping",
"a",
"HttpServletRequest",
"."
] | 93b69382f9c3ada939848c8f5f61ac991bd74969 | https://github.com/otto-de/hmac-auth/blob/93b69382f9c3ada939848c8f5f61ac991bd74969/hmac-auth-common/src/main/java/de/otto/hmac/authentication/WrappedRequest.java#L30-L36 |
138,598 | tresata/spark-scalding | src/main/java/com/tresata/spark/scalding/serialization/KryoSerialization.java | KryoSerialization.accept | public boolean accept(Class<?> aClass) {
try {
return (testKryo.getRegistration(aClass) != null);
} catch (IllegalArgumentException e) {
return false;
}
} | java | public boolean accept(Class<?> aClass) {
try {
return (testKryo.getRegistration(aClass) != null);
} catch (IllegalArgumentException e) {
return false;
}
} | [
"public",
"boolean",
"accept",
"(",
"Class",
"<",
"?",
">",
"aClass",
")",
"{",
"try",
"{",
"return",
"(",
"testKryo",
".",
"getRegistration",
"(",
"aClass",
")",
"!=",
"null",
")",
";",
"}",
"catch",
"(",
"IllegalArgumentException",
"e",
")",
"{",
"return",
"false",
";",
"}",
"}"
] | Uses the initialized Kryo instance from the JobConf to test if Kryo will accept the class
@param aClass
@return | [
"Uses",
"the",
"initialized",
"Kryo",
"instance",
"from",
"the",
"JobConf",
"to",
"test",
"if",
"Kryo",
"will",
"accept",
"the",
"class"
] | 907139a253c48ab4b4192b9d3b7cd5704f1d5c1b | https://github.com/tresata/spark-scalding/blob/907139a253c48ab4b4192b9d3b7cd5704f1d5c1b/src/main/java/com/tresata/spark/scalding/serialization/KryoSerialization.java#L83-L89 |
138,599 | WolfgangFahl/Mediawiki-Japi | src/main/java/com/bitplan/mediawiki/japi/PageInfo.java | PageInfo.getNameSpaceName | public static String getNameSpaceName(String pageTitle) {
Matcher matcher = namespacePattern.matcher(pageTitle);
if (matcher.find()) {
// LOGGER.log(Level.INFO,pageTitle);
return matcher.group(1);
}
return null;
} | java | public static String getNameSpaceName(String pageTitle) {
Matcher matcher = namespacePattern.matcher(pageTitle);
if (matcher.find()) {
// LOGGER.log(Level.INFO,pageTitle);
return matcher.group(1);
}
return null;
} | [
"public",
"static",
"String",
"getNameSpaceName",
"(",
"String",
"pageTitle",
")",
"{",
"Matcher",
"matcher",
"=",
"namespacePattern",
".",
"matcher",
"(",
"pageTitle",
")",
";",
"if",
"(",
"matcher",
".",
"find",
"(",
")",
")",
"{",
"// LOGGER.log(Level.INFO,pageTitle);",
"return",
"matcher",
".",
"group",
"(",
"1",
")",
";",
"}",
"return",
"null",
";",
"}"
] | get the name space name
@param pageTitle
@return | [
"get",
"the",
"name",
"space",
"name"
] | 78d0177ebfe02eb05da5550839727861f1e888a5 | https://github.com/WolfgangFahl/Mediawiki-Japi/blob/78d0177ebfe02eb05da5550839727861f1e888a5/src/main/java/com/bitplan/mediawiki/japi/PageInfo.java#L151-L158 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.