semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public void loadSourceCode() {
        int length = MAX_SOURCE_LENGTH;
        try {
            File file = new File(filename);
            length = (int) file.length();
        } catch (SecurityException ex) {
        }
        char[] buff = new char[length];
        InputStream is;
        InputStreamReader isr;
        CodeViewer cv = new CodeViewer();
        URL url;
        try {
            url = getClass().getResource(filename);
            is = url.openStream();
            isr = new InputStreamReader(is);
            BufferedReader reader = new BufferedReader(isr);
            sourceCode = new String("<html><pre>");
            String line = reader.readLine();
            while (line != null) {
                sourceCode += cv.syntaxHighlight(line) + " \n ";
                line = reader.readLine();
            }
            sourceCode += "</pre></html>";
        } catch (Exception ex) {
            sourceCode = getString("SourceCode.error");
        }
    }
protected void writeToResponse(InputStream stream, HttpServletResponse response) throws IOException {
        OutputStream output = response.getOutputStream();
        try {
            IOUtils.copy(stream, output);
        } finally {
            try {
                stream.close();
            } finally {
                output.close();
            }
        }
    }
public ProjectDeploymentConfiguration createNewProjectDeploymentConfig(int projectID, String name, String description) throws AdaptationException {
        ProjectDeploymentConfiguration config = null;
        Connection connection = null;
        Statement statement = null;
        ResultSet resultSet = null;
        try {
            String query = "INSERT INTO ProjectDeploymentConfigurations" + "(projectID, name, description) VALUES (" + projectID + ", '" + name + "', '" + description + "')";
            connection = DriverManager.getConnection(CONN_STR);
            statement = connection.createStatement();
            statement.executeUpdate(query);
            query = "SELECT * FROM ProjectDeploymentConfigurations WHERE " + " projectID   = " + projectID + "  AND " + " name        = '" + name + "' AND " + " description = '" + description + "'";
            resultSet = statement.executeQuery(query);
            if (!resultSet.next()) {
                connection.rollback();
                String msg = "Attempt to create " + "ProjectDeploymentConfiguration failed.";
                log.error(msg);
                throw new AdaptationException(msg);
            }
            config = getProjectDeploymentConfiguration(resultSet);
            connection.commit();
        } catch (SQLException ex) {
            try {
                connection.rollback();
            } catch (Exception e) {
            }
            String msg = "SQLException in createNewProjectDeploymentConfig";
            log.error(msg, ex);
            throw new AdaptationException(msg, ex);
        } finally {
            try {
                resultSet.close();
            } catch (Exception ex) {
            }
            try {
                statement.close();
            } catch (Exception ex) {
            }
            try {
                connection.close();
            } catch (Exception ex) {
            }
        }
        return config;
    }
public ProjectDeploymentConfiguration deleteProjectDeploymentConfig(int id) throws AdaptationException {
        ProjectDeploymentConfiguration config = null;
        Connection connection = null;
        Statement statement = null;
        ResultSet resultSet = null;
        try {
            String query = "SELECT * FROM ProjectDeploymentConfigurations " + "WHERE id = " + id;
            connection = DriverManager.getConnection(CONN_STR);
            statement = connection.createStatement();
            resultSet = statement.executeQuery(query);
            if (!resultSet.next()) {
                connection.rollback();
                String msg = "Attempt to delete project deployment " + "configuration failed.";
                log.error(msg);
                throw new AdaptationException(msg);
            }
            config = getProjectDeploymentConfiguration(resultSet);
            query = "DELETE FROM ProjectDeploymentConfigurations " + "WHERE id = " + id;
            statement.executeUpdate(query);
            connection.commit();
        } catch (SQLException ex) {
            try {
                connection.rollback();
            } catch (Exception e) {
            }
            String msg = "SQLException in deleteProjectDeploymentConfig";
            log.error(msg, ex);
            throw new AdaptationException(msg, ex);
        } finally {
            try {
                resultSet.close();
            } catch (Exception ex) {
            }
            try {
                statement.close();
            } catch (Exception ex) {
            }
            try {
                connection.close();
            } catch (Exception ex) {
            }
        }
        return config;
    }
