本文整理匯總了Java中org.databene.commons.ReaderLineIterator類的典型用法代碼示例。如果您正苦於以下問題:Java ReaderLineIterator類的具體用法?Java ReaderLineIterator怎麽用?Java ReaderLineIterator使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ReaderLineIterator類屬於org.databene.commons包,在下文中一共展示了ReaderLineIterator類的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: test
import org.databene.commons.ReaderLineIterator; //導入依賴的package包/類
@Test
public void test() throws Exception {
String filePath = "target/sepfwtest.csv";
FileWriter out = null;
try {
out = new FileWriter(filePath);
SeparatedFileWriter writer = new SeparatedFileWriter(out, SepPersonData.class, '\t', "VER1234");
writer.writeRow(new SepPersonData("Alice", "23"));
writer.writeRow(new SepPersonData("Bob", "34"));
IOUtil.close(writer);
} finally {
IOUtil.close(out);
}
ReaderLineIterator iterator = new ReaderLineIterator(new FileReader(filePath));
assertTrue(iterator.hasNext());
assertEquals("VER1234", iterator.next());
assertTrue(iterator.hasNext());
assertEquals("Alice\t23", iterator.next());
assertTrue(iterator.hasNext());
assertEquals("Bob\t34", iterator.next());
assertFalse(iterator.hasNext());
}
示例2: test
import org.databene.commons.ReaderLineIterator; //導入依賴的package包/類
@Test
public void test() throws Exception {
String filePath = "target/sepfwtest.csv";
FileWriter out = null;
try {
WebdecsSeparatedContent contenHandler = new WebdecsSeparatedContent();
out = new FileWriter(filePath);
Object writerId = contenHandler.createWriter(out, SepPersonData.class, '\t', null);
contenHandler.writeRow(new SepPersonData("Alice", "23"), writerId);
contenHandler.writeRow(new SepPersonData("Bob", "34"), writerId);
contenHandler.closeWriter(writerId);
} finally {
IOUtil.close(out);
}
ReaderLineIterator iterator = new ReaderLineIterator(new FileReader(filePath));
assertTrue(iterator.hasNext());
assertEquals("Alice\t23", iterator.next());
assertTrue(iterator.hasNext());
assertEquals("Bob\t34", iterator.next());
assertFalse(iterator.hasNext());
}
示例3: ArchetypeManager
import org.databene.commons.ReaderLineIterator; //導入依賴的package包/類
private ArchetypeManager() {
try {
// read archetypes in the order specified in the file 'archetypes.txt'
ReaderLineIterator iterator = new ReaderLineIterator(IOUtil.getReaderForURI(ARCHETYPES_INDEX));
ArrayBuilder<Archetype> builder = new ArrayBuilder<Archetype>(Archetype.class);
while (iterator.hasNext()) {
String name = iterator.next();
URL archUrl = new URL(ARCHETYPE_FOLDER_URL.toString() + "/" + name);
Archetype archetype = new Archetype(archUrl);
builder.add(archetype);
}
this.archetypes = builder.toArray();
} catch (IOException e) {
throw new ConfigurationError("Error parsing archetype definitions", e);
}
}
示例4: testNormal
import org.databene.commons.ReaderLineIterator; //導入依賴的package包/類
@Test
public void testNormal() throws Exception {
try {
Entity alice = createEntity("Person", "name", "Alice", "birthDate", TimeUtil.date(1987, 11, 31), "score", 23);
Entity bob = createEntity("Person", "name", "Bob", "birthDate", TimeUtil.date(1977, 11, 31), "score", 34);
SQLEntityExporter exporter = new SQLEntityExporter(FILENAME);
exporter.setDialect("hsql");
exporter.startProductConsumption(alice);
exporter.startProductConsumption(bob);
exporter.close();
BufferedReader reader = IOUtil.getReaderForURI(FILENAME);
ReaderLineIterator iterator = new ReaderLineIterator(reader);
assertTrue(iterator.hasNext());
assertEquals("insert into \"Person\" (name, birthDate, score) values ('Alice', '1987-12-31', 23);", iterator.next());
assertTrue(iterator.hasNext());
assertEquals("insert into \"Person\" (name, birthDate, score) values ('Bob', '1977-12-31', 34);", iterator.next());
assertFalse(iterator.hasNext());
} finally {
FileUtil.deleteIfExists(new File(FILENAME));
}
}
示例5: testShuffleFile
import org.databene.commons.ReaderLineIterator; //導入依賴的package包/類
@Test
public void testShuffleFile() throws IOException {
boolean[] check = new boolean[3];
String outFile = "target/LineShufflerTest.txt";
LineShuffler.shuffle("org/databene/benerator/util/test.txt", outFile, 3);
ReaderLineIterator iterator = new ReaderLineIterator(IOUtil.getReaderForURI(outFile));
int count = 0;
while (iterator.hasNext()) {
count++;
int value = Integer.parseInt(iterator.next());
assertFalse(check[value]);
check[value] = true;
}
assertEquals(3, count);
for (boolean c : check)
assertTrue(c);
}
示例6: testAnnotationBeanWriter
import org.databene.commons.ReaderLineIterator; //導入依賴的package包/類
/** Tests the BeanFlatFileWriter with FlatFileBeans. */
@Test
public void testAnnotationBeanWriter() throws Exception {
// set up the FlatFileService
FlatFileService service = getLoggingService(FlatFileService.class, "annotest");
// GIVEN an ArrayFlatFileWriter
String fileName = "target" + File.separator + getClass().getSimpleName() + ".anno.fcw";
MyFlatFileWriter writer = new MyFlatFileWriter(fileName, service, true);
// WHEN persisting 2 FFPerson and 1 FFAddress beans
writer.writeRow(new FFFlatPerson("Alice", 23, TimeUtil.date(1991, Calendar.JANUARY, 6), "Miez"));
writer.writeRow(new FFFlatPerson("Bob", 34, TimeUtil.date(1980, Calendar.FEBRUARY, 3), "Hasso"));
writer.writeRow(new FFAddress("MAIN STREET 321", "NEW YORK", 123.45));
writer.close();
// THEN the data shall be formatted properly according to the individual formats.
ReaderLineIterator iterator = new ReaderLineIterator(IOUtil.getReaderForURI(fileName));
assertTrue(iterator.hasNext());
assertEquals("PAlice 02319910106Miez ", iterator.next());
assertTrue(iterator.hasNext());
assertEquals("PBob 03419800203Hasso ", iterator.next());
assertTrue(iterator.hasNext());
assertEquals("AMAIN STREET 321 NEW YORK 0123.45", iterator.next());
assertFalse(iterator.hasNext());
// check that the whole file has been attached
Iterator<Attachment> iter = getLastTestStep().getAttachments().iterator();
assertTrue(iter.hasNext());
Attachment att = iter.next();
String contents = new String(att.getFileData(), "UTF-8");
assertTrue(contents.startsWith("PAlice 02319910106Miez "));
// tear down the FlatFileService
IOUtil.close(service);
assertNotFailed();
}
示例7: testAnnotationBeanWriter
import org.databene.commons.ReaderLineIterator; //導入依賴的package包/類
/** Tests the SeparatedFileWriter with SeparatedFileBeans. */
@Test
public void testAnnotationBeanWriter() throws Exception {
// set up the SeparatedFileService
SeparatedFileService service = getLoggingService(SeparatedFileService.class, "annotest");
// GIVEN a SeparatedFileWriter
String fileName = "target" + File.separator + getClass().getSimpleName() + ".anno.fcw";
MySeparatedFileWriter writer = new MySeparatedFileWriter(fileName, service, true);
// WHEN persisting 2 FFPerson and 1 FFAddress beans
writer.writeRow(new SepPersonData("Alice", "23"));
writer.writeRow(new SepPersonData("Bob", "34"));
writer.close();
// THEN the data shall be formatted properly according to the individual formats.
ReaderLineIterator iterator = new ReaderLineIterator(IOUtil.getReaderForURI(fileName));
assertTrue(iterator.hasNext());
assertEquals("VER1234", iterator.next());
assertTrue(iterator.hasNext());
assertEquals("Alice\t23", iterator.next());
assertTrue(iterator.hasNext());
assertEquals("Bob\t34", iterator.next());
assertFalse(iterator.hasNext());
// tear down the SeparatedFileService
IOUtil.close(service);
assertNotFailed();
}
示例8: SeedSentenceGenerator
import org.databene.commons.ReaderLineIterator; //導入依賴的package包/類
public SeedSentenceGenerator(String seedUri, int depth) throws IOException {
super(new SeedGenerator<String>(String.class, depth));
ReaderLineIterator iterator = new ReaderLineIterator(IOUtil.getReaderForURI(seedUri));
while (iterator.hasNext()) {
String line = iterator.next();
if (StringUtil.isEmpty(line))
continue;
((SeedGenerator<String>) getSource()).addSample(line.split("\\s"));
}
}
示例9: runShell
import org.databene.commons.ReaderLineIterator; //導入依賴的package包/類
private Object runShell(String uri, String text, String onError) {
ErrorHandler errorHandler = new ErrorHandler(getClass().getName(), Level.valueOf(onError));
StringWriter writer = new StringWriter();
if (text != null)
ShellUtil.runShellCommands(new ReaderLineIterator(new StringReader(text)), writer, errorHandler);
else if (uri != null)
ShellUtil.runShellCommand(uri, writer, errorHandler);
else
throw new ConfigurationError("At least uri or text must be provided in <execute> and <evaluate>");
String output = writer.toString();
System.out.println(output);
return LiteralParser.parse(output);
}
示例10: shuffle
import org.databene.commons.ReaderLineIterator; //導入依賴的package包/類
public static void shuffle(String inFilename, String outFilename, int bufferSize) throws IOException {
logger.info("shuffling " + inFilename + " and writing to " + outFilename + " (max. " + bufferSize + " lines)");
ReaderLineIterator iterator = new ReaderLineIterator(new BufferedReader(IOUtil.getReaderForURI(inFilename)));
List<String> lines = read(bufferSize, iterator);
shuffle(lines);
save(lines, outFilename);
}
示例11: read
import org.databene.commons.ReaderLineIterator; //導入依賴的package包/類
private static List<String> read(int bufferSize, ReaderLineIterator iterator) {
List<String> lines = new ArrayList<String>(Math.max(100000, bufferSize));
int lineCount = 0;
while (iterator.hasNext() && lineCount < bufferSize) {
String line = iterator.next();
if (!StringUtil.isEmpty(line)) {
lines.add(line);
lineCount++;
if (lineCount % 100000 == 99999)
logger.info("parsed " + lineCount + " lines");
}
}
return lines;
}
示例12: testMultiThreaded
import org.databene.commons.ReaderLineIterator; //導入依賴的package包/類
@Test
public void testMultiThreaded() throws Exception {
try {
ComplexTypeDescriptor type = createComplexType("testtype");
SimpleTypeDescriptor stringType = dataModel.getPrimitiveTypeDescriptor(String.class);
type.addComponent(createPart("a", stringType));
type.addComponent(createPart("b", stringType));
type.addComponent(createPart("c", stringType));
final CSVEntityExporter exporter = new CSVEntityExporter(
DEFAULT_FILE.getAbsolutePath(), type);
final Entity entity = new Entity(type, "a", "0123456789", "b", "5555555555", "c", "9876543210");
ExecutorService service = Executors.newCachedThreadPool();
Runnable runner = new Runnable() {
@Override
public void run() {
for (int i = 0; i < 500; i++)
exporter.startProductConsumption(entity);
exporter.finishProductConsumption(entity);
}
};
for (int i = 0; i < 20; i++)
service.execute(runner);
service.shutdown();
service.awaitTermination(2, TimeUnit.SECONDS);
exporter.close();
ReaderLineIterator iterator = new ReaderLineIterator(new FileReader(DEFAULT_FILE));
assertEquals("a,b,c", iterator.next());
String expectedContent = "0123456789,5555555555,9876543210";
while (iterator.hasNext()) {
String line = iterator.next();
assertEquals(expectedContent, line);
}
iterator.close();
} finally {
DEFAULT_FILE.delete();
}
}
示例13: runScript
import org.databene.commons.ReaderLineIterator; //導入依賴的package包/類
private static DBExecutionResult runScript(
Reader reader, char separator, Connection connection, boolean ignoreComments, ErrorHandler errorHandler) {
ReaderLineIterator iterator = new ReaderLineIterator(reader);
SQLScriptException exception = null;
Object result = null;
Boolean changedStructure = false;
try {
StringBuilder cmd = new StringBuilder();
while (iterator.hasNext()) {
String line = iterator.next().trim();
if (line.startsWith("--"))
continue;
if (cmd.length() > 0)
cmd.append('\n');
cmd.append(line);
boolean lineEndsWithSeparator = (line.length() > 0 && StringUtil.lastChar(line) == separator);
if (lineEndsWithSeparator || !iterator.hasNext()) {
if (lineEndsWithSeparator)
cmd.delete(cmd.length() - 1, cmd.length()); // delete trailing separators
String sql = cmd.toString().trim();
if (sql.length() > 0 && (!ignoreComments || !StringUtil.startsWithIgnoreCase(sql, "COMMENT"))) {
try {
if (SQLUtil.isQuery(sql))
result = queryAndSimplify(sql, connection);
else {
result = executeUpdate(sql, connection);
if (!Boolean.TRUE.equals(changedStructure)) {
// if we are not already certain that structure was changed, check it
Boolean tmp = SQLUtil.mutatesStructure(sql);
if (!(changedStructure == null && Boolean.FALSE.equals(tmp)))
changedStructure = tmp; // merge results using the worse one (true worse than null worse than false)
}
}
} catch (SQLException e) {
if (errorHandler == null)
errorHandler = new ErrorHandler(DBUtil.class);
errorHandler.handleError("Error in executing SQL: " + SystemInfo.getLineSeparator() + cmd, e);
// if we arrive here, the ErrorHandler decided not to throw an exception
// so we save the exception and line number and continue execution
if (exception != null) // only the first exception is saved
exception = new SQLScriptException(e, iterator.lineCount());
}
}
cmd.delete(0, cmd.length());
}
}
Object returnedValue = (exception != null ? exception : result);
return new DBExecutionResult(returnedValue, changedStructure);
} finally {
IOUtil.close(iterator);
}
}