http://yoonbumtae.com/?p=2776
'java' 카테고리의 다른 글
한자리 숫자일대 앞에 0을 붙여준다 (0) | 2021.07.29 |
---|---|
GZip을 이용한 String 압축 및 해제 (0) | 2019.12.26 |
숫자만 입력되었는지 체크하기 (0) | 2019.03.05 |
입력 날짜 및 시간 이후 시간 계산 (2) | 2018.03.07 |
용량 계산 (0) | 2017.12.27 |
http://yoonbumtae.com/?p=2776
한자리 숫자일대 앞에 0을 붙여준다 (0) | 2021.07.29 |
---|---|
GZip을 이용한 String 압축 및 해제 (0) | 2019.12.26 |
숫자만 입력되었는지 체크하기 (0) | 2019.03.05 |
입력 날짜 및 시간 이후 시간 계산 (2) | 2018.03.07 |
용량 계산 (0) | 2017.12.27 |
public static String plusZero(int num) {
int temp = num;
int length = (int) (Math.log10(temp) + 1);
String d = "";
if (length == 1) {
d = String.format("%02d", temp);
} else {
d = String.valueOf(temp);
}
return d;
}
메소드 참조 표현식(이중 콜론 연산자), 생성자참조 표현식 (0) | 2023.01.18 |
---|---|
GZip을 이용한 String 압축 및 해제 (0) | 2019.12.26 |
숫자만 입력되었는지 체크하기 (0) | 2019.03.05 |
입력 날짜 및 시간 이후 시간 계산 (2) | 2018.03.07 |
용량 계산 (0) | 2017.12.27 |
/**
* GZip를 이용한 스트링 압축
* @author jksong
* @Param
* @since 2019-09-09 오전 8:30
**/
public static byte[] zipStringToBytes(String input) throws IOException {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
GZIPOutputStream gzipOutputStream = new GZIPOutputStream(byteArrayOutputStream);
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(gzipOutputStream);
bufferedOutputStream.write(input.getBytes());
bufferedOutputStream.close();
byteArrayOutputStream.close();
return byteArrayOutputStream.toByteArray();
}
/**
* GZIPInputStream을 이용하여 byte배열 압축해제하기
* @author jksong
* @Param
* @since 2019-09-09 오전 8:30
**/
public String unzipStringFromBytes(byte[] bytes) throws IOException {
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
GZIPInputStream gzipInputStream = new GZIPInputStream(byteArrayInputStream);
BufferedInputStream bufferedInputStream = new BufferedInputStream(gzipInputStream);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
byte[] buffer = new byte[100];
int length;
while((length = bufferedInputStream.read(buffer)) > 0) {
byteArrayOutputStream.write(buffer, 0, length);
}
bufferedInputStream.close();
gzipInputStream.close();
byteArrayInputStream.close();
byteArrayOutputStream.close();
return byteArrayOutputStream.toString();
}
메소드 참조 표현식(이중 콜론 연산자), 생성자참조 표현식 (0) | 2023.01.18 |
---|---|
한자리 숫자일대 앞에 0을 붙여준다 (0) | 2021.07.29 |
숫자만 입력되었는지 체크하기 (0) | 2019.03.05 |
입력 날짜 및 시간 이후 시간 계산 (2) | 2018.03.07 |
용량 계산 (0) | 2017.12.27 |
public static boolean isIntegerNumeric(String s) {
try {
Integer.parseInt(s);
return true;
} catch(NumberFormatException e) {
return false;
}
}
public static boolean isDoubleNumeric(String s) {
try {
Double.parseDouble(s);
return true;
} catch(NumberFormatException e) {
return false;
}
}
public static boolean isFloatNumeric(String s) {
try {
Float.parseFloat(s);
return true;
} catch(NumberFormatException e) {
return false;
}
}
활용 방법
if (isIntegerNumeric(String) == false) {
logger.info("숫자만 입력 가능");
}
메소드 참조 표현식(이중 콜론 연산자), 생성자참조 표현식 (0) | 2023.01.18 |
---|---|
한자리 숫자일대 앞에 0을 붙여준다 (0) | 2021.07.29 |
GZip을 이용한 String 압축 및 해제 (0) | 2019.12.26 |
입력 날짜 및 시간 이후 시간 계산 (2) | 2018.03.07 |
용량 계산 (0) | 2017.12.27 |
public static String addDate(String fromDate, String format, int addYear, int addMonth, int addDate, int addHour, int addMinute, int addSecond) throws ParseException {
SimpleDateFormat sdf = new SimpleDateFormat(format);
Date date = sdf.parse(fromDate);
Calendar cal = new GregorianCalendar();
cal.setTime(date);
cal.add(Calendar.YEAR, +addYear);
cal.add(Calendar.MONTH, +addMonth);
cal.add(Calendar.DATE, +addDate);
cal.add(Calendar.HOUR, +addHour);
cal.add(Calendar.MINUTE, +addMinute);
cal.add(Calendar.SECOND, +addSecond);
SimpleDateFormat sdf2 = new SimpleDateFormat(format);
String toDate = sdf2.format(cal.getTime());
return toDate;
}
1년 후
String addDate(format, "yyyy-MM-dd HH:mm:ss", 1, 0, 0, 0, 0, 0);
10분 후
String addDate(format, "yyyy-MM-dd HH:mm:ss", 0, 0, 0, 0, 10, 0);
메소드 참조 표현식(이중 콜론 연산자), 생성자참조 표현식 (0) | 2023.01.18 |
---|---|
한자리 숫자일대 앞에 0을 붙여준다 (0) | 2021.07.29 |
GZip을 이용한 String 압축 및 해제 (0) | 2019.12.26 |
숫자만 입력되었는지 체크하기 (0) | 2019.03.05 |
용량 계산 (0) | 2017.12.27 |
public static String humanReadableByteCount(long bytes, boolean si) {
int unit = si ? 1000 : 1024;
if (bytes < unit) return bytes + " B";
int exp = (int) (Math.log(bytes) / Math.log(unit));
String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp-1) + (si ? "" : "i");
return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre);
}
메소드 참조 표현식(이중 콜론 연산자), 생성자참조 표현식 (0) | 2023.01.18 |
---|---|
한자리 숫자일대 앞에 0을 붙여준다 (0) | 2021.07.29 |
GZip을 이용한 String 압축 및 해제 (0) | 2019.12.26 |
숫자만 입력되었는지 체크하기 (0) | 2019.03.05 |
입력 날짜 및 시간 이후 시간 계산 (2) | 2018.03.07 |