風車のデモCSV分析枠組み

CSVファイルは、最初の行はヘッダであり、以下の

 

 次のように解析するコードは次のとおりです。

パッケージcom.netmarch。

輸入lombok.Data。
輸入org.apache.commons.lang3.builder.ToStringBuilder。


@data 
パブリック クラスCodecRegistries {
     プライベート文字列のインデックス。
    プライベート文字列名;
    / ** 
     * WAVE形式登録番号
     * / 
    プライベート整数進。
    / ** * 
     *コーデックID IANA名前空間で
     * / 
    プライベート文字列のMIMEタイプ。

    / ** * 
     * WAVE形式wFormatTag ID 
     * / 
    プライベート文字列wFormatTag。

    / ** * 
     * WAVEFORMATを使用
     * / 
    プライベート文字列の使用; 

    / ** * 
     * WAVEFORMAT名前
     * / 
    プライベート文字列FORMATNAME。

    / ** * 
     * WAVEFORMAT説明
     * / 
    プライベート文字列DESCR。

    / ** * 
     *追加情報
     * / 
    プライベート文字列の追加。

    / ** * 
     * 
     * / 
    プライベート文字列の接触; 

    @Override 
    公共の文字列のtoString(){
         返す 新しい ToStringBuilder(この
                .append( "インデックス"、インデックス)
                .append( "名称" 、名)
                .append( "進" 、六角)
                .append( "MIMEタイプ" 、MIMEタイプ)
                .append( "wFormatTag" 、wFormatTag)
                .append( "使用" 、使用)
                .append(「FORMATNAME " 、FORMATNAME)
                .append( "DESCR" 、DESCR)
                .append( "追加" 、追加の)
                .append( "接触" 、接点)
                .toString();
    } 
}
静的な地図<整数、CodecRegistries>コード= 新しい HashMapの<> (); 
   
 静的 ボイドreadCodeRegistries(文字列filename)
    { 
        試みる(InputStream InputStreamは= 新しいFileInputStreamを(filename)で){ 

            FileSource源 = FileSource.of(InputStreamを)。

            CsvParserConfigコンフィグ = CsvParserConfig.builder()
                    .charset(StandardCharsets.UTF_8)
                    .build(); 

            地図 <整数、CodecRegistries>マップ= Windmill.parse(ソース、Parsers.csv(設定))スキップ(1).MAP(行- > { 
                CodecRegistries登録= 新新CodecRegistries(); 

                registration.setIndex(row.cell( 0 ).asString()); 
                registration.setName(row.cell( 1。).asStringは()); 
          //カスタムデータは、に16をトランスコードこれは、0x0001の整数数値システムに番号を変換する
                整数ヘクス = 新しい新しい( - > row.cell(2).asString()、hexDecimal NumberValue <整数> Integer.decode(hexDecimal))値();. 

                registration.setHex(16進数) ; 
                registration.setMimeType(row.cell( 3 ).asString()); 
                registration.setWFormatTag(row.cell( 4。 5。).asString())。
                registration.setUse(row.cell(
        }).asString())。
                registration.setFormatName(row.cell( 6 ).asString())。
                registration.setDescr(row.cell( 7 ).asString())。
                registration.setAdditional(row.cell( 8 ).asString())。
                registration.setContact(row.cell( 9 ).asString())。
                戻り値の登録; 

            。}))(Collectors.toMap(CodecRegistries :: getHex、Function.identity())を集めます。
            codes.putAll(マップ)
        } キャッチ(IOExceptionを電子){ 
            System.err.println(E); 
    }

 

おすすめ

転載: www.cnblogs.com/passedbylove/p/11444562.html