當前位置: 首頁>>代碼示例>>Java>>正文


Java OutputStreamWriter.close方法代碼示例

本文整理匯總了Java中java.io.OutputStreamWriter.close方法的典型用法代碼示例。如果您正苦於以下問題:Java OutputStreamWriter.close方法的具體用法?Java OutputStreamWriter.close怎麽用?Java OutputStreamWriter.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.io.OutputStreamWriter的用法示例。


在下文中一共展示了OutputStreamWriter.close方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: saveDocument

import java.io.OutputStreamWriter; //導入方法依賴的package包/類
public static void saveDocument(Document doc, String filePath) {
    /**
     * @todo: Configurable parameters
     */
    try {
        /*The XOM bug: reserved characters are not escaped*/
        //Serializer serializer = new Serializer(new FileOutputStream(filePath), "UTF-8");
        //serializer.write(doc);
        OutputStreamWriter fw =
            new OutputStreamWriter(new FileOutputStream(filePath), "UTF-8");
        fw.write(doc.toXML());
        fw.flush();
        fw.close();
    }
    catch (IOException ex) {
        new ExceptionDialog(
            ex,
            "Failed to write a document to " + filePath,
            "");
    }
}
 
開發者ID:ser316asu,項目名稱:Wilmersdorf_SER316,代碼行數:22,代碼來源:FileStorage.java

示例2: post

import java.io.OutputStreamWriter; //導入方法依賴的package包/類
/**
 * Sends a POST request to a given url, with JSON data as payload
 * 
 * @param url
 * @param data
 * @return String
 */
public static String post(String uri, HashMap<String, String> payload) throws Exception {
	URL url = new URL(uri);
	Object connection = (uri.startsWith("https://") ? (HttpsURLConnection) url.openConnection()
			: (HttpURLConnection) url.openConnection());
	((URLConnection) connection).setConnectTimeout(8 * 1000);
	((URLConnection) connection).setRequestProperty("User-Agent", userAgent);

	((URLConnection) connection).setDoInput(true);
	((URLConnection) connection).setDoOutput(true);
	((HttpURLConnection) connection).setRequestMethod("POST");
	((URLConnection) connection).setRequestProperty("Accept", "application/json");
	((URLConnection) connection).setRequestProperty("Content-Type", "application/json; charset=UTF-8");
	OutputStreamWriter writer = new OutputStreamWriter(((URLConnection) connection).getOutputStream(), "UTF-8");
	writer.write(mapToJson(payload));
	writer.close();
	BufferedReader br = new BufferedReader(new InputStreamReader(((URLConnection) connection).getInputStream()));
	StringBuffer data = new StringBuffer();
	String line;
	while ((line = br.readLine()) != null) {
		data.append(line);
	}
	br.close();
	((HttpURLConnection) connection).disconnect();
	return data.toString();
}
 
開發者ID:Moudoux,項目名稱:EMC-Marketplace-Mod,代碼行數:33,代碼來源:Web.java

示例3: post

import java.io.OutputStreamWriter; //導入方法依賴的package包/類
public static String post(URLConnection connection,
                          String stringWriter,
                          Credentials credentials) throws Exception {

   connection.setDoInput(true);
   connection.setDoOutput(true);
   connection.setRequestProperty("Authorization",
                                 "Basic "
                                       + Base64.encode((credentials.getUserName() + ":" + new String(
                                             credentials.getPassword())).getBytes()));
   OutputStreamWriter postData = new OutputStreamWriter(connection.getOutputStream());
   postData.write(stringWriter);
   postData.flush();
   postData.close();

   BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
   String response = "";
   String line = "";
   while ((line = in.readLine()) != null)
      response = response + line;
   in.close();

   return response;
}
 
開發者ID:mqsysadmin,項目名稱:dpdirect,代碼行數:25,代碼來源:PostXML.java

示例4: saveContext

