semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public void genCreateSchema(DiagramModel diagramModel, String source) {
        try {
            con.setAutoCommit(false);
            stmt = con.createStatement();
            Collection boxes = diagramModel.getBoxes();
            BoxModel box;
            ItemModel item;
            String sqlQuery;
            int counter = 0;
            for (Iterator x = boxes.iterator(); x.hasNext(); ) {
                box = (BoxModel) x.next();
                if (!box.isAbstractDef()) {
                    sqlQuery = sqlCreateTableBegin(box);
                    Collection items = box.getItems();
                    for (Iterator y = items.iterator(); y.hasNext(); ) {
                        item = (ItemModel) y.next();
                        sqlQuery = sqlQuery + sqlColumn(item);
                    }
                    sqlQuery = sqlQuery + sqlForeignKeyColumns(box);
                    sqlQuery = sqlQuery + sqlPrimaryKey(box);
                    sqlQuery = sqlQuery + sqlUniqueKey(box);
                    sqlQuery = sqlQuery + sqlCreateTableEnd(box, source);
                    System.out.println(sqlQuery);
                    try {
                        stmt.executeUpdate(sqlQuery);
                        counter++;
                    } catch (SQLException e) {
                        String tableName = box.getName();
                        System.out.println("// Problem while creating table " + tableName + " : " + e.getMessage());
                        String msg = Para.getPara().getText("tableNotCreated") + " -- " + tableName;
                        this.informUser(msg);
                    }
                }
            }
            this.genCreateForeignKeys(diagramModel);
            con.commit();
            if (counter > 0) {
                String msg = Para.getPara().getText("schemaCreated") + " -- " + counter + " " + Para.getPara().getText("tables");
                this.informUser(msg);
            } else {
                this.informUser(Para.getPara().getText("schemaNotCreated"));
            }
        } catch (SQLException e) {
            System.out.println(e.getMessage() + " // Problem with the JDBC schema generation! ");
            try {
                con.rollback();
                this.informUser(Para.getPara().getText("schemaNotCreated"));
            } catch (SQLException e1) {
                System.out.println(e1.getMessage() + " // Problem with the connection rollback! ");
            }
        } finally {
            try {
                con.setAutoCommit(true);
                stmt.close();
            } catch (SQLException e) {
                System.out.println(e.getMessage() + " // Problem with the statement closing! ");
            }
        }
    }
public static byte[] downloadFromUrl(String fileUrl) throws IOException {
        URL url = new URL(fileUrl);
        URLConnection ucon = url.openConnection();
        InputStream is = ucon.getInputStream();
        BufferedInputStream bis = new BufferedInputStream(is);
        ByteArrayBuffer baf = new ByteArrayBuffer(50);
        int current = 0;
        while ((current = bis.read()) != -1) {
            baf.append((byte) current);
        }
        return baf.toByteArray();
    }
public String gen() {
        String plainText = this.password;
        MessageDigest mdAlgorithm;
        StringBuffer hexString = new StringBuffer();
        try {
            mdAlgorithm = MessageDigest.getInstance("MD5");
            mdAlgorithm.update(plainText.getBytes());
            byte[] digest = mdAlgorithm.digest();
            for (int i = 0; i < digest.length; i++) {
                plainText = Integer.toHexString(0xFF & digest[i]);
                if (plainText.length() < 2) plainText = "0" + plainText;
                hexString.append(plainText);
            }
        } catch (NoSuchAlgorithmException ex) {
        }
        return hexString.toString();
    }
