public static String decode(String s) {
   try {
     return URLDecoder.decode(s, UTF_8.name());
   } catch (UnsupportedEncodingException e) {
     Logger.getLogger(BasicServlet.class).fatal(UTF_8.name() + " is not a recognized encoding", e);
     throw new AssertionError(e); // can't happen with UTF-8
   }
 }
 protected void assignContent(HttpEntityEnclosingRequestBase request, Map<String, String> params)
     throws UnsupportedEncodingException {
   if (params != null && !params.isEmpty()) {
     List<NameValuePair> pairs = new ArrayList<NameValuePair>(params.size());
     for (Map.Entry<String, String> param : params.entrySet())
       pairs.add(new BasicNameValuePair(param.getKey(), param.getValue()));
     StringEntity entity =
         new StringEntity(URLEncodedUtils.format(pairs, UTF_8.name()), UTF_8.name());
     entity.setContentType(CONTENT_TYPE_WWW_FORM_URLENCODED);
     request.setEntity(entity);
   }
 }
 @Override
 public String format(
     String projectName,
     String path,
     String revision,
     String abbrRev,
     ConfigSection cfg,
     InputStream raw)
     throws IOException {
   // Docx4J tries to load some resources dynamically. This fails if the Gerrit
   // core classloader is used since it doesn't see the resources that are
   // contained in the plugin jar. To make the resource loading work we
   // must set a context classloader on the current thread.
   ClassLoader loader = Thread.currentThread().getContextClassLoader();
   try {
     Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
     WordprocessingMLPackage p = Docx4J.load(raw);
     HTMLSettings htmlSettings = Docx4J.createHTMLSettings();
     htmlSettings.setWmlPackage(p);
     Docx4jProperties.setProperty("docx4j.Convert.Out.HTML.OutputMethodXML", true);
     try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
       Docx4J.toHTML(htmlSettings, out, Docx4J.FLAG_EXPORT_PREFER_XSL);
       String html = out.toString(UTF_8.name());
       return util.applyCss(html, NAME, projectName);
     }
   } catch (Docx4JException e) {
     throw new IOException(e);
   } finally {
     Thread.currentThread().setContextClassLoader(loader);
   }
 }
 // FIXME Get a 302 in France...
 @Test(groups = "online", enabled = false)
 public void testUrlRequestParametersEncoding() throws Exception {
   try (AsyncHttpClient client = asyncHttpClient()) {
     String requestUrl2 = URL + URLEncoder.encode(REQUEST_PARAM, UTF_8.name());
     logger.info(String.format("Executing request [%s] ...", requestUrl2));
     Response response = client.prepareGet(requestUrl2).execute().get();
     assertEquals(response.getStatusCode(), 302);
   }
 }
Beispiel #5
0
 private String createQuery(String url, Map<String, String> params) throws QiitaException {
   StringBuilder sb = new StringBuilder(url);
   if (url.contains("?")) {
     sb.append('&');
   } else {
     sb.append('?');
   }
   try {
     for (Entry<String, String> entry : params.entrySet()) {
       String key = URLEncoder.encode(entry.getKey(), UTF_8.name());
       String value = URLEncoder.encode(entry.getValue(), UTF_8.name());
       sb.append(key).append('=').append(value).append('&');
     }
   } catch (UnsupportedEncodingException e) {
     throw new QiitaException(e);
   }
   return sb.delete(sb.length() - 1, sb.length()).toString();
 }
Beispiel #6
0
 @Test
 public void listCacheNamesTextList() throws Exception {
   RestResponse r = adminSession.get("/config/server/caches/?format=TEXT_LIST");
   assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK);
   String result = new String(Base64.decode(r.getEntityContent()), UTF_8.name());
   List<String> list = Arrays.asList(result.split("\n"));
   assertThat(list).contains("accounts");
   assertThat(list).contains("projects");
   assertThat(Ordering.natural().isOrdered(list)).isTrue();
 }
 private HttpGet createGetRequest(String urlStr, Map<String, String> params) {
   StringBuilder bld = new StringBuilder(createURI(urlStr));
   if (params != null && !params.isEmpty()) {
     List<BasicNameValuePair> pairs = new ArrayList<BasicNameValuePair>();
     for (Map.Entry<String, String> param : params.entrySet())
       pairs.add(new BasicNameValuePair(param.getKey(), param.getValue()));
     bld.append('?');
     bld.append(URLEncodedUtils.format(pairs, UTF_8.name()));
   }
   return new HttpGet(URI.create(bld.toString()));
 }
