List of usage examples for java.io OutputStreamWriter write
public void write(int c) throws IOException
From source file:com.hardcopy.retroband.MainActivity.java
public void guardarDatos(int[] accel) { try {/*from w w w .j av a 2 s .com*/ File ruta_sd = Environment.getExternalStorageDirectory(); File f = new File(ruta_sd.getAbsolutePath(), nombreArchivo); FileOutputStream fos = new FileOutputStream(f, true);// new // FileOutputStream(f);override OutputStreamWriter fout = new OutputStreamWriter(fos); for (int i = 0; i < accel.length; i += 3) { String texto = String.valueOf(accel[i]) + "," + String.valueOf(accel[i + 1]) + "," + String.valueOf(accel[i + 2]) + "\n"; // System.out.print(texto); fout.write(texto); } fout.close(); } catch (Exception ex) { Log.e("Ficheros", "Error al escribir fichero a tarjeta SD"); } }
From source file:fr.gouv.finances.dgfip.xemelios.importers.archives.ArchiveImporter.java
protected FileInfo doImportManifeste(Document manif, String archiveName) throws IOException { DocumentModel dm = documentsModel.getDocumentById("manifeste2"); String idColl = "0000"; String libColl = "Traabilit"; String idBudg = "00"; String libBudg = "--"; Pair collectivite = new Pair(idColl, libColl); Pair budget = new Pair(idBudg, libBudg); if (importedArchiveManifeste != null) { try {/*from w ww .j ava 2s . c o m*/ DataLayerManager.getImplementation().removeDocument(dm, budget, collectivite, archiveName + ".xml", user); } catch (Exception ex) { logger.error("while dropping previous manifeste", ex); } } File outputFile = null; try { outputFile = new File(FileUtils.getTempDir(), archiveName + ".xml"); Charset cs = Charset.forName("UTF-8"); OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(outputFile), cs); osw.write(manif.toXML()); osw.flush(); osw.close(); Class clazz = Class.forName(dm.getImportClass()); Constructor cc = clazz.getConstructor(XemeliosUser.class, PropertiesExpansion.class); Object obj = cc.newInstance(getUser(), applicationProperties); if (!(obj instanceof EtatImporteur)) { throw new DataConfigurationException( "Cette classe n'est pas un importeur.\nLe fichier de configuration qui vous a t livr est certainement invalide.\nVeuillez contacter votre fournisseur."); } EtatImporteur ei = (EtatImporteur) obj; // WARNING : if one name per archive (and not one per volume), change this ei.setArchiveName(archiveName); ei.setImpSvcProvider(importServiceProvider); importServiceProvider.setEtatImporter(ei); ei.setOverwriteRule("never"); ei.setApplicationConfiguration(applicationProperties); ei.setDocument(dm); File[] fichiers = new File[] { outputFile }; ei.setFilesToImport(fichiers); importServiceProvider.setCollectivite(collectivite); importServiceProvider.setBudget(budget); ei.setCollectivite(collectivite); ei.setBudget(budget); ei.run(); FileInfo fInfo = ei.getFileInfo(); if (ei.getWarningCount() > 0) fInfo.setWarningCount(ei.getWarningCount()); return fInfo; } catch (Exception ex) { logger.error("importer", ex); return new FileInfo(); } finally { if (outputFile.exists()) { outputFile.delete(); } } }
From source file:com.mocap.MocapFragment.java
public void SaveOBJ(Context context, MyGLSurfaceView glview) { Log.i(TAG, "DIR: "); float sVertices[] = glview.getsVertices(); FileOutputStream fOut = null; OutputStreamWriter osw = null; File mFile;/*from ww w . j av a2s . c om*/ if (Environment.DIRECTORY_PICTURES != null) { try { mFile = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "mocap.obj"); Log.i(TAG, "Long Vertices: " + sVertices.length); fOut = new FileOutputStream(mFile); osw = new OutputStreamWriter(fOut); osw.write("# *.obj file (Generate by Mocap 3D)\n"); osw.flush(); for (int i = 0; i < sVertices.length - 4; i = i + 3) { try { String data = "v " + Float.toString(sVertices[i]) + " " + Float.toString(sVertices[i + 1]) + " " + Float.toString(sVertices[i + 2]) + "\n"; Log.i(TAG, i + ": " + data); osw.write(data); osw.flush(); } catch (Exception e) { Toast.makeText(context, "erreur d'criture: " + e, Toast.LENGTH_SHORT).show(); Log.i(TAG, "Erreur: " + e); } } osw.write("# lignes:\n"); osw.write("l "); osw.flush(); ; for (int i = 1; i < (-1 + sVertices.length / 3); i++) { osw.write(i + " "); osw.flush(); } //popup surgissant pour le rsultat Toast.makeText(getActivity(), "Save : " + Environment.DIRECTORY_PICTURES + "/mocap.obj ", Toast.LENGTH_SHORT).show(); //lancement d'un explorateur de fichiers vers le fichier crer //systeme des intend try { File root = new File(Environment.DIRECTORY_PICTURES); Uri uri = Uri.fromFile(mFile); Intent intent = new Intent(); intent.setAction(Intent.ACTION_GET_CONTENT); intent.setData(uri); // Verify that the intent will resolve to an activity if (intent.resolveActivity(getActivity().getPackageManager()) != null) { Log.i(TAG, "intent pk: "); getActivity().startActivityForResult(intent, 1); } } catch (Exception e) { Log.i(TAG, "Erreur intent: " + e); } } catch (Exception e) { Toast.makeText(context, "Settings not saved", Toast.LENGTH_SHORT).show(); } finally { try { osw.close(); fOut.close(); } catch (IOException e) { Toast.makeText(context, "Settings not saved", Toast.LENGTH_SHORT).show(); } } } else { Toast.makeText(context, "Pas de carte ext", Toast.LENGTH_SHORT).show(); } }
From source file:com.globalsight.everest.tda.TdaHelper.java
private void writeTranslationUnit(OutputStreamWriter m_outputStream, HashMap needHitMTTuTuvMap) throws IOException { // put all tus into array. Object[] key_tus = needHitMTTuTuvMap.keySet().toArray(); Tu[] tusInArray = new Tu[key_tus.length]; for (int key = 0; key < key_tus.length; key++) { tusInArray[key] = (Tu) key_tus[key]; }/*from www .jav a2 s . co m*/ // put all tuvs into array Object[] value_tuvs = needHitMTTuTuvMap.values().toArray(); Tuv[] tuvsInArray = new Tuv[value_tuvs.length]; for (int value = 0; value < value_tuvs.length; value++) { tuvsInArray[value] = (Tuv) value_tuvs[value]; } for (int i = 0; i < tuvsInArray.length; i++) { Tu tu = (Tu) key_tus[i]; Tuv tuv = (Tuv) value_tuvs[i]; String m_strEOL = "\r\n"; String m_space = " "; m_outputStream.write("<trans-unit id=\"" + tu.getId() + "\""); m_outputStream.write(">"); m_outputStream.write(m_strEOL); m_outputStream.write("<source>"); m_outputStream.write(tuv.getGxmlExcludeTopTags()); m_outputStream.write("</source>"); m_outputStream.write(m_strEOL); m_outputStream.write("<target></target>"); m_outputStream.write(m_strEOL); m_outputStream.write("</trans-unit>"); m_outputStream.write(m_strEOL); } }
From source file:com.BeatYourRecord.SubmitActivity.java
private String uploadMetaData(String filePath, boolean retry) throws IOException { String uploadUrl = INITIAL_UPLOAD_URL; HttpURLConnection urlConnection = getGDataUrlConnection(uploadUrl); urlConnection.setRequestMethod("POST"); urlConnection.setDoOutput(true);//from w w w . ja v a2s. c om urlConnection.setRequestProperty("Content-Type", "application/atom+xml"); urlConnection.setRequestProperty("Slug", filePath); String atomData; int pos = filePath.indexOf("BYR"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy_MM_dd"); String currentDateandTime = sdf.format(new Date()); SharedPreferences pref1 = SubmitActivity.this.getSharedPreferences("TourPref", 0); // 0 - for private mode Editor editor1 = pref1.edit(); String username = pref1.getString("Username", null); String title = "BeatYourRecord Free Throws " + currentDateandTime + " Score : " + getTitleText() + " User : " + username; //this.initFile().getAbsolutePath(); String description = "Beat Your Record Free Throw Tournament. User : " + username + ". Go to" + " www.ec2-54-212-221-3.us-west-2.compute.amazonaws.com" + " to take part in our other tournaments"; String category = DEFAULT_VIDEO_CATEGORY; this.tags = DEFAULT_VIDEO_TAGS; if (!Util.isNullOrEmpty(this.getTagsText())) { this.tags = this.getTagsText(); } if (this.videoLocation == null) { String template = Util.readFile(this, R.raw.gdata).toString(); atomData = String.format(template, title, description, category, this.tags); } else { String template = Util.readFile(this, R.raw.gdata_geo).toString(); atomData = String.format(template, title, description, category, this.tags, videoLocation.getLatitude(), videoLocation.getLongitude()); } OutputStreamWriter outStreamWriter = new OutputStreamWriter(urlConnection.getOutputStream()); outStreamWriter.write(atomData); outStreamWriter.close(); int responseCode = urlConnection.getResponseCode(); if (responseCode < 200 || responseCode >= 300) { // The response code is 40X if ((responseCode + "").startsWith("4") && retry) { Log.d(LOG_TAG, "retrying to fetch auth token for " + youTubeName); this.clientLoginToken = authorizer.getFreshAuthToken(youTubeName, clientLoginToken); // Try again with fresh token return uploadMetaData(filePath, false); } else { throw new IOException(String.format("response code='%s' (code %d)" + " for %s", urlConnection.getResponseMessage(), responseCode, urlConnection.getURL())); } } return urlConnection.getHeaderField("Location"); }
From source file:com.wwpass.connection.WWPassConnection.java
private InputStream makeRequest(String method, String command, Map<String, ?> parameters) throws IOException, WWPassProtocolException { String commandUrl = SpfeURL + command + ".xml"; //String command_url = SpfeURL + command + ".json"; StringBuilder sb = new StringBuilder(); URLCodec codec = new URLCodec(); @SuppressWarnings("unchecked") Map<String, Object> localParams = (Map<String, Object>) parameters; for (Map.Entry<String, Object> entry : localParams.entrySet()) { sb.append(URLEncoder.encode(entry.getKey(), "UTF-8")); sb.append("="); if (entry.getValue() instanceof String) { sb.append(URLEncoder.encode((String) entry.getValue(), "UTF-8")); } else {/*www . j a v a 2 s . c o m*/ sb.append(new String(codec.encode((byte[]) entry.getValue()))); } sb.append("&"); } String paramsString = sb.toString(); sb = null; if ("GET".equalsIgnoreCase(method)) { commandUrl += "?" + paramsString; } else if ("POST".equalsIgnoreCase(method)) { } else { throw new IllegalArgumentException("Method " + method + " not supported."); } HttpsURLConnection conn = null; try { URL url = new URL(commandUrl); conn = (HttpsURLConnection) url.openConnection(); conn.setReadTimeout(timeoutMs); conn.setSSLSocketFactory(SPFEContext.getSocketFactory()); if ("POST".equalsIgnoreCase(method)) { conn.setDoOutput(true); OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream()); writer.write(paramsString); writer.flush(); } InputStream in = conn.getInputStream(); return getReplyData(in); } catch (MalformedURLException e) { throw new IllegalArgumentException("Command-parameters combination is invalid: " + e.getMessage()); } finally { if (conn != null) { conn.disconnect(); } } }
From source file:com.sun.faces.systest.ant.SystestClient.java
/** * Validate the response against the golden file (if any), skipping the * comparison on any golden file line that is also in the ignore file * (if any). Return <code>null</code> for no problems, or an error * message.//from w w w . ja va 2s . c o m */ protected String validateGolden() { if (golden == null) { return (null); } boolean ok = true; if (saveGolden.size() != saveResponse.size()) { ok = false; } if (ok) { for (int i = 0, size = saveGolden.size(); i < size; i++) { String golden = (String) saveGolden.get(i); String response = (String) saveResponse.get(i); if (!validateIgnore(golden) && !golden.equals(response)) { response = stripJsessionidFromLine(response); golden = stripJsessionidFromLine(golden); if (!golden.equals(response)) { ok = false; break; } } } } if (ok) { return (null); } System.out.println("EXPECTED: ======================================"); for (int i = 0, size = saveGolden.size(); i < size; i++) { System.out.println((String) saveGolden.get(i)); } System.out.println("================================================"); if (saveIgnore.size() >= 1) { System.out.println("IGNORED: ======================================="); for (int i = 0, size = saveIgnore.size(); i < size; i++) { System.out.println((String) saveIgnore.get(i)); } System.out.println("================================================"); } System.out.println("RECEIVED: ======================================"); for (int i = 0, size = saveResponse.size(); i < size; i++) { System.out.println((String) saveResponse.get(i)); } System.out.println("================================================"); // write the goldenfile if the GF size from the server was 0 // and the goldenfile doesn't already exist on the local filesystem. if (recordGolden != null) { File gf = new File(recordGolden); if (!gf.exists()) { System.out.println("[INFO] RECORDING GOLDENFILE: " + recordGolden); // write the goldenfile using the encoding specified in the response. // if there is no encoding available, default to ISO-8859-1 String encoding = "ISO-8859-1"; if (saveHeaders.containsKey("content-type")) { List vals = (List) saveHeaders.get("content-type"); if (vals != null) { String val = (String) vals.get(0); int charIdx = val.indexOf('='); if (charIdx > -1) { encoding = val.substring(charIdx + 1).trim(); } } } OutputStreamWriter out = null; try { out = new OutputStreamWriter(new FileOutputStream(gf), encoding); for (int i = 0, size = saveResponse.size(); i < size; i++) { out.write((String) saveResponse.get(i)); out.write('\n'); } out.flush(); } catch (Throwable t) { System.out.println("[WARNING] Unable to write goldenfile: " + t.toString()); } finally { try { if (out != null) { out.close(); } } catch (IOException ioe) { ; // do nothing } } } } return ("Failed Golden File Comparison"); }
From source file:cn.edu.henu.rjxy.lms.controller.TeaController.java
@RequestMapping("teacher/xgwork") public @ResponseBody String xgwork(HttpServletRequest request) throws IOException { String textWork = request.getParameter("arred");//? String time = request.getParameter("time");//?? String miaoshu = request.getParameter("miaoshu"); String starttime = request.getParameter("starttime"); String coursename = request.getParameter("courseName"); String term = request.getParameter("term"); String id = request.getParameter("id"); String tec_name = TeacherDao.getTeacherBySn(getCurrentUsername()).getTeacherName(); String collage = TeacherDao.getTeacherBySn(getCurrentUsername()).getTeacherCollege(); String sn = getCurrentUsername(); // ? ?? ?? String ff = getFileFolder(request) + "homework/" + term + "/" + collage + "/" + sn + "/" + tec_name + "/" + coursename + "/" + id + "/"; //?html/*from w w w .j a v a 2 s . c om*/ OutputStreamWriter pw = null; pw = new OutputStreamWriter(new FileOutputStream(new File(ff + File.separator + "textWork.html")), "GBK"); pw.write(textWork); pw.close(); //?? PrintStream ps = null; ps = new PrintStream(new FileOutputStream(new File(ff + File.separator + "Workall.txt"))); ps.printf(miaoshu);//??: ps.println(); ; ps.println(time);//??: ps.println(starttime);//??: ps.close(); return "1"; }
From source file:cn.edu.henu.rjxy.lms.controller.TeaController.java
@RequestMapping("teacher/work") public @ResponseBody String work(HttpServletRequest request) throws IOException { int length = 0; String textWork = request.getParameter("arred");//? String time = request.getParameter("time");//?? String starttime = request.getParameter("onetime");//?? String miaoshu = request.getParameter("miaoshu"); String coursename = request.getParameter("courseName"); String term = request.getParameter("term"); String tec_name = TeacherDao.getTeacherBySn(getCurrentUsername()).getTeacherName(); String collage = TeacherDao.getTeacherBySn(getCurrentUsername()).getTeacherCollege(); String sn = getCurrentUsername(); // ? ?? ?? String ff = getFileFolder(request) + "homework/" + term + "/" + collage + "/" + sn + "/" + tec_name + "/" + coursename + "/"; file(ff);//?? length = haveFile(ff);//w w w . j av a 2s .c o m ff = ff + (length + 1) + "/"; file(ff); //?html OutputStreamWriter pw = null; pw = new OutputStreamWriter(new FileOutputStream(new File(ff + File.separator + "textWork.html")), "GBK"); pw.write(textWork); pw.close(); //?? PrintStream ps = null; ps = new PrintStream(new FileOutputStream(new File(ff + File.separator + "Workall.txt"))); ps.printf(miaoshu);//??: ps.println(); ; ps.println(time);//??: ps.println(starttime);//?? ps.close(); return "1"; }
From source file:gdsc.smlm.ij.plugins.BenchmarkFilterAnalysis.java
private void saveFilter(Filter filter) { // Save the filter to file String filename = Utils.getFilename("Best_Filter_File", filterFilename); if (filename != null) { List<Filter> filters = new LinkedList<Filter>(); filters.add(filter);//from w w w. ja va2s . c o m FilterSet set = new FilterSet(filter.getName(), filters); List<FilterSet> list = new LinkedList<FilterSet>(); list.add(set); OutputStreamWriter out = null; try { filterFilename = filename; // Append .xml if no suffix if (filename.lastIndexOf('.') < 0) filterFilename += ".xml"; FileOutputStream fos = new FileOutputStream(filterFilename); out = new OutputStreamWriter(fos, "UTF-8"); out.write(XmlUtils.prettyPrintXml(XmlUtils.toXML(list))); } catch (Exception e) { IJ.log("Unable to save the filter sets to file: " + e.getMessage()); } finally { if (out != null) { try { out.close(); } catch (IOException e) { // Ignore } } } } }