Example usage for java.io OutputStreamWriter write

List of usage examples for java.io OutputStreamWriter write

Introduction

In this page you can find the example usage for java.io OutputStreamWriter write.

Prototype

public void write(int c) throws IOException 

Source Link

Document

Writes a single character.

Usage

From source file:org.opendatakit.survey.android.provider.SubmissionProvider.java

/**
 * This method actually writes the JSON appName-relative manifest to disk.
 *
 * @param payload//from www. j  a  v a2s . c o m
 * @param path
 * @return
 */
private static boolean exportFile(String payload, File outputFilePath, WebLogger log) {
    // write xml file
    FileOutputStream os = null;
    OutputStreamWriter osw = null;
    try {
        os = new FileOutputStream(outputFilePath, false);
        osw = new OutputStreamWriter(os, CharEncoding.UTF_8);
        osw.write(payload);
        osw.flush();
        osw.close();
        return true;

    } catch (IOException e) {
        log.e(t, "Error writing file");
        e.printStackTrace();
        try {
            osw.close();
            os.close();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        return false;
    }
}

From source file:com.krawler.common.util.BaseStringUtil.java

public static String makeExternalRequest(String urlstr, String postdata) {
    String result = "";
    try {/*  w  w  w  . jav a  2 s  .  co  m*/
        URL url = new URL(urlstr);
        try {
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setDoOutput(true);
            DataOutputStream d = new DataOutputStream(conn.getOutputStream());
            String data = postdata;
            OutputStreamWriter ow = new OutputStreamWriter(d);
            ow.write(data);
            ow.close();
            BufferedReader input = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            String inputLine;
            StringBuilder stringbufff = new StringBuilder();
            while ((inputLine = input.readLine()) != null) {
                stringbufff.append(inputLine);
            }
            result = stringbufff.toString();
            input.close();
        } catch (IOException ex) {
            System.out.print(ex);
        }

    } catch (MalformedURLException ex) {
        System.out.print(ex);
    } finally {
        return result;
    }
}

From source file:com.noshufou.android.su.util.Util.java

public static boolean writeDefaultStoreFile(Context context) {
    File storedDir = new File(context.getFilesDir().getAbsolutePath() + File.separator + "stored");
    storedDir.mkdirs();//  w  w  w . java 2  s  . c o  m
    File defFile = new File(storedDir.getAbsolutePath() + File.separator + "default");
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    String action = prefs.getString(Preferences.AUTOMATIC_ACTION, "prompt");
    try {
        OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(defFile.getAbsolutePath()));
        out.write(action);
        out.write("\n");
        out.flush();
        out.close();
    } catch (FileNotFoundException e) {
        Log.w(TAG, "Default file not written", e);
        return false;
    } catch (IOException e) {
        Log.w(TAG, "Default file not written", e);
        return false;
    }
    return true;
}

From source file:com.noshufou.android.su.util.Util.java

public static boolean writeOptionsFile(Context context) {
    File storedDir = new File(context.getFilesDir().getAbsolutePath() + File.separator + "stored");
    storedDir.mkdirs();//from w  w w  .jav  a2s.  com
    File optFile = new File(storedDir.getAbsolutePath() + File.separator + "options");
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    String ownerMode = prefs.getString(Preferences.USER_MODE, "owner_only");
    try {
        OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(optFile.getAbsolutePath()));
        out.write(ownerMode);
        out.write("\n");
        out.flush();
        out.close();
    } catch (FileNotFoundException e) {
        Log.w(TAG, "Options file not written", e);
        return false;
    } catch (IOException e) {
        Log.w(TAG, "Options file not written", e);
        return false;
    }
    return true;
}

From source file:at.tugraz.sss.serv.util.SSFileU.java

public static void writeStr(final String str, final String filePath) throws SSErr {

    OutputStreamWriter out = null;

    try {//  ww  w . ja  v a2 s.  c o m

        out = new OutputStreamWriter(openOrCreateFileWithPathForWrite(filePath), SSEncodingU.utf8.toString());

        out.write(str);
    } catch (Exception error) {
        SSServErrReg.regErrThrow(error);
    } finally {

        if (out != null) {
            try {
                out.close();
            } catch (IOException ex) {
                SSLogU.err(ex);
            }
        }
    }
}

From source file:com.noshufou.android.su.util.Util.java

private static boolean writeStoreFile(File storeFile, HashMap<String, String> cmds) {
    try {//from   w  w w .j a  va 2s  .  c  o m
        OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(storeFile));
        if (cmds.containsKey("any")) {
            out.write(cmds.get("any") + '\n');
            out.write("any\n");
        } else {
            for (Map.Entry<String, String> entry : cmds.entrySet()) {
                out.write(entry.getValue() + '\n');
                out.write(entry.getKey() + '\n');
            }
        }
        out.close();
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return false;
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return false;
    }
    return true;
}

From source file:com.wondershare.http.server.impl.HomePageServlet.java

@Override
protected void doGet(HttpRequest request, HttpResponse response, HttpContext context)
        throws IOException, ServletException {
    HttpEntity entity = new EntityTemplate(new ContentProducer() {
        @Override//from w ww  . jav a  2s. c o m
        public void writeTo(OutputStream outstream) throws IOException {
            OutputStreamWriter out = new OutputStreamWriter(outstream);
            out.write(Utils.openHTMLString(mContext, R.raw.home));
            out.flush();
        }
    });
    ((EntityTemplate) entity).setContentType("text/html");
    response.setEntity(entity);
}

From source file:hudson.plugins.sonar.template.SimpleTemplate.java

public void write(FilePath path, String pomName) throws IOException, InterruptedException {
    FilePath pom = path.child(pomName);//from  ww w  .  j av  a 2 s.c  o m
    OutputStreamWriter outputStream = new OutputStreamWriter(pom.write());
    try {
        outputStream.write(template);
    } finally {
        outputStream.close();
    }
}

From source file:javaapplication1.Prog.java

public void transferStuff(String obj, String user) throws MalformedURLException, IOException {

    URL object = new URL("http://localhost:8080/bankserver/users/" + user);
    HttpURLConnection con = (HttpURLConnection) object.openConnection();
    con.setDoOutput(true);/*  w ww.  ja  va2 s. c o  m*/
    con.setRequestProperty("Content-Type", "application/json");
    con.setRequestProperty("Accept", "application/json");
    con.setRequestMethod("PUT");
    OutputStreamWriter wr = new OutputStreamWriter(con.getOutputStream());
    wr.write(obj);
    wr.flush();
    wr.close();
    con.getInputStream();
}

From source file:at.tugraz.ist.akm.webservice.requestprocessor.HttpResponseDataAppender.java

public void appendHttpResponseData(HttpResponse httpResponse, final String contentType, final String data) {

    httpResponse.setEntity(new EntityTemplate(new ContentProducer() {
        @Override//w w w .  jav a2  s .  c  om
        public void writeTo(OutputStream outstream) throws IOException {
            OutputStreamWriter writer = new OutputStreamWriter(outstream, mDefaultEncoding);
            writer.write(data);
            writer.flush();
            writer.close();
        }
    }));
    httpResponse.setHeader(WebServerConstants.HTTP.KEY_CONTENT_TYPE, contentType);
}