Java实现从ClearCase的.mrgman文件中提取出文件列表的程序

15 篇文章 0 订阅

Java实现从ClearCase的.mrgman文件中提取出文件列表的程序





import java.io.BufferedReader;

import java.io.BufferedWriter;

import java.io.File;

import java.io.FileReader;

import java.io.FileWriter;

import java.io.IOException;



/**

 * Author: Zhusheng3@126.com 

 * Date:2007-12-9 上午06:38:24
 * Shenzhen

 */



public class MergeManFileTool

{





    public static File getDoubleQuotsString(File fileEndwithmrgman

           )

    {

        File outputFile = new File("temp/getDoubleQuotsString.txt");

        outputFile.getParentFile().mkdirs();

        BufferedReader br = null;

        BufferedWriter bw = null;

        int beginPos = 0;

        int endPos = 0;



        try

        {

            br = new BufferedReader(new FileReader(fileEndwithmrgman));

            bw = new BufferedWriter(new FileWriter(outputFile));

            String line = br.readLine();



   

            boolean needRightQuot = false;

            int begin = 0;



            while (line != null)

            {

                int position = 0;

                if (begin < line.length())

                {

                    position = line.indexOf("/"", begin);

                    while (position >= 0)

                    {



                        if (needRightQuot == true)

                        {

                            String result = line.substring(begin - 1,

                                    position + 1);



                            bw.write(result);

                            bw.newLine();



                            needRightQuot = false;

                        }

                        else

                        {

                            needRightQuot = true;

                        }

                        begin = position + 1;

                        position = line.indexOf("/"", begin);

                    }

                }

                if (needRightQuot == true)

                {

                    bw.write("--------------this line need a /" to close----:");

                    bw.newLine();

                    bw.write(line);

                    bw.newLine();

                }

                line = br.readLine();

            }



        }

        catch (Exception e)

        {





            e.printStackTrace();

        }

        finally

        {

            if (br != null)

            {

                try

                {

                    br.close();

                }

                catch (IOException e)

                {



                    e.printStackTrace();

                }

            }

            if (bw != null)

            {

                try

                {

                    bw.close();

                }

                catch (IOException e)

                {



                    e.printStackTrace();

                }

            }

        }

        return outputFile;



    }

    

    public static File getLineWhichIsFile(File in)

    {

        

        File out = new File("temp//getLineWhichIsFile.txt");

        BufferedReader br = null;

        BufferedWriter bw = null;

        int beginPos = 0;

        int endPos = 0;



        try

        {

            br = new BufferedReader(new FileReader(in));

            bw = new BufferedWriter(new FileWriter(out));

            String line = br.readLine();



            boolean isend = false;

            int begin = 0;



            while (line != null)

            {

                // 包含文件的行,把只有文件夹的行去除掉。

                if (line.contains("."))

                {

                    bw.write(line);

                    bw.newLine();

                }



                line = br.readLine();

            }



        }

        catch (Exception e)

        {

            System.out.println("--" + beginPos + ":" + endPos);



            e.printStackTrace();

        }

        finally

        {

            if (br != null)

            {

                try

                {

                    br.close();

                }

                catch (IOException e)

                {



                    e.printStackTrace();

                }

            }

            if (bw != null)

            {

                try

                {

                    bw.close();

                }

                catch (IOException e)

                {



                    e.printStackTrace();

                }

            }

        }

        return out;

    }

    public static File getLineBeginWith(File inputFile,

            String prefix)

    {



        File resultFile = new File("temp//getAllFiles.txt");

        BufferedReader br = null;

        BufferedWriter bw = null;

        int beginPos = 0;

        int endPos = 0;



        try

        {

            br = new BufferedReader(new FileReader(inputFile));

            bw = new BufferedWriter(new FileWriter(resultFile));

            String line = br.readLine();



            boolean isend = false;

            int begin = 0;



            while (line != null)

            {



                if (line.startsWith(prefix))

                {

                    bw.write(line.substring(1,line.length()-1));

                    bw.newLine();

                    //System.out.println(line.substring(1,line.length()-1));

                }



                line = br.readLine();

            }



        }

        catch (Exception e)

        {



            e.printStackTrace();

        }

        finally

        {

            if (br != null)

            {

                try

                {

                    br.close();

                }

                catch (IOException e)

                {



                    e.printStackTrace();

                }

            }

            if (bw != null)

            {

                try

                {

                    bw.close();

                }

                catch (IOException e)

                {



                    e.printStackTrace();

                }

            }

        }

        return resultFile;



    }

    public static File getFileInTypes(File in,String []types)

    {

        File out = new File("temp//getAllFilesInTypes.txt");

        

        BufferedReader br = null;

        BufferedWriter bw = null;

        int beginPos = 0;

        int endPos = 0;



        try

        {

            br = new BufferedReader(new FileReader(in));

            bw = new BufferedWriter(new FileWriter(out));

            String line = br.readLine();



            boolean isend = false;

            int begin = 0;



            while (line != null)

            {

                // 

                File eachFile = new File(line);

                if(FileTool.isFileInTypes(eachFile, types))

                {

                    bw.write(line);

                    bw.newLine();

                }



                line = br.readLine();

            }



        }

        catch (Exception e)

        {

            System.out.println("--" + beginPos + ":" + endPos);



            e.printStackTrace();

        }

        finally

        {

            if (br != null)

            {

                try

                {

                    br.close();

                }

                catch (IOException e)

                {



                    e.printStackTrace();

                }

            }

            if (bw != null)

            {

                try

                {

                    bw.close();

                }

                catch (IOException e)

                {



                    e.printStackTrace();

                }

            }

        }

        return out;

        

    }

    

    public static File parseFile_mrgman2Txt(File mrgmanFile)

    {



       //step1:get all string in double quots

       File quots = getDoubleQuotsString(mrgmanFile);

       

       //step2:get all lines including clearcase disk symbol-M:

       File include = getLineBeginWith(quots,"/"M:");

      

       //step3:get all lines which is file ,not a diretory

       File allFiles=getLineWhichIsFile(include);

       

       //step4:get all lines which file is in determined types

       File fileInType=getFileInTypes(allFiles,FileTool.types);

       

       

       return fileInType;



    }

    

    

    public static void main(String[] args)

    {

        File mrgman = new File("tw34.mrgman");

        getDoubleQuotsString(mrgman);

       File result =parseFile_mrgman2Txt(mrgman);

        

        result.renameTo(new File("result.txt"));

    }

    

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值