import java.io.OutputStreamWriter; //導入方法依賴的package包/類
/**
 * 保存文件
 * 
 * @param articleno
 *            小說編號
 * @param chapterno
 *            章節編號
 * @param content
 *            章節內容
 * @throws IOException
 *             IO異常
 */
public static void saveContext(int articleno, int chapterno, String content) throws IOException {
    String path = getTextFilePathByChapterno(articleno, chapterno);
    File file = new File(path);

    File parentPath = file.getParentFile();
    if (!parentPath.exists()) {
        parentPath.mkdirs();
    }
    try {
        OutputStreamWriter outputStream = new OutputStreamWriter(new FileOutputStream(file),
                YiDuConstants.yiduConf.getString(YiDuConfig.TXT_ENCODING));
        outputStream.write(content);
        outputStream.flush();
        outputStream.close();

    } catch (IOException e) {
        logger.error(e.getMessage(), e);
    }
}
 
開發者ID:luckyyeah,項目名稱:YiDu-Novel,代碼行數:32,代碼來源:Utils.java

示例5: createTestFile

import java.io.OutputStreamWriter; //導入方法依賴的package包/類
/**
 * Create an in-memory file with simple string content.
 *
 * @param content Content of the file.
 */
public FileObject createTestFile(String content) throws IOException {

    FileObject root = FileUtil.createMemoryFileSystem().getRoot();
    FileObject fo = root.createData(TEST_FILE_NAME);

    OutputStream os = fo.getOutputStream();
    try {
        OutputStreamWriter osw = new OutputStreamWriter(os, TEST_FILE_ENC);
        try {
            osw.write(content);
        } finally {
            osw.flush();
            osw.close();
        }
    } finally {
        os.close();
    }
    return fo;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:25,代碼來源:MatchingObjectTest.java

示例6: save

import java.io.OutputStreamWriter; //導入方法依賴的package包/類
/**
 * Saves result to report.txt according to the format
 *
 * <iteration>,<time>,<score>
 *
 * @throws IOException
 */
public void save() throws IOException {
    if (fs.exists(file)) {
        fs.delete(file, false);
    }
    FSDataOutputStream fsDataOutputStream = fs.create(file);
    OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fsDataOutputStream);
    BufferedWriter writer = new BufferedWriter(outputStreamWriter);

    for (int i = 0; i < time.size(); i++) {
        writer.write("" + i + "," + time.get(i) + "," + result.get(i) + "\n");
    }

    writer.flush();
    writer.close();
    outputStreamWriter.close();
    fsDataOutputStream.close();

}
 
開發者ID:Romm17,項目名稱:MRNMF,代碼行數:26,代碼來源:ResultHolder.java

示例7: writeToFile

import java.io.OutputStreamWriter; //導入方法依賴的package包/類
public static void writeToFile(String data, Context context) {
    try {
        OutputStreamWriter outputStreamWriter = new OutputStreamWriter(context.openFileOutput("imagenes.json", Context.MODE_PRIVATE));
        outputStreamWriter.write(data);
        outputStreamWriter.close();
    }
    catch (IOException e) {
        Log.e("Exception", "File write failed: " + e.toString());
    }
}
 
開發者ID:ur13l,項目名稱:Guanajoven,代碼行數:11,代碼來源:FileUtils.java

示例8: writeInternal

