Page MenuHomec4science

Reader.java
No OneTemporary

File Metadata

Created
Wed, Jan 8, 21:44

Reader.java

package io.bim;
import java.awt.Color;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.sql.SQLException;
import javax.swing.JTextPane;
import javax.swing.text.BadLocationException;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;
import database.DBconnector_client;
public class Reader implements Runnable {
private File input_f;
private BufferedReader br;
private DBconnector_client conn_mu;
private String path;
private JTextPane tp;
private StyledDocument doc;
public Reader(String bim_file_path, JTextPane txp){
path = bim_file_path;
conn_mu = new DBconnector_client();
tp = txp;
doc = tp.getStyledDocument();
}
@Override
public void run() {
try{
//check extension file
String[] pathCheck = path.split("\\.");
if(!pathCheck[pathCheck.length-1].equalsIgnoreCase("bim")) {
throw new IOException("Wrong Format for BIM File!");
}
SimpleAttributeSet attribute = new SimpleAttributeSet();
StyleConstants.setForeground(attribute, Color.BLACK);
try {
doc.insertString(doc.getLength(), "BIM file parsing, please wait..." + "\n", attribute);
} catch (BadLocationException e1) {
e1.printStackTrace();
}
input_f = new File(path);
br = new BufferedReader(new FileReader(input_f));
String newline;
long start = System.currentTimeMillis();
while((newline = br.readLine()) != null ){
String[] tokens = newline.split("\t");
conn_mu.insertMarker(tokens[1], tokens[4], tokens[5], Integer.parseInt(tokens[3]), -1, tokens[0]);
}
long end = System.currentTimeMillis();
try {
doc.insertString(doc.getLength(), "BIM file parsing completed!" + "\n\n", attribute);
doc.insertString(doc.getLength(), (end-start) + " ms\n", attribute);
} catch (BadLocationException e1) {
e1.printStackTrace();
}
}catch(IOException | SQLException e){
e.printStackTrace();
SimpleAttributeSet error = new SimpleAttributeSet();
StyleConstants.setForeground(error, Color.RED);
try {
doc.insertString(doc.getLength(), e.getMessage() + "\n", error);
} catch (BadLocationException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
}

Event Timeline