private void copyFile(String from, String to) throws Exception {
        URL monitorCallShellScriptUrl = Thread.currentThread().getContextClassLoader().getResource(from);
        File inScriptFile = null;
        try {
            inScriptFile = new File(monitorCallShellScriptUrl.toURI());
        } catch (URISyntaxException e) {
            throw e;
        }
        File outScriptFile = new File(to);
        FileChannel inChannel = new FileInputStream(inScriptFile).getChannel();
        FileChannel outChannel = new FileOutputStream(outScriptFile).getChannel();
        try {
            inChannel.transferTo(0, inChannel.size(), outChannel);
        } catch (IOException e) {
            throw e;
        } finally {
            if (inChannel != null) inChannel.close();
            if (outChannel != null) outChannel.close();
        }
        try {
            LinuxCommandExecutor cmdExecutor = new LinuxCommandExecutor();
            cmdExecutor.setWorkingDirectory(workingDirectory);
            cmdExecutor.runCommand("chmod 777 " + to);
        } catch (Exception e) {
            throw e;
        }
    }
public void simulationEnded() {
        if (getParameter("ladderMatch") != null) {
            int[] scores = models.world.getScores();
            if (models.simulator.getTick() < 100000) {
                for (int i = 0; i < scores.length; i++) {
                    scores[i] = -1;
                }
            }
            StringBuffer args = new StringBuffer("ladder_result.php?matchid=");
            args.append(this.matchId);
            args.append("&hillid=").append(this.hillId);
            for (int i = 0; i < scores.length; i++) {
                args.append("&p").append(i).append('=').append(scores[i]);
            }
            try {
                URL url = new URL(getCodeBase(), args.toString());
                URLConnection connection = url.openConnection();
                System.err.println(((HttpURLConnection) connection).getResponseCode());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return;
    }
public static void copy(final File src, final File dst) throws IOException, IllegalArgumentException {
        long fileSize = src.length();
        final FileInputStream fis = new FileInputStream(src);
        final FileOutputStream fos = new FileOutputStream(dst);
        final FileChannel in = fis.getChannel(), out = fos.getChannel();
        try {
            long offs = 0, doneCnt = 0;
            final long copyCnt = Math.min(65536, fileSize);
            do {
                doneCnt = in.transferTo(offs, copyCnt, out);
                offs += doneCnt;
                fileSize -= doneCnt;
            } while (fileSize > 0);
        } finally {
            try {
                in.close();
            } catch (final IOException e) {
            }
            try {
                out.close();
            } catch (final IOException e) {
            }
            try {
                fis.close();
            } catch (final IOException e) {
            }
            try {
                fos.close();
            } catch (final IOException e) {
            }
            src.delete();
        }
    }
private static void compressZip(String source, String dest) throws Exception {
        File baseFolder = new File(source);
        if (baseFolder.exists()) {
            if (baseFolder.isDirectory()) {
                List<File> fileList = getSubFiles(new File(source));
                ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(dest));
                zos.setEncoding("GBK");
                ZipEntry entry = null;
                byte[] buf = new byte[2048];
                int readLen = 0;
                for (int i = 0; i < fileList.size(); i++) {
                    File file = fileList.get(i);
                    if (file.isDirectory()) {
                        entry = new ZipEntry(getAbsFileName(source, file) + "/");
                    } else {
                        entry = new ZipEntry(getAbsFileName(source, file));
                    }
                    entry.setSize(file.length());
                    entry.setTime(file.lastModified());
                    zos.putNextEntry(entry);
                    if (file.isFile()) {
                        InputStream in = new BufferedInputStream(new FileInputStream(file));
                        while ((readLen = in.read(buf, 0, 1024)) != -1) {
                            zos.write(buf, 0, readLen);
                        }
                        in.close();
                    }
                }
                zos.close();
            } else {
                throw new Exception("Can not do this operation!.");
            }
        } else {
            baseFolder.mkdirs();
            compressZip(source, dest);
        }
    }
@TestTargetNew(level = TestLevel.COMPLETE, notes = "", method = "getLocalCertificates", args = {  })
    public final void test_getLocalCertificates() {
        try {
            URL url = new URL("https://localhost:55555");
            HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
            try {
                connection.getLocalCertificates();
                fail("IllegalStateException wasn't thrown");
            } catch (IllegalStateException ise) {
            }
        } catch (Exception e) {
            fail("Unexpected exception " + e + " for exception case");
        }
        try {
            HttpsURLConnection con = new MyHttpsURLConnection(new URL("https://www.fortify.net/"), "X.508");
            assertNull(con.getLocalCertificates());
            con = new MyHttpsURLConnection(new URL("https://www.fortify.net/"), "X.509");
            Certificate[] cert = con.getLocalCertificates();
            assertNotNull(cert);
            assertEquals(1, cert.length);
        } catch (Exception e) {
            fail("Unexpected exception " + e);
        }
    }
@TestTargetNew(level = TestLevel.COMPLETE, notes = "", method = "getLocalPrincipal", args = {  })
    public final void test_getLocalPrincipal() {
        try {
            URL url = new URL("https://localhost:55555");
            HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
            try {
                connection.getLocalPrincipal();
                fail("IllegalStateException wasn't thrown");
            } catch (IllegalStateException ise) {
            }
        } catch (Exception e) {
            fail("Unexpected exception " + e + " for exception case");
        }
        try {
            HttpsURLConnection con = new MyHttpsURLConnection(new URL("https://www.fortify.net/"), "X.508");
            assertNull(con.getLocalPrincipal());
            con = new MyHttpsURLConnection(new URL("https://www.fortify.net/"), "X.509");
            assertNotNull("Local principal is null", con.getLocalPrincipal());
        } catch (Exception e) {
            fail("Unexpected exception " + e);
        }
    }
@TestTargetNew(level = TestLevel.COMPLETE, notes = "", method = "getPeerPrincipal", args = {  })
    public final void test_getPeerPrincipal() throws Exception {
        try {
            URL url = new URL("https://localhost:55555");
            HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
            try {
                connection.getPeerPrincipal();
                fail("IllegalStateException wasn't thrown");
            } catch (IllegalStateException ise) {
            }
        } catch (Exception e) {
            fail("Unexpected exception " + e + " for exception case");
        }
        HttpsURLConnection con = new MyHttpsURLConnection(new URL("https://www.fortify.net/"), "X.508");
        try {
            Principal p = con.getPeerPrincipal();
            fail("SSLPeerUnverifiedException wasn't thrown");
        } catch (SSLPeerUnverifiedException e) {
        }
        con = new MyHttpsURLConnection(new URL("https://www.fortify.net/"), "X.509");
        try {
            Principal p = con.getPeerPrincipal();
            assertNotNull(p);
        } catch (Exception e) {
            fail("Unexpected exception " + e);
        }
    }
@TestTargetNew(level = TestLevel.COMPLETE, notes = "", method = "getServerCertificates", args = {  })
    public final void test_getServerCertificates() throws Exception {
        try {
            URL url = new URL("https://localhost:55555");
            HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
            try {
                connection.getServerCertificates();
                fail("IllegalStateException wasn't thrown");
            } catch (IllegalStateException ise) {
            }
        } catch (Exception e) {
            fail("Unexpected exception " + e + " for exception case");
        }
        HttpsURLConnection con = new MyHttpsURLConnection(new URL("https://www.fortify.net/"), "X.508");
        try {
            Certificate[] cert = con.getServerCertificates();
            fail("SSLPeerUnverifiedException wasn't thrown");
        } catch (SSLPeerUnverifiedException e) {
        }
        con = new MyHttpsURLConnection(new URL("https://www.fortify.net/"), "X.509");
        try {
            Certificate[] cert = con.getServerCertificates();
            assertNotNull(cert);
            assertEquals(1, cert.length);
        } catch (Exception e) {
            fail("Unexpected exception " + e);
        }
    }
private HashMap<String, GCVote> getVotes(ArrayList<String> waypoints, boolean blnSleepBeforeDownload) {
        if (blnSleepBeforeDownload) {
            try {
                Thread.sleep(PACKET_SLEEP_TIME);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        final String strWaypoints = this.join(waypoints, ",");
        try {
            String strParameters = URLEncoder.encode("waypoints", "UTF-8") + "=" + URLEncoder.encode(strWaypoints, "UTF-8");
            if (this.mstrUsername.length() > 0) {
                strParameters += "&" + URLEncoder.encode("userName", "UTF-8") + "=" + URLEncoder.encode(this.mstrUsername, "UTF-8");
                if (this.mstrPassword.length() > 0) {
                    strParameters += "&" + URLEncoder.encode("password", "UTF-8") + "=" + URLEncoder.encode(this.mstrPassword, "UTF-8");
                }
            }
            final URL url = new URL(BASE_URL_GET_VOTE);
            URLConnection conn = url.openConnection();
            conn.setDoOutput(true);
            final OutputStreamWriter osw = new OutputStreamWriter(conn.getOutputStream());
            osw.write(strParameters);
            osw.flush();
            final SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
            saxParserFactory.setValidating(false);
            saxParserFactory.setNamespaceAware(true);
            final SAXParser saxParser = saxParserFactory.newSAXParser();
            final XMLReader xmlReader = saxParser.getXMLReader();
            final GCVoteHandler gcVoteHandler = new GCVoteHandler();
            xmlReader.setContentHandler(gcVoteHandler);
            xmlReader.parse(new InputSource(new InputStreamReader(conn.getInputStream())));
            return gcVoteHandler.getVotes();
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
private static IProject createCopyProject(IProject project, String pName, IWorkspace ws, IProgressMonitor pm) throws Exception {
        pm.beginTask("Creating temp project", 1);
        IPath destination = new Path(pName);
        IJavaProject oldJavaproj = JavaCore.create(project);
        IClasspathEntry[] classPath = oldJavaproj.getRawClasspath();
        IProject newProject = ResourcesPlugin.getWorkspace().getRoot().getProject(pName);
        newProject.create(null);
        newProject.open(null);
        IProjectDescription desc = newProject.getDescription();
        desc.setNatureIds(new String[] { JavaCore.NATURE_ID });
        newProject.setDescription(desc, null);
        List<IClasspathEntry> newClassPath = new ArrayList<IClasspathEntry>();
        for (IClasspathEntry cEntry : classPath) {
            switch(cEntry.getEntryKind()) {
                case IClasspathEntry.CPE_SOURCE:
                    System.out.println("Source folder " + cEntry.getPath());
                    newClassPath.add(copySourceFolder(project, newProject, cEntry, destination));
                    break;
                case IClasspathEntry.CPE_LIBRARY:
                    System.out.println("library folder " + cEntry.getPath());
                    newClassPath.add(cEntry);
                    break;
                case IClasspathEntry.CPE_PROJECT:
                    System.out.println("project folder " + cEntry.getPath());
                    newClassPath.add(cEntry);
                    break;
                case IClasspathEntry.CPE_VARIABLE:
                    System.out.println("variable folder " + cEntry.getPath());
                    newClassPath.add(cEntry);
                    break;
                default:
                    System.out.println("container folder " + cEntry.getPath());
                    newClassPath.add(cEntry);
            }
        }
        copyDir(project.getLocation().toString(), "/translator", newProject.getLocation().toString(), "", new ArrayList<String>() {

            {
                add("generated");
                add("classes");
                add(".svn");
            }
        });
        newProject.refreshLocal(IResource.DEPTH_INFINITE, pm);
        newProject.build(IncrementalProjectBuilder.AUTO_BUILD, pm);
        newProject.touch(pm);
        IJavaProject javaproj = JavaCore.create(newProject);
        javaproj.setOutputLocation(new Path("/" + newProject.getName() + "/classes/bin"), null);
        javaproj.setRawClasspath(newClassPath.toArray(new IClasspathEntry[newClassPath.size()]), pm);
        Map opts = oldJavaproj.getOptions(true);
        javaproj.setOptions(opts);
        javaproj.makeConsistent(pm);
        javaproj.save(pm, true);
        return newProject;
    }
private static Long getNextPkValueForEntityIncreaseBy(String ename, int count, int increaseBy) {
        if (increaseBy < 1) increaseBy = 1;
        String where = "where eoentity_name = '" + ename + "'";
        ERXJDBCConnectionBroker broker = ERXJDBCConnectionBroker.connectionBrokerForEntityNamed(ename);
        Connection con = broker.getConnection();
        try {
            try {
                con.setAutoCommit(false);
                con.setReadOnly(false);
            } catch (SQLException e) {
                log.error(e, e);
            }
            for (int tries = 0; tries < count; tries++) {
                try {
                    ResultSet resultSet = con.createStatement().executeQuery("select pk_value from pk_table " + where);
                    con.commit();
                    boolean hasNext = resultSet.next();
                    long pk = 1;
                    if (hasNext) {
                        pk = resultSet.getLong("pk_value");
                        con.createStatement().executeUpdate("update pk_table set pk_value = " + (pk + increaseBy) + " " + where);
                    } else {
                        pk = maxIdFromTable(ename);
                        con.createStatement().executeUpdate("insert into pk_table (eoentity_name, pk_value) values ('" + ename + "', " + (pk + increaseBy) + ")");
                    }
                    con.commit();
                    return new Long(pk);
                } catch (SQLException ex) {
                    String s = ex.getMessage().toLowerCase();
                    boolean creationError = (s.indexOf("error code 116") != -1);
                    creationError |= (s.indexOf("pk_table") != -1 && s.indexOf("does not exist") != -1);
                    creationError |= s.indexOf("ora-00942") != -1;
                    if (creationError) {
                        try {
                            con.rollback();
                            log.info("creating pk table");
                            con.createStatement().executeUpdate("create table pk_table (eoentity_name varchar(100) not null, pk_value integer)");
                            con.createStatement().executeUpdate("alter table pk_table add primary key (eoentity_name)");
                            con.commit();
                        } catch (SQLException ee) {
                            throw new NSForwardException(ee, "could not create pk table");
                        }
                    } else {
                        throw new NSForwardException(ex, "Error fetching PK");
                    }
                }
            }
        } finally {
            broker.freeConnection(con);
        }
        throw new IllegalStateException("Couldn't get PK");
    }
public static final void copy(String source, String destination) {
        FileInputStream fis = null;
        FileOutputStream fos = null;
        try {
            fis = new FileInputStream(source);
            fos = new FileOutputStream(destination);
            java.nio.channels.FileChannel channelSrc = fis.getChannel();
            java.nio.channels.FileChannel channelDest = fos.getChannel();
            channelSrc.transferTo(0, channelSrc.size(), channelDest);
            fis.close();
            fos.close();
        } catch (FileNotFoundException e2) {
            e2.printStackTrace();
        } catch (IOException e2) {
            e2.printStackTrace();
        }
    }
private boolean verifyAppId(String appid) {
        try {
            String urlstr = "http://" + appid + ".appspot.com";
            URL url = new URL(urlstr);
            BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
            StringBuffer buf = new StringBuffer();
            String line;
            while ((line = reader.readLine()) != null) {
                buf.append(line);
            }
            reader.close();
            return buf.toString().contains("hyk-proxy");
        } catch (Exception e) {
        }
        return false;
    }