import java.io.OutputStreamWriter; //導入方法依賴的package包/類
protected void writeInternal(Object o, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException {
  
  
  Charset charset = this.getCharset(outputMessage.getHeaders());
  OutputStreamWriter writer = new OutputStreamWriter(outputMessage.getBody(), charset);
  
  try {
    if(this.jsonPrefix != null) {
      writer.append(this.jsonPrefix);
    }
    
    this.gson.toJson(o, writer);
    
    writer.close();
  } catch (JsonIOException var7) {
    throw new HttpMessageNotWritableException("Could not write JSON: " + var7.getMessage(), var7);
  }
}
 
開發者ID:Huawei,項目名稱:Server_Management_Common_eSightApi,代碼行數:19,代碼來源:GsonHttpMessageConverter.java

示例9: doInBackground

import java.io.OutputStreamWriter; //導入方法依賴的package包/類
@Override
protected final Void doInBackground(ItemState... itemStates) {
    for (ItemState state : itemStates) {
        try {
            HttpURLConnection urlConnection = ConnectionUtil.createUrlConnection(serverUrl + "/rest/items/" + state.mItemName + "/state");
            try {
                urlConnection.setRequestMethod("PUT");
                urlConnection.setDoOutput(true);
                urlConnection.setRequestProperty("Content-Type", "text/plain");
                urlConnection.setRequestProperty("Accept", "application/json");

                OutputStreamWriter osw = new OutputStreamWriter(urlConnection.getOutputStream());
                osw.write(state.mItemState);
                osw.flush();
                osw.close();
                Log.v("Habpanelview", "set request response: " + urlConnection.getResponseMessage()
                        + "(" + urlConnection.getResponseCode() + ")");
            } finally {
                urlConnection.disconnect();
            }
        } catch (IOException | GeneralSecurityException e) {
            Log.e("Habpanelview", "Failed to set state for item " + state.mItemName, e);
        }

        if (isCancelled()) {
            return null;
        }
    }
    return null;
}
 
開發者ID:vbier,項目名稱:habpanelviewer,代碼行數:31,代碼來源:SetItemStateTask.java

示例10: writedoc

import java.io.OutputStreamWriter; //導入方法依賴的package包/類
/**
 *  Writes the given element's subtree to the specified file.
 *
 * @param  fname           The output file name
 * @param  ele             The xml Element subtree to write to file
 * @param  doc             The Document
 * @return                 True if content previously existed in the given file and the content is the same
 *      as the new content provided
 * @exception  Hexception  If exception
 */
private boolean writedoc(
		String fname,
		Element ele,
		Document doc)
		 throws Hexception {
	try {
		boolean contentEquals = false;

		String s1 = null;
		File f = new File(fname);
		if (f.exists())
			s1 = Files.readFileToEncoding(f, "UTF-8").toString();

		FileOutputStream fos = new FileOutputStream(f);
		OutputStreamWriter osw = new OutputStreamWriter(fos, "UTF-8");
		Writer wtr = new BufferedWriter(osw);
		OutputFormat format = new OutputFormat(doc, "UTF-8", true);
		// Indenting true
		format.setMethod("xml");
		// May not ne necessary to call this
		format.setLineWidth(0);
		// No line wrapping
		XMLSerializer ser = new XMLSerializer(wtr, format);
		ser.serialize(ele);
		fos.close();
		osw.close();
		wtr.close();

		if (s1 != null)
			contentEquals = s1.contentEquals(Files.readFileToEncoding(f, "UTF-8"));

		return contentEquals;
	} catch (IOException ioe) {
		throw new Hexception("cannot write file \"" + fname
				 + "\"  reason: " + ioe);
	}
}
 
開發者ID:NCAR,項目名稱:joai-project,代碼行數:48,代碼來源:Harvester.java

示例11: dump

import java.io.OutputStreamWriter; //導入方法依賴的package包/類
/**
 * Ascii file dump.
 *
 * dumpFile must not be null.
 */
private void dump(String varName,
                  File dumpFile) throws IOException, BadSpecial {
    String val = shared.userVars.get(varName);

    if (val == null)
        throw new BadSpecial(SqltoolRB.plvar_undefined.getString(varName));

    OutputStreamWriter osw = new OutputStreamWriter(
            new FileOutputStream(dumpFile), (shared.encoding == null)
            ? DEFAULT_FILE_ENCODING : shared.encoding);

    try {
        osw.write(val);

        if (val.length() > 0) {
            char lastChar = val.charAt(val.length() - 1);

            if (lastChar != '\n' && lastChar != '\r') osw.write(LS);
        }

        osw.flush();
    } finally {
        try {
            osw.close();
        } catch (IOException ioe) {
            // Intentionally empty
        } finally {
            osw = null;  // Encourage GC of buffers
        }
    }

    // Since opened in overwrite mode, since we didn't exception out,
    // we can be confident that we wrote all the bytest in the file.
    stdprintln(SqltoolRB.file_wrotechars.getString(
            Long.toString(dumpFile.length()), dumpFile.toString()));
}
 
開發者ID:tiweGH,項目名稱:OpenDiabetes,代碼行數:42,代碼來源:SqlFile.java

示例12: onClick

import java.io.OutputStreamWriter; //導入方法依賴的package包/類
@Override
public void onClick(View view) {
    switch (view.getId()) {
        case R.id.bStart:
            startRecording();
            break;
        case R.id.bStop:
            stopRecording();
            break;
        case R.id.bExport:
            try {
                // create and write output file in cache directory
                File outputFile = new File(getActivity().getCacheDir(), "recording.csv");
                OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(outputFile));
                writer.write(Util.recordingToCSV(mRecording));
                writer.close();

                // get Uri from FileProvider
                Uri contentUri = FileProvider.getUriForFile(getActivity(), "com.martindisch.accelerometer.fileprovider", outputFile);

                // create sharing intent
                Intent shareIntent = new Intent();
                shareIntent.setAction(Intent.ACTION_SEND);
                // temp permission for receiving app to read this file
                shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                shareIntent.setType("text/csv");
                shareIntent.putExtra(Intent.EXTRA_STREAM, contentUri);
                startActivity(Intent.createChooser(shareIntent, "Choose an app"));
            } catch (IOException e) {
                Toast.makeText(getActivity(), R.string.error_file, Toast.LENGTH_SHORT).show();
            }
            break;
    }
}
 
