List of usage examples for java.io FileReader getEncoding
public String getEncoding()
From source file:net.longfalcon.newsj.Nfo.java
private String getSmallBinaryNfo(NewsClient newsClient, ReleaseNfo releaseNfo) { Binary binary = releaseNfo.getBinary(); Group group = groupDAO.findGroupByGroupId(binary.getGroupId()); try {//from w ww .j a va 2 s .c om newsClient.selectNewsgroup(group.getName()); } catch (IOException e) { _log.error(e); return null; } String nfo; List<Part> partList = partDAO.findPartsByBinaryId(binary.getId()); try { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); Directory tempDir = fileSystemService.getDirectory("/temp"); File tempFile = tempDir.getTempFile(String.valueOf(System.currentTimeMillis())); for (Part part : partList) { BufferedReader bufferedReader = newsClient.retrieveArticleBody(part.getNumber()); if (bufferedReader != null) { YDecoder.decode(bufferedReader, tempFile); } else { return null; } } FileReader fileReader = new FileReader(tempFile); String enc = fileReader.getEncoding(); InputStream inputStream = new FileInputStream(tempFile); StreamUtil.transferByteArray(inputStream, byteArrayOutputStream, 1024); nfo = byteArrayOutputStream.toString(enc); } catch (IOException e) { _log.error(e); return null; } return nfo; }
From source file:cz.urbangaming.galgs.GAlg.java
public boolean onCreateOptionsMenu(Menu menu) { //TODO: OMG, put this in a separate, non blocking task!!! Log.d(DEBUG_TAG, "CALLED onCreateOptionsMenu!"); try {// www . j a va2s .c o m File rbClassFile = new File(galgsRubyClassesDirectory, GALGS_CLASS_FILE); Log.d(DEBUG_TAG, "rbClassFile.getAbsolutePath() " + rbClassFile.getAbsolutePath()); Log.d(DEBUG_TAG, "rbClassFile.exists() " + rbClassFile.exists()); Log.d(DEBUG_TAG, "rbClassFile.length() " + rbClassFile.length()); Log.d(DEBUG_TAG, "rbClassFile.canRead() " + rbClassFile.canRead()); Log.d(DEBUG_TAG, "rbClassFile.canWrite() " + rbClassFile.canWrite()); FileReader rbClassFileReader = new FileReader(rbClassFile); Log.d(DEBUG_TAG, "rbClassFile " + rbClassFileReader.getEncoding()); loadRubyMethodsToMenu(new BufferedReader(rbClassFileReader)); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } //JavaAlgs Action provider javaAlgsActionProvider = new JavaAlgsActionProvider(this); //RubyAlgs Action provider Log.d(DEBUG_TAG, "Ruby methods just before creatingProvider:" + rubyMethods); rubyAlgsActionProvider = new RubyAlgsActionProvider(this, rubyMethods); // Inflate the menu items for use in the action bar MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.galg, menu); menu.getItem(0).setActionProvider(javaAlgsActionProvider); menu.getItem(1).setActionProvider(rubyAlgsActionProvider); return super.onCreateOptionsMenu(menu); }
From source file:it.doqui.index.ecmengine.business.personalization.importer.ArchiveImporterJob.java
/** * Restituisce l'encoding del file specificato. * * @param file Il file di cui ricavare l'encoding. * @return L'encoding del file specificato. *///from w w w . ja v a 2 s .co m private String getEncoding(File file) { String encoding = ""; try { FileReader fr = new FileReader(file); encoding = fr.getEncoding(); fr.close(); } catch (Exception e) { } return encoding; }
From source file:org.apache.ofbiz.content.data.DataResourceWorker.java
public static void renderFile(String dataResourceTypeId, String objectInfo, String rootDir, Appendable out) throws GeneralException, IOException { // TODO: this method assumes the file is a text file, if it is an image we should respond differently, see the comment above for IMAGE_OBJECT type data resource if (dataResourceTypeId.equals("LOCAL_FILE") && UtilValidate.isNotEmpty(objectInfo)) { File file = FileUtil.getFile(objectInfo); if (!file.isAbsolute()) { throw new GeneralException("File (" + objectInfo + ") is not absolute"); }// ww w . ja v a 2s .c o m FileReader in = new FileReader(file); UtilIO.copy(in, true, out); } else if (dataResourceTypeId.equals("OFBIZ_FILE") && UtilValidate.isNotEmpty(objectInfo)) { String prefix = System.getProperty("ofbiz.home"); String sep = ""; if (objectInfo.indexOf("/") != 0 && prefix.lastIndexOf("/") != (prefix.length() - 1)) { sep = "/"; } File file = FileUtil.getFile(prefix + sep + objectInfo); FileReader in = new FileReader(file); UtilIO.copy(in, true, out); } else if (dataResourceTypeId.equals("CONTEXT_FILE") && UtilValidate.isNotEmpty(objectInfo)) { String prefix = rootDir; String sep = ""; if (objectInfo.indexOf("/") != 0 && prefix.lastIndexOf("/") != (prefix.length() - 1)) { sep = "/"; } File file = FileUtil.getFile(prefix + sep + objectInfo); FileReader in = null; try { in = new FileReader(file); String enc = in.getEncoding(); if (Debug.infoOn()) Debug.logInfo("in serveImage, encoding:" + enc, module); } catch (FileNotFoundException e) { Debug.logError(e, " in renderDataResourceAsHtml(CONTEXT_FILE), in FNFexception:", module); throw new GeneralException("Could not find context file to render", e); } catch (Exception e) { Debug.logError(" in renderDataResourceAsHtml(CONTEXT_FILE), got exception:" + e.getMessage(), module); } UtilIO.copy(in, true, out); } }
From source file:org.ofbiz.content.data.DataResourceWorker.java
public static void renderFile(String dataResourceTypeId, String objectInfo, String rootDir, Appendable out) throws GeneralException, IOException { // TODO: this method assumes the file is a text file, if it is an image we should respond differently, see the comment above for IMAGE_OBJECT type data resource if (dataResourceTypeId.equals("LOCAL_FILE") && UtilValidate.isNotEmpty(objectInfo)) { File file = FileUtil.getFile(objectInfo); if (!file.isAbsolute()) { throw new GeneralException("File (" + objectInfo + ") is not absolute"); }/* w ww . j ava 2s .co m*/ FileReader in = new FileReader(file); UtilIO.copy(in, true, out); } else if (dataResourceTypeId.equals("OFBIZ_FILE") && UtilValidate.isNotEmpty(objectInfo)) { String prefix = System.getProperty("ofbiz.home"); String sep = ""; if (objectInfo.indexOf("/") != 0 && prefix.lastIndexOf("/") != (prefix.length() - 1)) { sep = "/"; } File file = FileUtil.getFile(prefix + sep + objectInfo); FileReader in = new FileReader(file); UtilIO.copy(in, true, out); } else if (dataResourceTypeId.equals("CONTEXT_FILE") && UtilValidate.isNotEmpty(objectInfo)) { String prefix = rootDir; String sep = ""; if (objectInfo.indexOf("/") != 0 && prefix.lastIndexOf("/") != (prefix.length() - 1)) { sep = "/"; } File file = FileUtil.getFile(prefix + sep + objectInfo); FileReader in = null; try { in = new FileReader(file); String enc = in.getEncoding(); if (Debug.infoOn()) Debug.logInfo("in serveImage, encoding:" + enc, module); } catch (FileNotFoundException e) { Debug.logError(e, " in renderDataResourceAsHtml(CONTEXT_FILE), in FNFexception:", module); throw new GeneralException("Could not find context file to render", e); } catch (Exception e) { Debug.logError(" in renderDataResourceAsHtml(CONTEXT_FILE), got exception:" + e.getMessage(), module); } UtilIO.copy(in, true, out); //out.flush(); } }