Compress the Javascript.

@param uri
the URI for the JS file

@param code
the actual Javascript code

@return the compressed code for the JS file
186539
private String compressJavascriptEmbedded(final String uri, final String code) {
        if(code == null || code.isEmpty()) {
            return code;
        }

        int index = uri.lastIndexOf('/');
        String name = uri;
        if(index > 0) {
            name = uri.substring(index + 1);
        }

        List<SourceFile> externs = Collections.emptyList();
        List<SourceFile> inputs = Arrays.asList(SourceFile.fromCode(name, code));

        CompilerOptions options = new CompilerOptions();
        CompilationLevel.SIMPLE_OPTIMIZATIONS.setOptionsForCompilationLevel(options);
        com.google.javascript.jscomp.Compiler compiler = new com.google.javascript.jscomp.Compiler();
        Result result = compiler.compile(externs, inputs, options);

        if (result.success) {
            return compiler.toSource();
        }

        throw new IllegalArgumentException("Unable to compress javascript");
    }
1057461
function( HTMLCode ){

        var processedHTMLCode =
                HTMLCode
                    .replace( /<!-- InstanceBegin template[^>]+ -->/i, "" )
                    .replace( "<!-- InstanceEnd -->", "" ), // 重複を避けるため、あらかじめ削除。
            $ = cheerio.load( utils.activateInstanceTags( processedHTMLCode ), { decodeEntities: false } );

        // このテンプレートから生成されるHTMLコードに対し、出自を示すタグ<!-- InstanceBegin template -->を付与する。
        // また、このタグには、任意の属性を適用できるようプレースホルダ（__template_attr__）を設置する。
        // なお、このテンプレートが親テンプレートを持つ場合、すでに<!-- InstanceBegin 〜 -->記述を持つ可能性がある。
        // そのため、変数processedHTMLCodeの定義時において、あらかじめ<!-- InstanceBegin 〜 -->を削除している。
        $( "html" )
            .prepend( [
                "<!--",
                " InstanceBegin template=\"/" + this.id + "\"",
                "<%=",
                " typeof __template_attr__ !== 'undefined' ? __template_attr__: ",
                " typeof __default__.__template_attr__ !== 'undefined' ? __default__.__template_attr__: '' ",
                " %>",
                " -->"
            ].join( "" ) )
            .append( "<!-- InstanceEnd -->" );

        // InstanceEditableのうち、入れ子の親になっている要素のみを削除
        $( "InstanceEditable" ).each( function( index, elm ){
            var $this = $( elm ),
                hasNestedEditable = ~$this.html().indexOf( "<!-- TemplateBeginEditable " );

            if( hasNestedEditable ){
                $this.after( $this.contents() ).remove();
            }
        } );

        processedHTMLCode = utils.replaceWithPatterns(
            this.convertResourcePathFormat( $.html() ),
            {
                "<instanceeditable name=\"([^\"]+)\">[\\s\\S]*?</instanceeditable>": "<!-- InstanceBeginEditable name=\"$1\" --><% if( typeof $1 !== 'undefined' ){ %><%= $1 %><% } else { %><%= __default__.$1 %><% } %><!-- InstanceEndEditable -->",
                "<!-- TemplateBeginEditable name=\"([^\"]+)\" -->[\\s\\S]*?<!-- TemplateEndEditable -->": "<!-- InstanceBeginEditable name=\"$1\" --><% if( typeof $1 !== 'undefined' ){ %><%= $1 %><% } else { %><%= __default__.$1 %><% } %><!-- InstanceEndEditable -->"
            }
        );

        utils.log( this.id, "templateSrc", processedHTMLCode );

        return processedHTMLCode;
    }
1035508
public static String encodeString(String uri)
  {
    CharBuffer cb = CharBuffer.allocate();

    for (int i = 0; i < uri.length(); i++) {
      char ch = uri.charAt(i);

      switch (ch) {
      case '<':
        cb.append("&lt;");
        break;
      case '>':
        cb.append("&gt;");
        break;
      case '&':
        cb.append("&amp;");
        break;
      default:
        cb.append(ch);
      }
    }

    return cb.close();
  }
