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


Java OutputStreamWriter.append方法代碼示例

本文整理匯總了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);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:26,代碼來源:DefaultMatcherTest.java

示例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");
    }
}
 
開發者ID:kefik,項目名稱:Pogamut3,代碼行數:29,代碼來源:DefaultT3dGenerator.java

示例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);
  }
}
 
開發者ID:Huawei,項目名稱:Server_Management_Common_eSightApi,代碼行數:19,代碼來源:GsonHttpMessageConverter.java

示例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();
    }
}
 
開發者ID:mnirfan,項目名稱:kuliah-pemrograman-mobile,代碼行數:17,代碼來源:MainActivity.java

示例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());

        }

    }
 
開發者ID:chooka888,項目名稱:BluetoothDuck,代碼行數:27,代碼來源:BTTerminal.java

示例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;
  }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:36,代碼來源:GsonMessageBodyProvider.java

示例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));
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:37,代碼來源:SnapshotTest.java

示例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();
	}
}
 
開發者ID:runtimeco,項目名稱:Android-DFU-App,代碼行數:33,代碼來源:UARTActivity.java

示例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);
}
 
開發者ID:grantharper,項目名稱:security-demo,代碼行數:15,代碼來源:InsecureController.java

示例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);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:9,代碼來源:StreamEncoderOut.java

示例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);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:68,代碼來源:MultiFileSystemRevealTest.java

示例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));
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:50,代碼來源:ParserManagerTest.java

示例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) {
	}
}
 
開發者ID:leon66666,項目名稱:JavaCommon,代碼行數:45,代碼來源:FileIODemo.java

示例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;
}
 
開發者ID:voroshkov,項目名稱:Chorus-RF-Laptimer,代碼行數:45,代碼來源:RaceResultFragment.java


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