package CoreFS.Util;

import java.io.File;
import java.util.Arrays;
import java.util.StringTokenizer;

public class RemoteFileUtil {
    String srcDirectory;
    String trueDirectory;
    String separatedFiles[];
    String separatedFilesAndSize[][];
    int FileNum;
    String fileRealName;
    String urlFile;
    
    private void getFileAttribute(String drictory)
    {
        File file = new File(drictory);
        separatedFiles = new String[file.list().length];
        separatedFiles = file.list();
        separatedFilesAndSize = new String[separatedFiles.length][2];
        Arrays.sort(separatedFiles);
        FileNum = separatedFiles.length;
        for(int i = 0; i < FileNum; i++)
        {
            separatedFilesAndSize[i][0] = separatedFiles[i];
            separatedFilesAndSize[i][1] = String.valueOf(getFileSize(separatedFiles[i]));
        }

        fileRealName = getRealName(separatedFiles[FileNum - 1]);
    }
    
    private String getRealName(String sFileName)
    {
        StringTokenizer st = new StringTokenizer(sFileName, ".");
        int Tokens = st.countTokens();
        String tName = "";
        for(int i = 1; i < Tokens; i++)
        {
            tName = (new StringBuilder()).append(tName).append(st.nextToken()).toString();
            if(i < Tokens - 1)
                tName = (new StringBuilder()).append(tName).append(".").toString();
        }

        return tName;
    }
    
    private long getFileSize(String FileName)
    {
        FileName = (new StringBuilder()).append(srcDirectory).append("\\").append(FileName).toString();
        return (new File(FileName)).length();
    }
    
    public static void main(String[] args) {
    	RemoteFileUtil test = new RemoteFileUtil();
    	String remotefile = "http://localhost:8088/remoteFile";
    	Long size = test.getFileSize(remotefile);
    	//System.out.println(size);
    }

}
