package xxxx.service;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.security.MessageDigest;
public class Util {
文字列が空かどうか判定
public static boolean isEmpty(String buff) {
boolean flg = false;
if (buff == null || buff == "") {
flg = true;
}
return flg;
}
テキストファイルの文字コード変換
public static void convertFile(
String fromFilePath,
String fromCharSet,
String toFilePath,
String toCharSet
){
try{
FileInputStream inStream = new FileInputStream(fromFilePath);
FileOutputStream otStream = new FileOutputStream(toFilePath);
InputStreamReader inReader = new InputStreamReader(inStream,fromCharSet);
OutputStreamWriter otWriter = new OutputStreamWriter(otStream,toCharSet);
int contents;
while((contents = inReader.read()) != -1){
otWriter.write(contents);
}
inReader.close();
otWriter.close();
}
catch(Exception e){
e.printStackTrace();
}
}
MD5変換
public static String hexString(String value) throws Exception{
MessageDigest md5 = MessageDigest.getInstance("MD5");
md5.update(value.getBytes());
byte[] hash = md5.digest();
byte[] bin = hash;
String s = "";
int size = bin.length;
for (int i = 0; i < size; i++) {
int n = bin[i];
if (n < 0) {
n += 256;
}
String hex = Integer.toHexString(n);
if (hex.length() == 1) {
hex = "0" + hex;
}
s += hex;
}
return s;
}
}