use of java.nio.charset.Charset in project android by JetBrains.
the class GradleImport method copyTextFile.
public void copyTextFile(@Nullable ImportModule module, @NonNull File source, @NonNull File dest) throws IOException {
assert isTextFile(source) : source;
Charset encoding = null;
// A specific encoding configured for a given file always wins:
if (module != null) {
encoding = module.getFileEncoding(source);
if (encoding != null) {
copyTextFileWithEncoding(source, dest, encoding);
return;
}
encoding = module.getProjectEncoding(source);
}
if (encoding == null) {
encoding = getEncodingFromWorkspaceSetting();
}
// For XML files we can sometimes read the encoding right out of the XML prologue
if (SdkUtils.endsWithIgnoreCase(source.getPath(), DOT_XML)) {
String defaultCharset = encoding != null ? encoding.name() : SdkConstants.UTF_8;
String xml = PositionXmlParser.getXmlString(Files.toByteArray(source), defaultCharset);
// Replace prologue if it specifies the encoding
if (xml.startsWith("<?xml")) {
int prologueEnd = xml.indexOf("?>");
if (prologueEnd != -1) {
xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + xml.substring(prologueEnd + 2);
}
}
Files.write(xml, dest, Charsets.UTF_8);
} else if (encoding != null) {
copyTextFileWithEncoding(source, dest, encoding);
} else {
Files.copy(source, dest);
}
}
use of java.nio.charset.Charset in project adempiere by adempiere.
the class WFileImport method cmd_loadFile.
/**************************************************************************
* Load File
*/
private void cmd_loadFile() {
Media media = null;
media = Fileupload.get();
if (media == null)
return;
if (media.isBinary()) {
m_file_istream = media.getStreamData();
} else {
ListItem listitem = fCharset.getSelectedItem();
if (listitem == null) {
m_file_istream = new ReaderInputStream(media.getReaderData());
} else {
Charset charset = (Charset) listitem.getValue();
m_file_istream = new ReaderInputStream(media.getReaderData(), charset.name());
}
}
log.config(media.getName());
bFile.setLabel(media.getName());
cmd_reloadFile();
}
use of java.nio.charset.Charset in project adempiere by adempiere.
the class WFileImport method dynInit.
/**
* Dynamic Init
*/
private void dynInit() {
// Load Formats
pickFormat.appendItem(s_none, s_none);
String sql = MRole.getDefault().addAccessSQL("SELECT Name FROM AD_ImpFormat", "AD_ImpFormat", MRole.SQL_FULLYQUALIFIED, MRole.SQL_RO);
try {
PreparedStatement pstmt = DB.prepareStatement(sql, null);
ResultSet rs = pstmt.executeQuery();
while (rs.next()) pickFormat.appendItem(rs.getString(1), rs.getString(1));
rs.close();
pstmt.close();
} catch (SQLException e) {
log.log(Level.SEVERE, sql, e);
}
pickFormat.setSelectedIndex(0);
pickFormat.addEventListener(Events.ON_SELECT, this);
Charset charset = Ini.getCharset();
for (int i = 0; i < fCharset.getItemCount(); i++) {
ListItem listitem = fCharset.getItemAtIndex(i);
Charset compare = (Charset) listitem.getValue();
if (charset == compare) {
fCharset.setSelectedIndex(i);
break;
}
}
fCharset.addEventListener(Events.ON_SELECT, this);
confirmPanel.setEnabled("Ok", false);
}
use of java.nio.charset.Charset in project adempiere by adempiere.
the class WFileImport method cmd_reloadFile.
/**
* Reload/Load file
*/
private void cmd_reloadFile() {
if (m_file_istream == null)
return;
m_data.clear();
rawData.setText("");
try {
// see NaturalAccountMap
ListItem listitem = fCharset.getSelectedItem();
Charset charset = null;
if (listitem == null)
return;
charset = (Charset) listitem.getValue();
BufferedReader in = new BufferedReader(new InputStreamReader(m_file_istream, charset), 10240);
// not safe see p108 Network pgm
String s = null;
String concat = "";
while ((s = in.readLine()) != null) {
m_data.add(s);
concat += s;
concat += "\n";
if (m_data.size() < MAX_LOADED_LINES) {
rawData.setValue(concat);
}
}
in.close();
} catch (Exception e) {
log.log(Level.SEVERE, "", e);
bFile.setLabel(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.setValue(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 adempiere by adempiere.
the class WFileImport method jbInit.
// init
/**
* Static Init
* @throws Exception
*/
private void jbInit() throws Exception {
Charset[] charsets = Ini.getAvailableCharsets();
for (int i = 0; i < charsets.length; i++) fCharset.appendItem(charsets[i].displayName(), charsets[i]);
bFile.setLabel(Msg.getMsg(Env.getCtx(), "FileImportFile"));
bFile.setTooltiptext(Msg.getMsg(Env.getCtx(), "FileImportFileInfo"));
bFile.addEventListener(Events.ON_CLICK, this);
fCharset.setMold("select");
fCharset.setRows(0);
fCharset.setTooltiptext(Msg.getMsg(Env.getCtx(), "Charset", false));
info.setValue(" ");
labelFormat.setValue(Msg.translate(Env.getCtx(), "AD_ImpFormat_ID"));
pickFormat.setMold("select");
pickFormat.setRows(0);
bNext.setTooltiptext(Msg.getMsg(Env.getCtx(), "Next"));
bNext.setLabel(">");
bNext.addEventListener(Events.ON_CLICK, this);
record.setValue("------");
bPrevious.setTooltiptext(Msg.getMsg(Env.getCtx(), "Previous"));
bPrevious.setLabel("<");
bPrevious.addEventListener(Events.ON_CLICK, this);
northPanel.appendChild(bFile);
northPanel.appendChild(fCharset);
northPanel.appendChild(info);
northPanel.appendChild(labelFormat);
northPanel.appendChild(pickFormat);
northPanel.appendChild(bPrevious);
northPanel.appendChild(record);
northPanel.appendChild(bNext);
rawData.setWidth("100%");
rawData.setCols(80);
rawData.setRows(MAX_SHOWN_LINES);
rawData.setHeight("40%");
previewPanel.setWidth("100%");
previewPanel.setHeight("58%");
previewPanel.setStyle("overflow: auto");
// Elaine 2008/11/07 - fix text area is not expanded in IE7
centerPanel.setWidth("100%");
centerPanel.setHeight("100%");
centerPanel.appendChild(rawData);
centerPanel.appendChild(new Separator());
centerPanel.appendChild(previewPanel);
confirmPanel.addActionListener(Events.ON_CLICK, this);
}
Aggregations