semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
private boolean doesURLExists(String programURIStr) throws Exception {
        boolean retVal = true;
        TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {

            public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                return null;
            }

            public void checkClientTrusted(X509Certificate[] certs, String authType) {
            }

            public void checkServerTrusted(X509Certificate[] certs, String authType) {
            }
        } };
        SSLContext sc = SSLContext.getInstance("SSL");
        sc.init(null, trustAllCerts, new java.security.SecureRandom());
        HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
        HostnameVerifier allHostsValid = new HostnameVerifier() {

            public boolean verify(String hostname, SSLSession session) {
                return true;
            }
        };
        HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);
        URL url = new URL(programURIStr);
        HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
        urlConn.setConnectTimeout(30000);
        urlConn.connect();
        log.debug("HTTP Status code: " + urlConn.getResponseCode() + " for URL: " + programURIStr);
        if (HttpURLConnection.HTTP_OK != urlConn.getResponseCode()) {
            urlConn.disconnect();
            throw new Exception("HTTP status code " + urlConn.getResponseCode() + " for " + programURIStr);
        }
        urlConn.disconnect();
        return retVal;
    }
private static void fileUpload() throws Exception {
        file = new File("c:/Documents and Settings/dinesh/Desktop/ZShareUploaderPlugin.java");
        httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost("http://flameupload.com/cgi/ubr_upload.pl?upload_id=" + uploadid);
        MultipartEntity mpEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
        ContentBody cbFile = new FileBody(file);
        mpEntity.addPart("upfile_0", cbFile);
        mpEntity.addPart("uploaded", new StringBody("on"));
        mpEntity.addPart("hotfile", new StringBody("on"));
        mpEntity.addPart("turbobit", new StringBody("on"));
        mpEntity.addPart("depositfiles", new StringBody("on"));
        mpEntity.addPart("fileserve", new StringBody("on"));
        mpEntity.addPart("filefactory", new StringBody("on"));
        mpEntity.addPart("netload", new StringBody("on"));
        mpEntity.addPart("uploadstation", new StringBody("on"));
        mpEntity.addPart("badongo", new StringBody("on"));
        mpEntity.addPart("uploading", new StringBody("on"));
        mpEntity.addPart("megashare", new StringBody("on"));
        mpEntity.addPart("_2shared", new StringBody("on"));
        httppost.setEntity(mpEntity);
        NULogger.getLogger().log(Level.INFO, "executing request {0}", httppost.getRequestLine());
        NULogger.getLogger().info("Now uploading your file into flameupload.com");
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity resEntity = response.getEntity();
        NULogger.getLogger().info(response.getStatusLine().toString());
        NULogger.getLogger().info(EntityUtils.toString(resEntity));
        Header[] allHeaders = response.getAllHeaders();
        for (int i = 0; i < allHeaders.length; i++) {
            System.out.println(allHeaders[i].getName() + "=" + allHeaders[i].getValue());
        }
        if (response.getStatusLine().getStatusCode() == 302) {
            NULogger.getLogger().info("Files uploaded successfully");
        } else {
            throw new Exception("There might be a problem with your internet connection or server error. Please try again later :(");
        }
    }
public void includeJs(Group group, Writer out, PageContext pageContext) throws IOException {
        includeResource(pageContext, out, RetentionHelper.buildRootRetentionFilePath(group, ".js"), JS_BEGIN_TAG, JS_END_TAG);
        ByteArrayOutputStream outtmp = new ByteArrayOutputStream();
        if (AbstractGroupBuilder.getInstance().buildGroupJsIfNeeded(group, outtmp, pageContext.getServletContext())) {
            FileOutputStream fileStream = new FileOutputStream(new File(RetentionHelper.buildFullRetentionFilePath(group, ".js")));
            IOUtils.copy(new ByteArrayInputStream(outtmp.toByteArray()), fileStream);
            fileStream.close();
        }
    }
public void includeCss(Group group, Writer out, PageContext pageContext) throws IOException {
        ByteArrayOutputStream outtmp = new ByteArrayOutputStream();
        if (AbstractGroupBuilder.getInstance().buildGroupJsIfNeeded(group, outtmp, pageContext.getServletContext())) {
            FileOutputStream fileStream = null;
            try {
                fileStream = new FileOutputStream(new File(RetentionHelper.buildFullRetentionFilePath(group, ".css")));
                IOUtils.copy(new ByteArrayInputStream(outtmp.toByteArray()), fileStream);
            } finally {
                if (fileStream != null) fileStream.close();
            }
        }
    }
public boolean copy(File src, File dest, byte[] b) {
        if (src.isDirectory()) {
            String[] ss = src.list();
            for (int i = 0; i < ss.length; i++) if (!copy(new File(src, ss[i]), new File(dest, ss[i]), b)) return false;
            return true;
        }
        delete(dest);
        dest.getParentFile().mkdirs();
        try {
            FileInputStream fis = new FileInputStream(src);
            try {
                FileOutputStream fos = new FileOutputStream(dest);
                try {
                    int read;
                    while ((read = fis.read(b)) != -1) fos.write(b, 0, read);
                } finally {
                    try {
                        fos.close();
                    } catch (IOException ignore) {
                    }
                    register(dest);
                }
            } finally {
                fis.close();
            }
            if (log.isDebugEnabled()) log.debug("Success: M-COPY " + src + " -> " + dest);
            return true;
        } catch (IOException e) {
            log.error("Failed: M-COPY " + src + " -> " + dest, e);
            return false;
        }
    }
