/**
  * @param req The request.
  * @return The query string of the request in its raw (not URI-encoded) form. This is suitable for
  *     passing as the 'query' parameter to one of the multi-argument {@link URI} constructors.
  */
 private static String getQueryString(HttpServletRequest req) throws UnsupportedEncodingException {
   StringBuilder buf = new StringBuilder();
   Map<String, String[]> params = req.getParameterMap();
   if (params.size() == 0) return null;
   for (Entry<String, String[]> entry : params.entrySet()) {
     String name = entry.getKey();
     String[] values = entry.getValue();
     if (values.length == 0) {
       buf.append("&").append(name);
     } else {
       for (String value : values) {
         buf.append("&").append(name).append("=").append(value);
       }
     }
   }
   return buf.substring(1);
 }
  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 #3
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 #4
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();
   }
 }