1241618
function encodeURIComponentPretty (str) {
  return encodeURI(str).replace(/[\/?#]/g, function (c) {
    return '%' + c.charCodeAt(0).toString(16).toUpperCase()
  })
}
1057400
function encodeURIComponentRFC3986(str) {
  return encodeURIComponent(str).replace(
    /[!'()*]/g,
    c => `%${c.charCodeAt(0).toString(16)}`
  );
}
475965
private static String compress(String str) throws EncoderException {
	ByteArrayOutputStream rstBao = null;
	GZIPOutputStream zos = null;
    try {
    	rstBao = new ByteArrayOutputStream();
    	zos = new GZIPOutputStream(rstBao);
    	zos.write(str.getBytes());
    	IOUtils.closeQuietly(zos);
	    
    	byte[] bytes = rstBao.toByteArray();
    	return Base64.encodeBase64String(bytes);
    } catch(Exception e){
    	throw new EncoderException("Molfile could not be compressed. " + str);
   } finally{
	   IOUtils.closeQuietly(zos);
   }
	  
  }
1014996
@Override
    public String resolve(String code, Object... arguments) {
        return String.format(code, arguments);
    }
1158412
function(code) {

		var tokens = new TokenStream(code),
			hasCRLF = code.indexOf("\r") > -1,
			lines = code.split(/\r?\n/),
			line,
			token,
			tt,
			replacement,
			colAdjust = 0,
			lastLine = 0;

		while ((tt = tokens.get()) !== 0) {
			token = tokens.token();

			if (tt === Tokens.URI) { // URI

				if (lastLine !== token.startLine) {
					colAdjust = 0;
					lastLine = token.startLine;
				}

				replacement = this.replacer(token.value.replace(URL_PARENS, ""));

				// 5 is for url() characters
				line = lines[token.startLine - 1];
				lines[token.startLine - 1] = line.substring(0, token.startCol + colAdjust - 1) +
					"url(" + replacement + ")" + line.substring(token.endCol + colAdjust - 1);
				colAdjust += ((replacement.length + 5) - token.value.length);
			}
		}

		return lines.join(hasCRLF ? "\r\n" : "\n");
	}
1250461
@SneakyThrows
    public static String compress(final String srcTxt) {
        try (val rstBao = new ByteArrayOutputStream(); val zos = new GZIPOutputStream(rstBao)) {
            zos.write(srcTxt.getBytes(StandardCharsets.UTF_8));
            zos.flush();
            zos.finish();
            val bytes = rstBao.toByteArray();
            val base64 = StringUtils.remove(EncodingUtils.encodeBase64(bytes), '\0');
            return new String(StandardCharsets.UTF_8.encode(base64).array(), StandardCharsets.UTF_8);
        }
    }
403658
private String encodeUri( String uri )
    {
        String newUri = "";
        StringTokenizer st = new StringTokenizer( uri, "/ ", true );
        while ( st.hasMoreTokens())
        {
            String tok = st.nextToken();
            if ( tok.equals( "/" ))
                newUri += "/";
            else if ( tok.equals( " " ))
                newUri += "%20";
            else
            {
                newUri += URLEncoder.encode( tok );
                // For Java 1.4 you'll want to use this instead:
                // try { newUri += URLEncoder.encode( tok, "UTF-8" ); } catch ( java.io.UnsupportedEncodingException uee ) {}
            }
        }
        return newUri;
    }
180337
public static byte[] compress(String s, String encoding)
            throws UnsupportedEncodingException, IOException
    {
        byte[] data = s.getBytes(encoding);
        return compress(data);
    }
520117
public org.jsoup.nodes.Document getFromXml(String uri){
        // 取回資料，並轉化為XML格式
        String xml = getFromRemote(uri);

        // 轉化為 Jsoup 物件
        return xmlToJsoupDoc(xml);
    }
1253613
private String getAuthCode(URI uri) {
		String query = uri.getQuery();
		Map<String, String> map = Splitter.on("&").trimResults().withKeyValueSeparator('=').split(query);
		return map.get("code");
	}
393282
public static String getUri(String uri) throws IOException {
        CloseableHttpClient c = newHttpClient(new URL(uri));
        HttpGet get = new HttpGet(uri);
        LOG.debug("GET {}", uri);
        CloseableHttpResponse res = c.execute(get, HttpClientContext.create());
        return checkResponse(res);
    }
1091122
function getNodeFromCode(code) {
    if (convert.mapFileCommentRegex.test(code)) {
        try {
            return SourceNode.fromStringWithSourceMap(
                convertCode2Script(code),
                new SourceMapConsumer(convert.fromComment(code).toObject())
            );
        } catch (error) {
            console.error('getNodeFromCode() error: ' + error);
            const node = new SourceNode();
            node.add(convertCode2Script(code));
            return node;
        }
    } else {
        const node = new SourceNode();
        node.add(convertCode2Script(code));
        return node;
    }
}
650193
public static String decoded(String uri)
	{
		String decoded = uri.replaceAll("%20", " ");
		decoded = decoded.replaceAll("%22", "\"");
		decoded = decoded.replaceAll("%27", "'");
		decoded = decoded.replaceAll("\\s", " ");
		decoded = decoded.replaceAll("%25", "%");
		decoded = decoded.replaceAll("\\" + File.separator, "/");
		return decoded;
	}
209231
public boolean shouldCompress(String requestUri) {
		String uri = requestUri.toLowerCase();
		return checkSuffixes(uri, zipSuffixes);
	}