開發者ID:martindisch,項目名稱:SensorTag-Accelerometer,代碼行數:35,代碼來源:DeviceFragment.java

示例13: createInfoFile

import java.io.OutputStreamWriter; //導入方法依賴的package包/類
private void createInfoFile(Path dir) throws IOException
{
    Path info = Files.createFile(dir.resolve("info.txt"));
    Map<String, String> machineenv = DockerMachine.machineenv();
    OutputStreamWriter out = new OutputStreamWriter(Files.newOutputStream(info, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING));
    out.write("Java version = " + System.getProperty("java.version") + "\n");
    out.write("Docker version = " + DockerContainer.version(machineenv) + "\n");
    out.write("VBoxVersion version = " + DockerMachine.vboxversion() + "\n");
    out.write("Machine Env = " + Arrays.toString(machineenv.entrySet().toArray()) + "\n");
    out.close();
}
 
開發者ID:drytoastman,項目名稱:scorekeeperfrontend,代碼行數:12,代碼來源:DebugCollector.java

示例14: writeSrcFile

import java.io.OutputStreamWriter; //導入方法依賴的package包/類
private void writeSrcFile(Path srcFilePath, String fileName, String data)
    throws IOException {
  OutputStreamWriter osw = getOutputStreamWriter(srcFilePath, fileName);
  osw.write(data);
  osw.close();
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:7,代碼來源:TestAggregatedLogFormat.java

示例15: writeContent

import java.io.OutputStreamWriter; //導入方法依賴的package包/類
static void writeContent(HttpURLConnection urlConn, String content) throws IOException {
    OutputStreamWriter out = new OutputStreamWriter(
            urlConn.getOutputStream());
    out.write(content);
    out.close();
}
 
開發者ID:wso2-extensions,項目名稱:siddhi-io-http,代碼行數:7,代碼來源:HttpServerUtil.java


注:本文中的java.io.OutputStreamWriter.close方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。