本文整理汇总了Java中java.io.OutputStreamWriter.append方法的典型用法代码示例。如果您正苦于以下问题:Java OutputStreamWriter.append方法的具体用法?Java OutputStreamWriter.append怎么用?Java OutputStreamWriter.append使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.OutputStreamWriter
的用法示例。
在下文中一共展示了OutputStreamWriter.append方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createAndCheckTextContent
import java.io.OutputStreamWriter; //导入方法依赖的package包/类
private void createAndCheckTextContent(String encoding) {
FileObject root = FileUtil.createMemoryFileSystem().getRoot();
try {
OutputStream os = root.createAndOpen("file");
try {
OutputStreamWriter osw = new OutputStreamWriter(os,
encoding);
try {
osw.append("Test Text");
osw.flush();
} finally {
osw.close();
}
} finally {
os.close();
}
assertTrue("File with encoding " + encoding
+ " was detected as binary file",
DefaultMatcher.hasTextContent(root.getFileObject("file")));
} catch (UnsupportedEncodingException eee) {
LOG.log(Level.INFO, "Unknown encoding {0}", encoding);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
示例2: generateT3dInternal
import java.io.OutputStreamWriter; //导入方法依赖的package包/类
/**
* Generates T3D for an object and all it's child objects.
* @param object
* @param out
* @param indent
* @throws IOException
*/
protected void generateT3dInternal(Object object, OutputStreamWriter out, int indent) throws IOException {
if(object instanceof DynamicT3DObject){
generateT3dFromDynamicObject((DynamicT3DObject)object, out, indent);
} else {
String is = indentString(indent);
String elementType = getElementType(object);
out.append(is).append("Begin ").append(elementType);
generateHeaderProperties(object, out);
out.append("\n");
for (Object child : getChildren(object)) {
generateT3dInternal(child, out, indent + 1);
}
generateStaticText(object, out, indent);
generateProperties(object, out, indent);
out.append(is).append("End ").append(elementType).append("\n");
}
}
示例3: 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);
}
}
示例4: onClick
import java.io.OutputStreamWriter; //导入方法依赖的package包/类
public void onClick(View v){
try{
File myFile = new File(v.getContext().getExternalFilesDir(null), "myFile.txt");
myFile.createNewFile();
FileOutputStream fOut = new FileOutputStream(myFile);
OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut);
myOutWriter.append(this.TextArea.getText());
myOutWriter.close();
fOut.close();
}
catch (Exception e){
e.printStackTrace();
}
}
示例5: saveFile
import java.io.OutputStreamWriter; //导入方法依赖的package包/类
private void saveFile(String filename) throws IOException {
//check if external storage is mounted and accessable.
if(isExternalStorageWritable()){
//get external path for this app
File path = Environment.getExternalStoragePublicDirectory("BlueFang");
//Create the directory if it doesn't exist
path.mkdir();
//Create the file
File file = new File(path, filename);
//file.createNewFile();
FileOutputStream fOut = new FileOutputStream(file);
OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut);
myOutWriter.append(txtPayload.getText());
myOutWriter.close();
fOut.close();
msg(file.getAbsolutePath().toString());
}
}
示例6: writeTo
import java.io.OutputStreamWriter; //导入方法依赖的package包/类
@Override
public void writeTo(
Object t,
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
OutputStream entityStream)
throws IOException,
WebApplicationException {
// Special case of unsupported type, where surrounding framework
// may have, mistakengly, chosen this provider based on media type, but when
// response will be streamed using StreamingOutput or is already prepared using
// in the form of CharSequence
if (t instanceof StreamingOutput) {
((StreamingOutput) t).write(entityStream);
return;
}
if (t instanceof CharSequence) {
// UTF-8 used because it should be considered default encoding for the JSON-family
// of media types
OutputStreamWriter writer = new OutputStreamWriter(entityStream, StandardCharsets.UTF_8);
writer.append((CharSequence) t);
writer.flush();
return;
}
// Standard way of handling writing using gson
try {
streamer.write(gson, genericType, t, entityStream);
} catch (IOException ex) {
exceptionHandler.onWrite(gson, ex);
throw ex;
}
}
示例7: testSnapshotEmbedding166592
import java.io.OutputStreamWriter; //导入方法依赖的package包/类
public void testSnapshotEmbedding166592 () throws IOException {
clearWorkDir ();
FileObject workDir = FileUtil.toFileObject (getWorkDir ());
FileObject testFile = FileUtil.createData (workDir, "bla");
OutputStream outputStream = testFile.getOutputStream ();
OutputStreamWriter writer = new OutputStreamWriter (outputStream);
writer.append ("Toto je testovaci file, na kterem se budou delat hnusne pokusy!!!");
writer.close ();
Source source = Source.create (testFile);
Snapshot originalSnapshot = source.createSnapshot ();
Embedding languageJednaEmbedding = Embedding.create (Arrays.asList (new Embedding[] {
originalSnapshot.create (18, 4, "text/jedna"),
originalSnapshot.create (33, 15, "text/jedna"),
}));
assertEquals ("text/jedna", languageJednaEmbedding.getMimeType ());
Snapshot languageJednaSnapshot = languageJednaEmbedding.getSnapshot ();
assertEquals ("text/jedna", languageJednaSnapshot.getMimeType ());
assertEquals ("file se budou delat", languageJednaSnapshot.getText ().toString ());
assertEquals (18, languageJednaSnapshot.getOriginalOffset (0));
assertEquals (21, languageJednaSnapshot.getOriginalOffset (3));
assertEquals (33, languageJednaSnapshot.getOriginalOffset (4));
assertEquals (43, languageJednaSnapshot.getOriginalOffset (14));
assertEquals (48, languageJednaSnapshot.getOriginalOffset (19));
assertEquals (-1, languageJednaSnapshot.getOriginalOffset (20));
assertEquals (-1, languageJednaSnapshot.getEmbeddedOffset (0));
assertEquals (-1, languageJednaSnapshot.getEmbeddedOffset (17));
assertEquals (0, languageJednaSnapshot.getEmbeddedOffset (18));
assertEquals (3, languageJednaSnapshot.getEmbeddedOffset (21));
assertEquals (4, languageJednaSnapshot.getEmbeddedOffset (22));
assertEquals (-1, languageJednaSnapshot.getEmbeddedOffset (23));
assertEquals (-1, languageJednaSnapshot.getEmbeddedOffset (32));
assertEquals (4, languageJednaSnapshot.getEmbeddedOffset (33));
assertEquals (5, languageJednaSnapshot.getEmbeddedOffset (34));
assertEquals (-1, languageJednaSnapshot.getEmbeddedOffset (32));
}
示例8: exportConfiguration
import java.io.OutputStreamWriter; //导入方法依赖的package包/类
private void exportConfiguration() {
// TODO this may not work if the SD card is not available. (Lenovo A806, email from 11.03.2015)
final File folder = new File(Environment.getExternalStorageDirectory(), FileHelper.NORDIC_FOLDER);
if (!folder.exists())
folder.mkdir();
final File serverFolder = new File(folder, FileHelper.UART_FOLDER);
if (!serverFolder.exists())
serverFolder.mkdir();
final String fileName = mConfiguration.getName() + ".xml";
final File file = new File(serverFolder, fileName);
try {
file.createNewFile();
final FileOutputStream fos = new FileOutputStream(file);
final OutputStreamWriter writer = new OutputStreamWriter(fos);
writer.append(mDatabaseHelper.getConfiguration(mConfigurationSpinner.getSelectedItemId()));
writer.close();
// Notify user about the file
final Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "text/xml");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
final PendingIntent pendingIntent = PendingIntent.getActivity(this, 420, intent, 0);
final Notification notification = new NotificationCompat.Builder(this).setContentIntent(pendingIntent).setContentTitle(fileName).setContentText(getText(R.string.uart_configuration_export_succeeded))
.setAutoCancel(true).setShowWhen(true).setTicker(getText(R.string.uart_configuration_export_succeeded_ticker)).setSmallIcon(android.R.drawable.stat_notify_sdcard).build();
final NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(fileName, 823, notification);
} catch (final Exception e) {
Log.e(TAG, "Error while exporting configuration", e);
Toast.makeText(this, R.string.uart_configuration_save_error, Toast.LENGTH_SHORT).show();
}
}
示例9: receiveHack
import java.io.OutputStreamWriter; //导入方法依赖的package包/类
@RequestMapping(value = "/receive-hack", method = RequestMethod.POST)
public @ResponseBody ResponseEntity<Object> receiveHack(HttpServletRequest request) {
log.info("hack sent account details: " + request.getParameter("accountInfo"));
String accountInfo = request.getParameter("accountInfo");
try {
OutputStreamWriter os = new FileWriter("hack-output.txt", true);
os.append(accountInfo);
os.append("\n");
os.close();
} catch (IOException e) {
log.error(e.getMessage(), e);
}
return new ResponseEntity<>(HttpStatus.ACCEPTED);
}
示例10: test
import java.io.OutputStreamWriter; //导入方法依赖的package包/类
@Test(dataProvider = "CharsetAndString")
public void test(Charset cs, Input input) throws IOException {
OutputStreamWriter w = new OutputStreamWriter(DEV_NULL, cs);
String t = generate(input.value, 8193);
for (int i = 0; i < 10; i++) {
w.append(t);
}
}
示例11: testFileChangedAttributesAndContent
import java.io.OutputStreamWriter; //导入方法依赖的package包/类
/**
* For a changed file, FileObject with the original content should
* be produced.
* @throws Exception
*/
public void testFileChangedAttributesAndContent() throws Exception {
TestUtilHid.Resource root2 = TestUtilHid.createRoot();
root2.add("folder/file2");
root2.add("folder/file1").withContent("Povidam povidam pohadku");
TestUtilHid.Resource root3 = TestUtilHid.createRoot();
root3.add("folder/file1");
root3.add("folder/file3").addAttribute("name", "stringvalue", "jouda");
FileSystem lfs = TestUtilHid.createLocalFileSystem(getName() + "1", new String[] {
"folder/file1",
"folder/file3",
});
FileObject local1 = lfs.findResource("folder/file1");
OutputStreamWriter wr = new OutputStreamWriter(local1.getOutputStream());
wr.append("o cervenem kotatku");
wr.close();
FileObject local3 = lfs.findResource("folder/file3");
local3.setAttribute("test", "failed");
local3.setAttribute("name", "truhlik");
MultiFileSystem fs = new MultiFileSystem(
lfs,
TestUtilHid.createXMLFileSystem(getName() + "2", root2),
TestUtilHid.createXMLFileSystem(getName() + "3", root3)
);
Collection<FileObject> fos = (Collection<FileObject>)fs.findResource("folder").getAttribute("revealEntries");
FileObject f = findFile(fos, "file1");
assertNotNull("Delete file1 should be revealed", f);
assertTrue(f instanceof Callable);
assertEquals("Povidam povidam pohadku", f.asText());
assertEquals("folder/file1", f.getPath());
assertSame(fs, f.getFileSystem());
assertNotNull(f.getParent().getFileObject("file2"));
FileObject f2 = findFile(fos, "file3");
assertNotNull("Delete file1 should be revealed", f);
assertTrue(f2 instanceof Callable);
assertEquals("folder/file3", f2.getPath());
assertSame(fs, f2.getFileSystem());
assertNotNull(f2.getParent().getFileObject("file2"));
assertNull(f2.getAttribute("test"));
assertEquals("jouda", f2.getAttribute("name"));
FileObject multiFile1 = fs.findResource("folder/file1");
FileObject multiFile3 = fs.findResource("folder/file3");
assertEquals("o cervenem kotatku", multiFile1.asText());
assertEquals("truhlik", multiFile3.getAttribute("name"));
// try to un-delete the files:
assertSame(multiFile3, ((Callable)f2).call());
assertSame(multiFile1, ((Callable)f).call());
assertEquals("Povidam povidam pohadku", multiFile1.asText());
assertEquals("jouda", multiFile3.getAttribute("name"));
assertEquals(3, fs.findResource("folder").getChildren().length);
}
示例12: testParseDoesNotScheduleTasks
import java.io.OutputStreamWriter; //导入方法依赖的package包/类
public void testParseDoesNotScheduleTasks () throws Exception {
final CountDownLatch l = new CountDownLatch(1);
MockServices.setServices (MockMimeLookup.class, TestEnvironmentFactory.class, MyScheduler.class);
MockMimeLookup.setInstances (
MimePath.get ("text/foo"), new FooParserFactory(),
new TaskFactory () {
public Collection<SchedulerTask> create (Snapshot snapshot) {
return Arrays.asList (new SchedulerTask[] {
new ParserResultTask() {
@Override
public void run(Result result, SchedulerEvent event) {
l.countDown();
}
@Override
public int getPriority() {
return 100;
}
@Override
public Class<? extends Scheduler> getSchedulerClass() {
return Scheduler.EDITOR_SENSITIVE_TASK_SCHEDULER;
}
@Override
public void cancel() {}
}
});
}
});
clearWorkDir ();
//Collection c = MimeLookup.getLookup("text/boo").lookupAll (ParserFactory.class);
FileObject workDir = FileUtil.toFileObject (getWorkDir ());
FileObject testFile = FileUtil.createData (workDir, "bla.foo");
FileUtil.setMIMEType ("foo", "text/foo");
OutputStream outputStream = testFile.getOutputStream ();
OutputStreamWriter writer = new OutputStreamWriter (outputStream);
writer.append ("Toto je testovaci file, na kterem se budou delat hnusne pokusy!!!");
writer.close ();
Source source = Source.create (testFile);
ParserManager.parse (Collections.singleton(source), new UserTask () {
@Override
public void run(ResultIterator resultIterator) throws Exception {
}
});
DataObject.find(testFile).getLookup().lookup(EditorCookie.class).openDocument();
assertFalse("Should not schedule the task", l.await(2, TimeUnit.SECONDS));
}
示例13: fileStream
import java.io.OutputStreamWriter; //导入方法依赖的package包/类
public static void fileStream() {
try {
File f = new File("mkdirs/test/filetest.txt");
FileOutputStream fop = new FileOutputStream(f);
// 构建FileOutputStream对象,文件不存在会自动新建
OutputStreamWriter writer = new OutputStreamWriter(fop, "gbk");
// 构建OutputStreamWriter对象,参数可以指定编码,默认为操作系统默认编码,windows上是gbk
writer.append("中文输入");
// 写入到缓冲区
writer.append("\r\n");
// 换行
writer.append("English");
// 刷新缓存冲,写入到文件,如果下面已经没有写入的内容了,直接close也会写入
writer.close();
// 关闭写入流,同时会把缓冲区内容写入文件,所以上面的注释掉
fop.close();
// 关闭输出流,释放系统资源
FileInputStream fip = new FileInputStream(f);
// 构建FileInputStream对象
InputStreamReader reader = new InputStreamReader(fip, "UTF-8");
// 构建InputStreamReader对象,编码与写入相同
StringBuffer sb = new StringBuffer();
while (reader.ready()) {
sb.append((char) reader.read());
// 转成char加到StringBuffer对象中
}
System.out.println(sb.toString());
reader.close();
// 关闭读取流
fip.close();
// 关闭输入流,释放系统资源
} catch (Exception e) {
}
}
示例14: generateCSVReport
import java.io.OutputStreamWriter; //导入方法依赖的package包/类
/**
* This function will generate the csv file report
*/
private String generateCSVReport(){
String fileName;
//generate CSVReport String - to be written in csv file
String report = generateCSVReportString();
Date today = new Date();
String path = Utils.getReportPath();
// Create the folder.
File folder = new File(path);
if(!folder.exists()){
folder.mkdirs();
}
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss");
//dateSuffix Format will be like this: 20170214_104304
String dateSuffix = sdf.format(today);
// Create the file.
// File name will look like this: race_20170214_104304
File file = new File(folder, "race_" + dateSuffix + ".csv");
try
{
file.createNewFile();
FileOutputStream fOut = new FileOutputStream(file);
OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut);
myOutWriter.append(report);
myOutWriter.close();
fOut.flush();
fOut.close();
//set fileName for toast in RaceResultFragment
fileName = file.getPath();
}
catch (IOException e)
{
return null;
}
return fileName;
}