List of usage examples for java.net URLDecoder decode
public static String decode(String s, Charset charset)
From source file:com.github.dactiv.common.utils.EncodeUtils.java
/** * URL ?, EncodeUTF-8. //from ww w .ja v a 2 s . c o m */ public static String urlDecode(String part) { try { return URLDecoder.decode(part, DEFAULT_URL_ENCODING); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return part; }
From source file:com.google.youtube.captions.SubmitCaptionTask.java
@Override public void doPost(HttpServletRequest req, HttpServletResponse resp) { LOG.info("Starting up..."); String fileName = null;// w ww . jav a2 s .c o m String channelId = null; BlobKey blobKey = null; try { String blobKeyString = req.getParameter("blobKey"); if (Util.isEmptyOrNull(blobKeyString)) { throw new IllegalArgumentException("Required parameter 'blobKey' not found."); } blobKeyString = URLDecoder.decode(blobKeyString, "UTF-8"); blobKey = new BlobKey(blobKeyString); String authSubToken = req.getParameter("authSubToken"); if (Util.isEmptyOrNull(authSubToken)) { throw new IllegalArgumentException("Required parameter 'authSubToken' not found."); } authSubToken = URLDecoder.decode(authSubToken, "UTF-8"); channelId = req.getParameter("channelId"); if (Util.isEmptyOrNull(channelId)) { throw new IllegalArgumentException("Required parameter 'channelId' not found."); } channelId = URLDecoder.decode(channelId, "UTF-8"); LOG.fine("Channel id is " + channelId); BlobInfoFactory blobInfoFactory = new BlobInfoFactory(); BlobInfo blobInfo = blobInfoFactory.loadBlobInfo(blobKey); // Possible valid track name formats: // 6VVuLGk8kVU_en.sbv // 6VVuLGk8kVU_es_Spanish Track.srt fileName = blobInfo.getFilename(); String regex = "(.{11})_([^_]+?)(?:_(.+))?\\.\\w{3}"; Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(fileName); if (!matcher.matches()) { throw new IllegalArgumentException( String.format("Couldn't parse video id and language " + "from file name '%s'.", fileName)); } String videoId = matcher.group(1); String languageCode = matcher.group(2); String trackName = matcher.group(3); LOG.info(String.format( "File name is '%s', videoId is '%s', language code is '%s', track " + "name is '%s'.", fileName, videoId, languageCode, trackName)); YouTubeService service = new YouTubeService(SystemProperty.applicationId.get(), Util.DEVELOPER_KEY); service.setAuthSubToken(authSubToken); String captionsUrl = String.format(CAPTION_FEED_URL_FORMAT, videoId); GDataRequest request = service.createInsertRequest(new URL(captionsUrl)); request.setHeader("Content-Language", languageCode); if (trackName != null) { request.setHeader("Slug", trackName); } request.setHeader("Content-Type", CONTENT_TYPE); request.getRequestStream().write(blobstoreService.fetchData(blobKey, 0, blobInfo.getSize() - 1)); request.execute(); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(request.getResponseStream())); StringBuilder builder = new StringBuilder(); String line = null; while ((line = bufferedReader.readLine()) != null) { builder.append(line); } bufferedReader.close(); String responseBody = builder.toString(); LOG.info("Response to captions request: " + responseBody); regex = ".+reasonCode=[\"'](.+?)[\"'].+"; pattern = Pattern.compile(regex); matcher = pattern.matcher(responseBody); if (matcher.matches()) { throw new ServiceException("Caption file was rejected: " + matcher.group(1)); } JSONObject jsonResponse = new JSONObject(); jsonResponse.put("fileName", fileName); jsonResponse.put("success", true); try { channelService.sendMessage(new ChannelMessage(channelId, jsonResponse.toString())); } catch (ChannelFailureException e) { LOG.log(Level.WARNING, "", e); } } catch (IllegalArgumentException e) { reportError(channelId, fileName, e); } catch (MalformedURLException e) { reportError(channelId, fileName, e); } catch (IOException e) { reportError(channelId, fileName, e); } catch (ServiceException e) { reportError(channelId, fileName, e); } catch (JSONException e) { LOG.log(Level.WARNING, "", e); } finally { if (blobKey != null) { blobstoreService.delete(blobKey); LOG.info(String.format("Blob entry '%s' was deleted.", blobKey.getKeyString())); } } }
From source file:com.netsteadfast.greenstep.bsc.action.StrategyMapSaveOrUpdateAction.java
@SuppressWarnings("unchecked") private Map<String, Object> fillStrategyMapItems() throws Exception { String mapData = this.getFields().get("mapData"); mapData = SimpleUtils.deB64(mapData); // decode-base64 btoa String jsonData = URLDecoder.decode(mapData, "utf8"); // ? decode encodeURIComponent Map<String, Object> dataMap = (Map<String, Object>) new ObjectMapper().readValue(jsonData, LinkedHashMap.class); return dataMap; }
From source file:com.huawei.streaming.cql.DriverTest.java
private static void setDir() throws UnsupportedEncodingException { String classPath = DriverTest.class.getResource("/").getPath(); classPath = URLDecoder.decode(classPath, "UTF-8"); inPutDir = classPath + BASICPATH + CQLTestCommons.INPUT_DIR_NAME + File.separator; outPutDir = classPath + BASICPATH + CQLTestCommons.OUTPUT_DIR_NAME + File.separator; resultPutDir = classPath + BASICPATH + CQLTestCommons.RESULT_DIR_NAME + File.separator; }
From source file:eu.europa.ec.markt.dss.validation102853.toolbox.XPointerResourceResolver.java
/** * Indicates if the given URI is an XPointer query. * * @param uriValue URI to be analysed// ww w . j av a 2s .c o m * @return true if it is an XPointer query */ public static boolean isXPointerQuery(String uriValue, final boolean strict) { if (uriValue.isEmpty() || uriValue.charAt(0) != '#') { return false; } final String decodedUri; try { decodedUri = URLDecoder.decode(uriValue, "utf-8"); } catch (UnsupportedEncodingException e) { LOG.warn("utf-8 not a valid encoding", e); return false; } final String parts[] = decodedUri.substring(1).split("\\s"); // plain ID reference. if (parts.length == 1 && !parts[0].startsWith(XNS_OPEN)) { return strict ? false : true; } int ii = 0; for (; ii < parts.length - 1; ++ii) { if (!parts[ii].endsWith(")") || !parts[ii].startsWith(XNS_OPEN)) { return false; } } if (!parts[ii].endsWith(")") || !parts[ii].startsWith(XP_OPEN)) { return false; } return true; }
From source file:co.cask.cdap.metrics.query.MetricQueryParser.java
private static String urlDecode(String str) { try {//from www . j a v a 2 s . c om return URLDecoder.decode(str, CharEncoding.UTF_8); } catch (UnsupportedEncodingException e) { throw new IllegalArgumentException("unsupported encoding in path element", e); } }
From source file:de.hybris.platform.b2b.punchout.services.impl.DefaultCipherServiceTest.java
private static String decode(final String encoded) { try {// w w w.j av a 2 s.c o m return URLDecoder.decode(encoded, DefaultCipherService.CHARACTER_ENCODING); } catch (final UnsupportedEncodingException e) { return null; } }
From source file:de.yaio.services.plantuml.server.controller.PlantumProvider.java
protected String getUmlSource(String source) { // build the UML source from the compressed part of the URL String text;//from w w w .java 2s . co m try { text = URLDecoder.decode(source, "UTF-8"); } catch (UnsupportedEncodingException uee) { text = "' invalid encoded string"; } Transcoder transcoder = TranscoderUtil.getDefaultTranscoder(); try { text = transcoder.decode(text); } catch (IOException ioe) { text = "' unable to decode string"; } // encapsulate the UML syntax if necessary String uml; if (text.startsWith("@start")) { uml = text; } else { StringBuilder plantUmlSource = new StringBuilder(); plantUmlSource.append("@startuml\n"); plantUmlSource.append(text); if (text.endsWith("\n") == false) { plantUmlSource.append("\n"); } plantUmlSource.append("@enduml"); uml = plantUmlSource.toString(); } return uml; }
From source file:com.sap.prd.mobile.ios.ota.lib.LibUtils.java
public static String urlDecode(String string) { if (string == null) { return null; }//ww w.j av a 2 s . co m try { return URLDecoder.decode(string, "UTF-8"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); //should never happen } }
From source file:com.microsoft.alm.plugin.idea.git.starters.SimpleCheckoutStarter.java
/** * Creates a SimpleCheckoutStarter object after parsing the URI attributes for the Git Url and Url encoding if provided * * @param args Uri attributes/*from w w w . java 2 s . c o m*/ * @return SimpleCheckoutStarter with URI's decoded Git Url * @throws RuntimeException * @throws UnsupportedEncodingException */ public static SimpleCheckoutStarter createWithUriAttributes(Map<String, String> args) throws RuntimeException, UnsupportedEncodingException { String url = args.get(URL_ARGUMENT); String ref = args.get(REF_ARGUMENT); String encoding = args.get(ENCODING_ARGUMENT); if (StringUtils.isEmpty(url)) { throw new RuntimeException( TfPluginBundle.message(TfPluginBundle.STARTER_ERRORS_SIMPLECHECKOUT_URI_MISSING_GIT_URL)); } // if an encoding scheme is found then decode the url if (StringUtils.isNotEmpty(encoding)) { url = URLDecoder.decode(url, encoding); } if (StringUtils.isNotEmpty(ref)) { ref = URLDecoder.decode(ref, encoding); } else { ref = StringUtils.EMPTY; } return createWithGitUrl(url, ref); }