Created
April 14, 2016 07:34
-
-
Save yusuke/00c04018cf6b007784024f4dac00a031 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright 2015 Yusuke Yamamoto | |
* | |
* Licensed under the Apache License,Version2.0(the"License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing,software | |
* Distributed under the License is distributed on an"AS IS"BASIS, | |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,either express or implied. | |
* See the License for the specific language governing permissions and | |
* limitations under the License. | |
*/ | |
package samuraism.core.keiri.bizstation; | |
import au.com.bytecode.opencsv.CSVReader; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
import java.io.*; | |
import java.text.ParseException; | |
public abstract class CSVProcess { | |
private Logger logger = LoggerFactory.getLogger(CSVProcess.class); | |
String path; | |
protected int lineNum = 0; | |
public CSVProcess(String in) throws FileNotFoundException, UnsupportedEncodingException { | |
this.path = in; | |
} | |
public void process(boolean discardFirstLine) throws IOException, ParseException { | |
String pathname = System.getProperty("user.home") + File.separator + path; | |
File file = new File(pathname); | |
InputStream in; | |
logger.info("ファイルパス:"+pathname); | |
if (file.exists()) { | |
logger.info("CSV読み込み:"+pathname); | |
in = new FileInputStream(file); | |
} else { | |
logger.info("リソース読み込み:"+path); | |
in = CSVYayoiProcess.class.getResourceAsStream(path); | |
} | |
CSVReader reader = new au.com.bytecode.opencsv.CSVReader(new BufferedReader(new InputStreamReader(in, "Shift_JIS"))); | |
// discard first line | |
if (discardFirstLine) { | |
reader.readNext(); | |
} | |
String[] line; | |
while ((line = reader.readNext()) != null) { | |
lineNum++; | |
// if (!line[1].equals("")) { | |
processLine(line); | |
// } | |
} | |
reader.close(); | |
processed(); | |
} | |
abstract void processLine(String[] line) throws IOException, ParseException; | |
abstract void processed() throws IOException; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment