Package com.alibaba.antx.config

Examples of com.alibaba.antx.config.ConfigException


        try {
            suburi = new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), subpath, uri.getQuery(),
                    uri.getFragment()).normalize();
        } catch (URISyntaxException e) {
            throw new ConfigException(e);
        }

        return new ResourceURI(suburi, options);
    }
View Full Code Here


        try {
            superuri = new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), superpath,
                    uri.getQuery(), uri.getFragment()).normalize();
        } catch (URISyntaxException e) {
            throw new ConfigException(e);
        }

        return new ResourceURI(superuri, options);
    }
View Full Code Here

        Scanner scanner = new DirectoryScanner(getConfigEntryResource().getFile(), handler);

        try {
            scanner.scan();
        } catch (ScannerException e) {
            throw new ConfigException(e);
        }

        subEntries = handler.getSubEntries();

        getGenerator().init();
View Full Code Here

        String componentName = "";

        try {
            componentNamePattern = new PathNameCompiler().compile("META-INF/**/autoconf/auto-config.xml");
        } catch (MalformedPatternException e) {
            throw new ConfigException(e);
        }

        if (matcher.matches(name.replace('\\', '/'), componentNamePattern)) {
            componentName = matcher.getMatch().group(1);
        }
View Full Code Here

    public byte[] getContent() {
        try {
            return StreamUtil.readBytes(getInputStream(), true).toByteArray();
        } catch (IOException e) {
            throw new ConfigException(e);
        }
    }
View Full Code Here

        scanner.setInputStream(istream);

        try {
            scanner.scan();
        } catch (ScannerException e) {
            throw new ConfigException(e);
        }

        subEntries = handler.getSubEntries();

        getGenerator().init();
View Full Code Here

            if (ostream == null) {
                if (outputFile == null) {
                    destfile = getConfigEntryResource().getFile();

                    if ((destfile == null) || !destfile.exists()) {
                        throw new ConfigException("Could not find " + getConfigEntryResource().getURL());
                    }

                    outputFile = new File(destfile.getParentFile(), destfile.getName() + ".tmp");
                }

                outputFile.getParentFile().mkdirs();

                ostream = new BufferedOutputStream(new FileOutputStream(outputFile), 8192);
                needCloseOutputStream = true;
            }

            // �����istream
            if (istream == null) {
                istream = getConfigEntryResource().getURL().openStream();

                if (!(istream instanceof BufferedInputStream)) {
                    istream = new BufferedInputStream(istream, 8192);
                }

                needCloseInputStream = true;
            }

            zis = new ZipInputStream(istream);
            zos = new ZipOutputStream(ostream);

            ZipEntry zipEntry;

            getGenerator().startSession(getConfigSettings().getPropertiesSet());

            while ((zipEntry = zis.getNextEntry()) != null) {
                allSuccess &= processZipEntry(zipEntry, zis, zos, dirs);
            }

            allSuccess &= getGenerator().getSession().generateLazyItems(new ZipCallback(zos, dirs));

            getGenerator().getSession().checkNonprocessedTemplates();
            getGenerator().getSession().generateLog(new ZipCallback(zos, dirs));

            success = true;
        } catch (IOException e) {
            throw new ConfigException(e);
        } finally {
            getGenerator().closeSession();

            // ����zip�ļ��������ر���
            if (zos != null) {
                try {
                    zos.finish();
                } catch (IOException e) {
                }
            }

            // �������������ɵ�ǰentry���Դ򿪵ģ��Źر���
            if (needCloseInputStream && (istream != null)) {
                try {
                    istream.close();
                } catch (IOException e) {
                }
            }

            // ������������ɵ�ǰentry���Դ򿪵ģ��Źر���
            if (needCloseOutputStream && (ostream != null)) {
                try {
                    ostream.flush();
                    ostream.close();
                } catch (IOException e) {
                }

                // ����ɹ�������ʱ�ļ��ij���ʽ�ļ�������ɾ����ʱ�ļ�
                if (success) {
                    // ����û��ָ��outputFileʱ�����������
                    if (getOutputFile() == null) {
                        // ��windows�£��۲쵽renameʧ�ܣ���Ϊlock��ԭ�򡣹�һ�����ԡ�
                        int retryTimes = 10;
                        boolean succ = false;
                        String message = String.format("Moving file %s to %s failed.", outputFile.getName(),
                                destfile.getName());

                        for (int i = 0; i < retryTimes; i++) {
                            destfile.delete();
                            succ = outputFile.renameTo(destfile);

                            if (succ) {
                                break;
                            }

                            getConfigSettings().warn(
                                    String.format(message + "  Wait 0.5s and try again...%d of %d", i + 1, retryTimes));

                            try {
                                System.gc();
                                Thread.sleep(500);
                            } catch (InterruptedException e) {
                            }
                        }

                        if (!succ) {
                            throw new ConfigException(message);
                        }
                    }
                } else {
                    outputFile.delete();
                }
View Full Code Here

        public void nextEntry(ConfigDescriptor descriptor, InputStream is, String dest) {
            try {
                makeParentDirs(dest);
                zos.putNextEntry(new ZipEntry(dest));
            } catch (IOException e) {
                throw new ConfigException(e);
            }

            getGenerator().getSession().setInputStream(is);
            getGenerator().getSession().setOutputStream(zos);
        }
View Full Code Here

        public void logEntry(ConfigDescriptor descriptor, String logfileName) {
            try {
                makeParentDirs(logfileName);
                zos.putNextEntry(new ZipEntry(logfileName));
            } catch (IOException e) {
                throw new ConfigException(e);
            }

            getGenerator().getSession().setOutputStream(zos);
        }
View Full Code Here

        File templateFile = new File(templateBase, base + template);
        File templateFileInPlace = new File(templateBase, template);

        if (!templateFile.exists()) {
            if (!templateFileInPlace.exists()) {
                throw new ConfigException("Could not find template file: " + templateFileInPlace.getAbsolutePath()
                        + " for descriptor: " + descriptor.getURL());
            }

            if (templateFileInPlace.getAbsolutePath().equals(destFile.getAbsolutePath())) {
                templateFile.getParentFile().mkdirs();

                try {
                    StreamUtil.io(new FileInputStream(templateFileInPlace), new FileOutputStream(templateFile), true,
                            true);
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            } else {
                templateFile = templateFileInPlace;
            }
        } else {
            template = base + template;
        }

        // ����destFile�ĸ�Ŀ¼
        File destBase = destFile.getParentFile();

        destBase.mkdirs();

        if (!destBase.isDirectory()) {
            throw new ConfigException("Could not create directory: " + destBase.getAbsolutePath());
        }

        try {
            istream = new BufferedInputStream(new FileInputStream(templateFile), 8192);
            ostream = new BufferedOutputStream(new FileOutputStream(destFile), 8192);
        } catch (FileNotFoundException e) {
            throw new ConfigException(e);
        }

        generator.getSession().setInputStream(istream);
        generator.getSession().setOutputStream(ostream);
View Full Code Here

TOP

Related Classes of com.alibaba.antx.config.ConfigException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.