当前位置: 首页>>代码示例>>Java>>正文


Java IOUtil.getReaderForURI方法代码示例

本文整理汇总了Java中org.databene.commons.IOUtil.getReaderForURI方法的典型用法代码示例。如果您正苦于以下问题:Java IOUtil.getReaderForURI方法的具体用法?Java IOUtil.getReaderForURI怎么用?Java IOUtil.getReaderForURI使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.databene.commons.IOUtil的用法示例。


在下文中一共展示了IOUtil.getReaderForURI方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testReader

import org.databene.commons.IOUtil; //导入方法依赖的package包/类
@Test
public void testReader() throws Exception {
    Reader in = null;
    try {
        in = IOUtil.getReaderForURI("org/aludratest/content/separated/persons.csv");
        WebdecsSeparatedContent contenHandler = new WebdecsSeparatedContent();
        Object readerId = contenHandler.createReader(in, SepPersonData.class, ',');
        assertEquals("VER1234", contenHandler.readHeader(readerId));
        assertEquals(new SepPersonData("Alice", "23"), contenHandler.readRow(readerId));
        assertEquals(new SepPersonData("Bob", "34"), contenHandler.readRow(readerId));
        assertNull(contenHandler.readRow(readerId));
        contenHandler.closeReader(readerId);
    } finally {
        IOUtil.close(in);
    }
}
 
开发者ID:AludraTest,项目名称:aludratest,代码行数:17,代码来源:WedecsSeparatedContentTest.java

示例2: ArchetypeManager

import org.databene.commons.IOUtil; //导入方法依赖的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);
       }
}
 
开发者ID:raphaelfeng,项目名称:benerator,代码行数:17,代码来源:ArchetypeManager.java

示例3: createBeneratorXml

import org.databene.commons.IOUtil; //导入方法依赖的package包/类
public void createBeneratorXml() throws IOException, ParseException {
 	File descriptorFile = new File(setup.getProjectFolder(), "benerator.xml");
 	if (descriptorFile.exists()) { // not applicable for XML schema based generation
  	BufferedReader reader = IOUtil.getReaderForURI(descriptorFile.getAbsolutePath());
DefaultHTMLTokenizer tokenizer = new DefaultHTMLTokenizer(reader);
  	String lineSeparator = setup.getLineSeparator();
  	if (StringUtil.isEmpty(lineSeparator))
  		lineSeparator = SystemInfo.getLineSeparator();
LFNormalizingStringBuilder writer = new LFNormalizingStringBuilder(lineSeparator);
  	while (tokenizer.nextToken() != HTMLTokenizer.END)
  		processToken(setup, tokenizer, writer);
  	String xml = writer.toString();
  	xml = resolveVariables(xml);
IOUtil.writeTextFile(descriptorFile.getAbsolutePath(), xml, "UTF-8");
 	}
 	monitor.advance();
 }
 
开发者ID:raphaelfeng,项目名称:benerator,代码行数:18,代码来源:ProjectBuilder.java

示例4: testNormal

import org.databene.commons.IOUtil; //导入方法依赖的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));
	}
}
 
开发者ID:raphaelfeng,项目名称:benerator,代码行数:22,代码来源:SQLEntityExporterTest.java

示例5: testShuffleFile

import org.databene.commons.IOUtil; //导入方法依赖的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);
  }
 
开发者ID:raphaelfeng,项目名称:benerator,代码行数:18,代码来源:LineShufflerTest.java

示例6: testReader

import org.databene.commons.IOUtil; //导入方法依赖的package包/类
@Test
public void testReader() throws Exception {
    Reader in = null;
    try {
        in = IOUtil.getReaderForURI("org/aludratest/content/separated/persons.csv");
        SeparatedFileReader<SepPersonData> reader = null;
        reader = new SeparatedFileReader<SepPersonData>(in, SepPersonData.class, ',');
        assertArrayEquals(new String[] { "VER1234" }, reader.readRaw());
        assertEquals(new SepPersonData("Alice", "23"), reader.readRow());
        assertEquals(new SepPersonData("Bob", "34"), reader.readRow());
        assertNull(reader.readRow());
    } finally {
        IOUtil.close(in);
    }
}
 
开发者ID:AludraTest,项目名称:aludratest,代码行数:16,代码来源:SeparatedFileReaderTest.java

示例7: testAnnotationBeanWriter

import org.databene.commons.IOUtil; //导入方法依赖的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();
}
 
开发者ID:AludraTest,项目名称:aludratest,代码行数:39,代码来源:FlatFileServiceIntegrationTest.java

示例8: getContentOfURI

import org.databene.commons.IOUtil; //导入方法依赖的package包/类
public static String getContentOfURI(String uri, String encoding) throws IOException {
    Reader reader = IOUtil.getReaderForURI(uri, encoding);
    StringWriter writer = new StringWriter();
    IOUtil.transfer(reader, writer);
    IOUtil.close(reader);
    IOUtil.close(writer);
    return writer.toString();
}
 
开发者ID:AludraTest,项目名称:aludratest,代码行数:9,代码来源:GitClientIntegrationTest.java

示例9: testAnnotationBeanWriter

import org.databene.commons.IOUtil; //导入方法依赖的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();
}
 
开发者ID:AludraTest,项目名称:aludratest,代码行数:30,代码来源:SeparatedFileServiceTest.java

示例10: main

import org.databene.commons.IOUtil; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
     BufferedReader reader = IOUtil.getReaderForURI("org/databene/benerator/products.csv");
     CSVToJavaBeanMapper<Product> mapper = new CSVToJavaBeanMapper<Product>(reader, Product.class);
     DataContainer<Product> value = new DataContainer<Product>();
     while ((value = mapper.next(value)) != null)
System.out.println(value.getData());
 }
 
开发者ID:raphaelfeng,项目名称:benerator,代码行数:8,代码来源:BeanGraphDemo.java

示例11: SeedSentenceGenerator

import org.databene.commons.IOUtil; //导入方法依赖的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"));
}
  }
 
开发者ID:raphaelfeng,项目名称:benerator,代码行数:11,代码来源:SeedSentenceGenerator.java

示例12: shuffle

import org.databene.commons.IOUtil; //导入方法依赖的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);
}
 
开发者ID:raphaelfeng,项目名称:benerator,代码行数:8,代码来源:LineShuffler.java

示例13: executeScriptFile

import org.databene.commons.IOUtil; //导入方法依赖的package包/类
public static DBExecutionResult executeScriptFile(
  		String scriptUri, String encoding, char separator, Connection connection, boolean ignoreComments, ErrorHandler errorHandler) 
  			throws IOException {
BufferedReader reader = IOUtil.getReaderForURI(scriptUri, encoding);
return runScript(reader, separator, connection, ignoreComments, errorHandler);
  }
 
开发者ID:aravindc,项目名称:jdbacl,代码行数:7,代码来源:DBUtil.java


注:本文中的org.databene.commons.IOUtil.getReaderForURI方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。