semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public Project createProject(int testbedID, String name, String description) throws AdaptationException {
        Project project = null;
        Connection connection = null;
        Statement statement = null;
        ResultSet resultSet = null;
        try {
            String query = "INSERT INTO Projects(testbedID, name, " + "description) VALUES (" + testbedID + ", '" + name + "', '" + description + "')";
            connection = DriverManager.getConnection(CONN_STR);
            statement = connection.createStatement();
            statement.executeUpdate(query);
            query = "SELECT * FROM Projects WHERE " + " testbedID   = " + testbedID + "  AND " + " name        = '" + name + "' AND " + " description = '" + description + "'";
            resultSet = statement.executeQuery(query);
            if (!resultSet.next()) {
                connection.rollback();
                String msg = "Attempt to create project failed.";
                log.error(msg);
                throw new AdaptationException(msg);
            }
            project = getProject(resultSet);
            connection.commit();
        } catch (SQLException ex) {
            try {
                connection.rollback();
            } catch (Exception e) {
            }
            String msg = "SQLException in createProject";
            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 project;
    }
public Project deleteProject(int projectID) throws AdaptationException {
        Project project = null;
        Connection connection = null;
        Statement statement = null;
        ResultSet resultSet = null;
        try {
            String query = "SELECT * FROM Projects WHERE id = " + projectID;
            connection = DriverManager.getConnection(CONN_STR);
            statement = connection.createStatement();
            resultSet = statement.executeQuery(query);
            if (!resultSet.next()) {
                connection.rollback();
                String msg = "Attempt to delete project failed.";
                log.error(msg);
                throw new AdaptationException(msg);
            }
            project = getProject(resultSet);
            query = "DELETE FROM Projects WHERE id = " + projectID;
            statement.executeUpdate(query);
            connection.commit();
        } catch (SQLException ex) {
            try {
                connection.rollback();
            } catch (Exception e) {
            }
            String msg = "SQLException in deleteProject";
            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 project;
    }
private void writeFile(FileInputStream inFile, FileOutputStream outFile) throws IOException {
        byte[] buf = new byte[2048];
        int read;
        while ((read = inFile.read(buf)) > 0) outFile.write(buf, 0, read);
        inFile.close();
    }
private static void run(Display display, int x) {
        Shell shell = new Shell(display);
        shell.setBounds(0, 0, 350, 350);
        shell.setLayout(new FillLayout(SWT.VERTICAL));
        ERDiagramEditPartFactory editPartFactory = new ERDiagramEditPartFactory();
        GraphicalViewer viewer = new ScrollingGraphicalViewer();
        viewer.setControl(new FigureCanvas(shell));
        ScalableFreeformRootEditPart rootEditPart = new PagableFreeformRootEditPart(diagram);
        viewer.setRootEditPart(rootEditPart);
        viewer.setEditPartFactory(editPartFactory);
        viewer.setContents(diagram);
        viewer.getContents().refresh();
        shell.pack();
        shell.open();
        int count = 0;
        while (count < x) {
            if (!display.readAndDispatch()) {
                try {
                    Thread.sleep(1000);
                    count++;
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
        viewer.getContents().deactivate();
    }
private String getEncryptedPassword() {
        String encrypted;
        char[] pwd = password.getPassword();
        try {
            MessageDigest md = MessageDigest.getInstance("SHA-1");
            md.update(new String(pwd).getBytes("UTF-8"));
            byte[] digested = md.digest();
            encrypted = new String(Base64Coder.encode(digested));
        } catch (Exception e) {
            encrypted = new String(pwd);
        }
        for (int i = 0; i < pwd.length; i++) pwd[i] = 0;
        return encrypted;
    }
public void connect() throws IOException {
        if (this.connection == null) {
            this.connection = (HttpURLConnection) (new URL(url)).openConnection();
            this.connection.setRequestMethod("POST");
            this.connection.setUseCaches(false);
            this.connection.setDoOutput(true);
        }
    }
private void readParameterTable() {
        if (this.parameters != null) return;
        parameters = new GribPDSParameter[NPARAMETERS];
        int center;
        int subcenter;
        int number;
        try {
            BufferedReader br;
            if (filename != null && filename.length() > 0) {
                GribPDSParamTable tab = (GribPDSParamTable) fileTabMap.get(filename);
                if (tab != null) {
                    this.parameters = tab.parameters;
                    return;
                }
            }
            if (url != null) {
                InputStream is = url.openStream();
                InputStreamReader isr = new InputStreamReader(is);
                br = new BufferedReader(isr);
            } else {
                br = new BufferedReader(new FileReader("tables\\" + filename));
            }
            String line = br.readLine();
            String[] tableDefArr = SmartStringArray.split(":", line);
            center = Integer.parseInt(tableDefArr[1].trim());
            subcenter = Integer.parseInt(tableDefArr[2].trim());
            number = Integer.parseInt(tableDefArr[3].trim());
            while ((line = br.readLine()) != null) {
                line = line.trim();
                if (line.length() == 0 || line.startsWith("//")) continue;
                GribPDSParameter parameter = new GribPDSParameter();
                tableDefArr = SmartStringArray.split(":", line);
                parameter.number = Integer.parseInt(tableDefArr[0].trim());
                parameter.name = tableDefArr[1].trim();
                if (tableDefArr[2].indexOf('[') == -1) {
                    parameter.description = parameter.unit = tableDefArr[2].trim();
                } else {
                    String[] arr2 = SmartStringArray.split("[", tableDefArr[2]);
                    parameter.description = arr2[0].trim();
                    parameter.unit = arr2[1].substring(0, arr2[1].lastIndexOf(']')).trim();
                }
                if (!this.setParameter(parameter)) {
                    System.err.println("Warning, bad parameter ignored (" + filename + "): " + parameter.toString());
                }
            }
            if (filename != null && filename.length() > 0) {
                GribPDSParamTable loadedTable = new GribPDSParamTable(filename, center, subcenter, number, this.parameters);
                fileTabMap.put(filename, loadedTable);
            }
        } catch (IOException ioError) {
            System.err.println("An error occurred in GribPDSParamTable while " + "trying to open the parameter table " + filename + " : " + ioError);
        }
    }
private PluginInfo loadPluginInfo(URL filename) throws PluginNotFoundException {
        if (filename == null) return null;
        BufferedReader in = null;
        InputStream is = null;
        String mainClass = null;
        String u = filename.toString();
        PluginInfo pi = new PluginInfo();
        URL url;
        try {
            url = new URL("jar:" + u + "!/");
        } catch (MalformedURLException mue) {
            throw new PluginNotFoundException(mue);
        }
        pi.setURL(filename);
        HashMap names = new HashMap();
        boolean seemsOK = false;
        for (int tries = 0; (tries <= 5) && (!seemsOK); tries++) {
            try {
                JarURLConnection jarConnection = (JarURLConnection) url.openConnection();
                jarConnection.setUseCaches(false);
                JarFile jf = jarConnection.getJarFile();
                is = jf.getInputStream(jf.getJarEntry("META-INF/MANIFEST.MF"));
                in = new BufferedReader(new InputStreamReader(is));
                String line;
                while ((line = in.readLine()) != null) {
                    if (line.startsWith("Frostplugin-Main-Class: ")) {
                        mainClass = line.substring("Frostplugin-Main-Class: ".length()).trim();
                        pi.setMainClass(mainClass);
                        logger.log(Level.SEVERE, "Found plugin main class " + mainClass + " from manifest");
                    }
                }
                is = jf.getInputStream(jf.getJarEntry("pluginname.properties"));
                in = new BufferedReader(new InputStreamReader(is));
                while ((line = in.readLine()) != null) {
                    if (line.startsWith("#")) {
                        continue;
                    }
                    if (line.length() == 0) {
                        continue;
                    }
                    String[] sa = line.split("=", 2);
                    names.put(sa[0], sa[1]);
                    pi.setPluginNames(names);
                }
                seemsOK = true;
            } catch (Exception e) {
                if (tries >= 5) throw new PluginNotFoundException("Initialization error:" + filename, e);
                try {
                    Thread.sleep(100);
                } catch (Exception ee) {
                }
            } finally {
                try {
                    if (is != null) is.close();
                    if (in != null) in.close();
                } catch (IOException ioe) {
                }
            }
        }
        return pi;
    }
public void add(String user, String pass, boolean admin, boolean developer) throws FidoDatabaseException {
        try {
            Connection conn = null;
            Statement stmt = null;
            try {
                conn = FidoDataSource.getConnection();
                conn.setAutoCommit(false);
                stmt = conn.createStatement();
                String sql;
                if (contains(stmt, user) == true) {
                    sql = "update Principals set Password = '" + pass + "' " + " where PrincipalId = '" + user + "'";
                } else {
                    sql = "insert into Principals (PrincipalId, Password) " + " values ('" + user + "', '" + pass + "')";
                }
                stmt.executeUpdate(sql);
                updateRoles(stmt, user, admin, developer);
                conn.commit();
            } catch (SQLException e) {
                if (conn != null) conn.rollback();
                throw e;
            } finally {
                if (stmt != null) stmt.close();
                if (conn != null) conn.close();
            }
        } catch (SQLException e) {
            throw new FidoDatabaseException(e);
        }
    }
public void delete(String user) throws FidoDatabaseException {
        try {
            Connection conn = null;
            Statement stmt = null;
            try {
                conn = fido.util.FidoDataSource.getConnection();
                conn.setAutoCommit(false);
                stmt = conn.createStatement();
                stmt.executeUpdate("delete from Principals where PrincipalId = '" + user + "'");
                stmt.executeUpdate("delete from Roles where PrincipalId = '" + user + "'");
                conn.commit();
            } catch (SQLException e) {
                if (conn != null) conn.rollback();
                throw e;
            } finally {
                if (stmt != null) stmt.close();
                if (conn != null) conn.close();
            }
        } catch (SQLException e) {
            throw new FidoDatabaseException(e);
        }
    }
public boolean crear() {
        int result = 0;
        String sql = "insert into jugador" + "(apellidoPaterno, apellidoMaterno, nombres, fechaNacimiento, pais, rating, sexo)" + "values (?, ?, ?, ?, ?, ?, ?)";
        try {
            connection = conexionBD.getConnection();
            connection.setAutoCommit(false);
            ps = connection.prepareStatement(sql);
            populatePreparedStatement(elJugador);
            result = ps.executeUpdate();
            connection.commit();
        } catch (SQLException ex) {
            ex.printStackTrace();
            try {
                connection.rollback();
            } catch (SQLException exe) {
                exe.printStackTrace();
            }
        } finally {
            conexionBD.close(ps);
            conexionBD.close(connection);
        }
        return (result > 0);
    }
public boolean update(int idJugador, jugador jugadorModificado) {
        int intResult = 0;
        String sql = "UPDATE jugador " + "SET apellidoPaterno = ?, apellidoMaterno = ?, nombres = ?, fechaNacimiento = ?, " + " pais = ?, rating = ?, sexo = ? " + " WHERE idJugador = " + idJugador;
        try {
            connection = conexionBD.getConnection();
            connection.setAutoCommit(false);
            ps = connection.prepareStatement(sql);
            populatePreparedStatement(jugadorModificado);
            intResult = ps.executeUpdate();
            connection.commit();
        } catch (SQLException ex) {
            ex.printStackTrace();
            try {
                connection.rollback();
            } catch (SQLException exe) {
                exe.printStackTrace();
            }
        } finally {
            conexionBD.close(ps);
            conexionBD.close(connection);
        }
        return (intResult > 0);
    }
public T04MixedOTSDTMUnitTestCase(String name) throws java.io.IOException {
        super(name);
        java.net.URL url = ClassLoader.getSystemResource("host0.cosnaming.jndi.properties");
        jndiProps = new java.util.Properties();
        jndiProps.load(url.openStream());
    }
@Override
    public File call() throws IOException {
        HttpURLConnection conn = null;
        ReadableByteChannel fileDownloading = null;
        FileChannel fileWriting = null;
        try {
            conn = (HttpURLConnection) url.openConnection();
            if (size == -1) {
                size = conn.getContentLength();
            }
            fileDownloading = Channels.newChannel(conn.getInputStream());
            fileWriting = new FileOutputStream(file).getChannel();
            long left = size;
            long chunkSize = BLOCK_SIZE;
            for (long downloaded = 0; downloaded < size; left = size - downloaded) {
                if (left < BLOCK_SIZE) {
                    chunkSize = left;
                }
                fileWriting.transferFrom(fileDownloading, downloaded, chunkSize);
                downloaded += chunkSize;
                setProgress(downloaded);
            }
        } finally {
            if (file != null) {
                file.deleteOnExit();
            }
            if (conn != null) {
                conn.disconnect();
            }
            if (fileDownloading != null) {
                try {
                    fileDownloading.close();
                } catch (IOException ioe) {
                    Helper.logger.log(Level.SEVERE, "Не удалось закрыть поток скачивания", ioe);
                }
            }
            if (fileWriting != null) {
                try {
                    fileWriting.close();
                } catch (IOException ioe) {
                    Helper.logger.log(Level.SEVERE, "Не удалось закрыть поток записи в файл", ioe);
                }
            }
        }
        return file;
    }
public static void zip(String destination, String folder) {
        File fdir = new File(folder);
        File[] files = fdir.listFiles();
        PrintWriter stdout = new PrintWriter(System.out, true);
        int read = 0;
        FileInputStream in;
        byte[] data = new byte[1024];
        try {
            ZipOutputStream out = new ZipOutputStream(new FileOutputStream(destination));
            out.setMethod(ZipOutputStream.DEFLATED);
            for (int i = 0; i < files.length; i++) {
                try {
                    stdout.println(files[i].getName());
                    ZipEntry entry = new ZipEntry(files[i].getName());
                    in = new FileInputStream(files[i].getPath());
                    out.putNextEntry(entry);
                    while ((read = in.read(data, 0, 1024)) != -1) {
                        out.write(data, 0, read);
                    }
                    out.closeEntry();
                    in.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            out.close();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
public static void unzip(String destDir, String zipPath) {
        PrintWriter stdout = new PrintWriter(System.out, true);
        int read = 0;
        byte[] data = new byte[1024];
        ZipEntry entry;
        try {
            ZipInputStream in = new ZipInputStream(new FileInputStream(zipPath));
            stdout.println(zipPath);
            while ((entry = in.getNextEntry()) != null) {
                if (entry.getMethod() == ZipEntry.DEFLATED) {
                    stdout.println("  Inflating: " + entry.getName());
                } else {
                    stdout.println(" Extracting: " + entry.getName());
                }
                FileOutputStream out = new FileOutputStream(destDir + File.separator + entry.getName());
                while ((read = in.read(data, 0, 1024)) != -1) {
                    out.write(data, 0, read);
                }
                out.close();
            }
            in.close();
            stdout.println();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
public static void main(String[] args) throws ParseException, FileNotFoundException, IOException {
        InputStream input = new BufferedInputStream(UpdateLanguages.class.getResourceAsStream("definition_template"));
        Translator t = new Translator(input, "UTF8");
        Node template = Translator.Start();
        File langs = new File("support/support/translate/languages");
        for (File f : langs.listFiles()) {
            if (f.getName().endsWith(".lng")) {
                input = new BufferedInputStream(new FileInputStream(f));
                try {
                    Translator.ReInit(input, "UTF8");
                } catch (java.lang.NullPointerException e) {
                    new Translator(input, "UTF8");
                }
                Node newFile = Translator.Start();
                ArrayList<Addition> additions = new ArrayList<Addition>();
                syncKeys(template, newFile, additions);
                ArrayList<String> fileLines = new ArrayList<String>();
                Scanner scanner = new Scanner(new BufferedReader(new FileReader(f)));
                while (scanner.hasNextLine()) {
                    fileLines.add(scanner.nextLine());
                }
                int offset = 0;
                for (Addition a : additions) {
                    System.out.println("Key added " + a + " to " + f.getName());
                    if (a.afterLine < 0 || a.afterLine >= fileLines.size()) {
                        fileLines.add(a.getAddition(0));
                    } else {
                        fileLines.add(a.afterLine + (offset++) + 1, a.getAddition(0));
                    }
                }
                f.delete();
                Writer writer = new BufferedWriter(new FileWriter(f));
                for (String s : fileLines) writer.write(s + "\n");
                writer.close();
                System.out.println("Language " + f.getName() + " had " + additions.size() + " additions");
            }
        }
        File defFile = new File(langs, "language.lng");
        defFile.delete();
        defFile.createNewFile();
        InputStream copyStream = new BufferedInputStream(UpdateLanguages.class.getResourceAsStream("definition_template"));
        OutputStream out = new BufferedOutputStream(new FileOutputStream(defFile));
        int c = 0;
        while ((c = copyStream.read()) >= 0) out.write(c);
        out.close();
        System.out.println("Languages updated.");
    }
public static void kopirujSoubor(File vstup, File vystup) throws IOException {
        FileChannel sourceChannel = new FileInputStream(vstup).getChannel();
        FileChannel destinationChannel = new FileOutputStream(vystup).getChannel();
        sourceChannel.transferTo(0, sourceChannel.size(), destinationChannel);
        sourceChannel.close();
        destinationChannel.close();
    }
public static void main(String[] args) throws UnsupportedEncodingException {
        MessageDigest md = null;
        String password = "admin!@#$" + "ZKNugmkm";
        try {
            md = MessageDigest.getInstance("SHA-512");
            md.update(password.getBytes("utf8"));
            byte[] b = md.digest();
            StringBuilder output = new StringBuilder(32);
            for (int i = 0; i < b.length; i++) {
                String temp = Integer.toHexString(b[i] & 0xff);
                if (temp.length() < 2) {
                    output.append("0");
                }
                output.append(temp);
            }
            System.out.println(output);
            System.out.println(output.length());
            System.out.println(RandomUtils.createRandomString(8));
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
    }
@Override
        public void fileUpload(UploadEvent uploadEvent) {
            FileOutputStream tmpOutStream = null;
            try {
                tmpUpload = File.createTempFile("projectImport", ".xml");
                tmpOutStream = new FileOutputStream(tmpUpload);
                IOUtils.copy(uploadEvent.getInputStream(), tmpOutStream);
                panel.setGeneralMessage("Project file " + uploadEvent.getFileName() + " uploaded and ready for import.");
            } catch (Exception e) {
                panel.setGeneralMessage("Could not upload file: " + e);
            } finally {
                if (tmpOutStream != null) {
                    IOUtils.closeQuietly(tmpOutStream);
                }
            }
        }