public void writeEnvToCsv(int customerId, ZipOutputStream zos, List<SummaryDetailsResponse> summaryDetailsResponseList, QueryHelper queryHelper) {
//Headers size = size(No of distinct entities) * 2 + 1
final CsvWriter writer = new CsvWriter(new OutputStreamWriter(zos), new CsvWriterSettings());
final String[] headers = new String[summaryDetailsResponseList.get(0).getEntities().size() * 2 + 1];
String header;
int index = 0, i, k;
headers[index++] = Entities;
for (i = 0; i < summaryDetailsResponseList.get(0).getEntities().size(); i++) {
header = summaryDetailsResponseList.get(0).getEntities().get(i).getEntityType();
if (valueMap.get(header) != null) {
header = valueMap.get(header);
}
headers[index++] = header + " " + Count;
headers[index++] = header + "(s)";
}
writer.writeHeaders(headers);
for (index = 0; index < summaryDetailsResponseList.size(); index++) {
final String[] values = new String[summaryDetailsResponseList.get(index).getEntities().size() * 2 + 1];
i = 0;
k = 0;
values[i++] = summaryDetailsResponseList.get(index).getRecordName();
for (; i <= summaryDetailsResponseList.get(index).getEntities().size() * 2; ) {
values[i++] = String.valueOf(summaryDetailsResponseList.get(index).getEntities().get(k).getEntityData().get(0).getTotal());
try {
StringBuilder strConcat = new StringBuilder();
List<String> hostNames = queryHelper.getHostNames(customerId,
String.valueOf(summaryDetailsResponseList.get(index).getEntities().get(k).getEntityData().get(0).getQuery()));
for (String host : hostNames) {
if (strConcat.toString().equals(""))
strConcat.append(host);
else
strConcat.append(", ").append(host);
}
values[i++] = strConcat.toString();
} catch (Exception e) {
e.printStackTrace();
}
k++;
}
writer.writeRow(CSVUtils.escapeCSVRow(values));
}
writer.flush();
}
Basically I want to write UT to verify this function. Can we verify the CSVWriter that it has written correct data for headers and rows or ZipOutputStream in any way.
I was able to verify the records writer has written if I pass writer to the function instead of creating it inside the function but I don't want to do this.
I have a need to display large text files. Display text without the need to scroll as an e-book. I can break a long text on the page, but it takes me too much time. For example - the following code handles 1.4 MB of text for about 10-15 seconds.
public void split(TextPaint textPaint, String filepath,Context context) {
int pages = 0;
File file = new File(filepath);
char[] bufferChar = new char[1024];
String uncompletedtext="";
//How lines we can show
int maxLinesOnpage = 0;
StaticLayout staticLayout = new StaticLayout(
context.getString(R.string.lorem_ipsum),
textPaint,
pageWidth,
Layout.Alignment.ALIGN_NORMAL,
lineSpacingMultiplier,
lineSpacingExtra,
false
);
int startLineTop = staticLayout.getLineTop(0);
int endLine = staticLayout.getLineForVertical(startLineTop + pageHeight);
int endLineBottom = staticLayout.getLineBottom(endLine);
if (endLineBottom > startLineTop + pageHeight) {
maxLinesOnpage = endLine - 1;
} else {
maxLinesOnpage = endLine;
}
//let's paginate
try {
BufferedReader buffer = new BufferedReader(new FileReader(file));
while (buffer.read(bufferChar)>=0) {
uncompletedtext += new String(bufferChar);
boolean allcomplete = false;
staticLayout = new StaticLayout(
uncompletedtext,
textPaint,
pageWidth,
Layout.Alignment.ALIGN_NORMAL,
lineSpacingMultiplier,
lineSpacingExtra,
false
);
staticLayout.getLineCount();
int curTextPages= (int) Math.floor(staticLayout.getLineCount() / maxLinesOnpage);
uncompletedtext=uncompletedtext.substring(staticLayout.getLineEnd(curTextPages));
pages+=curTextPages;
Log.e("PAGES","" + pages);
}
} catch (Exception e) {
e.printStackTrace();
}
Log.e("FILE READED FULLY!!", "READ COMPLETE!!!!!!!!!!!!!!!!");
}
It is too long. I can not understand how applications such as FBReader and СoolReader handle large files (More than 9 MB) instantly.
I saw the source of the applications, but they have too much functionality to quickly find answer.
I really need help and tips. Thanks.
Thanks to all! I find solution! Not elegant but very fast code (10Mb ~ 600 ms)
public void split(TextPaint textPaint, String filepath,Context context) {
File file = new File(filepath);
char[] bufferChar = new char[512];
//How lines on page
int maxLinesOnpage = 0;
int symbolsOnLine = 0;
StaticLayout staticLayout = new StaticLayout(
context.getString(R.string.lorem_ipsum),//short text with 100 lines (\r\n\r\n\r\n\r\n\r\n\r\n)
textPaint, //MONOSPACE!!!
pageWidth,
Layout.Alignment.ALIGN_NORMAL,
lineSpacingMultiplier,
lineSpacingExtra,
false
);
int startLineTop = staticLayout.getLineTop(0);
int endLine = staticLayout.getLineForVertical(startLineTop + pageHeight);
int endLineBottom = staticLayout.getLineBottom(endLine);
if (endLineBottom > startLineTop + pageHeight) {
maxLinesOnpage = endLine - 1;
} else {
maxLinesOnpage = endLine;
}
symbolsOnLine = staticLayout.getLineEnd(0);
try {
RandomAccessFile rac = new RandomAccessFile(file, "r");
byte[] buffer = new byte[2048];
int wordLen = 0; //Length of word in symbols
int wordInBytes = 0; //Lenght of word
int startLinePos = 0; //Start first line position
int lineWidth = 0; //Current line length
int totalLines =0; //Total lines on current page
Log.e("Start pagination", "" + totalLines);
long timeout= System.currentTimeMillis();
int buflen=0; //buffer size
int totalReadedBytes = 0; //Total bytes readed
byte skipBytes = 0;
while ( (buflen=rac.read(buffer))!=-1){
for (int i=0;i<buflen;i++) {
totalReadedBytes++;
wordInBytes++;
if (skipBytes==0){ //Bytes on one symbol
if (unsignedToBytes(buffer[i])>=192){skipBytes=2;}
if (unsignedToBytes(buffer[i])>=224){skipBytes=3;}
if (unsignedToBytes(buffer[i])>=240){skipBytes=4;}
if (unsignedToBytes(buffer[i])>=248){skipBytes=5;}
if (unsignedToBytes(buffer[i])>=252){skipBytes=6;}
}
//Full bytes on symbol or not
if (skipBytes>0){
skipBytes--;
if (skipBytes>0){continue;}
}
if (buffer[i] == 13) {//We have a \r symbol. Ignore.
continue;
}
if (buffer[i]==10){//New line symbol
if (lineWidth + wordLen>symbolsOnLine){
totalLines++;
if (totalLines > maxLinesOnpage) {
int[] pgsbytes = {startLinePos, totalReadedBytes};
pages.add(pgsbytes);
startLinePos = totalReadedBytes ;
totalLines = 0;
}
}
wordLen=0;
wordInBytes=0;
totalLines++;
lineWidth=0;
if (totalLines>maxLinesOnpage){
int[] pgsbytes = {startLinePos, totalReadedBytes-1};
pages.add(pgsbytes);
startLinePos = totalReadedBytes-1;
totalLines=0;
}
}
if (buffer[i]==32){//Space symbol
if (lineWidth + wordLen+1<=symbolsOnLine){//Word fits in line
lineWidth+=wordLen + 1;
wordLen=0;
if (lineWidth==symbolsOnLine){
totalLines++;
if (totalLines > maxLinesOnpage) {
int[] pgsbytes = {startLinePos, totalReadedBytes};
pages.add(pgsbytes);
startLinePos = totalReadedBytes ;
totalLines = 0;
}
lineWidth = 0;
wordLen = 0;
wordInBytes=0;
}
} else {
if (lineWidth + wordLen==symbolsOnLine){
totalLines++;
if (totalLines > maxLinesOnpage) {
int[] pgsbytes = {startLinePos, totalReadedBytes};
pages.add(pgsbytes);
startLinePos = totalReadedBytes ;
totalLines = 0;
}
lineWidth = 0;
wordLen = 0;
wordInBytes=0;
} else {
totalLines++;
if (totalLines > maxLinesOnpage) {
int[] pgsbytes = {startLinePos, totalReadedBytes - 1 - wordInBytes};
pages.add(pgsbytes);
startLinePos = totalReadedBytes - 1;
totalLines = 0;
}
lineWidth = wordLen + 1;
wordLen = 0;
wordInBytes=0;
}
}
}
if (buffer[i]!=32&&buffer[i]!=10&&buffer[i]!=13){wordLen++; }
if (wordLen==symbolsOnLine){
totalLines++;
if (totalLines>maxLinesOnpage){
int[] pgsbytes = {startLinePos, totalReadedBytes-1 - wordInBytes};
pages.add(pgsbytes);
startLinePos = totalReadedBytes-1;
totalLines=0;
}
lineWidth=0;
wordLen=0;
wordInBytes=0;
}
}
}
rac.close();
timeout = System.currentTimeMillis() - timeout;
Log.e("TOTAL Time", " time " + timeout + "ms");
} catch (Exception e) {
e.printStackTrace();
}
Log.e("FILE READED FULLY!!", "READ COMPLETE!!!!!!!!!!!!!!!!");
}
So I was wondering how I can actively change the color of keywords in the java text pane. I understand a document listener is will have to be used, but at the moment it doesn't seem to be working, in fact putting it in the document listener leads to me not being able to properly open a file or color at all. So how can I actively call a method that changes color of keywords in java. This is the code that will search for keywords and it works when I open files, just not actively.
public void findKeyWords(String directory) throws FileNotFoundException
{
final StyleContext cont = StyleContext.getDefaultStyleContext();
final AttributeSet jKeyWord = cont.addAttribute(cont.getEmptySet(),
StyleConstants.Foreground,Color.RED);
final AttributeSet jOperator = cont.addAttribute(cont.getEmptySet(),
StyleConstants.Foreground,Color.MAGENTA);
final AttributeSet jtypes = cont.addAttribute(cont.getEmptySet(),
StyleConstants.Foreground,Color.CYAN);
ArrayList<String> words = loadKeyWords(directory);
for (String line : words)
{
searchJava(line,jKeyWord);
}
ArrayList<String> operators = loadOperators(directory);
for (String line : operators)
{
searchJava(line, jOperator);
}
ArrayList<String> types1 = loadTypes(directory);
for (String line : types1)
{
searchJava(line, jtypes);
}
}
private ArrayList<String> loadKeyWords(String directory) throws FileNotFoundException
{
ArrayList<String> javaWords = new ArrayList<String>();
final String dir = System.getProperty("user.dir");
File file = new File(dir + "/" + directory + "/keywords.txt");
Scanner scan = new Scanner(file);
while(scan.hasNext())
{
javaWords.add(scan.next() + " ");
}
scan.close();
return javaWords;
}
private ArrayList<String> loadOperators(String directory) throws FileNotFoundException
{
ArrayList<String> javaWords = new ArrayList<String>();
final String dir = System.getProperty("user.dir");
File file = new File(dir + "/" + directory + "/operators.txt");
Scanner scan = new Scanner(file);
while(scan.hasNext())
{
javaWords.add(scan.next());
}
scan.close();
return javaWords;
}
private ArrayList<String> loadTypes(String directory) throws FileNotFoundException
{
ArrayList<String> javaWords = new ArrayList<String>();
final String dir = System.getProperty("user.dir");
File file = new File(dir + "/" + directory + "/types.txt");
Scanner scan = new Scanner(file);
while(scan.hasNext())
{
javaWords.add(" " + scan.next());
}
scan.close();
return javaWords;
}
public void searchJava(String wordToSearch, AttributeSet javaAttr)
{
final AttributeSet attr = javaAttr;
Document text = textArea.getDocument();
int m;
int t;
int total = 0;
for (String line : textArea.getText().split("\n"))
{
m = line.indexOf(wordToSearch);
if(m == -1)
{
if(isUnix())
{
total += line.length() + 1;
}
else if(isWindows())
{
total += line.length();
}
else if(isMac())
{
total += line.length() + 1;
}
else
{
total += line.length() + 1;
}
continue;
}
try{
text.remove(total + m, wordToSearch.length());
text.insertString(total + m, wordToSearch, attr);
}catch(BadLocationException ex)
{}
while(true)
{
m = line.indexOf(wordToSearch, m + 1 );
if (m == -1)
{
break;
}
try
{
text.remove(total + m, wordToSearch.length());
text.insertString(total + m, wordToSearch, attr);
}catch(BadLocationException e)
{
}
}
if(isUnix())
{
total += line.length() + 1;
}
else if(isWindows())
{
total += line.length();
}
else if(isMac())
{
total += line.length() + 1;
}
else
{
JOptionPane.showMessageDialog(null, "Eric You Troll" );
total += line.length() + 1;
}
}
}
I wrote this program that goes through every line and try to find particular data and then based on that, find the specific xml file and extract the data and upload it on the excel sheet. The excel sheet is about 90,000 lines so I can understand why the code maybe slow. But it seems to be too slow, it updates about 5000 lines in 1 hour, and for 90,000 lines; it will take forever.
I uploaded xml beans and gave -Xmx to be 2048m, so its not a memory issue. When I changed the parameter to be 1 to 100, it did updated; so I know for sure that the code is working, but its just too slow.
Any suggestions?
import java.util.*;
import java.io.*;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class XMLRead {
public static void main(String[] Args) throws Exception{
FileInputStream fis = new FileInputStream(new File("C:/Desktop/TestECG.xlsx"));
XSSFWorkbook workbook = new XSSFWorkbook (fis);
XSSFSheet sheet = workbook.getSheet("ecg");
for (int i = 1; i <= 91332; i++){
if(sheet.getRow(i).getCell(2) == sheet.getRow(i-1).getCell(2) && sheet.getRow(i).getCell(15) == sheet.getRow(i-1).getCell(15) && sheet.getRow(i).getCell(16) == sheet.getRow(i-1).getCell(16)) {
XSSFCell lame = sheet.getRow(i-1).getCell(19);
String lamer = lame.toString();
sheet.getRow(i).getCell(19).setCellValue(lamer);
}
else{
XSSFCell TimeCell = sheet.getRow(i).getCell(16);
String TimeString = TimeCell.toString();
String gettime[] = TimeString.split(":");
String TimeHour = gettime[0];
String TimeMinute = gettime[1];
String TimeSecond = gettime[2];
XSSFCell DateCell = sheet.getRow(i).getCell(15);
String DateString = DateCell.toString();
String DateYear = DateString.substring(5, 9);
String TempDateMonth = DateString.substring(2,5);
String DateMonth = "";
if (TempDateMonth.equals("Jan")){
DateMonth = "01";
}
else if (TempDateMonth.equals("Feb")){
DateMonth = "02";
}
else if (TempDateMonth.equals("Mar")){
DateMonth = "03";
}
else if (TempDateMonth.equals("Apr")){
DateMonth = "04";
}
else if (TempDateMonth.equals("May")){
DateMonth = "05";
}
else if (TempDateMonth.equals("Jun")){
DateMonth = "06";
}
else if (TempDateMonth.equals("Jul")){
DateMonth = "07";
}
else if (TempDateMonth.equals("Aug")){
DateMonth = "08";
}
else if (TempDateMonth.equals("Sep")){
DateMonth = "09";
}
else if (TempDateMonth.equals("Oct")){
DateMonth = "10";
}
else if (TempDateMonth.equals("Nov")){
DateMonth = "11";
}
else if (TempDateMonth.equals("Dec")){
DateMonth = "12";
}
String DateDay = "";
String TempDateDay = DateString.substring(0, 2);
if (Integer.parseInt(TempDateDay.trim())< 10){
DateDay = "0" + TempDateDay;
}
else if (Integer.parseInt(TempDateDay.trim()) >= 10){
DateDay = TempDateDay;
}
String CombineLowValue = DateYear + DateMonth + DateDay + TimeHour + TimeMinute + TimeSecond;
XSSFCell SubjIDCell = sheet.getRow(i).getCell(2);
String SUBID = SubjIDCell.toString();
File ECGDirectory = new File("C:/Users/ahmeda/Documents/ECG/");
String[] names = ECGDirectory.list();
String RightXML = null;
String getTheName = null;
searchloop: for(String name: names){
if (new File("C:/Documents/ECG/" + name).isDirectory())
{
RightXML = ListFiles("C:/Documents/ECG/" + name + "/",SUBID, CombineLowValue);
if (RightXML != null){
getTheName = name;
break searchloop;
}
}
}
if(getTheName != null && RightXML != null){
File readXMLfile = new File("C:/Users/ahmeda/Documents/ECG/" + getTheName + "/" + RightXML);
Scanner read = new Scanner(readXMLfile);
int onlyoneIDroot = 0;
int onlyonelowvalue = 0;
int onlyoneidextension = 0;
String searchidroot = "id root";
String searchlowvalue = "low value";
String searchidextension = "id extension";
while (read.hasNextLine()){
String readline = read.nextLine();
if (readline.indexOf(searchidroot.toLowerCase()) != -1 && onlyoneIDroot != 1){
String getid[] = readline.split("=");
String almost[] = getid[1].split("\"");
searchidroot = almost[1];
onlyoneIDroot++;
}
else if (readline.indexOf(searchlowvalue.toLowerCase()) != -1 && onlyonelowvalue != 1){
String getid[] = readline.split("=");
String almost[] = getid[1].split("\"");
searchlowvalue = almost[1];
onlyonelowvalue++;
}
else if (readline.indexOf(searchidextension.toLowerCase()) != -1 && onlyoneidextension != 1){
String getid[] = readline.split("=");
String almost[] = getid[1].split("\"");
searchidextension = almost[1];
onlyoneidextension++;
}
}
if(SUBID.equals(searchidextension) && CombineLowValue.equals(searchlowvalue)){
sheet.getRow(i).getCell(19).setCellValue(searchidroot);
System.out.println("I am right here, just to see if this is even working.");
}
read.close();
}
}
}
fis.close();
FileOutputStream fos =new FileOutputStream(new File("C:/Users/ahmeda/Desktop/TestECG.xlsx"));
workbook.write(fos);
workbook.close();
fos.close();
System.out.println("Done");
}
static String ListFiles(String file, String ID, String LowValue) {
String files = null;
File folder = new File(file);
File[] listOfFiles = folder.listFiles();
//int x = 0;
for (int i = 0; i < listOfFiles.length; i++) {
if (listOfFiles[i].isFile()) {
String getDate[] = listOfFiles[i].getName().split("_");
String getID = getDate[2].substring(0,4);
//System.out.println(listOfFiles[i].getName().split("_"));
//System.out.println(getDate[2]);
/*System.out.println(getID);
System.out.println(ID);
System.out.println(getDate[3]);
System.out.println(LowValue);*/
if(getID.equals(ID) && getDate[3].equals(LowValue)){
files = listOfFiles[i].getName();
//System.out.println(files);
return files;
}
}
}
return files;
}
}
Below is the code which converts the .sql file for insert statements into .tbl file. As the input file is .sql file it contains varchar(string) values inside single quotes. How can I prevent these quotes from getting in my tbl file?
Input:
INSERT INTO
post_tran(post_tran_id,tran_nr,datetime_tran_local,system_trace_audit_nr,settle_
amount_rsp,settle_tran_fee_rsp,post_tran_cust_id,prev_post_tran_id,next_post_tra
n_id,message_type,tran_postilion_originated,sink_node_name,settle_entity_id,batc
h_nr,tran_completed,tran_type,rsp_code_rsp,auth_type,auth_reason,retrieval_refer
ence_nr,settle_amount_req,settle_tran_fee_req,settle_currency_code,datetime_req,
recon_business_date,realtime_business_date,acquiring_inst_id_code) VALUES(
1,2,'2002-04-02 19:02:28','008497',4120,10, 2, 0,0,'0200', 0, 'LinkSink',
1,1,0,'01','01','00',0,'000000000102',6000,0,'840', '', '2004-02-11
12:00:00', '2004-02-11 12:00:00', '2200017000')
For example:
While processing sink_node_name, its data value should be LinkSink instead of 'LinkSink'.
public class SqlToTblCoverter {
private File source_folder = null;
private File destination_folder = null;
private String source_absolute_path = null;
private String destination_absolute_path = null;
private String absolute_file_name = null;
private String absolute_new_file_name = null;
private List<String> column_name_list = null;
private List<String> column_values_list = null;
public SqlToTblCoverter(String source_folder_name,
String destination_folder_name) {
source_folder = new File(source_folder_name);
destination_folder = new File(destination_folder_name);
source_absolute_path = source_folder.getAbsolutePath();
destination_absolute_path = destination_folder.getAbsolutePath();
column_name_list = new ArrayList<String>();
column_values_list = new ArrayList<String>();
}
public void run() throws IOException {
validateInputs();
migrateFiles();
}
private void validateInputs() {
if (source_folder.isDirectory() == false) {
System.out.println("Source must be a FOLDER");
} else if (destination_folder.isDirectory() == false) {
System.out.println("Destination must be a FOLDER");
}
}
private void migrateFiles() throws IOException {
String[] file_list = source_folder.list();
String file_name1 = file_list[0];
// System.out.println(file_name1);
String file_name2 = file_list[1];
// System.out.println(file_name2);
String f1 = migrateFileContains(file_name1);
String f2 = migrateFileContains(file_name2);
Migrator mg = new Migrator();
mg.migrate(f1, f2);
}
private String migrateFileContains(String file_name) throws IOException {
absolute_file_name = source_absolute_path + File.separator + file_name;
absolute_new_file_name = destination_absolute_path + File.separator
+ getNewFileName(file_name);
BufferedReader br = new BufferedReader(new InputStreamReader(
new FileInputStream(new File(absolute_file_name))));
String line_info = br.readLine();
StringBuffer new_query = new StringBuffer("");
FileWriter fw = new FileWriter(new File(absolute_new_file_name));
while (line_info != null) {
String convertQuery = convertQuery(line_info);
if (convertQuery.isEmpty()) {
line_info = br.readLine();
continue;
}
new_query.append(convertQuery);
new_query.append(System.getProperty("line.separator"));
fw.write(new_query.toString());
new_query.setLength(0);
line_info = br.readLine();
}
br.close();
fw.close();
return absolute_new_file_name;
}
private String convertQuery(String query) {
String new_query = "";
if (query.startsWith("INSERT")) {
int round_bracket_start = query.indexOf('(');
int round_bracket_end = query.indexOf(')');
int round_bracket_start_after_values = query.indexOf('(',
round_bracket_end);
String query_column_name = query.substring(round_bracket_start + 1,
round_bracket_end);
String query_column_values = query.substring(
round_bracket_start_after_values + 1, query.length() - 1);
covertColumnNameList(query_column_name);
covertColumnValueList(',' + query_column_values + ',');
new_query = createNewQuery() + "\n";
}
column_name_list.clear();
column_values_list.clear();
return new_query;
}
private void covertColumnNameList(String query_column_name) {
String[] column_list = query_column_name.split(",");
for (String column_name : column_list) {
column_name_list.add(column_name);
}
}
private void covertColumnValueList(String query_column_values) {
if (query_column_values.equals(",")) {
return;
}
String column_value = null;
int comma_index = query_column_values.indexOf(',');
int next_comma_index = 0;
if (query_column_values.charAt(comma_index + 1) == '\'') {
int quote_index = query_column_values.indexOf('\'', comma_index);
int next_quote_index = query_column_values.indexOf('\'',
quote_index + 1);
next_comma_index = query_column_values.indexOf(',',
next_quote_index);
column_value = query_column_values.substring(comma_index + 2,
next_comma_index - 1);
} else {
next_comma_index = query_column_values
.indexOf(',', comma_index + 1);
column_value = query_column_values.substring(comma_index + 1,
next_comma_index);
}
column_values_list.add(column_value);
covertColumnValueList(query_column_values.substring(next_comma_index));
}
private String createNewQuery() {
StringBuffer buffer = new StringBuffer("");
if (column_name_list.size() != column_values_list.size()) {
System.out.println("Error : " + absolute_file_name);
} else {
for (int index = 0; index < column_name_list.size(); index++) {
buffer.append(createNewColumn(column_name_list.get(index),
column_values_list.get(index)));
}
}
return buffer.toString();
}
private String createNewColumn(String column_name, String column_value) {
StringBuffer buffer = new StringBuffer("");
buffer.append("[name]".trim());
buffer.append(column_name.trim());
buffer.append("[/name]=[data]".trim());
buffer.append(column_value.trim());
buffer.append("[/data]".trim());
buffer.append("\r\n");
return buffer.toString();
}
private String getNewFileName(String file_name) {
String new_file_name = "";
int dot_index = file_name.indexOf('.');
new_file_name = file_name.subSequence(0, dot_index) + ".tbl";
return new_file_name;
}
}
You can replace covertColumnValueList with below code:
private void covertColumnValueList(String query_column_values) {
String temp_val = null;
for (String col_val : query_column_values.split(",")) {
if (col_val.contains("\'")) {
temp_val = col_val.replaceAll("\'", "");
column_values_list.add(temp_val.trim());
} else
column_values_list.add(col_val.trim());
}
}
I assume you have query_column_values something like below:
String query_column_values = "1,2,'2002-04-02 19:02:28','008497',4120,10, 2, 0,0,'0200', 0, 'LinkSink', 1,1,0,'01','01','00',0,'000000000102',6000,0,'840', '', '2004-02-11 12:00:00', '2004-02-11 12:00:00', '2200017000'";
replace '' by current date: Once you populate this list, replace list value at specified index.
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Calendar cal = Calendar.getInstance();
column_values_list.set( 23, dateFormat.format(cal.getTime()));
The code to remove the delimiting apostrophes is there in covertColumnValueList, but it doesn't handle the case where a space precedes the apostroph. See the simple fix below.
//....
int next_comma_index = 0;
// skip space(s)
while( query_column_values.charAt(comma_index + 1) == ' ' ){
comma_index++;
}
if (query_column_values.charAt(comma_index + 1) == '\'') {
//...
private void covertColumnValueList(String query_column_values) {
if (query_column_values.equals(",")) {
return;
}
String column_value = null;
int comma_index = query_column_values.indexOf(',');
int next_comma_index = 0;
if (query_column_values.charAt(comma_index + 1) == '\'') {
int quote_index = query_column_values.indexOf('\'', comma_index);
int next_quote_index = query_column_values.indexOf('\'',
quote_index + 1);
next_comma_index = query_column_values.indexOf(',',
next_quote_index);
column_value = query_column_values.substring(comma_index + 2,
next_comma_index - 1);
column_value=column_value.replace("\'","") ;
} else {
next_comma_index = query_column_values
.indexOf(',', comma_index + 1);
column_value = query_column_values.substring(comma_index + 1,
next_comma_index);
column_value=column_value.replace("\'","") ;
}
column_values_list.add(column_value);
covertColumnValueList(query_column_values.substring(next_comma_index));
}