001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.zip;
016    
017    import com.liferay.portal.kernel.util.ReflectionUtil;
018    
019    import java.lang.reflect.Field;
020    
021    /**
022     * @author Shuyang Zhou
023     */
024    public class TrueZIPHelperUtil {
025    
026            public static void initialize() {
027                    try {
028                            Class.forName(
029                                    "de.schlichtherle.io.ArchiveControllers", true,
030                                    TrueZIPHelperUtil.class.getClassLoader());
031    
032                            Class<?> clazz = Class.forName(
033                                    "de.schlichtherle.io.ArchiveControllers$ShutdownHook");
034    
035                            Field field = ReflectionUtil.getDeclaredField(clazz, "SINGLETON");
036    
037                            Thread thread = (Thread)field.get(null);
038    
039                            Runtime runtime = Runtime.getRuntime();
040    
041                            if (runtime.removeShutdownHook(thread)) {
042                                    _thread = thread;
043                            }
044                    }
045                    catch (Exception e) {
046                            ReflectionUtil.throwException(e);
047                    }
048            }
049    
050            public static void shutdown() {
051                    Thread thread = _thread;
052    
053                    if (thread != null) {
054                            thread.start();
055    
056                            try {
057                                    thread.join();
058                            }
059                            catch (InterruptedException ie) {
060                                    ReflectionUtil.throwException(ie);
061                            }
062                    }
063            }
064    
065            private static volatile Thread _thread;
066    
067    }