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


Java OutputStreamWriter類代碼示例

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


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

示例1: testExtract

import java.io.OutputStreamWriter; //導入依賴的package包/類
public void testExtract() throws Exception
{
    List<File> fileList = FolderWalker.open(FOLDER);
    Map<String, String> phraseMap = new TreeMap<String, String>();
    int i = 0;
    for (File file : fileList)
    {
        System.out.print(++i + " / " + fileList.size() + " " + file.getName() + " ");
        String path = file.getAbsolutePath();
        List<String> phraseList = MutualInformationEntropyPhraseExtractor.extract(IOUtil.readTxt(path), 3);
        System.out.print(phraseList);
        for (String phrase : phraseList)
        {
            phraseMap.put(phrase, file.getAbsolutePath());
        }
        System.out.println();
    }
    BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("data/phrase.txt")));
    for (Map.Entry<String, String> entry : phraseMap.entrySet())
    {
        bw.write(entry.getKey() + "\t" + entry.getValue());
        bw.newLine();
    }
    bw.close();
}
 
開發者ID:priester,項目名稱:hanlpStudy,代碼行數:26,代碼來源:TestPhrase.java

示例2: send

import java.io.OutputStreamWriter; //導入依賴的package包/類
/**
 * Write reader to request body
 * <p>
 * The given reader will be closed once sending completes
 *
 * @param input
 * @return this request
 * @throws HttpRequestException
 */
public HttpRequest send(final Reader input) throws HttpRequestException {
    try {
        openOutput();
    } catch (IOException e) {
        throw new HttpRequestException(e);
    }
    final Writer writer = new OutputStreamWriter(output,
            output.encoder.charset());
    return new FlushOperation<HttpRequest>(writer) {

        @Override
        protected HttpRequest run() throws IOException {
            return copy(input, writer);
        }
    }.call();
}
 
開發者ID:bingo-oss,項目名稱:linkopensdk-android,代碼行數:26,代碼來源:HttpRequest.java

示例3: testRepositioningInfo

import java.io.OutputStreamWriter; //導入依賴的package包/類
/**
 * This method tests if Repositinioning Information works.
 * It creates a document using an xml file with preserveOriginalContent
 * and collectRepositioningInfo options keeping true and which has all
 * sorts of special entities like &amp, &quot etc. + it contains both
 * kind of unix and dos stype new line characters.  It then saves the
 * document to the temporary location on the disk using
 * "save preserving document format" option and then compares the contents of
 * both the original and the temporary document to see if they are equal.
 * @throws java.lang.Exception
 */
public void testRepositioningInfo() throws Exception {

  // here we need to save the document to the file
    String encoding = ((DocumentImpl)doc).getEncoding();
    File outputFile = File.createTempFile("test-inline1","xml");
    OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(outputFile),encoding);
    writer.write(doc.toXml(null, true));
    writer.flush();
    writer.close();
    Reader readerForSource = new BomStrippingInputStreamReader(new URL(testFile).openStream(),encoding);
    Reader readerForDesti = new BomStrippingInputStreamReader(new FileInputStream(outputFile),encoding);
    while(true) {
      int input1 = readerForSource.read();
      int input2 = readerForDesti.read();
      if(input1 < 0 || input2 < 0) {
        assertTrue(input1 < 0 && input2 < 0);
        readerForSource.close();
        readerForDesti.close();
        outputFile.delete();
        return;
      } else {
        assertEquals(input1,input2);
      }
    }
}
 
開發者ID:GateNLP,項目名稱:gate-core,代碼行數:37,代碼來源:TestRepositioningInfo.java

示例4: dumpCorpusFolderToFile

import java.io.OutputStreamWriter; //導入依賴的package包/類
/**
 * 多語料文件合並功能:文件夾的分詞標注數據合並為一個文件
 *
 * @throws Exception
 */
public void dumpCorpusFolderToFile() throws Exception {
    final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(CORPUS_FILE_PATH)));
    CorpusLoader.walk(CORPUS_FOLDER_PATH, document -> {
        List<List<Word>> simpleSentenceList = document.getSimpleSentenceList();
        for (List<Word> wordList : simpleSentenceList) {
            try {
                for (Word word : wordList) {
                    bw.write(word.toString());
                    bw.write(' ');
                }
                bw.newLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    });
    bw.close();
}
 
開發者ID:shibing624,項目名稱:crf-seg,代碼行數:24,代碼來源:GenerateBMESWithPosDemo.java

示例5: save

import java.io.OutputStreamWriter; //導入依賴的package包/類
public void save(OutputStream outStream) throws IOException {
    BufferedWriter out = new BufferedWriter(new OutputStreamWriter(outStream, "UTF-8"));
    String aKey;
    Object aValue;
    for (Enumeration e = keys(); e.hasMoreElements();) {
        aKey = (String) e.nextElement();
        aValue = get(aKey);
        out.write(aKey + " = " + aValue);
        out.newLine();
    }
    out.flush();
    out.close();
}
 
開發者ID:ser316asu,項目名稱:SER316-Ingolstadt,代碼行數:14,代碼來源:LoadableProperties.java

示例6: writeInternal

import java.io.OutputStreamWriter; //導入依賴的package包/類
@Override
protected void writeInternal(Object o, Type type, HttpOutputMessage outputMessage)
    throws IOException, HttpMessageNotWritableException {
    Charset charset = getCharset(outputMessage.getHeaders());

    try (OutputStreamWriter writer = new OutputStreamWriter(outputMessage.getBody(), charset)) {
        if (ignoreType) {
            gsonForWriter.toJson(o, writer);
            return;
        }

        if (type != null) {
            gsonForWriter.toJson(o, type, writer);
            return;
        }

        gsonForWriter.toJson(o, writer);
    } catch (JsonIOException ex) {
        throw new HttpMessageNotWritableException("Could not write JSON: " + ex.getMessage(), ex);
    }
}
 
開發者ID:FlowCI,項目名稱:flow-platform,代碼行數:22,代碼來源:RawGsonMessageConverter.java

示例7: convert

import java.io.OutputStreamWriter; //導入依賴的package包/類
@Override
public RequestBody convert(T value) throws IOException {
  //if (String.class.getName().equals(value.getClass().getName())) {
  //  return RequestBody.create(MediaType.parse("text/plain"), value.toString());
  //}

  Buffer buffer = new Buffer();
  Writer writer = new OutputStreamWriter(buffer.outputStream(), UTF_8);
  JsonWriter jsonWriter = gson.newJsonWriter(writer);
  try {
    adapter.write(jsonWriter, value);
    jsonWriter.flush();
  } catch (IOException e) {
    throw new AssertionError(e); // Writing to Buffer does no I/O.
  } finally {
    jsonWriter.close();
  }

  return RequestBody.create(MEDIA_TYPE, buffer.readByteString());
}
 
開發者ID:Lingzh0ng,項目名稱:BrotherWeather,代碼行數:21,代碼來源:PPRestRequestBodyConverter.java

示例8: writetxt

import java.io.OutputStreamWriter; //導入依賴的package包/類
public static void writetxt(String txtPath, String txtCont)
{
	try
	{
		File f = new File(txtPath);
		if (!f.exists())
		{
			f.createNewFile();
		}
		OutputStreamWriter write = new OutputStreamWriter(new FileOutputStream(f,true), "UTF-8");
		BufferedWriter writer = new BufferedWriter(write);
		writer.write(txtCont);
		writer.close();
	} catch (Exception e)
	{
		e.printStackTrace();
	}
}
 
開發者ID:guozhaotong,項目名稱:FacetExtract,代碼行數:19,代碼來源:gNullRowFilter.java

示例9: postString

import java.io.OutputStreamWriter; //導入依賴的package包/類
/**
 * Posts string data (i.e. JSON string) to the specified URL 
 * connection.
 *
 * @param con  The URL connection. Must be in HTTP POST mode. Must not 
 *             be {@code null}.
 * @param data The string data to post. Must not be {@code null}.
 *
 * @throws JSONRPC2SessionException If an I/O exception is encountered.
 */
private static void postString(final URLConnection con, final String data)
	throws JSONRPC2SessionException {
	
	try {
		OutputStreamWriter wr = new OutputStreamWriter(con.getOutputStream(), "UTF-8");
		wr.write(data);
		wr.flush();
		wr.close();

	} catch (IOException e) {

		throw new JSONRPC2SessionException(
				"Network exception: " + e.getMessage(),
				JSONRPC2SessionException.NETWORK_EXCEPTION,
				e);
	}
}
 
開發者ID:CactusSoft,項目名稱:zabbkit-android,代碼行數:28,代碼來源:JSONRPC2Session.java

示例10: copyFile

import java.io.OutputStreamWriter; //導入依賴的package包/類
void copyFile(Path src, Path target) throws Exception {

        try (InputStream in = Files.newInputStream(src);
                BufferedReader reader
                = new BufferedReader(new InputStreamReader(in));
                OutputStream out = new BufferedOutputStream(
                        Files.newOutputStream(target, CREATE, APPEND));
                BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out))) {
            String line = null;
            while ((line = reader.readLine()) != null) {
                bw.write(line);
            }
        } catch (IOException x) {
            throw new Exception(x.getMessage());
        }
    }
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:17,代碼來源:CatalogFileInputTest.java

示例11: handleStatusOk

import java.io.OutputStreamWriter; //導入依賴的package包/類
@Override
protected void handleStatusOk(final HttpServletRequest req, final HttpServletResponse resp, String escapdPathInfo)
		throws ServletException {

	try {
		final String body = catalogSupplier.get();
		try (final OutputStream os = resp.getOutputStream();
				final OutputStreamWriter osw = new OutputStreamWriter(os)) {
			osw.write(body);
			osw.flush();
		}
	} catch (final Exception e) {
		final String msg = "Error while assembling test catalog for all tests.";
		LOGGER.error(msg, e);
		throw new ServletException(msg, e);
	}

}
 
開發者ID:eclipse,項目名稱:n4js,代碼行數:19,代碼來源:TestCatalogAssemblerResource.java

示例12: calulateHash

import java.io.OutputStreamWriter; //導入依賴的package包/類
static public byte[] calulateHash(JsonElement contents) {
  MessageDigest md;
  try {
    md = MessageDigest.getInstance("MD5");
  } catch (NoSuchAlgorithmException e) {
    throw new InternalError("MD5 MessageDigest is not available");
  }
  OutputStream byteSink = new OutputStream() {
    @Override
    public void write(int b) throws IOException {
      // ignore, since this is only used to calculate MD5
    }
  };
  DigestOutputStream dis = new DigestOutputStream(byteSink, md);
  new Gson().toJson(contents, new OutputStreamWriter(dis, Charset.forName(DEFAULT_CHARSET_NAME)));
  return dis.getMessageDigest().digest();
}
 
開發者ID:dreaminglion,項目名稱:iosched-reader,代碼行數:18,代碼來源:CloudFileManager.java

示例13: writePasswordFile

import java.io.OutputStreamWriter; //導入依賴的package包/類
/**
 * Writes the user's password to a tmp file with 0600 permissions.
 * @return the filename used.
 */
public static String writePasswordFile(Configuration conf)
    throws IOException {
  // Create the temp file to hold the user's password.
  String tmpDir = conf.get(
      ConfigurationConstants.PROP_JOB_LOCAL_DIRECTORY, "/tmp/");
  File tempFile = File.createTempFile("mysql-cnf", ".cnf", new File(tmpDir));

  // Make the password file only private readable.
  DirectImportUtils.setFilePermissions(tempFile, "0600");

  // If we're here, the password file is believed to be ours alone.  The
  // inability to set chmod 0600 inside Java is troublesome. We have to
  // trust that the external 'chmod' program in the path does the right
  // thing, and returns the correct exit status. But given our inability to
  // re-read the permissions associated with a file, we'll have to make do
  // with this.
  String password = DBConfiguration.getPassword((JobConf) conf);
  BufferedWriter w = new BufferedWriter(new OutputStreamWriter(
      new FileOutputStream(tempFile)));
  w.write("[client]\n");
  w.write("password=" + password + "\n");
  w.close();

  return tempFile.toString();
}
 
開發者ID:aliyun,項目名稱:aliyun-maxcompute-data-collectors,代碼行數:30,代碼來源:MySQLUtils.java

示例14: httpsPost

import java.io.OutputStreamWriter; //導入依賴的package包/類
public T httpsPost(String jsonBody, Class<T> clazz) throws IOException {
URL url = new URL(HTTPS_PROTOCOL, ACCOUNT_KEY_SERVICE_HOST, HTTPS_PORT,
	ACCOUNT_KEY_ENDPOINT);
httpsConnection = (HttpsURLConnection) url.openConnection();
httpsConnection.setRequestMethod(HttpRequestMethod.POST.toString());
setConnectionParameters(httpsConnection, HttpRequestMethod.POST);

httpsConnection.setFixedLengthStreamingMode(jsonBody.getBytes().length);
try (OutputStreamWriter out = new OutputStreamWriter(
	httpsConnection.getOutputStream())) {
    out.write(jsonBody);
}
StringBuilder sb = new StringBuilder();
try (BufferedReader in = new BufferedReader(new InputStreamReader(
	httpsConnection.getInputStream()))) {
    String inputLine;
    while ((inputLine = in.readLine()) != null) {
	sb.append(inputLine);
    }
}
// setFieldNamingPolicy is used to here to convert from
// lower_case_with_underscore names retrieved from end point to camel
// case to match POJO class
Gson gson = new GsonBuilder().setFieldNamingPolicy(
	FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();
return gson.fromJson(sb.toString(), clazz);
   }
 
開發者ID:ahmed-ebaid,項目名稱:invest-stash-rest,代碼行數:28,代碼來源:HttpRequests.java

示例15: createTestFile

import java.io.OutputStreamWriter; //導入依賴的package包/類
private static FileObject createTestFile (FileObject root, String path, String fileName, String content) throws IOException {
    FileObject pkg = path != null ?
            FileUtil.createFolder(root, path) :
            root;
    assertNotNull (pkg);
    FileObject data = pkg.createData(fileName);
    FileLock lock = data.lock();
    try {
        PrintWriter out = new PrintWriter (new OutputStreamWriter (data.getOutputStream(lock)));
        try {
            out.println (content);
        } finally {
            out.close();
        }
    } finally {
        lock.releaseLock();
    }
    return data;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:20,代碼來源:DefaultSourceLevelQueryImplTest.java


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