use of java.nio.charset.Charset in project adempiere by adempiere.
the class ImpFormat method loadFile.
// updateDB
public void loadFile(Properties ctx, File file, String trxName, int AD_Client_ID, int AD_Org_ID, boolean excludeHeaderRow) {
m_AD_Client_ID = AD_Client_ID;
m_AD_Org_ID = AD_Org_ID;
if (file == null)
throw new AdempiereException("No file");
try {
Charset charset = Ini.getCharset();
BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file), charset), 10240);
String s = null;
boolean first = true;
while ((s = in.readLine()) != null) {
if (first && excludeHeaderRow) {
first = false;
continue;
}
first = false;
updateDB(ctx, s, trxName);
}
in.close();
} catch (Exception e) {
throw new AdempiereException("Load error", e);
}
}
use of java.nio.charset.Charset in project adempiere by adempiere.
the class VFileImport method cmd_reloadFile.
/**
* Reload/Load file
*/
private void cmd_reloadFile() {
if (m_file == null)
return;
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
m_data.clear();
rawData.setText("");
try {
// see NaturalAccountMap
Charset charset = (Charset) fCharset.getSelectedItem();
BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(m_file), charset), 10240);
// not safe see p108 Network pgm
String s = null;
while ((s = in.readLine()) != null) {
m_data.add(s);
if (m_data.size() <= MAX_LOADED_LINES) {
rawData.append(s);
rawData.append("\n");
}
}
in.close();
rawData.setCaretPosition(0);
} catch (Exception e) {
log.log(Level.SEVERE, "", e);
bFile.setText(Msg.getMsg(Env.getCtx(), "FileImportFile"));
}
// second line as first may be heading
int index = 1;
if (m_data.size() == 1)
index = 0;
int length = 0;
if (m_data.size() > 0)
length = m_data.get(index).toString().length();
info.setText(Msg.getMsg(Env.getCtx(), "Records") + "=" + m_data.size() + ", " + Msg.getMsg(Env.getCtx(), "Length") + "=" + length + " ");
setCursor(Cursor.getDefaultCursor());
log.config("Records=" + m_data.size() + ", Length=" + length);
}
use of java.nio.charset.Charset in project asterixdb by apache.
the class DatasourceFactoryProvider method initFactories.
protected static Map<String, Class> initFactories() throws AsterixException {
Map<String, Class> factories = new HashMap<>();
ClassLoader cl = ParserFactoryProvider.class.getClassLoader();
final Charset encoding = Charset.forName("UTF-8");
try {
Enumeration<URL> urls = cl.getResources(RESOURCE);
for (URL url : Collections.list(urls)) {
InputStream is = url.openStream();
String config = IOUtils.toString(is, encoding);
is.close();
String[] classNames = config.split("\n");
for (String className : classNames) {
if (className.startsWith("#")) {
continue;
}
final Class<?> clazz = Class.forName(className);
List<String> formats = ((IRecordReaderFactory) clazz.newInstance()).getRecordReaderNames();
for (String format : formats) {
if (factories.containsKey(format)) {
throw new AsterixException(ErrorCode.PROVIDER_DATASOURCE_FACTORY_DUPLICATE_FORMAT_MAPPING, format);
}
factories.put(format, clazz);
}
}
}
} catch (IOException | ClassNotFoundException | InstantiationException | IllegalAccessException e) {
throw new AsterixException(e);
}
return factories;
}
use of java.nio.charset.Charset in project asterixdb by apache.
the class StreamRecordReaderProvider method initRecordReaders.
protected static Map<String, List<Pair<String[], Class>>> initRecordReaders() throws AsterixException {
Map<String, List<Pair<String[], Class>>> recordReaders = new HashMap<>();
ClassLoader cl = StreamRecordReaderProvider.class.getClassLoader();
final Charset encoding = Charset.forName("UTF-8");
try {
Enumeration<URL> urls = cl.getResources(RESOURCE);
for (URL url : Collections.list(urls)) {
InputStream is = url.openStream();
String config = IOUtils.toString(is, encoding);
is.close();
String[] classNames = config.split("\n");
for (String className : classNames) {
if (className.startsWith("#")) {
continue;
}
final Class<?> clazz = Class.forName(className);
StreamRecordReader newInstance = (StreamRecordReader) clazz.getConstructor().newInstance();
List<String> formats = newInstance.getRecordReaderFormats();
String[] configs = newInstance.getRequiredConfigs().split(":");
for (String format : formats) {
if (!recordReaders.containsKey(format)) {
recordReaders.put(format, new ArrayList<>());
}
recordReaders.get(format).add(Pair.of(configs, clazz));
}
}
}
} catch (IOException | ClassNotFoundException | InvocationTargetException | IllegalAccessException | NoSuchMethodException | InstantiationException e) {
throw new AsterixException(e);
}
return recordReaders;
}
use of java.nio.charset.Charset in project adempiere by adempiere.
the class Preference method cmd_save.
// load
/**
* Save Settings
*/
private void cmd_save() {
log.config("");
// UI
// AutoCommit
Ini.setProperty(Ini.P_A_COMMIT, (autoCommit.isSelected()));
Env.setAutoCommit(Env.getCtx(), autoCommit.isSelected());
Ini.setProperty(Ini.P_A_NEW, (autoNew.isSelected()));
Env.setAutoNew(Env.getCtx(), autoNew.isSelected());
// AdempiereSys
Ini.setProperty(Ini.P_ADEMPIERESYS, adempiereSys.isSelected());
// LogMigrationScript
Ini.setProperty(Ini.P_LOGMIGRATIONSCRIPT, logMigrationScript.isSelected());
if (MSystem.isSwingRememberPasswordAllowed()) {
// AutoLogin
Ini.setProperty(Ini.P_A_LOGIN, (autoLogin.isSelected()));
// Save Password
Ini.setProperty(Ini.P_STORE_PWD, (storePassword.isSelected()));
} else {
Ini.setProperty(Ini.P_A_LOGIN, false);
Ini.setProperty(Ini.P_STORE_PWD, false);
}
// Show Acct Tab
Ini.setProperty(Ini.P_SHOW_ACCT, (showAcct.isSelected()));
Env.setContext(Env.getCtx(), "#ShowAcct", (showAcct.isSelected()));
// Show Trl Tab
Ini.setProperty(Ini.P_SHOW_TRL, (showTrl.isSelected()));
Env.setContext(Env.getCtx(), "#ShowTrl", (showTrl.isSelected()));
// Show Advanced Tab
Ini.setProperty(Ini.P_SHOW_ADVANCED, (showAdvanced.isSelected()));
Env.setContext(Env.getCtx(), "#ShowAdvanced", (showAdvanced.isSelected()));
// ConnectionProfile
ValueNamePair ppNew = (ValueNamePair) connectionProfile.getSelectedItem();
String cpNew = ppNew.getValue();
String cpOld = CConnection.get().getConnectionProfile();
CConnection.get().setConnectionProfile(cpNew);
if (!cpNew.equals(cpOld) && (cpNew.equals(CConnection.PROFILE_WAN) || cpOld.equals(CConnection.PROFILE_WAN)))
ADialog.info(0, this, "ConnectionProfileChange");
Ini.setProperty(Ini.P_CACHE_WINDOW, cacheWindow.isSelected());
// Print Preview
Ini.setProperty(Ini.P_PRINTPREVIEW, (printPreview.isSelected()));
// Validate Connection on Startup
Ini.setProperty(Ini.P_VALIDATE_CONNECTION_ON_STARTUP, (validateConnectionOnStartup.isSelected()));
// Single Instance per Window
Ini.setProperty(Ini.P_SINGLE_INSTANCE_PER_WINDOW, (singleInstancePerWindow.isSelected()));
// Open Window Maximized
Ini.setProperty(Ini.P_OPEN_WINDOW_MAXIMIZED, (openWindowMaximized.isSelected()));
// TraceLevel/File
Level level = (Level) traceLevel.getSelectedItem();
CLogMgt.setLevel(level);
Ini.setProperty(Ini.P_TRACELEVEL, level.getName());
Ini.setProperty(Ini.P_TRACEFILE, traceFile.isSelected());
// Printer
String printer = (String) fPrinter.getSelectedItem();
Env.setContext(Env.getCtx(), "#Printer", printer);
Ini.setProperty(Ini.P_PRINTER, printer);
// Date (remove seconds)
java.sql.Timestamp ts = (java.sql.Timestamp) fDate.getValue();
if (ts != null)
Env.setContext(Env.getCtx(), "#Date", ts);
// Charset
Charset charset = (Charset) fCharset.getSelectedItem();
Ini.setProperty(Ini.P_CHARSET, charset.name());
//UI
ValueNamePair laf = plafEditor.getSelectedLook();
ValueNamePair theme = plafEditor.getSelectedTheme();
if (laf != null) {
String clazz = laf.getValue();
String currentLaf = UIManager.getLookAndFeel().getClass().getName();
if (clazz != null && clazz.length() > 0 && !currentLaf.equals(clazz)) {
//laf changed
AdempierePLAF.setPLAF(laf, theme, true);
AEnv.updateUI();
} else {
if (UIManager.getLookAndFeel() instanceof MetalLookAndFeel) {
MetalTheme currentTheme = MetalLookAndFeel.getCurrentTheme();
String themeClass = currentTheme.getClass().getName();
String sTheme = theme.getValue();
if (sTheme != null && sTheme.length() > 0 && !sTheme.equals(themeClass)) {
ValueNamePair plaf = new ValueNamePair(UIManager.getLookAndFeel().getClass().getName(), UIManager.getLookAndFeel().getName());
AdempierePLAF.setPLAF(plaf, theme, true);
AEnv.updateUI();
}
}
}
}
Ini.saveProperties(Ini.isClient());
dispose();
}
Aggregations