Codota Logo
CsvConfiguration
Code IndexAdd Codota to your IDE (free)

How to use
CsvConfiguration
in
com.asakusafw.runtime.io.csv

Best Java code snippets using com.asakusafw.runtime.io.csv.CsvConfiguration (Showing top 19 results out of 315)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
List l =
  • Codota Iconnew LinkedList()
  • Codota IconCollections.emptyList()
  • Codota Iconnew ArrayList()
  • Smart code suggestions by Codota
}
origin: asakusafw/asakusafw-examples

/**
 * Returns this CSV format configuration.
 * @param head whether configure for head of file or not
 * @return CSV format configuration
 */
protected CsvConfiguration getConfiguration(boolean head) {
  List<String> headers = new ArrayList<>();
  if(head) {
    headers.add("店舗コード");
    headers.add("名称");
  }
  CsvConfiguration config = new CsvConfiguration(Charset.forName("UTF-8"), headers, "true", "false", "yyyy-MM-dd", 
      "yyyy-MM-dd HH:mm:ss");
  config.setLineBreakInValue(false);
  return config;
}
@Override
origin: asakusafw/asakusafw

/**
 * Creates a new instance.
 * @param stream the source stream
 * @param path the source path
 * @param config current configuration
 * @throws IllegalArgumentException if some parameters were {@code null}
 */
public CsvParser(InputStream stream, String path, CsvConfiguration config) {
  if (stream == null) {
    throw new IllegalArgumentException("stream must not be null"); //$NON-NLS-1$
  }
  if (config == null) {
    throw new IllegalArgumentException("config must not be null"); //$NON-NLS-1$
  }
  this.reader = new InputStreamReader(stream, config.getCharset());
  this.path = path;
  this.separator = config.getSeparatorChar();
  this.trueFormat = config.getTrueFormat();
  this.dateFormat = DateFormatter.newInstance(config.getDateFormat());
  this.dateTimeFormat = DateTimeFormatter.newInstance(config.getDateTimeFormat());
  this.headerCellsFormat = config.getHeaderCells();
  this.forceConsumeHeader = config.isForceConsumeHeader();
  this.allowLineBreakInValue = config.isLineBreakInValue();
  readerBuffer.clear();
  readerBuffer.flip();
}
origin: stackoverflow.com

private Serializer getSerializer() {
   CsvConfiguration config = new CsvConfiguration();
   config.setFieldDelimiter(';');
   config.setDefaultQuoteMode(QuoteMode.NEVER); //!!!!
   return CsvIOFactory.createFactory(config, MyCsvDto.class).createSerializer();
 }
origin: asakusafw/asakusafw

/**
 * Creates a new instance.
 * @param stream the target stream
 * @param path the destination path
 * @param config current configuration
 * @throws IllegalArgumentException if some parameters were {@code null}
 */
public CsvEmitter(OutputStream stream, String path, CsvConfiguration config) {
  if (stream == null) {
    throw new IllegalArgumentException("stream must not be null"); //$NON-NLS-1$
  }
  if (config == null) {
    throw new IllegalArgumentException("config must not be null"); //$NON-NLS-1$
  }
  this.writer = new OutputStreamWriter(stream, config.getCharset());
  this.separator = config.getSeparatorChar();
  this.escapePattern = Pattern.compile(
      "[" + ESCAPE + separator + LINE_DELIMITER + "]"); //$NON-NLS-1$ //$NON-NLS-2$
  this.trueFormat = escape(config.getTrueFormat());
  this.escapeTrue = hasEscapeTarget(config.getTrueFormat());
  this.falseFormat = escape(config.getFalseFormat());
  this.escapeFalse = hasEscapeTarget(config.getFalseFormat());
  this.dateFormat = DateFormatter.newInstance(config.getDateFormat());
  this.escapeDate = hasMetaCharacter(dateFormat.getPattern());
  this.dateTimeFormat = DateTimeFormatter.newInstance(config.getDateTimeFormat());
  this.escapeDateTime = hasMetaCharacter(dateTimeFormat.getPattern());
  this.headerCellsFormat = config.getHeaderCells();
  this.forceEscapeMask = buildQuoteMask(config.getForceQuoteColumns());
  this.columnIndex = 0;
}
origin: stackoverflow.com

public static Object[][] getCsvData( File csvFile ) 
 {   
   CsvConfiguration conf = new CsvConfiguration( 1 );
   DataContext csvContext = DataContextFactory.createCsvDataContext( csvFile, conf );
   Schema schema = csvContext.getDefaultSchema();
   Table[] tables = schema.getTables();
   Table table = tables[0]; // a representation of the csv file name including extension
   DataSet dataSet = csvContext.query()
       .from( table )
       .selectAll()
       .where("run").eq("Y")
       .execute();
   List<Row> rows = dataSet.toRows();
   Object[][] myArray = get2ArgArrayFromRows( rows );
   return myArray;
 }
origin: asakusafw/asakusafw

private String[][] parse(int columns, String string) {
  CsvConfiguration conf = new CsvConfiguration(
      CsvConfiguration.DEFAULT_CHARSET,
      CsvConfiguration.DEFAULT_HEADER_CELLS,
      CsvConfiguration.DEFAULT_TRUE_FORMAT,
      CsvConfiguration.DEFAULT_FALSE_FORMAT,
      CsvConfiguration.DEFAULT_DATE_FORMAT,
      CsvConfiguration.DEFAULT_DATE_TIME_FORMAT);
  List<String[]> results = new ArrayList<>();
  ByteArrayInputStream input = new ByteArrayInputStream(string.getBytes(conf.getCharset()));
  try (CsvParser parser = new CsvParser(input, string, conf)) {
    StringOption buffer = new StringOption();
    while (parser.next()) {
      String[] line = new String[columns];
      for (int i = 0; i < columns; i++) {
        parser.fill(buffer);
        line[i] = buffer.or((String) null);
      }
      parser.endRecord();
      results.add(line);
    }
  } catch (Exception e) {
    throw new AssertionError(e);
  }
  return results.toArray(new String[results.size()][]);
}
origin: asakusafw/asakusafw

private CsvParser create(String content) {
  CsvConfiguration conf = createConfiguration();
  return new CsvParser(
      new ByteArrayInputStream(content.getBytes(conf.getCharset())),
      testName.getMethodName(),
      conf);
}
origin: asakusafw/asakusafw

private CsvConfiguration createConfiguration() {
  CsvConfiguration conf = new CsvConfiguration(
      CsvConfiguration.DEFAULT_CHARSET,
      headers,
      trueFormat,
      falseFormat,
      dateFormat,
      dateTimeFormat);
  conf.setForceQuoteColumns(quote.stream().mapToInt(i -> i).toArray());
  return conf;
}
origin: stackoverflow.com

CsvConfiguration config = new CsvConfiguration();
config.setFieldDelimiter(',');
return config;
origin: asakusafw/asakusafw

private CsvConfiguration createConfiguration() {
  CsvConfiguration conf = new CsvConfiguration(
      CsvConfiguration.DEFAULT_CHARSET,
      headers,
      trueFormat,
      falseFormat,
      dateFormat,
      dateTimeFormat);
  return conf;
}
origin: asakusafw/asakusafw

/**
 * Simple stress test for {@link DecimalOption} type.
 * @throws Exception if failed
 */
@Test
public void stress_decimal() throws Exception {
  int count = 5000000;
  CsvConfiguration conf = createConfiguration();
  try (RCReader reader = new RCReader("3.141592\r\n".getBytes(conf.getCharset()), count);
      CsvParser parser = new CsvParser(reader, "testing", conf)) {
    int rows = 0;
    DecimalOption date = new DecimalOption();
    while (parser.next()) {
      parser.fill(date);
      parser.endRecord();
      if (rows == 0) {
        assertThat(date, is(new DecimalOption(new BigDecimal("3.141592"))));
      }
      rows++;
    }
    assertThat(rows, is(count));
  }
}
origin: asakusafw/asakusafw-examples

