protected void setDocumentContent(IDocument document, InputStream contentStream, String encoding)
      throws IOException {
    Reader in = null;

    try {
      if (encoding == null) {
        encoding = GeneralUtils.DEFAULT_FILE_CHARSET_NAME;
      }

      in = new BufferedReader(new InputStreamReader(contentStream, encoding), DEFAULT_BUFFER_SIZE);
      StringBuilder buffer = new StringBuilder(DEFAULT_BUFFER_SIZE);
      char[] readBuffer = new char[2048];
      int n = in.read(readBuffer);
      while (n > 0) {
        buffer.append(readBuffer, 0, n);
        n = in.read(readBuffer);
      }

      document.set(buffer.toString());

    } finally {
      if (in != null) {
        ContentUtils.close(in);
      } else {
        ContentUtils.close(contentStream);
      }
    }
  }
Exemple #2
0
 private static IPath getPathForLevelUp(int levelUp) {
   StringBuilder sb = new StringBuilder();
   for (int i = 0; i < levelUp; i++) {
     sb.append("../"); // $NON-NLS-1$
   }
   return new Path(sb.toString());
 }
Exemple #3
0
 public static String getRelativePath(IPath filePath, IPath pathToGitRoot) {
   StringBuilder sb = new StringBuilder();
   String file = null;
   if (!filePath.hasTrailingSeparator()) {
     file = filePath.lastSegment();
     filePath = filePath.removeLastSegments(1);
   }
   for (int i = 0; i < pathToGitRoot.segments().length; i++) {
     if (pathToGitRoot.segments()[i].equals(".."))
       sb.append(
               filePath.segment(filePath.segments().length - pathToGitRoot.segments().length + i))
           .append("/");
     // else TODO
   }
   if (file != null) sb.append(file);
   return sb.toString();
 }
 public EmailContent(String fileName) throws URISyntaxException, IOException {
   URL entry = GitActivator.getDefault().getBundleContext().getBundle().getEntry(fileName);
   if (entry == null) throw new IOException("File not found: " + fileName);
   BufferedReader reader = new BufferedReader(new InputStreamReader(entry.openStream()));
   String line = null;
   try {
     title = reader.readLine();
     StringBuilder stringBuilder = new StringBuilder();
     String ls = System.getProperty("line.separator");
     while ((line = reader.readLine()) != null) {
       stringBuilder.append(line);
       stringBuilder.append(ls);
     }
     content = stringBuilder.toString();
   } finally {
     reader.close();
   }
 }