スキップしてメイン コンテンツに移動

投稿

ラベル(encode)が付いた投稿を表示しています

Linuxで任意の文字列をbase64エンコードする方法

Linuxでbase64エンコードをするにはbase64コマンドを使えばOKです。 base64コマンド ファイルであれば下記のようにファイル名を指定すると、ファイルの中身をbase64エンコードした結果が標準出力に出力されます。 base64 {エンコード対象のファイル} ファイルに保存したい場合は、リダイレクトを使います。 base64 {エンコード対象のファイル} > {エンコードされたファイル} ファイルではなく文字列をbase64エンコードする場合 echoコマンドとパイプを使えば容易に実現できます。注意点として、base64コマンドでオプションを何も与えないと76文字ごとに改行が勝手に入るので、改行を除きたい場合は -w 0 をオプションに指定します。 echo "エンコードしたい文字列" | base64 -w 0

Encode Java Object to XML and Decode XML to Java Object

In current software development world, serializing object to some human readable format such as "XML", "JSON" is quite common. In this post I will show you a small code snippet for encoding Java Object to XML and decoding XML to Java Object only using Java Standard API. I think this approach is suitable if you need to quick and simple solution to encoding and decoding java object to XML string. Actually code is very simple. Please see the code below :) If you need to input or output XML to file, you should pass FileOutputStream or FileInputStream instead of ByteArrayOutputStream or ByteArrayInputStream. package com.dukesoftware.utils.xml; import java.beans.XMLDecoder; import java.io.BufferedInputStream; import java.io.ByteArrayInputStream; import java.io.FileInputStream; import java.io.FileNotFoundException; public class XMLUtils { public final static Object decodeToXML(String file) throws FileNotFoundException{ try(XMLDecoder decoder =

URI Encode for Java

I always forget and struggling about the behavior of Java methods and classes for encoding uri. To clear my heads I will post small test codes. import java.net.URI; import java.net.URLEncoder; import java.util.BitSet; import org.apache.commons.httpclient.util.URIUtil; public class URIEncodeExample { // hehe using Japanese :p private static final String INPUT = "あいうえお/"; public static void main(String[] args) throws Exception { // java.net.URI // slash is not encoded because it is detected as a path separator // %E3%81%82%E3%81%84%E3%81%86%E3%81%88%E3%81%8A/ System.out.println(URI.create(INPUT).toASCIIString()); // java.net.URI + relativize // slash is not encoded because it is detected as a path separator // %E3%81%82%E3%81%84%E3%81%86%E3%81%88%E3%81%8A/ URI root = new URI("http", "dummy.com", null, null); URI uri = new URI("http", "dummy.com",