/**
 * Returns this CSV format configuration.
 * @param head whether configure for head of file or not
 * @return CSV format configuration
 */
protected CsvConfiguration getConfiguration(boolean head) {
  List<String> headers = new ArrayList<>();
  if(head) {
    headers.add("カテゴリコード");
    headers.add("販売数量");
    headers.add("売上合計");
  }
  CsvConfiguration config = new CsvConfiguration(Charset.forName("UTF-8"), headers, "true", "false", "yyyy-MM-dd", 
      "yyyy-MM-dd HH:mm:ss");
  config.setLineBreakInValue(false);
  return config;
}
@Override
origin: stackoverflow.com

public static Object[][] getCsvData(File csvFile) {
   CsvConfiguration conf = new CsvConfiguration(1);
   DataContext csvContext = DataContextFactory.createCsvDataContext(
       csvFile, conf);
   Schema schema = csvContext.getDefaultSchema();
   Table[] tables = schema.getTables();
   Table table = tables[0];
   DataSet dataSet = csvContext.query().from(table).selectAll().where("run").eq("Y").execute();
   List<Row> rows = dataSet.toRows();
   Object[][] myArray = new Object[rows.size()][2];
   int i = 0;
   SelectItem[] cols = rows.get(0).getSelectItems();
   for (Row r : rows) {
     Object[] data = r.getValues();
     for (int j = 0; j < cols.length; j++) {
       if (data[j] == null)
         data[j] = ""; // force empty string where there are NULL
                 // values
     }
     myArray[i][0] = cols;
     myArray[i][1] = data;
     i++;
   }
   logger.info("Row count: " + rows.size());
   logger.info("Column names: " + Arrays.toString(cols));
   return myArray;
 }
origin: asakusafw/asakusafw

/**
 * Simple stress test for {@link Date} type.
 * @throws Exception if failed
 */
@Test
public void stress_date() throws Exception {
  int count = 5000000;
  CsvConfiguration conf = createConfiguration();
  try (RCReader reader = new RCReader("1999-12-31\r\n".getBytes(conf.getCharset()), count);
      CsvParser parser = new CsvParser(reader, "testing", conf)) {
    int rows = 0;
    DateOption date = new DateOption();
    while (parser.next()) {
      parser.fill(date);
      parser.endRecord();
      if (rows == 0) {
        assertThat(date, is(new DateOption(new Date(1999, 12, 31))));
      }
      rows++;
    }
    parser.close();
    assertThat(rows, is(count));
  }
}
origin: asakusafw/asakusafw-examples

/**
 * Returns this CSV format configuration.
 * @param head whether configure for head of file or not
 * @return CSV format configuration
 */
protected CsvConfiguration getConfiguration(boolean head) {
  List<String> headers = new ArrayList<>();
  if(head) {
    headers.add("ファイル名");
    headers.add("日時");
    headers.add("店舗コード");
    headers.add("商品コード");
    headers.add("メッセージ");
  }
  CsvConfiguration config = new CsvConfiguration(Charset.forName("UTF-8"), headers, "true", "false", "yyyy-MM-dd", 
      "yyyy-MM-dd HH:mm:ss");
  config.setLineBreakInValue(false);
  return config;
}
@Override
origin: stackoverflow.com

CsvConfiguration conf = new CsvConfiguration( 1 );
DataContext csvContext = DataContextFactory.createCsvDataContext( csvFile, conf );
Schema schema = csvContext.getDefaultSchema();
origin: asakusafw/asakusafw

/**
 * Simple stress test for {@link DateTime} type.
 * @throws Exception if failed
 */
