![JAR search and dependency download from the Maven repository](/logo.png)
org.kawanfw.sql.servlet.sql.CallableStatementHolderListReader Maven / Gradle / Ivy
/*
* This file is part of AceQL.
* AceQL: Remote JDBC access over HTTP.
* Copyright (C) 2015, KawanSoft SAS
* (http://www.kawansoft.com). All rights reserved.
*
* AceQL is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* AceQL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA
*
* Any modifications to this file must keep this entire header
* intact.
*/
package org.kawanfw.sql.servlet.sql;
/**
* @author Alexandre Becquereau
*/
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import org.apache.commons.io.IOUtils;
import org.kawanfw.commons.api.server.CommonsConfigurator;
import org.kawanfw.commons.util.HtmlConverter;
import org.kawanfw.sql.json.no_obfuscation.CallableStatementHolder;
import org.kawanfw.sql.json.no_obfuscation.CallableStatementHolderTransport;
import org.kawanfw.sql.util.crypto.CallableStatementHolderCrypto;
public class CallableStatementHolderListReader {
/** The reader of the file */
private BufferedReader bufferedReader;
/** the user commons configurator, for decryption if necessary */
private CommonsConfigurator commonsConfigurator;
/** The file corresponfing to the reader */
private File file;
/**
* Read a file containing a list of Statement
*
* @param file
* the file containing the statements
* @param commonsConfigurator
* the user commons configurator, for decryption if necessary
*/
public CallableStatementHolderListReader(File file,
CommonsConfigurator commonsConfigurator)
throws FileNotFoundException {
bufferedReader = new BufferedReader(new FileReader(file));
this.commonsConfigurator = commonsConfigurator;
this.file = file;
}
/**
* Reads a line of the file and 1) Convert it from Json 2) Convert it from
* HTML
*
* @return a StatementHolder
* @throws IOException
*/
public CallableStatementHolder readLine() throws IOException {
String line = bufferedReader.readLine();
if (line == null) {
return null;
}
String jsonString = HtmlConverter.fromHtml(line);
CallableStatementHolder callableStatementHolder = null;
callableStatementHolder = CallableStatementHolderTransport
.fromJson(jsonString);
if (this.commonsConfigurator != null) {
char[] password = commonsConfigurator.getEncryptionPassword();
if (password != null) {
CallableStatementHolderCrypto statementHolderCrypto = new CallableStatementHolderCrypto(
callableStatementHolder, password);
try {
callableStatementHolder = statementHolderCrypto.decrypt();
} catch (Exception e) {
throw new IOException(e);
}
}
}
return callableStatementHolder;
}
/**
* Closes the BufferedReader & delete the underlying file
*/
public void close() {
IOUtils.closeQuietly(bufferedReader);
file.delete();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy