当前位置: 首页>>代码示例>>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;未经允许,请勿转载。