@Test
public void stress_datetime() throws Exception {
  int count = 5000000;
  CsvConfiguration conf = createConfiguration();
  try (RCReader reader = new RCReader("1999-12-31 01:23:45\r\n".getBytes(conf.getCharset()), count);
      CsvParser parser = new CsvParser(reader, "testing", conf)) {
    int rows = 0;
    DateTimeOption date = new DateTimeOption();
    while (parser.next()) {
      parser.fill(date);
      parser.endRecord();
      if (rows == 0) {
        assertThat(date, is(new DateTimeOption(new DateTime(1999, 12, 31, 1, 23, 45))));
      }
      rows++;
    }
    parser.close();
    assertThat(rows, is(count));
  }
}
origin: asakusafw/asakusafw-examples

/**
 * Returns this CSV format configuration.
 * @param head whether configure for head of file or not
 * @return CSV format configuration
 */
protected CsvConfiguration getConfiguration(boolean head) {
  List<String> headers = new ArrayList<>();
  if(head) {
    headers.add("日時");
    headers.add("店舗コード");
    headers.add("商品コード");
    headers.add("数量");
    headers.add("販売単価");
    headers.add("販売金額");
  }
  CsvConfiguration config = new CsvConfiguration(Charset.forName("UTF-8"), headers, "true", "false", "yyyy-MM-dd", 
      "yyyy-MM-dd HH:mm:ss");
  config.setLineBreakInValue(false);
  return config;
}
@Override
origin: asakusafw/asakusafw-examples

/**
 * Returns this CSV format configuration.
 * @param head whether configure for head of file or not
 * @return CSV format configuration
 */
protected CsvConfiguration getConfiguration(boolean head) {
  List<String> headers = new ArrayList<>();
  if(head) {
    headers.add("商品コード");
    headers.add("商品名");
    headers.add("部門コード");
    headers.add("部門名");
    headers.add("カテゴリコード");
    headers.add("カテゴリ名");
    headers.add("単価");
    headers.add("登録日");
    headers.add("適用開始日");
    headers.add("適用終了日");
  }
  CsvConfiguration config = new CsvConfiguration(Charset.forName("UTF-8"), headers, "true", "false", "yyyy-MM-dd", 
      "yyyy-MM-dd HH:mm:ss");
  config.setLineBreakInValue(false);
  return config;
}
@Override
com.asakusafw.runtime.io.csvCsvConfiguration

Javadoc

CSV configurations.

Most used methods

  • <init>
    Creates a new instance.
  • getCharset
    Returns the character set encoding name.
  • getDateFormat
    The Date format in SimpleDateFormat.
  • getDateTimeFormat
    The DateTime format in SimpleDateFormat.
  • getFalseFormat
    The boolean false format.
  • getForceQuoteColumns
    Returns column indices which quoting is always required.
  • getHeaderCells
    The header cell values.
  • getSeparatorChar
    Returns the field separator character.
  • getTrueFormat
    The boolean true format.
  • isForceConsumeHeader
    Returns whether forcibly consumes header cells or not.
  • isLineBreakInValue
    Returns whether allows line breaks in value.
  • setDefaultQuoteMode
  • isLineBreakInValue,
  • setDefaultQuoteMode,
  • setFieldDelimiter,
  • setForceQuoteColumns,
  • setLineBreakInValue

Popular in Java

  • Making http requests using okhttp
  • findViewById (Activity)
  • getApplicationContext (Context)
  • orElseThrow (Optional)
  • InputStream (java.io)
    A readable source of bytes.Most clients will use input streams that read data from the file system (
  • Socket (java.net)
    Provides a client-side TCP socket.
  • Charset (java.nio.charset)
    A charset is a named mapping between Unicode characters and byte sequences. Every Charset can decode
  • Arrays (java.util)
    This class contains various methods for manipulating arrays (such as sorting and searching). This cl
  • Pattern (java.util.regex)
    A compiled representation of a regular expression. A regular expression, specified as a string, must
  • JList (javax.swing)
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now