Java Text File Save writeFile(IFile annotationFile, StringBuffer head, String annotatedSignature, String nextLines, BufferedReader tailReader, IProgressMonitor monitor)

Here you can find the source of writeFile(IFile annotationFile, StringBuffer head, String annotatedSignature, String nextLines, BufferedReader tailReader, IProgressMonitor monitor)

Description

Write back the given annotationFile, with the following content: - head (assumed to include a member and its original signature - annotatedSignature - nextLines (optionally, may be null) - the still unconsumed content of tailReader

License

Open Source License

Declaration

private static void writeFile(IFile annotationFile, StringBuffer head, String annotatedSignature,
        String nextLines, BufferedReader tailReader, IProgressMonitor monitor)
        throws CoreException, IOException 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2015, 2016 GK Software AG.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors://  w w w .  j  a v a 2s  .c om
 *     Stephan Herrmann - initial API and implementation
 *******************************************************************************/

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;

import org.eclipse.core.resources.IFile;

import org.eclipse.core.resources.IResource;

import org.eclipse.core.runtime.CoreException;

import org.eclipse.core.runtime.IProgressMonitor;

public class Main {
    /**
     * Write back the given annotationFile, with the following content:
     * - head (assumed to include a member and its original signature
     * - annotatedSignature
     * - nextLines (optionally, may be null)
     * - the still unconsumed content of tailReader
     */
    private static void writeFile(IFile annotationFile, StringBuffer head, String annotatedSignature,
            String nextLines, BufferedReader tailReader, IProgressMonitor monitor)
            throws CoreException, IOException {
        head.append(' ').append(annotatedSignature).append('\n');
        if (nextLines != null)
            head.append(nextLines).append('\n');
        String line;
        while ((line = tailReader.readLine()) != null)
            head.append(line).append('\n');
        ByteArrayInputStream newContent = new ByteArrayInputStream(head.toString().getBytes("UTF-8")); //$NON-NLS-1$
        annotationFile.setContents(newContent, IResource.KEEP_HISTORY, monitor);
    }
}

Related

  1. writeFile(final String aText, final File aFile, final String aEncoding)
  2. writeFile(final String file, final String text)
  3. writeFile(final String name, final String s)
  4. writeFile(final String nameFile, final List listMsg)
  5. writeFile(final String outputDir, final String response, final String fileName)
  6. writeFile(IFile file, final InputStream contents, final String charset, IProgressMonitor monitor)
  7. writeFile(List data, File f)
  8. writeFile(List fileLines, String pathname)
  9. writeFile(List lines, String filePath)