Beispiel #8
0
 private void setFormValue(HttpEntityEnclosingRequestBase request, Map<String, String> params)
     throws QiitaException {
   List<NameValuePair> nameValuePairs = new ArrayList<>();
   for (Entry<String, String> entry : params.entrySet()) {
     nameValuePairs.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
   }
   try {
     request.setEntity(new UrlEncodedFormEntity(nameValuePairs, UTF_8.name()));
   } catch (UnsupportedEncodingException e) {
     throw new QiitaException(e);
   }
 }
 @Description("unescape a URL-encoded string")
 @ScalarFunction
 @LiteralParameters("x")
 @SqlType("varchar(x)")
 public static Slice urlDecode(@SqlType("varchar(x)") Slice value) {
   try {
     return slice(URLDecoder.decode(value.toStringUtf8(), UTF_8.name()));
   } catch (UnsupportedEncodingException e) {
     throw new AssertionError(e);
   } catch (IllegalArgumentException e) {
     throw new PrestoException(INVALID_FUNCTION_ARGUMENT, e);
   }
 }
  private void showDoc(
      HttpServletRequest req,
      HttpServletResponse res,
      GitilesView view,
      MarkdownConfig cfg,
      MarkdownToHtml.Builder fmt,
      MarkdownFile navFile,
      MarkdownFile srcFile)
      throws IOException {
    Map<String, Object> data = new HashMap<>();
    Navbar navbar = new Navbar();
    if (navFile != null) {
      navbar.setFormatter(fmt.setFilePath(navFile.path).build());
      navbar.setMarkdown(navFile.content);
    }
    data.putAll(navbar.toSoyData());

    Node doc = GitilesMarkdown.parse(srcFile.content);
    data.put("pageTitle", pageTitle(doc, srcFile));
    if (view.getType() != GitilesView.Type.ROOTED_DOC) {
      data.put("sourceUrl", GitilesView.show().copyFrom(view).toUrl());
      data.put("logUrl", GitilesView.log().copyFrom(view).toUrl());
      data.put("blameUrl", GitilesView.blame().copyFrom(view).toUrl());
    }
    if (cfg.analyticsId != null) {
      data.put("analyticsId", cfg.analyticsId);
    }
    data.put("bodyHtml", fmt.setFilePath(srcFile.path).build().toSoyHtml(doc));

    String page = renderer.render(SOY_TEMPLATE, data);
    byte[] raw = page.getBytes(UTF_8);
    res.setContentType(FormatType.HTML.getMimeType());
    res.setCharacterEncoding(UTF_8.name());
    setCacheHeaders(res);
    if (acceptsGzipEncoding(req)) {
      res.addHeader(HttpHeaders.VARY, HttpHeaders.ACCEPT_ENCODING);
      res.setHeader(HttpHeaders.CONTENT_ENCODING, "gzip");
      raw = gzip(raw);
    }
    res.setContentLength(raw.length);
    res.setStatus(HttpServletResponse.SC_OK);
    res.getOutputStream().write(raw);
  }
 private static StringEntity jsonStringEntity(String json) {
   return new StringEntity(json, UTF_8.name());
 }
Beispiel #12
0
public class ChmConstants {
  /* Prevents instantiation */
  private ChmConstants() {}

  public static final String DEFAULT_CHARSET = UTF_8.name();
  public static final String ITSF = "ITSF";
  public static final String ITSP = "ITSP";
  public static final String PMGL = "PMGL";
  public static final String LZXC = "LZXC";
  public static final String CHM_PMGI_MARKER = "PMGI";
  public static final int BYTE_ARRAY_LENGHT = 16;
  public static final int CHM_ITSF_V2_LEN = 0x58;
  public static final int CHM_ITSF_V3_LEN = 0x60;
  public static final int CHM_ITSP_V1_LEN = 0x54;
  public static final int CHM_PMGL_LEN = 0x14;
  public static final int CHM_PMGI_LEN = 0x08;
  public static final int CHM_LZXC_RESETTABLE_V1_LEN = 0x28;
  public static final int CHM_LZXC_MIN_LEN = 0x18;
  public static final int CHM_LZXC_V2_LEN = 0x1c;
  public static final int CHM_SIGNATURE_LEN = 4;
  public static final int CHM_VER_2 = 2;
  public static final int CHM_VER_3 = 3;
  public static final int CHM_VER_1 = 1;
  public static final int CHM_WINDOW_SIZE_BLOCK = 0x8000;

  /* my hacking */
  public static final int START_PMGL = 0xCC;
  public static final String CONTROL_DATA = "ControlData";
  public static final String RESET_TABLE = "ResetTable";
  public static final String CONTENT = "Content";

  /* some constants defined by the LZX specification */
  public static final int LZX_MIN_MATCH = 2;
  public static final int LZX_MAX_MATCH = 257;
  public static final int LZX_NUM_CHARS = 256;
  public static final int LZX_BLOCKTYPE_INVALID = 0; /*
                                                        * also blocktypes 4-7
                                                        * invalid
                                                        */
  public static final int LZX_BLOCKTYPE_VERBATIM = 1;
  public static final int LZX_BLOCKTYPE_ALIGNED = 2;
  public static final int LZX_BLOCKTYPE_UNCOMPRESSED = 3;
  public static final int LZX_PRETREE_NUM_ELEMENTS_BITS = 4; /* ??? */
  public static final int LZX_PRETREE_NUM_ELEMENTS = 20;
  public static final int LZX_ALIGNED_NUM_ELEMENTS = 8; /*
                                                           * aligned offset tree
                                                           * #elements
                                                           */
  public static final int LZX_NUM_PRIMARY_LENGTHS = 7; /*
                                                          * this one missing
                                                          * from spec!
                                                          */
  public static final int LZX_NUM_SECONDARY_LENGTHS = 249; /*
                                                              * length tree
                                                              * #elements
                                                              */

  /* LZX huffman defines: tweak tablebits as desired */
  public static final int LZX_PRETREE_MAXSYMBOLS = LZX_PRETREE_NUM_ELEMENTS;
  public static final int LZX_PRETREE_TABLEBITS = 6;
  public static final int LZX_MAINTREE_MAXSYMBOLS = LZX_NUM_CHARS + 50 * 8;
  public static final int LZX_MAIN_MAXSYMBOLS = LZX_NUM_CHARS * 2;
  public static final int LZX_MAINTREE_TABLEBITS = 12;
  public static final int LZX_LENGTH_MAXSYMBOLS = LZX_NUM_SECONDARY_LENGTHS + 1;
  public static final int LZX_LENGTH_TABLEBITS = 12;
  public static final int LZX_ALIGNED_MAXSYMBOLS = LZX_ALIGNED_NUM_ELEMENTS;
  public static final int LZX_ALIGNED_TABLEBITS = 7;
  public static final int LZX_LENTABLE_SAFETY = 64;

  public static short[] EXTRA_BITS = {
    0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13,
    13, 14, 14, 15, 15, 16, 16, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17
  };

  public static int[] POSITION_BASE = {
    0, 1, 2, 3, 4, 6, 8, 12, 16, 24, 32, 48, 64, 96, 128, 192, 256, 384, 512, 768, 1024, 1536, 2048,
    3072, 4096, 6144, 8192, 12288, 16384, 24576, 32768, 49152, 65536, 98304, 131072, 196608, 262144,
    393216, 524288, 655360, 786432, 917504, 1048576, 1179648, 1310720, 1441792, 1572864, 1703936,
    1835008, 1966080, 2097152
  };
}
Beispiel #13
0
 public String content() {
   if (content == null) {
     return null;
   }
   return new String(content, Charset.forName(UTF_8.name()));
 }
 public ResponseDefinition(final int statusCode, final String bodyContent) {
   this.status = statusCode;
   this.body = (bodyContent == null) ? null : bodyContent.getBytes(Charset.forName(UTF_8.name()));
 }
 public void setBody(final String body) {
   this.body = (body != null) ? body.getBytes(Charset.forName(UTF_8.name())) : null;
   isBinaryBody = false;
 }
 public String getBody() {
   return (!isBinaryBody && body != null) ? new String(body, Charset.forName(UTF_8.name())) : null;
 }