Example usage for java.net URLDecoder decode

List of usage examples for java.net URLDecoder decode

Introduction

In this page you can find the example usage for java.net URLDecoder decode.

Prototype

public static String decode(String s, Charset charset) 

Source Link

Document

Decodes an application/x-www-form-urlencoded string using a specific java.nio.charset.Charset Charset .

Usage

From source file:it.polimi.chansonnier.agent.YoutubeGrabber.java

/**
 * /*from ww  w .ja  va  2  s  .c  o  m*/
 * @param pageUrl
 * @return url of the FLV file
 * @throws Exception
 */
private String getVideoUrl(String pageUrl) throws Exception {
    URL page = new URL(pageUrl);
    String query = page.getQuery();
    String[] tokens = query.split("&");
    HashMap<String, String> params = new HashMap<String, String>();
    for (int i = 0; i < tokens.length; i++) {
        String[] parts = tokens[i].split("=");
        params.put(parts[0], parts[1]);
    }
    String video_id = params.get("v");
    if (video_id == null)
        video_id = inbtwn(URLDecoder.decode(getRedirUrl(pageUrl), "UTF-8"), "v=", "&");
    String pageSource = URLUtils.retrieve(new URL("http://www.youtube.com/watch?v=" + video_id));

    String title = inbtwn(pageSource, "'VIDEO_TITLE': '", "',");
    if (title == null)
        title = inbtwn(pageSource, "name=\"title\" content=\"", "\"");
    if (title == null) {
        throw new RuntimeException("The page does not contain a video (" + pageUrl + ").");
    }
    title = setHTMLEntity(title);

    String token = inbtwn(pageSource, "\"t\": \"", "\"");
    if (token == null)
        token = inbtwn(pageSource, "&t=", "&");
    if (!token.endsWith("%3D"))
        token = inbtwnmore(pageSource, "&t=", "&", 2);

    String dl_flvlow = null;
    String dl_flvmed = null;
    String dl_flvmed2 = null;
    String dl_flvhigh = null;

    dl_flvmed = getRedirUrl(
            "http://www.youtube.com/get_video?video_id=" + video_id + "&t=" + token + "&fmt=34");
    if (dl_flvmed != null) {
        _log.debug("flvmed for video " + video_id);
        return dl_flvmed;
    }
    dl_flvmed2 = getRedirUrl(
            "http://www.youtube.com/get_video?video_id=" + video_id + "&t=" + token + "&fmt=6");
    if (dl_flvmed2 != null) {
        _log.debug("flvmed2 for video " + video_id);
        return dl_flvmed2;
    }
    dl_flvlow = getRedirUrl("http://www.youtube.com/get_video?video_id=" + video_id + "&t=" + token + "&fmt=5");
    if (dl_flvlow != null) {
        _log.debug("flvlow for video " + video_id);
        return dl_flvlow;
    }
    dl_flvhigh = getRedirUrl(
            "http://www.youtube.com/get_video?video_id=" + video_id + "&t=" + token + "&fmt=35");
    if (dl_flvhigh != null) {
        _log.debug("flvhigh for video " + video_id);
        return dl_flvhigh;
    }

    // other formats
    String dl_3gplow = null;
    String dl_3gpmed = null;
    String dl_3gphigh = null;
    String dl_mp4high = null;
    String dl_mp4hd = null;
    String dl_mp4hd2 = null;

    if (dl_3gplow == null)
        dl_3gplow = getRedirUrl(
                "http://www.youtube.com/get_video?video_id=" + video_id + "&t=" + token + "&fmt=13");
    if (dl_3gplow != null)
        return dl_3gplow;
    if (dl_3gpmed == null)
        dl_3gpmed = getRedirUrl(
                "http://www.youtube.com/get_video?video_id=" + video_id + "&t=" + token + "&fmt=17");
    if (dl_3gpmed != null)
        return dl_3gpmed;
    if (dl_3gphigh == null)
        dl_3gphigh = getRedirUrl(
                "http://www.youtube.com/get_video?video_id=" + video_id + "&t=" + token + "&fmt=36");
    if (dl_3gphigh != null)
        return dl_3gphigh;
    if (dl_mp4high == null)
        dl_mp4high = getRedirUrl(
                "http://www.youtube.com/get_video?video_id=" + video_id + "&t=" + token + "&fmt=18");
    if (dl_mp4high != null)
        return dl_mp4high;
    if (dl_mp4hd == null)
        dl_mp4hd = getRedirUrl(
                "http://www.youtube.com/get_video?video_id=" + video_id + "&t=" + token + "&fmt=22");
    if (dl_mp4hd != null)
        return dl_mp4hd;
    if (dl_mp4hd2 == null)
        dl_mp4hd2 = getRedirUrl(
                "http://www.youtube.com/get_video?video_id=" + video_id + "&t=" + token + "&fmt=37");
    if (dl_mp4hd2 != null)
        return dl_mp4hd2;
    throw new Exception("No suitable file found.");

}