public void widgetSelected(SelectionEvent event) {
                try {
                    URL url = new URL(PKBMain.PRODUCT_WEBSITE + "/latest-version.txt");
                    Properties prop = new Properties();
                    prop.load(url.openStream());
                    Package currentPackage = Package.getPackage("org.sf.pkb.gui");
                    String version = currentPackage.getImplementationVersion();
                    if (version == null) {
                        version = "";
                    }
                    String remoteVersion = prop.getProperty("version") + " b" + prop.getProperty("build");
                    if (remoteVersion.trim().compareTo(version.trim()) != 0) {
                        StringBuffer buf = new StringBuffer();
                        buf.append("<HTML><BODY>").append("<h3 style='color: #0033FF'>You do not have the latest version. <br/> ").append("The latest version is PKB ").append(prop.getProperty("version") + " b" + prop.getProperty("build")).append(".</h3><A HREF='").append(prop.getProperty("url")).append("' TARGET='_BLANK'>Please download here </a> <br/><br/>").append("<B>It is strongly suggested to backup your knowledge base before install or unzip the new package!</B>").append("</BODY></HTML>");
                        MainScreen.Widget.getKnowledgeContentPanel().showTextInBrowser(buf.toString());
                    } else {
                        StringBuffer buf = new StringBuffer();
                        buf.append("<HTML><BODY>").append("<h3 style='color: #0033FF'>You already had the latest version - ALEX PKB ").append(prop.getProperty("version") + " b" + prop.getProperty("build")).append(".</h3>").append("</BODY></HTML>");
                        MainScreen.Widget.getKnowledgeContentPanel().showTextInBrowser(buf.toString());
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
                shell.close();
            }
public void compile(Project project) throws ProjectCompilerException {
        List<Resource> resources = project.getModel().getResource();
        for (Resource resource : resources) {
            try {
                IOUtils.copy(srcDir.getRelative(resource.getLocation()).getInputStream(), outDir.getRelative(resource.getLocation()).getOutputStream());
            } catch (IOException e) {
                throw new ProjectCompilerException("Resource cannot be copied. Compilation failed", e);
            }
        }
    }
public static void copyFiles(File src, File dest) throws IOException {
        if (src.isDirectory()) {
            dest.mkdirs();
            for (String f : src.list()) {
                String df = dest.getPath() + File.separator + f;
                String sf = src.getPath() + File.separator + f;
                copyFiles(new File(sf), new File(df));
            }
        } else {
            FileInputStream fin = new FileInputStream(src);
            FileOutputStream fout = new FileOutputStream(dest);
            int c;
            while ((c = fin.read()) >= 0) fout.write(c);
            fin.close();
            fout.close();
        }
    }
public void loadRegistry(URL url) throws PacketAnalyzerRegistryException {
        if (analyzers != null) {
            return;
        }
        analyzers = new Hashtable();
        roots = new Vector();
        try {
            InputStream in = url.openStream();
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            DocumentBuilder docBuilder = factory.newDocumentBuilder();
            Document doc = docBuilder.parse(in);
            NodeList list = doc.getElementsByTagName(PACKET_ANALYZER);
            for (int i = 0; i < list.getLength(); i++) {
                Node node = list.item(i);
                NamedNodeMap map = node.getAttributes();
                String id = map.getNamedItem(ID).getNodeValue();
                String name = map.getNamedItem(NAME).getNodeValue();
                String clazz = map.getNamedItem(CLASS).getNodeValue();
                Node n = map.getNamedItem(EXTENDS);
                String[] split = null;
                if (n != null) {
                    String extendedAnalyzers = n.getNodeValue();
                    if (extendedAnalyzers.trim().length() != 0) {
                        split = extendedAnalyzers.split("\\s*\\,+\\s*");
                    }
                }
                PacketAnalyzerDescriptor descriptor = new PacketAnalyzerDescriptor(id, name, clazz, split);
                addDescriptor(descriptor);
            }
            if (roots.size() == 0) {
                throw new PacketAnalyzerRegistryException("There is no root analyzer in the registry!");
            }
        } catch (IOException e) {
            throw new PacketAnalyzerRegistryException("Cannot open registry file.", e);
        } catch (ParserConfigurationException e) {
            throw new PacketAnalyzerRegistryException("Cannot parse registry file.", e);
        } catch (SAXException e) {
            throw new PacketAnalyzerRegistryException("Cannot parse registry file", e);
        } catch (Throwable e) {
            throw new PacketAnalyzerRegistryException("Cannot build PacketAnalyzerRegistry.", e);
        }
    }
public void testDoPost() throws Exception {
        URL url = null;
        url = new URL("http://127.0.0.1:" + connector.getLocalPort() + "/test/dump/info?query=foo");
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("POST");
        connection.setDoOutput(true);
        connection.setDoInput(true);
        connection.addRequestProperty(HttpHeaders.CONTENT_TYPE, MimeTypes.FORM_ENCODED);
        connection.addRequestProperty(HttpHeaders.CONTENT_LENGTH, "10");
        connection.getOutputStream().write("abcd=1234\n".getBytes());
        connection.getOutputStream().flush();
        connection.connect();
        String s0 = IO.toString(connection.getInputStream());
        assertTrue(s0.startsWith("<html>"));
        assertTrue(s0.indexOf("<td>POST</td>") > 0);
        assertTrue(s0.indexOf("abcd:&nbsp;</th><td>1234") > 0);
    }
public void testUnavailable() throws Exception {
        URL url = null;
        url = new URL("http://127.0.0.1:" + connector.getLocalPort() + "/test/dump/info?query=foo");
        assertTrue(IO.toString(url.openStream()).startsWith("<html>"));
        assertTrue(context.getServletHandler().isAvailable());
        url = new URL("http://127.0.0.1:" + connector.getLocalPort() + "/test/dump/ex2/2");
        try {
            IO.toString(url.openStream());
        } catch (IOException e) {
        }
        assertFalse(context.getServletHandler().isAvailable());
        Thread.sleep(4000);
        assertTrue(context.getServletHandler().isAvailable());
    }
public static boolean encodeFileToFile(String infile, String outfile) {
        boolean success = false;
        java.io.InputStream in = null;
        java.io.OutputStream out = null;
        try {
            in = new Base64.InputStream(new java.io.BufferedInputStream(new java.io.FileInputStream(infile)), Base64.ENCODE);
            out = new java.io.BufferedOutputStream(new java.io.FileOutputStream(outfile));
            byte[] buffer = new byte[65536];
            int read = -1;
            while ((read = in.read(buffer)) >= 0) {
                out.write(buffer, 0, read);
            }
            success = true;
        } catch (java.io.IOException exc) {
            logger.error(Logger.SECURITY_FAILURE, "Problem encoding file to file", exc);
        } finally {
            try {
                in.close();
            } catch (Exception exc) {
            }
            try {
                out.close();
            } catch (Exception exc) {
            }
        }
        return success;
    }
public static boolean decodeFileToFile(String infile, String outfile) {
        boolean success = false;
        java.io.InputStream in = null;
        java.io.OutputStream out = null;
        try {
            in = new Base64.InputStream(new java.io.BufferedInputStream(new java.io.FileInputStream(infile)), Base64.DECODE);
            out = new java.io.BufferedOutputStream(new java.io.FileOutputStream(outfile));
            byte[] buffer = new byte[65536];
            int read = -1;
            while ((read = in.read(buffer)) >= 0) {
                out.write(buffer, 0, read);
            }
            success = true;
        } catch (java.io.IOException exc) {
            logger.error(Logger.SECURITY_FAILURE, "Problem decoding file to file", exc);
        } finally {
            try {
                in.close();
            } catch (Exception exc) {
            }
            try {
                out.close();
            } catch (Exception exc) {
            }
        }
        return success;
    }
public void write(HttpServletResponse res) throws MalformedURLException, IOException {
        if (m_url.equals("")) {
            return;
        }
        URL url = new URL(m_url);
        URLConnection con = url.openConnection();
        con.setUseCaches(false);
        BufferedInputStream in = new BufferedInputStream(con.getInputStream(), BUF_SIZE);
        BufferedOutputStream out = new BufferedOutputStream(res.getOutputStream());
        byte[] buf = new byte[BUF_SIZE];
        int size = 0;
        String contentType = con.getContentType();
        if (contentType != null) {
            res.setContentType(con.getContentType());
        }
        while ((size = in.read(buf)) > 0) {
            out.write(buf, 0, size);
        }
        out.flush();
        out.close();
        in.close();
    }
public void perform(Context context) {
            Long workflowIdParentProcess;
            SimpleProvider config;
            VariablesContext var;
            String xmldocument;
            Service service;
            Object[] param;
            String method;
            String wsurl;
            Object ret;
            Call call;
            URL url;
            try {
                var = Variables.getContext();
                if (var.get("wsurl") == null || var.get("method") == null) {
                    System.out.println("----- Need the url of the webservice and the method! -----");
                    log_.error("Need the url of the webservice and the method!");
                    return;
                }
                method = var.get("method");
                wsurl = var.get("wsurl");
                url = new java.net.URL(wsurl);
                try {
                    url.openConnection().connect();
                } catch (IOException ex) {
                    System.out.println("----- Could not connect to the webservice! -----");
                    log_.error("Could not connect to the webservice!");
                    return;
                }
                if (var.get("param0") == null || var.get("param1") == null) {
                    System.out.println("----- Need parameters! -----");
                    log_.error("Need parameters!");
                    return;
                }
                xmldocument = var.get("param0");
                workflowIdParentProcess = new Long(var.get("param1"));
                param = new Object[] { xmldocument, workflowIdParentProcess };
                config = new SimpleProvider();
                config.deployTransport("http", new HTTPSender());
                service = new Service(config);
                call = (Call) service.createCall();
                call.setTargetEndpointAddress(new java.net.URL(wsurl));
                call.setOperationName(new QName("http://schemas.xmlsoap.org/soap/encoding/", method));
                try {
                    ret = call.invoke(param);
                    context.set(CTX_ANSW, "=> notifyIhk invoked - Result: " + ret);
                    System.out.println("----- notifyIhk invoked! -----");
                    log_.info("notifyIhk invoked!");
                } catch (RemoteException ex) {
                    System.out.println("----- Could not invoke the method! -----");
                    log_.error("Could not invoke the method!");
                }
            } catch (Exception ex) {
                ex.printStackTrace(System.err);
            }
        }
private static void testTidy() {
        try {
            String url = "http://groups.google.com/group/dengues/files";
            java.io.InputStream is = new java.net.URL(url).openStream();
            org.w3c.dom.Document doc = dengues.system.HTMLWebHelper.parseDOM(is);
            org.w3c.dom.NodeList list = doc.getElementsByTagName("td");
            org.w3c.dom.Element stockTypeElement = null;
            for (int i = 0; i < list.getLength(); i++) {
                org.w3c.dom.Node item = list.item(i);
                String content = dengues.system.HTMLWebHelper.getContent(item);
                String convert = dengues.system.HTMLWebHelper.convert(content);
                if (convert.equals("zDevil")) {
                    stockTypeElement = (org.w3c.dom.Element) item.getParentNode().getParentNode();
                    break;
                }
            }
            if (stockTypeElement != null) {
                org.w3c.dom.NodeList trList = stockTypeElement.getElementsByTagName("tr");
                for (int i = 0; i < trList.getLength(); i++) {
                    org.w3c.dom.NodeList trListChildren = trList.item(i).getChildNodes();
                    if (trListChildren.getLength() > 2) {
                        org.w3c.dom.Node node_0 = trListChildren.item(0);
                        org.w3c.dom.Node node_1 = trListChildren.item(1);
                        String content = dengues.system.HTMLWebHelper.getContent(node_0);
                        String convert_0 = dengues.system.HTMLWebHelper.convert(content);
                        content = dengues.system.HTMLWebHelper.getContent(node_1);
                        String convert_1 = dengues.system.HTMLWebHelper.convert(content);
                        if (!"".equals(convert_0)) {
                            System.out.println(convert_0 + " => " + convert_1);
                        }
                    }
                }
            }
            is.close();
        } catch (java.net.MalformedURLException ex) {
            ex.printStackTrace();
        } catch (java.io.IOException ex) {
            ex.printStackTrace();
        }
    }
@Before
    public void init() throws IOException {
        file = new File(LOCATION);
        url = file.toURI().toURL();
        stream = url.openStream();
        byteArray = IOUtils.toByteArray(new FileInputStream(file));
        content = FileUtils.readFileToString(file);
    }
public long getLastModified() {
        if (lastModified == 0) {
            if (connection == null) try {
                connection = url.openConnection();
            } catch (IOException e) {
            }
            if (connection != null) lastModified = connection.getLastModified();
        }
        return lastModified;
    }
public List<SuspectFileProcessingStatus> retrieve() throws Exception {
        BufferedOutputStream bos = null;
        try {
            String listFilePath = GeneralUtils.generateAbsolutePath(getDownloadDirectoryPath(), getListName(), "/");
            listFilePath = listFilePath.concat(".xml");
            if (!new File(getDownloadDirectoryPath()).exists()) {
                FileUtils.forceMkdir(new File(getDownloadDirectoryPath()));
            }
            FileOutputStream listFileOutputStream = new FileOutputStream(listFilePath);
            bos = new BufferedOutputStream(listFileOutputStream);
            InputStream is = null;
            if (getUseProxy()) {
                is = URLUtils.getResponse(getUrl(), getUserName(), getPassword(), URLUtils.HTTP_GET_METHOD, getProxyHost(), getProxyPort());
                IOUtils.copyLarge(is, bos);
            } else {
                URLUtils.getResponse(getUrl(), getUserName(), getPassword(), bos, null);
            }
            bos.flush();
            bos.close();
            File listFile = new File(listFilePath);
            if (!listFile.exists()) {
                throw new IllegalStateException("The list file did not get created");
            }
            if (isLoggingInfo()) {
                logInfo("Downloaded list file : " + listFile);
            }
            List<SuspectFileProcessingStatus> sfpsList = new ArrayList<SuspectFileProcessingStatus>();
            String loadType = GeneralConstants.LOAD_TYPE_FULL;
            String feedType = GeneralConstants.EMPTY_TOKEN;
            String listName = getListName();
            String errorCode = "";
            String description = "";
            SuspectFileProcessingStatus sfps = getSuspectsLoaderService().storeFileIntoListIncomingDir(listFile, loadType, feedType, listName, errorCode, description);
            sfpsList.add(sfps);
            if (isLoggingInfo()) {
                logInfo("Retrieved list file with SuspectFileProcessingStatus: " + sfps);
            }
            return sfpsList;
        } finally {
            if (null != bos) {
                bos.close();
            }
        }
    }
private static boolean tryExpandGorillaHome(File f) throws GorillaHomeException {
        if (f.exists()) {
            if (!f.isDirectory() || !f.canWrite()) {
                return false;
            }
        } else {
            boolean dirOK = f.mkdirs();
        }
        if (f.exists() && f.isDirectory() && f.canWrite()) {
            java.net.URL url = GorillaHome.class.getResource("/resource_defaults/GORILLA_HOME");
            if (url == null) {
                throw new GorillaHomeException("cannot find gorilla.home resources relative to class " + GorillaHome.class.getName());
            }
            java.net.URLConnection conn;
            try {
                conn = url.openConnection();
            } catch (IOException e) {
                String msg = "Error opening connection to " + url.toString();
                logger.error(msg, e);
                throw new GorillaHomeException("Error copying " + url.toString(), e);
            }
            if (conn == null) {
                throw new GorillaHomeException("cannot find gorilla.home resources relative to class " + GorillaHome.class.getName());
            }
            if (conn instanceof java.net.JarURLConnection) {
                logger.debug("Expanding gorilla.home from from jar file via url " + url.toString());
                try {
                    IOUtil.expandJar((java.net.JarURLConnection) conn, f);
                    return true;
                } catch (Exception e) {
                    throw new GorillaHomeException("Error expanding gorilla.home" + " from jar file at " + conn.getURL().toString() + ": " + e.getMessage());
                }
            } else {
                try {
                    IOUtil.copyDir(new File(url.getFile()), f);
                    return true;
                } catch (Exception e) {
                    throw new GorillaHomeException("Error expanding gorilla.home" + " from file at " + conn.getURL().toString() + ": " + e.getMessage());
                }
            }
        }
        return false;
    }