0

Base64 でエンコードされた画像を含むログファイルがあります。これらのログファイルを処理し、base64 でエンコードされた「もの」を抽出してデコードし、「実際の」画像ファイルとして保存したいと考えています。

Sequence*OutputFormat クラスを使用する以外に、hadoop から画像ファイルを生成する方法がないように思われるので、これを行う方法を探していました。

つまり、カスタム OutputFormat を作成せずに、hadoop の base64 でエンコードされたファイルから jpg ファイルを生成することは可能ですか?

敬具/ヨハン

4

1 に答える 1

0

「カスタムOutputFormat」の意味がわかりませんが、これは私がWebアプリで行っていることです(ただし、hadoopに関連するものではありません)。HTH。

import sun.misc.BASE64Decoder;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.io.PrintStream;

public static void storeImage(String imageBase64, String path) {
    imageBase64 = imageBase64.replace("\n", "");
    try {
        new BASE64Decoder().decodeBufferToByteBuffer(imageBase64);
        OutputStream out = new FileOutputStream(path);
        PrintStream p = new PrintStream(out);
        p.write(new BASE64Decoder().decodeBuffer(imageBase64));
        p.flush();
        p.close();

    } catch (Exception e) {
        log.error("Error storing image.", e);
        e.printStackTrace();
    }
}
于 2012-09-15T02:56:20.207 に答える