public static void main(String[] args) {
        try {
            File fichierXSD = new File("D:/Users/Balley/données/gml/commune.xsd");
            URL urlFichierXSD = fichierXSD.toURI().toURL();
            InputStream isXSD = urlFichierXSD.openStream();
            DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder builder = dbFactory.newDocumentBuilder();
            Document documentXSD = (builder.parse(isXSD));
            ChargeurGMLSchema chargeur = new ChargeurGMLSchema(documentXSD);
            SchemaConceptuelJeu sc = chargeur.gmlSchema2schemaConceptuel(documentXSD);
            System.out.println(sc.getFeatureTypes().size());
            for (int i = 0; i < sc.getFeatureTypes().size(); i++) {
                System.out.println(sc.getFeatureTypes().get(i).getTypeName());
                for (int j = 0; j < sc.getFeatureTypes().get(i).getFeatureAttributes().size(); j++) {
                    System.out.println("    " + sc.getFeatureTypes().get(i).getFeatureAttributes().get(j).getMemberName() + " : " + sc.getFeatureTypes().get(i).getFeatureAttributes().get(j).getValueType());
                }
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ParserConfigurationException e) {
            e.printStackTrace();
        } catch (SAXException e) {
            e.printStackTrace();
        }
    }
public String sendRequest(java.lang.String servletName, java.lang.String request) {
        String reqxml = "";
        org.jdom.Document retdoc = null;
        String myurl = java.util.prefs.Preferences.systemRoot().get("serverurl", "");
        String myport = java.util.prefs.Preferences.systemRoot().get("portno", "8080");
        if (this.serverURL == null) {
            try {
                java.net.URL codebase = newgen.presentation.NewGenMain.getAppletInstance().getCodeBase();
                if (codebase != null) serverURL = codebase.getHost(); else serverURL = "localhost";
            } catch (Exception exp) {
                exp.printStackTrace();
                serverURL = "localhost";
            }
            newgen.presentation.component.IPAddressPortNoDialog ipdig = new newgen.presentation.component.IPAddressPortNoDialog(myurl, myport);
            ipdig.show();
            serverURL = myurl = ipdig.getIPAddress();
            myport = ipdig.getPortNo();
            java.util.prefs.Preferences.systemRoot().put("serverurl", serverURL);
            java.util.prefs.Preferences.systemRoot().put("portno", myport);
            System.out.println(serverURL);
        }
        try {
            System.out.println("http://" + serverURL + ":" + myport + "/newgenlibctxt/" + servletName);
            java.net.URL url = new java.net.URL("http://" + serverURL + ":" + myport + "/newgenlibctxt/" + servletName);
            java.net.URLConnection urlconn = (java.net.URLConnection) url.openConnection();
            urlconn.setDoOutput(true);
            urlconn.setRequestProperty("Content-type", "text/xml; charset=UTF-8");
            java.io.OutputStream os = urlconn.getOutputStream();
            String req1xml = request;
            java.util.zip.CheckedOutputStream cos = new java.util.zip.CheckedOutputStream(os, new java.util.zip.Adler32());
            java.util.zip.GZIPOutputStream gop = new java.util.zip.GZIPOutputStream(cos);
            java.io.OutputStreamWriter dos = new java.io.OutputStreamWriter(gop, "UTF-8");
            System.out.println(req1xml);
            dos.write(req1xml);
            dos.flush();
            dos.close();
            System.out.println("url conn: " + urlconn.getContentEncoding() + "  " + urlconn.getContentType());
            java.io.InputStream ios = urlconn.getInputStream();
            java.util.zip.CheckedInputStream cis = new java.util.zip.CheckedInputStream(ios, new java.util.zip.Adler32());
            java.util.zip.GZIPInputStream gip = new java.util.zip.GZIPInputStream(cis);
            java.io.InputStreamReader br = new java.io.InputStreamReader(gip, "UTF-8");
            retdoc = (new org.jdom.input.SAXBuilder()).build(br);
        } catch (java.net.ConnectException conexp) {
            javax.swing.JOptionPane.showMessageDialog(null, newgen.presentation.NewGenMain.getAppletInstance().getMyResource().getString("ConnectExceptionMessage"), "Critical error", javax.swing.JOptionPane.ERROR_MESSAGE);
        } catch (Exception exp) {
            exp.printStackTrace(System.out);
        }
        System.out.println(reqxml);
        return "";
    }
public void copyFile(File sourceFile, File destFile) throws IOException {
        if (!destFile.exists()) {
            destFile.createNewFile();
        }
        FileChannel source = null;
        FileChannel destination = null;
        try {
            source = new FileInputStream(sourceFile).getChannel();
            destination = new FileOutputStream(destFile).getChannel();
            destination.transferFrom(source, 0, source.size());
        } finally {
            if (source != null) {
                source.close();
            }
            if (destination != null) {
                destination.close();
            }
        }
    }
public boolean getFiles(String pRemoteDirectory, String pLocalDirectory) throws IOException {
        final String methodSignature = "boolean getFiles(String,String): ";
        FTPClient fc = new FTPClient();
        fc.connect(getRemoteHost());
        fc.login(getUserName(), getPassword());
        fc.changeWorkingDirectory(pRemoteDirectory);
        FTPFile[] files = fc.listFiles();
        boolean retrieved = false;
        logInfo("Listing Files: ");
        int retrieveCount = 0;
        File tmpFile = null;
        for (int i = 0; i < files.length; i++) {
            tmpFile = new File(files[i].getName());
            if (!tmpFile.isDirectory()) {
                FileOutputStream fos = new FileOutputStream(pLocalDirectory + "/" + files[i].getName());
                retrieved = fc.retrieveFile(files[i].getName(), fos);
                if (false == retrieved) {
                    logInfo("Unable to retrieve file: " + files[i].getName());
                } else {
                    logInfo("Successfully retrieved file: " + files[i].getName());
                    retrieveCount++;
                }
                if (null != fos) {
                    fos.flush();
                    fos.close();
                }
            }
        }
        logInfo("Retrieve count: " + retrieveCount);
        if (retrieveCount > 0) {
            return true;
        }
        return false;
    }
public boolean getFile(String pRemoteDirectory, String pLocalDirectory, String pFileName) throws IOException {
        FTPClient fc = new FTPClient();
        fc.connect(getRemoteHost());
        fc.login(getUserName(), getPassword());
        fc.changeWorkingDirectory(pRemoteDirectory);
        String workingDirectory = fc.printWorkingDirectory();
        FileOutputStream fos = null;
        logInfo("Connected to remote host=" + getRemoteHost() + "; userName=" + getUserName() + "; " + "; remoteDirectory=" + pRemoteDirectory + "; localDirectory=" + pLocalDirectory + "; workingDirectory=" + workingDirectory);
        try {
            fos = new FileOutputStream(pLocalDirectory + "/" + pFileName);
            boolean retrieved = fc.retrieveFile(pFileName, fos);
            if (true == retrieved) {
                logInfo("Successfully retrieved file: " + pFileName);
            } else {
                logError("Could not retrieve file: " + pFileName);
            }
            return retrieved;
        } finally {
            if (null != fos) {
                fos.flush();
                fos.close();
            }
        }
    }
public static void copyFile(File source, File dest) throws IOException {
        FileChannel in = null, out = null;
        try {
            in = new FileInputStream(source).getChannel();
            out = new FileOutputStream(dest).getChannel();
            in.transferTo(0, in.size(), out);
        } catch (FileNotFoundException fnfe) {
            Log.debug(fnfe);
        } finally {
            if (in != null) in.close();
            if (out != null) out.close();
        }
    }
public PTask stop(PTask task, SyrupConnection con) throws Exception {
        PreparedStatement s = null;
        ResultSet result = null;
        try {
            s = con.prepareStatementFromCache(sqlImpl().sqlStatements().checkWorkerStatement());
            s.setString(1, task.key());
            result = s.executeQuery();
            con.commit();
            if (result.next()) {
                String url = result.getString("worker");
                InputStream i = null;
                try {
                    Object b = new URL(url).getContent();
                    if (b instanceof InputStream) {
                        i = (InputStream) b;
                        byte[] bb = new byte[256];
                        int ll = i.read(bb);
                        String k = new String(bb, 0, ll);
                        if (k.equals(task.key())) {
                            return task;
                        }
                    }
                } catch (Exception e) {
                } finally {
                    if (i != null) {
                        i.close();
                    }
                }
                PreparedStatement s2 = null;
                s2 = con.prepareStatementFromCache(sqlImpl().sqlStatements().resetWorkerStatement());
                s2.setString(1, task.key());
                s2.executeUpdate();
                task = sqlImpl().queryFunctions().readPTask(task.key(), con);
                sqlImpl().loggingFunctions().log(task.key(), LogEntry.STOPPED, con);
                con.commit();
            }
        } finally {
            con.rollback();
            close(result);
        }
        return task;
    }
private String getRenderedBody(String spec) throws Exception {
        log.entering(Rss2MailTask.class.getName(), "getRenderedBody");
        final URL url = new URL(spec);
        final HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.connect();
        final InputStream inputStream = connection.getInputStream();
        final BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
        String line = "";
        final StringBuffer bf = new StringBuffer();
        while (line != null) {
            line = reader.readLine();
            if (line != null) {
                bf.append(line);
            }
        }
        log.exiting(Rss2MailTask.class.getName(), "getRenderedBody");
        return bf.toString();
    }
private int getRootNodeId(DataSource dataSource) throws SQLException {
        Connection conn = null;
        Statement st = null;
        ResultSet rs = null;
        String query = null;
        try {
            conn = dataSource.getConnection();
            st = conn.createStatement();
            query = "select " + col.id + " from " + DB.Tbl.tree + " where " + col.parentId + " is null";
            rs = st.executeQuery(query);
            while (rs.next()) {
                return rs.getInt(col.id);
            }
            query = "insert into " + DB.Tbl.tree + "(" + col.lKey + ", " + col.rKey + ", " + col.level + ") values(1,2,0)";
            st.executeUpdate(query, new String[] { col.id });
            rs = st.getGeneratedKeys();
            while (rs.next()) {
                int genId = rs.getInt(1);
                rs.close();
                conn.commit();
                return genId;
            }
            throw new SQLException("Не удается создать корневой элемент для дерева.");
        } finally {
            try {
                rs.close();
            } catch (Exception e) {
            }
            try {
                st.close();
            } catch (Exception e) {
            }
            try {
                conn.rollback();
            } catch (Exception e) {
            }
            try {
                conn.close();
            } catch (Exception e) {
            }
        }
    }
public void handleHandshake(Packet2Handshake par1Packet2Handshake) {
        boolean flag = true;
        String s = par1Packet2Handshake.username;
        if (s == null || s.trim().length() == 0) {
            flag = false;
        } else if (!s.equals("-")) {
            try {
                Long.parseLong(s, 16);
            } catch (NumberFormatException numberformatexception) {
                flag = false;
            }
        }
        if (!flag) {
            netManager.networkShutdown("disconnect.genericReason", new Object[] { "The server responded with an invalid server key" });
        } else if (par1Packet2Handshake.username.equals("-")) {
            addToSendQueue(new Packet1Login(mc.session.username, 29));
        } else {
            try {
                URL url = new URL((new StringBuilder()).append("http://session.minecraft.net/game/joinserver.jsp?user=").append(mc.session.username).append("&sessionId=").append(mc.session.sessionId).append("&serverId=").append(par1Packet2Handshake.username).toString());
                BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(url.openStream()));
                String s1 = bufferedreader.readLine();
                bufferedreader.close();
                if (s1.equalsIgnoreCase("ok")) {
                    addToSendQueue(new Packet1Login(mc.session.username, 29));
                } else {
                    netManager.networkShutdown("disconnect.loginFailedInfo", new Object[] { s1 });
                }
            } catch (Exception exception) {
                exception.printStackTrace();
                netManager.networkShutdown("disconnect.genericReason", new Object[] { (new StringBuilder()).append("Internal client error: ").append(exception.toString()).toString() });
            }
        }
    }
public static String hashMD5(String entrada) {
        MessageDigest m;
        try {
            m = MessageDigest.getInstance("MD5");
            m.update(entrada.getBytes(), 0, entrada.length());
            return new BigInteger(1, m.digest()).toString(16);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return null;
    }
public void download() {
        try {
            URL url = new URL(srcURL + src);
            URLConnection urlc = url.openConnection();
            InputStream is = urlc.getInputStream();
            BufferedInputStream bis = new BufferedInputStream(is);
            FileOutputStream fos = new FileOutputStream(dest);
            BufferedOutputStream bos = new BufferedOutputStream(fos);
            byte[] buffer = new byte[1000000];
            int readSize;
            readSize = bis.read(buffer);
            while (readSize > 0) {
                bos.write(buffer, 0, readSize);
                readSize = bis.read(buffer);
            }
            bos.close();
            fos.close();
            bis.close();
            is.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
private boolean loadSource(URL url) {
        if (url == null) {
            if (sourceURL != null) {
                sourceCodeLinesList.clear();
            }
            return false;
        } else {
            if (url.equals(sourceURL)) {
                return true;
            } else {
                sourceCodeLinesList.clear();
                try {
                    BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
                    String line;
                    while ((line = br.readLine()) != null) {
                        sourceCodeLinesList.addElement(line.replaceAll("\t", "   "));
                    }
                    br.close();
                    return true;
                } catch (IOException e) {
                    System.err.println("Could not load source at " + url);
                    return false;
                }
            }
        }
    }
protected Source getStylesheetSource(Resource stylesheetLocation) throws ApplicationContextException {
        if (logger.isDebugEnabled()) {
            logger.debug("Loading XSLT stylesheet from " + stylesheetLocation);
        }
        try {
            URL url = stylesheetLocation.getURL();
            String urlPath = url.toString();
            String systemId = urlPath.substring(0, urlPath.lastIndexOf('/') + 1);
            return new StreamSource(url.openStream(), systemId);
        } catch (IOException ex) {
            throw new ApplicationContextException("Can't load XSLT stylesheet from " + stylesheetLocation, ex);
        }
    }
public void copyFile(String source_file_path, String destination_file_path) {
        FileWriter fw = null;
        FileReader fr = null;
        BufferedReader br = null;
        BufferedWriter bw = null;
        File source = null;
        try {
            fr = new FileReader(source_file_path);
            fw = new FileWriter(destination_file_path);
            br = new BufferedReader(fr);
            bw = new BufferedWriter(fw);
            source = new File(source_file_path);
            int fileLength = (int) source.length();
            char charBuff[] = new char[fileLength];
            while (br.read(charBuff, 0, fileLength) != -1) bw.write(charBuff, 0, fileLength);
        } catch (FileNotFoundException fnfe) {
            System.out.println(source_file_path + " does not exist!");
        } catch (IOException ioe) {
            System.out.println("Error reading/writing files!");
        } finally {
            try {
                if (br != null) br.close();
                if (bw != null) bw.close();
            } catch (IOException ioe) {
            }
        }
    }