将文件移动到linux上托管的tomcat服务器上的另一个目录时出现不可预知的行为

时间:2013-01-10 18:53:44

标签: java tomcat

我在服务器上有一个位置说/home/work/inbox,我已经配置了一个石英监视器,以便拾取放置在该位置的任何.xml文件,并为每个文件启动工作流,然后相应的文件在/ home / work / inbox / metadata等子目录下移动。测试时我将.xml和.pdf文件放在收件箱目录中,有时.xml和.pdf文件都被移动到元数据文件夹我在下面的代码中做错了什么?为什么它有时仅移动.xml并且有时会移动所有这些?

Class clazz extends JobDetail implements Job{

    private static final String EXT_XML = ".XML";
    public void execute(final JobExecutionContext context)
        throws JobExecutionException
    {
        LOG.info("Monitor is on: " + getServerName());
        try
        {
            final ApplicationContext appContext = this.getApplicationContext(context);
            // Assume the code below is returning /home/work
            LandingStrip landingStrip = LandingStripFactory.getLS();
            // the code below returns all the files under /home/work/inbox
            final File[] files = landingStrip.getAllRtSuperQuickInboxFiles();
            if (files != null)
                {
                    LOG.info("Found " + files.length + " keyed files");
                    final ArrayList<File> contentFiles = new ArrayList<File>();
                    for (final File file : files)
                    {
                        final String fileName = file.getName();
                        if ((fileName.toUpperCase()).endsWith(EXT_XML))
                        {
                            contentFiles.add(file);
                        }
                    }

                    if (!contentFiles.isEmpty())
                    {
                        moveMetadataFile(contentFiles);
                    }
                    else
                    {
                        // Do nothing
                    }
                }
            }

        }
        catch (final Exception e)
        {
            LOG.error("Error" + e.getMessage(), e);
        }
    }

    private ApplicationContext getApplicationContext(final JobExecutionContext cxt)
        throws JobExecutionException
    {
        ApplicationContext context = null;

        try
        {
            context = (ApplicationContext) cxt.getScheduler().getContext()
                                              .get(APPLICATION_CONTEXT_KEY);
        }
        catch (final SchedulerException ex)
        {
            throw new JobExecutionException(ex.getMessage());
        }

        if (context == null)
        {
            throw new JobExecutionException(
                "No application context available in scheduler context for key "
                + APPLICATION_CONTEXT_KEY);
        }

        return context;
    }


    private void moveMetadataFile(final List<File> metadataFiles)
    {
        final LandingStrip landingStrip = LandingStripFactory.getLS();

        for (File metadataFile : metadataFiles)
        {
            try
            {
                landingStrip.moveRtSuperQuickMetadataFile(metadataFile.getName());
            }
            catch (IOException e)
            {
                LOG.error("Error in moving regtext metadata file:" +               

                metadataFile.getName());
            }
        }
    }


// Get all files is in another class and the inbox string returns /home/work/inbox
   @Override
    public File[] getAllRtSuperQuickInboxFiles()
    {
        final String inbox = buildPath(getBaseDir(), RT_SUPERQUICK_INBOX);
        final File dir = new File(inbox);

        return dir.listFiles();
    }

0 个答案:

没有答案