Decoding URI query string in Java

Use URLDecoder.decode(proxyRequestParam.replace(“+”, “%2B”), “UTF-8”) .replace(“%2B”, “+”) to simulate decodeURIComponent. Java’s URLDecoder decodes the plus sign to a space, which is not what you want, therefore you need the replace statements. Warning: the .replace(“%2B”, “+”) at the end will corrupt your data if the original (pre-x-www-form-urlencoded) contained that string, as @xehpuk pointed out.

How to get h264 video info?

I’ve found out that the best way for this is using FFprobe with -show_streams parameter. It shows both h.264 profile and B-frames usage for video streams of the movie. ffprobe -show_streams -i “file.mp4” [STREAM] index=0 codec_name=h264 codec_long_name=H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 profile=High codec_type=video codec_time_base=1001/48000 codec_tag_string=avc1 codec_tag=0x31637661 width=1920 height=1080 has_b_frames=0 sample_aspect_ratio=0:1 … Read more

Unable to do low-level decoding of video on Android 4.2 without using media extractor

try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); FileInputStream fis = new FileInputStream(new File( “ur file path”)); byte[] buf = new byte[1024]; int n; while (-1 != (n = fis.read(buf))) { baos.write(buf, 0, n); } byte[] videoBytes = baos.toByteArray(); // use this videoBytes which is low level of original video } catch (Exception e) { e.printStackTrace(); … Read more

Decode gzipped web page retrieved via cURL in PHP

The following command enables cURL’s “auto encoding” mode, where it will announce to the server which encoding methods it supports (via the Accept-Encoding header), and then automatically decompress the response for you: // Allow cURL to use gzip compression, or any other supported encoding // A blank string activates ‘auto’ mode curl_setopt($ch, CURLOPT_ENCODING , ”); … Read more

How can I send and receive WebSocket messages on the server side?

Note: This is some explanation and pseudocode as to how to implement a very trivial server that can handle incoming and outcoming WebSocket messages as per the definitive framing format. It does not include the handshaking process. Furthermore, this answer has been made for educational purposes; it is not a full-featured implementation. Specification (RFC 6455) … Read more

How to decode Unicode escape sequences like “\u00ed” to proper UTF-8 encoded characters?

Try this: $str = preg_replace_callback(‘/\\\\u([0-9a-fA-F]{4})/’, function ($match) { return mb_convert_encoding(pack(‘H*’, $match[1]), ‘UTF-8’, ‘UCS-2BE’); }, $str); In case it’s UTF-16 based C/C++/Java/Json-style: $str = preg_replace_callback(‘/\\\\u([0-9a-fA-F]{4})/’, function ($match) { return mb_convert_encoding(pack(‘H*’, $match[1]), ‘UTF-8’, ‘UTF-16BE’); }, $str);

Why does base64 encoding require padding if the input length is not divisible by 3?

Your conclusion that padding is unnecessary is right. It’s always possible to determine the length of the input unambiguously from the length of the encoded sequence. However, padding is useful in situations where base64 encoded strings are concatenated in such a way that the lengths of the individual sequences are lost, as might happen, for … Read more