From source file:com.aliyun.odps.mapred.bridge.streaming.PipeMapper.java

@Override
String getPipeCommand(JobConf job) {
    String str = job.get("stream.map.streamprocessor");
    if (str == null) {
        return str;
    }//from   w  ww .j  a  va2  s .co m
    try {
        return URLDecoder.decode(str, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        System.err.println("stream.map.streamprocessor in jobconf not found");
        return null;
    }
}

From source file:com.yunda.htmlsnap.web.api.HtmlSnapController.java

@RequestMapping(method = RequestMethod.GET)
public void snap(@RequestParam("htmlUrl") String htmlUrl, @RequestParam("imgType") String imgType,
        HttpServletRequest request, HttpServletResponse response) {
    logger.info("?:" + htmlUrl);
    //JavaHost.printAllVirtualDns();
    response.setContentType("image/" + imgType);
    response.setHeader("Content-Type", "image/" + imgType);
    boolean flag = false;
    ServletOutputStream sos = null;/*w  w  w . j  a  va 2s.  c  om*/
    if (StringUtils.isNotBlank(htmlUrl)) {
        BrowserService browserService = null;
        try {
            browserService = BrowserFactory.getBrowerService();
            sos = response.getOutputStream();
            flag = browserService.generatePng(URLDecoder.decode(htmlUrl, "UTF-8"), sos, imgType);
        } catch (IOException e) {
            logger.error("??:" + e);
        } finally {
            BrowserFactory.recycleService(browserService);
        }
    }
    logger.info("?" + flag);
    if (!flag) {
        response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }
    if (null != sos) {
        try {
            sos.flush();
            sos.close();
        } catch (IOException e1) {
            logger.error("?", e1);
        }
    }
}

From source file:com.glodon.paas.document.api.PublicRestAPITest.java

@Test
public void downloadPublicFile() throws Exception {
    File folder = getFile(simpleCall(createPost("/file/1/2/3?folder")), null);
    simpleCall(createPost("/public/" + folder.getId()));
    HttpResponse responseResult = call(// www  .ja v  a 2  s  .  c om
            createGet("/public/file/download/" + folder.getId(), new BasicHeader("User-Agent", "msie")));
    String name = URLDecoder.decode(responseResult.getHeaders("Content-Disposition")[0].toString(), "UTF-8");
    assertEquals("Content-Disposition: attachment; filename=\"3.zip\"", name);
}

From source file:com.thinkgem.jeesite.modules.sso.util.Encodes.java

/**
 * URL ?, EncodeUTF-8. /*www .j  av a 2  s  .  c  om*/
 */
public static String urlDecode(String part) {

    try {
        return URLDecoder.decode(part, DEFAULT_URL_ENCODING);
    } catch (UnsupportedEncodingException e) {
        return "";
    }
}

From source file:apm.common.utils.Encodes.java

/**
 * URL ?, EncodeUTF-8. /* www .j  av a2  s .  c  om*/
 */
public static String urlDecode(String part) {

    try {
        return URLDecoder.decode(part, DEFAULT_URL_ENCODING);
    } catch (UnsupportedEncodingException e) {
        throw Exceptions.unchecked(e);
    }
}

From source file:com.intuit.tank.http.json.JsonResponse.java

@Override
public String getValue(String key) {

    try {//from   ww  w. j a v  a 2s  . c o m
        if (NumberUtils.isDigits(key)) {
            Integer.parseInt(key);
            JSONObject jsonResponse = new JSONObject(this.response);
            return (String) jsonResponse.get(key);
        }
    } catch (Exception e) {
    }
    try {
        if (this.jsonMap == null) {
            initialize();
        }
        String keyTrans = key.replace("@", "");
        // note that indexing is 1 based not zero based
        JXPathContext context = JXPathContext.newContext(this.jsonMap);
        String output = URLDecoder.decode(String.valueOf(context.getValue(keyTrans)), "UTF-8");
        if (output.equalsIgnoreCase("null"))
            return "";
        return output;
    } catch (Exception ex) {
        return "";
    }
}

From source file:com.wondersgroup.api.framework.utils.Encodes.java

/**
 * URL ?, EncodeUTF-8./*  w w w . j  av  a2  s.c  o m*/
 */
public static String urlDecode(String part) {

    try {
        return URLDecoder.decode(part, DEFAULT_URL_ENCODING);
    } catch (UnsupportedEncodingException e) {
        return null;
    }
}

From source file:com.alta189.cyborg.commandkit.util.HttpUtil.java

public static String decode(String raw) {
    String result = null;/*  ww w  . j  a  v  a2 s . co  m*/
    try {
        result = URLDecoder.decode(raw, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return result;
}

From source file:com.net.wx.util.Encodes.java

/**
 * URL ?, EncodeUTF-8.// w ww .j ava  2  s .co m
 */
public static String urlDecode(String part) {

    try {
        return URLDecoder.decode(part, DEFAULT_URL_ENCODING);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
        return null;
    }
}