Spring FileCopyUtils有奇怪的行为

时间:2014-08-27 08:15:22

标签: java spring replication

我不知道这里是否有人使用Spring框架提供的 FileCopyUtils ,但我在我的系统中使用了图像的复制方法。它的目标是捕捉"我系统的临时文件夹中的图像并复制到服务器上的另一个文件夹。下面是一些评论的方法:

public Set<Image> imageReplication(String destination) throws IOException {
    Set<Image> img = new HashSet<>();
    Image image =null;
    try {
        List<ImageJson> imagePathTmpList = dashboardFacade.getImagePathTmpList();

        Gson gson = null;

        String subdomain = dashboardFacade.getAgency().getSubdomain();
        File base = new File("/home/manolo/joocebox-img/" + subdomain + "/"+ destination);


        for (ImageJson imageJsonList : imagePathTmpList) {
            gson = new Gson();
            image = new Image();

            FileMeta imgTmp = gson.fromJson(imageJsonList.getJson(), FileMeta.class);
            //File Old path
            String oldPath = imgTmp.getFileTmpPath();

            //New File Path
            String newPath = base + "/" + imgTmp.getFileName();

            //Checks if the base directory exists, if not it creates the path and makes copies of the files. I believe here that trigger the exeption.
            if(!base.exists()){
                base.mkdirs();
                FileCopyUtils.copy(new FileInputStream(oldPath), new FileOutputStream(newPath));
            }else{
                FileCopyUtils.copy(new FileInputStream(oldPath), new FileOutputStream(newPath));
            }

            image.setJson(newPath);
            img.add(image);

        }

    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }finally{
        deleteTmp();
    }

    return img;
}

好的家伙问题是,在检查我的方式时,&#34; base&#34;存在于服务器中,它不是创建的,并且正在启动FileNotFoundException异常。

但奇怪的是,在我的机器上行为是正常的。并且只发生在我的Amazon EC2实例上。

我想知道你是否同意我的逻辑,如果我错过了什么。

最好的问候


堆栈跟踪:

java.io.FileNotFoundException: /home/ubuntu/joocebox-img/manolo/Test/MyImage.jpg (No such file or directory)
    at java.io.FileOutputStream.open(Native Method)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:221)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:110)
    at br.com.joocebox.controller.FileController.imageReplication(FileController.java:161)
    at br.com.joocebox.controller.FileController$$FastClassBySpringCGLIB$$282cc946.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:708)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:644)
    at br.com.joocebox.controller.FileController$$EnhancerBySpringCGLIB$$e30b112a.imageReplication(<generated>)
    at br.com.joocebox.controller.DestinationController.addDestination(DestinationController.java:108)
    at br.com.joocebox.controller.DestinationController$$FastClassBySpringCGLIB$$49da9f7c.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:708)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:644)
    at br.com.joocebox.controller.DestinationController$$EnhancerBySpringCGLIB$$289546a0.addDestination(<generated>)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:749)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:689)
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:938)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:863)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:313)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)

0 个答案:

没有答案