本文整理汇总了Java中org.databene.commons.Encodings类的典型用法代码示例。如果您正苦于以下问题:Java Encodings类的具体用法?Java Encodings怎么用?Java Encodings使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Encodings类属于org.databene.commons包,在下文中一共展示了Encodings类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: importStates
import org.databene.commons.Encodings; //导入依赖的package包/类
private void importStates() {
this.states = new OrderedNameMap<State>();
String filename = "/org/databene/domain/address/state_" + isoCode + ".csv";
if (!IOUtil.isURIAvailable(filename)) {
LOGGER.debug("No states defined for {}", this);
return;
}
ComplexTypeDescriptor stateDescriptor = (ComplexTypeDescriptor) new BeanDescriptorProvider().getTypeDescriptor(State.class.getName());
CSVEntitySource source = new CSVEntitySource(filename, stateDescriptor, Encodings.UTF_8);
source.setContext(new DefaultBeneratorContext());
DataIterator<Entity> iterator = source.iterator();
DataContainer<Entity> container = new DataContainer<Entity>();
while ((container = iterator.next(container)) != null) {
Entity entity = container.getData();
State state = new State();
mapProperty("id", entity, state, true);
mapProperty("name", entity, state, true);
mapProperty("defaultLanguage", entity, state, false);
state.setCountry(this);
addState(state);
}
IOUtil.close(iterator);
}
示例2: testGraph
import org.databene.commons.Encodings; //导入依赖的package包/类
@Test
public void testGraph() throws Exception {
ComplexTypeDescriptor countryDescriptor = createCountryDescriptor();
ComplexTypeDescriptor personDescriptor = createPersonDescriptor(countryDescriptor);
// Define expected countries
Entity germany = new Entity(countryDescriptor, "isoCode", "DE", "name", "Germany");
Entity usa = new Entity(countryDescriptor, "isoCode", "US", "name", "USA");
// Define expected persons
Entity alice = new Entity(personDescriptor, "name", "Alice", "age", 23, "country", germany);
Entity bob = new Entity(personDescriptor, "name", "Bob", "age", 34, "country", usa);
// iterate CSV file and check iterator output
CSVEntityIterator iterator = new CSVEntityIterator(GRAPH_URI, personDescriptor, null, ',', Encodings.UTF_8);
assertEquals(alice, nextOf(iterator));
assertEquals(bob, nextOf(iterator));
assertUnavailable(iterator);
}
示例3: testInlineJavaScript
import org.databene.commons.Encodings; //导入依赖的package包/类
@Test
public void testInlineJavaScript() {
EvaluateStatement stmt = new EvaluateStatement(
true,
constant("message"),
constant("'Hello World'"),
null,
null,
null,
null,
constant("fatal"),
constant(Encodings.UTF_8),
constant(false),
null,
null);
stmt.execute(context);
assertEquals("Hello World", context.get("message"));
}
示例4: testUriMapping
import org.databene.commons.Encodings; //导入依赖的package包/类
@Test
public void testUriMapping() {
EvaluateStatement stmt = new EvaluateStatement(
true,
constant("message"),
null,
constant("/org/databene/benerator/engine/statement/HelloWorld.js"),
null,
null,
null,
constant("fatal"),
constant(Encodings.UTF_8),
constant(false),
null,
null);
stmt.execute(context);
assertEquals("Hello World", context.get("message"));
}
示例5: testShell
import org.databene.commons.Encodings; //导入依赖的package包/类
@Test
public void testShell() {
String cmd = "echo 42";
if (SystemInfo.isWindows())
cmd = "cmd.exe /C " + cmd;
EvaluateStatement stmt = new EvaluateStatement(
true,
constant("result"),
constant(cmd),
null,
constant("shell"),
null,
null,
constant("fatal"),
constant(Encodings.UTF_8),
constant(false),
null,
null);
stmt.execute(context);
assertEquals(42, context.get("result"));
}
示例6: testStorageSystem
import org.databene.commons.Encodings; //导入依赖的package包/类
@Test
public void testStorageSystem() {
StSys stSys = new StSys();
Expression<StSys> stSysEx = ExpressionUtil.constant(stSys);
EvaluateStatement stmt = new EvaluateStatement(
true,
constant("message"),
constant("HelloHi"),
null,
null,
stSysEx,
null,
constant("fatal"),
constant(Encodings.UTF_8),
constant(false),
null,
null);
stmt.execute(context);
assertEquals("HelloHi", stSys.execInfo);
}
示例7: test
import org.databene.commons.Encodings; //导入依赖的package包/类
@Test
public void test() throws ParseException {
// prepare
SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy");
ParseFormatConverter<Date> converter = new ParseFormatConverter<Date>(Date.class, format, false);
WeightedCSVSampleGenerator<Date> generator = new WeightedCSVSampleGenerator<Date>(
Date.class, FILE_PATH, Encodings.UTF_8, converter);
generator.init(context);
// run test
List<Date> expectedDates = CollectionUtil.toList(sdf.parse("01.02.2003"), sdf.parse("02.02.2003"),
sdf.parse("03.02.2003"));
for (int i = 0; i < 10; i++) {
Date generatedDate = GeneratorUtil.generateNonNull(generator);
assertTrue("generated date not in expected value set: " + sdf.format(generatedDate),
expectedDates.contains(generatedDate));
}
}
示例8: testEurope
import org.databene.commons.Encodings; //导入依赖的package包/类
@Test
public void testEurope() {
WeightedDatasetCSVGenerator<String> source = new WeightedDatasetCSVGenerator<String>(
String.class, FAMILY_NAME + "_{0}.csv", "europe", REGION, false, Encodings.UTF_8);
NonNullGenerator<String> generator = WrapperFactory.asNonNullGenerator(source);
generator.init(context);
boolean mueller = false; // German name
boolean garcia = false; // Spanish name
for (int i = 0; i < 100000 && (!mueller || !garcia); i++) {
String name = generator.generate();
if ("Müller".equals(name))
mueller = true;
if ("García".equals(name))
garcia = true;
}
assertTrue(mueller);
assertTrue(garcia);
}
示例9: dropTables
import org.databene.commons.Encodings; //导入依赖的package包/类
protected void dropTables() throws Exception {
try {
connection = DBUtil.connect(ENVIRONMENT, false);
DBUtil.executeScriptFile(DROP_TABLES_FILE_NAME, Encodings.UTF_8, connection, false, null);
} finally {
DBUtil.close(connection);
}
}
示例10: testRunScript
import org.databene.commons.Encodings; //导入依赖的package包/类
@Test
public void testRunScript() throws Exception {
Connection connection = HSQLUtil.connectInMemoryDB(getClass().getSimpleName());
ErrorHandler errorHandler = new ErrorHandler(getClass());
DBExecutionResult result = DBUtil.executeScriptFile(SCRIPT_FILE, Encodings.ISO_8859_1, connection, true, errorHandler);
assertTrue(result.changedStructure);
Object[][] rows = (Object[][]) DBUtil.queryAndSimplify("select * from T1", connection);
assertEquals(1, rows.length);
assertTrue(Arrays.equals(ArrayUtil.buildObjectArrayOfType(Object.class, 1, "R&B"), rows[0]));
int count = (Integer) DBUtil.queryAndSimplify("select count(*) from T1", connection);
assertEquals(1, count);
}
示例11: testWriteDocument
import org.databene.commons.Encodings; //导入依赖的package包/类
@Test
public void testWriteDocument() throws Exception {
Document doc = XMLUtil.createDocument("root");
Element root = doc.getDocumentElement();
root.setAttribute("att", "val");
Element node = doc.createElement("node");
root.appendChild(node);
node.setTextContent("text");
ByteArrayOutputStream out = new ByteArrayOutputStream();
content.writeDocument(doc, Encodings.UTF_8, out);
assertEquals(SIMPLE_XML, new String(out.toByteArray(), Encodings.UTF_8));
}
示例12: testCreateDocument
import org.databene.commons.Encodings; //导入依赖的package包/类
@Test
public void testCreateDocument() throws Exception {
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("attvar", "val");
variables.put("textvar", "text");
Document doc = content.createDocument(FTL_TEMPLATE, Encodings.UTF_8, variables);
verifySimpleDocument(doc);
}
示例13: iterateCsv
import org.databene.commons.Encodings; //导入依赖的package包/类
private static void iterateCsv(GeneratorFactory generatorFactory) {
Generator<String[]> generator = SourceFactory.createCSVLineGenerator(
"org/databene/benerator/products.csv", ';', Encodings.UTF_8, true);
init(generator);
String[] row;
while ((row = generateNonNull(generator)) != null) // null signals that the generator is used up
System.out.println(Arrays.toString(row));
close(generator);
}
示例14: setCountry
import org.databene.commons.Encodings; //导入依赖的package包/类
private void setCountry(String countryCode) {
try {
Map<String, String> formats = IOUtil.readProperties("/org/databene/domain/address/postalCodeFormat.properties", Encodings.UTF_8);
pattern = Pattern.compile(formats.get(countryCode));
} catch (IOException e) {
throw new ConfigurationError("Error initializing " + getClass().getSimpleName() +
" with country code '" + countryCode + "'");
}
}
示例15: createArtificialNameGenerator
import org.databene.commons.Encodings; //导入依赖的package包/类
private TokenCombiner createArtificialNameGenerator() {
try {
return new TokenCombiner(ORG + "artificialName.csv", false, '-', Encodings.UTF_8, false);
} catch (Exception e) {
LOGGER.info("Cannot create artificial company name generator: " + e.getMessage());
return null;
}
}