use of java.io.OutputStreamWriter in project hazelcast by hazelcast.
the class HTTPCommunicator method mapPut.
public int mapPut(String mapName, String key, String value) throws IOException {
final String url = address + "maps/" + mapName + "/" + key;
final HttpURLConnection urlConnection = setupConnection(url, "POST");
// post the data
OutputStream out = urlConnection.getOutputStream();
Writer writer = new OutputStreamWriter(out, "UTF-8");
writer.write(value);
writer.close();
out.close();
return urlConnection.getResponseCode();
}
use of java.io.OutputStreamWriter in project hazelcast by hazelcast.
the class HTTPCommunicator method doPost.
private static ConnectionResponse doPost(String url, String... params) throws IOException {
HttpURLConnection urlConnection = setupConnection(url, "POST");
// post the data
OutputStream out = urlConnection.getOutputStream();
Writer writer = new OutputStreamWriter(out, "UTF-8");
String data = "";
for (String param : params) {
data += URLEncoder.encode(param, "UTF-8") + "&";
}
writer.write(data);
writer.close();
out.close();
try {
InputStream inputStream = urlConnection.getInputStream();
byte[] buffer = new byte[4096];
int readBytes = inputStream.read(buffer);
return new ConnectionResponse(readBytes == -1 ? "" : new String(buffer, 0, readBytes), urlConnection.getResponseCode());
} finally {
urlConnection.disconnect();
}
}
use of java.io.OutputStreamWriter in project HanLP by hankcs.
the class TestDependencyCorpus method testMakeCRF.
/**
* 导出CRF训练语料
*
* @throws Exception
*/
public void testMakeCRF() throws Exception {
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("D:\\Tools\\CRF++-0.58\\example\\dependency\\dev.txt")));
LinkedList<CoNLLSentence> coNLLSentences = CoNLLLoader.loadSentenceList("D:\\Doc\\语料库\\依存分析训练数据\\THU\\dev.conll.fixed.txt");
for (CoNLLSentence coNLLSentence : coNLLSentences) {
for (CoNLLWord coNLLWord : coNLLSentence.word) {
bw.write(coNLLWord.NAME);
bw.write('\t');
bw.write(coNLLWord.CPOSTAG);
bw.write('\t');
bw.write(coNLLWord.POSTAG);
bw.write('\t');
int d = coNLLWord.HEAD.ID - coNLLWord.ID;
int posDistance = 1;
if (// 在后面
d > 0) {
for (int i = 1; i < d; ++i) {
if (coNLLSentence.word[coNLLWord.ID - 1 + i].CPOSTAG.equals(coNLLWord.HEAD.CPOSTAG)) {
++posDistance;
}
}
} else {
for (// 在前面
int i = 1; // 在前面
i < -d; // 在前面
++i) {
if (coNLLSentence.word[coNLLWord.ID - 1 - i].CPOSTAG.equals(coNLLWord.HEAD.CPOSTAG)) {
++posDistance;
}
}
}
bw.write((d > 0 ? "+" : "-") + posDistance + "_" + coNLLWord.HEAD.CPOSTAG);
bw.newLine();
}
bw.newLine();
}
bw.close();
}
use of java.io.OutputStreamWriter in project HanLP by hankcs.
the class TestICWB method testDumpPeople2014ToBEMS.
public void testDumpPeople2014ToBEMS() throws Exception {
final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("D:\\Tools\\CRF++-0.58\\example\\seg_cn\\2014.txt")));
CorpusLoader.walk("D:\\JavaProjects\\CorpusToolBox\\data\\2014", new CorpusLoader.Handler() {
@Override
public void handle(Document document) {
List<List<Word>> simpleSentenceList = document.getSimpleSentenceList();
for (List<Word> wordList : simpleSentenceList) {
try {
for (Word word : wordList) {
bw.write(word.value);
bw.write(' ');
}
bw.newLine();
} catch (IOException e) {
e.printStackTrace();
}
}
}
});
bw.close();
}
use of java.io.OutputStreamWriter in project Gaffer by gchq.
the class AddElementsFromHdfsIT method shouldThrowExceptionWhenAddElementsFromHdfsWhenFailureDirectoryContainsFiles.
@Test
public void shouldThrowExceptionWhenAddElementsFromHdfsWhenFailureDirectoryContainsFiles() throws Exception {
final FileSystem fs = FileSystem.getLocal(createLocalConf());
fs.mkdirs(new Path(failureDir));
try (final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(fs.create(new Path(failureDir + "/someFile.txt"), true)))) {
writer.write("Some content");
}
try {
addElementsFromHdfs(ByteEntityKeyPackage.class);
fail("Exception expected");
} catch (final OperationException e) {
assertEquals("Failure directory is not empty: " + failureDir, e.getCause().getMessage());
}
//Previous job will output data successfully to the output dir but not load it.
fs.delete(new Path(outputDir), true);
try {
addElementsFromHdfs(ClassicKeyPackage.class);
fail("Exception expected");
} catch (final OperationException e) {
assertEquals("Failure directory is not empty: " + failureDir, e.getCause().getMessage());
}
}
Aggregations