📄 utils.java
字号:
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package eti.bi.util;
import java.io.BufferedWriter;
import java.io.EOFException;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import eti.bi.common.Constants;
import eti.bi.exception.AppException;
/**
* A utility class that perform the utility functions that can be used by all the
* modules in the BI platform.
*
* @since 1.0
* @version $Revision$ $Date$
* @author $Author$
*/
public class Utils {
private static final String DATE_PATTERN = "yyyyMMdd";
/**
* Copy a file
* @param aSrcFile The source of the file to be copied.
* @param aDstFile The destination of the file to be copied to.
* @throws IOException If any I/O error occurs.
*/
public static void copyFile(File aSrcFile, File aDstFile) throws IOException
{
RandomAccessFile aRAF1 = null;
RandomAccessFile aRAF2 = null;
try
{
aRAF1 = new RandomAccessFile(aSrcFile, "r");
aRAF2 = new RandomAccessFile(aDstFile, "rw");
while (true)
{
aRAF2.writeByte(aRAF1.readUnsignedByte());
}
}
catch(EOFException e)
{
}
catch(Exception e)
{
System.out.println("Utilss Exception Caught:"+e);
}
finally
{
aRAF1.close();
aRAF2.close();
}
}
public static Date parseDate(String aDateStr) throws ParseException
{
SimpleDateFormat aSDF = new SimpleDateFormat(DATE_PATTERN);
return aSDF.parse(aDateStr);
}
public static String formatDate(Date aDate) throws ParseException
{
SimpleDateFormat aSDF = new SimpleDateFormat(DATE_PATTERN);
return aSDF.format(aDate);
}
public static String formatBimlId(Long aBimlId)
{
DecimalFormat aDF = new DecimalFormat(Constants.BIML_ID_PATTERN);
return aDF.format(aBimlId.longValue());
}
public static void exportToFile(String aContent, String aDestFilename) throws AppException
{
try {
BufferedWriter aBufferedWriter = new BufferedWriter(new FileWriter(aDestFilename));
aBufferedWriter.write(aContent);
aBufferedWriter.flush();
aBufferedWriter.close();
} catch (Exception e) {
System.err.println("Error exporting file: " + aDestFilename + " Exception: " + e.getMessage());
throw new AppException("Error exporting file: " + aDestFilename, e);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -