semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public static String GetMD5SUM(String s) throws NoSuchAlgorithmException {
        MessageDigest algorithm = MessageDigest.getInstance("MD5");
        algorithm.reset();
        algorithm.update(s.getBytes());
        byte messageDigest[] = algorithm.digest();
        String md5sum = Base64.encode(messageDigest);
        return md5sum;
    }
public static boolean copyFileToDir(File inputFile, File outputDir) {
        try {
            String outputFileName = inputFile.getName();
            int index = 1;
            while (existFileInDir(outputFileName, outputDir)) {
                outputFileName = index + inputFile.getName();
                index++;
            }
            String directory = getDirectoryWithSlash(outputDir.getAbsolutePath());
            File outputFile = new File(directory + outputFileName);
            FileReader in = new FileReader(inputFile);
            FileWriter out = new FileWriter(outputFile);
            int c;
            while ((c = in.read()) != -1) out.write(c);
            in.close();
            out.close();
        } catch (IOException e) {
            return false;
        }
        return true;
    }
private static void salvarObra(Artista artista, Obra obra) throws Exception {
        Connection conn = null;
        PreparedStatement ps = null;
        int categoria;
        System.out.println("Migracao.salvarObra() obra: " + obra.toString2());
        if (obra.getCategoria() != null) {
            categoria = getCategoria(obra.getCategoria().getNome()).getCodigo();
        } else {
            categoria = getCategoria("Sem Categoria").getCodigo();
        }
        try {
            conn = C3P0Pool.getConnection();
            String sql = "insert into obra VALUES (?,?,?,?,?,?)";
            ps = conn.prepareStatement(sql);
            ps.setNull(1, Types.INTEGER);
            ps.setString(2, obra.getTitulo());
            ps.setInt(3, obra.getSelec());
            ps.setInt(4, categoria);
            ps.setInt(5, artista.getNumeroInscricao());
            ps.setInt(6, obra.getCodigo());
            ps.executeUpdate();
            conn.commit();
        } catch (Exception e) {
            if (conn != null) conn.rollback();
            throw e;
        } finally {
            close(conn, ps);
        }
    }
private static void salvarArtista(Artista artista) throws Exception {
        Connection conn = null;
        PreparedStatement ps = null;
        try {
            conn = C3P0Pool.getConnection();
            String sql = "insert into artista VALUES (?,?,?,?,?,?,?)";
            ps = conn.prepareStatement(sql);
            ps.setInt(1, artista.getNumeroInscricao());
            ps.setString(2, artista.getNome());
            ps.setBoolean(3, artista.isSexo());
            ps.setString(4, artista.getEmail());
            ps.setString(5, artista.getObs());
            ps.setString(6, artista.getTelefone());
            ps.setNull(7, Types.INTEGER);
            ps.executeUpdate();
            salvarEndereco(conn, ps, artista);
            conn.commit();
        } catch (Exception e) {
            if (conn != null) conn.rollback();
            throw e;
        } finally {
            close(conn, ps);
        }
    }
private static void salvarCategoria(Categoria categoria) throws Exception {
        Connection conn = null;
        PreparedStatement ps = null;
        try {
            conn = C3P0Pool.getConnection();
            String sql = "insert into categoria VALUES (?,?)";
            ps = conn.prepareStatement(sql);
            ps.setNull(1, Types.INTEGER);
            ps.setString(2, categoria.getNome());
            ps.executeUpdate();
            conn.commit();
        } catch (Exception e) {
            if (conn != null) conn.rollback();
            throw e;
        } finally {
            close(conn, ps);
        }
    }
public String getValidationKey(String transactionId, double transactionAmount) {
        try {
            java.security.MessageDigest d = java.security.MessageDigest.getInstance("MD5");
            d.reset();
            String value = this.getPostingKey() + transactionId + transactionAmount;
            d.update(value.getBytes());
            byte[] buf = d.digest();
            return Base64.encodeBytes(buf);
        } catch (java.security.NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return "";
    }
public static void copyAll(URL url, Writer out) {
        Reader in = null;
        try {
            in = new InputStreamReader(new BufferedInputStream(url.openStream()));
            copyAll(in, out);
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            close(in);
        }
    }
public static void copyAll(URL url, StringBuilder ret) {
        Reader in = null;
        try {
            in = new InputStreamReader(new BufferedInputStream(url.openStream()));
            copyAll(in, ret);
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            close(in);
        }
    }
public FTPSource(SourceDetail sourceDetail) throws SourceException {
        this.sourceDetail = sourceDetail;
        localPathMap = new HashMap<String, String>();
        client = new FTPClient();
        try {
            client.connect(sourceDetail.getHost());
            client.login(sourceDetail.getUser(), sourceDetail.getPassword());
            workingDirectory = new File(ConfigManager.getGUIConfig().getWorkingDirectoryName() + File.separator + sourceDetail.getName());
            workingDirectory.mkdir();
        } catch (Exception e) {
            throw new SourceException(e);
        }
    }
private String grabInformationFromWeb(String query, String infoName) throws Exception {
        String result = "";
        URL url = new URL(query);
        HttpURLConnection request = null;
        request = (HttpURLConnection) url.openConnection();
        if (request != null) {
            InputStream in = url.openStream();
            int c = 0;
            StringBuilder sb = new StringBuilder();
            while ((c = in.read()) != -1) {
                sb = sb.append((char) c);
            }
            String s = sb.toString();
            result = Utils.getTagValue(s, "<" + infoName + ">", "</" + infoName + ">");
            in.close();
        }
        return result;
    }
public static void copy(File from, File to, CopyMode mode) throws IOException {
        if (!from.exists()) {
            IllegalArgumentException e = new IllegalArgumentException("Source doesn't exist: " + from.getCanonicalFile());
            log.throwing("IOUtils", "copy", e);
            throw e;
        }
        if (from.isFile()) {
            if (!to.canWrite()) {
                IllegalArgumentException e = new IllegalArgumentException("Cannot write to target location: " + to.getCanonicalFile());
                log.throwing("IOUtils", "copy", e);
                throw e;
            }
        }
        if (to.exists()) {
            if ((mode.val & CopyMode.OverwriteFile.val) != CopyMode.OverwriteFile.val) {
                IllegalArgumentException e = new IllegalArgumentException("Target already exists: " + to.getCanonicalFile());
                log.throwing("IOUtils", "copy", e);
                throw e;
            }
            if (to.isDirectory()) {
                if ((mode.val & CopyMode.OverwriteFolder.val) != CopyMode.OverwriteFolder.val) {
                    IllegalArgumentException e = new IllegalArgumentException("Target is a folder: " + to.getCanonicalFile());
                    log.throwing("IOUtils", "copy", e);
                    throw e;
                } else to.delete();
            }
        }
        if (from.isFile()) {
            FileChannel in = new FileInputStream(from).getChannel();
            FileLock inLock = in.lock();
            FileChannel out = new FileOutputStream(to).getChannel();
            FileLock outLock = out.lock();
            try {
                in.transferTo(0, (int) in.size(), out);
            } finally {
                inLock.release();
                outLock.release();
                in.close();
                out.close();
            }
        } else {
            to.mkdirs();
            File[] contents = to.listFiles();
            for (File file : contents) {
                File newTo = new File(to.getCanonicalPath() + "/" + file.getName());
                copy(file, newTo, mode);
            }
        }
    }
@Override
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        InputStream is = null;
        InputStream page = null;
        OutputStream os = null;
        String rootUrl = null;
        try {
            boolean isMultipart = ServletFileUpload.isMultipartContent(request);
            if (!isMultipart) {
                request.setAttribute("error", "Form isn't a multipart form");
                RequestDispatcher rd = request.getRequestDispatcher("/WEB-INF/error.jsp");
                rd.forward(request, response);
            }
            ServletFileUpload upload = new ServletFileUpload();
            String webUrl = null;
            FileItemIterator iter = upload.getItemIterator(request);
            while (iter.hasNext()) {
                FileItemStream item = iter.next();
                String name = item.getFieldName();
                if (name.equals("webpage")) {
                    is = item.openStream();
                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    IOUtils.copy(is, baos);
                    page = new ByteArrayInputStream(baos.toByteArray());
                } else if (name.equals("weburl")) {
                    InputStream wpIs = null;
                    try {
                        webUrl = Streams.asString(item.openStream());
                        URL u = new URL(webUrl);
                        wpIs = new BufferedInputStream(u.openStream());
                        ByteArrayOutputStream baos = new ByteArrayOutputStream();
                        IOUtils.copy(wpIs, baos);
                        page = new ByteArrayInputStream(baos.toByteArray());
                    } finally {
                        IOUtils.closeQuietly(wpIs);
                    }
                } else if (name.equals("rooturl")) {
                    rootUrl = Streams.asString(item.openStream());
                }
            }
            if (page == null) {
                request.setAttribute("error", "Form doesn't have an html file");
                RequestDispatcher rd = request.getRequestDispatcher("/WEB-INF/error.jsp");
                rd.forward(request, response);
            }
            ToMailerDelegate delegate = new ToMailerDelegate(page, rootUrl);
            os = new BufferedOutputStream(response.getOutputStream());
            os.write(delegate.getMailer());
            os.flush();
        } catch (Exception e) {
            streamException(request, response, e);
        } finally {
            IOUtils.closeQuietly(page);
            IOUtils.closeQuietly(is);
            IOUtils.closeQuietly(os);
        }
    }
public void setInitialValues(String Tag, Vector subfields) {
        this.tftag.setText(Tag);
        presentineditor = new ArrayList();
        this.glosf = subfields;
        for (int i = 0; i < subfields.size(); i++) {
            this.dlm2.addElement(subfields.elementAt(i).toString().trim());
            presentineditor.add(subfields.elementAt(i).toString().trim());
        }
        String xmlreq = CataloguingXMLGenerator.getInstance().getSubFieldsRepeat("5", Tag);
        try {
            java.net.URL url = new java.net.URL(ResourceBundle.getBundle("Administration").getString("ServerURL") + ResourceBundle.getBundle("Administration").getString("ServletSubPath") + "MarcDictionaryServlet");
            java.net.URLConnection urlconn = (java.net.URLConnection) url.openConnection();
            urlconn.setDoOutput(true);
            java.io.OutputStream dos = urlconn.getOutputStream();
            dos.write(xmlreq.getBytes());
            java.io.InputStream ios = urlconn.getInputStream();
            SAXBuilder saxb = new SAXBuilder();
            Document retdoc = saxb.build(ios);
            Element retroot = retdoc.getRootElement();
            hashtable = new Hashtable();
            List list = retroot.getChildren();
            System.out.println("Point of execution came here " + list.size());
            for (int i = 0; i < list.size(); i++) {
                List chilist = ((Element) list.get(i)).getChildren();
                hashtable.put(((Element) chilist.get(0)).getText().trim(), ((Element) chilist.get(1)).getText().trim());
            }
            System.out.println(hashtable);
            Enumeration keys = hashtable.keys();
            while (keys.hasMoreElements()) this.dlm1.addElement(keys.nextElement());
        } catch (Exception e) {
            System.out.println(e);
        }
    }
public static URLConnection openProxiedConnection(URL url) throws IOException {
        if (proxyHost != null) {
            System.getProperties().put("proxySet", "true");
            System.getProperties().put("proxyHost", proxyHost);
            System.getProperties().put("proxyPort", proxyPort);
        }
        URLConnection cnx = url.openConnection();
        if (proxyUsername != null) {
            cnx.setRequestProperty("Proxy-Authorization", proxyEncodedPassword);
        }
        return cnx;
    }
public InputStream getImageAsStream(Photo photo, int size) throws IOException, FlickrException {
        String urlStr = "";
        if (size == Size.SQUARE) {
            urlStr = photo.getSmallSquareUrl();
        } else if (size == Size.THUMB) {
            urlStr = photo.getThumbnailUrl();
        } else if (size == Size.SMALL) {
            urlStr = photo.getSmallUrl();
        } else if (size == Size.MEDIUM) {
            urlStr = photo.getMediumUrl();
        } else if (size == Size.LARGE) {
            urlStr = photo.getLargeUrl();
        } else if (size == Size.ORIGINAL) {
            urlStr = photo.getOriginalUrl();
        } else {
            throw new FlickrException("0", "Unknown Photo-size");
        }
        URL url = new URL(urlStr);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        if (transport instanceof REST) {
            if (((REST) transport).isProxyAuth()) {
                conn.setRequestProperty("Proxy-Authorization", "Basic " + ((REST) transport).getProxyCredentials());
            }
        }
        conn.connect();
        return conn.getInputStream();
    }
public BufferedImage getImage(String urlStr) throws IOException {
        URL url = new URL(urlStr);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        if (transport instanceof REST) {
            if (((REST) transport).isProxyAuth()) {
                conn.setRequestProperty("Proxy-Authorization", "Basic " + ((REST) transport).getProxyCredentials());
            }
        }
        conn.connect();
        InputStream in = null;
        try {
            in = conn.getInputStream();
            return ImageIO.read(in);
        } finally {
            IOUtilities.close(in);
        }
    }
private void jbInit() throws Exception {
        getContentPane().setLayout(borderLayout1);
        this.setTitle("�ϥλ���");
        jTextPane1.setEditable(false);
        this.getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);
        jScrollPane1.getViewport().add(jTextPane1);
        this.setSize(400, 600);
        this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        URL url = ReadmeFrame.class.getResource("readme.txt");
        BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
        StringBuilder strBuilder = new StringBuilder();
        while (reader.ready()) {
            strBuilder.append(reader.readLine());
            strBuilder.append('\n');
        }
        reader.close();
        jTextPane1.setText(strBuilder.toString());
    }
private void update(String statement, SyrupConnection con, boolean do_log) throws Exception {
        Statement s = null;
        try {
            s = con.createStatement();
            s.executeUpdate(statement);
            con.commit();
        } catch (Throwable e) {
            if (do_log) {
                logger.log(Level.INFO, "Update failed. Transaction is rolled back", e);
            }
            con.rollback();
        }
    }
public static InputStream retrievePricesHTML(String username, String password) throws IOException, SAXException {
        List<String> cookies = new ArrayList<String>();
        URL url = new URL("http://motormouth.com.au/default_fl.aspx");
        HttpURLConnection loginConnection = (HttpURLConnection) url.openConnection();
        String viewStateValue = HTMLParser.parseHTMLInputTagValue(new InputStreamReader(loginConnection.getInputStream()), "__VIEWSTATE");
        setCookies(cookies, loginConnection);
        HttpURLConnection postCredsConnection = (HttpURLConnection) url.openConnection();
        postCredsConnection.setDoOutput(true);
        postCredsConnection.setRequestMethod("POST");
        postCredsConnection.setInstanceFollowRedirects(false);
        postCredsConnection.setRequestProperty("Cookie", buildCookieString(cookies));
        OutputStreamWriter postCredsWriter = new OutputStreamWriter(postCredsConnection.getOutputStream());
        postCredsWriter.append("__VIEWSTATE=").append(URLEncoder.encode(viewStateValue, "UTF-8")).append('&');
        postCredsWriter.append("Login_Module1%3Ausername=").append(URLEncoder.encode(username, "UTF-8")).append('&');
        postCredsWriter.append("Login_Module1%3Apassword=").append(URLEncoder.encode(password, "UTF-8")).append('&');
        postCredsWriter.append("Login_Module1%3AButtonLogin.x=0").append('&');
        postCredsWriter.append("Login_Module1%3AButtonLogin.y=0");
        postCredsWriter.flush();
        postCredsWriter.close();
        int postResponseCode = postCredsConnection.getResponseCode();
        if (postResponseCode == 302) {
            setCookies(cookies, postCredsConnection);
            URL dataUrl = new URL(url, postCredsConnection.getHeaderField("Location"));
            HttpURLConnection dataConnection = (HttpURLConnection) dataUrl.openConnection();
            dataConnection.setRequestProperty("Cookie", buildCookieString(cookies));
            InputStream dataInputStream = dataConnection.getInputStream();
            return dataInputStream;
        } else if (postResponseCode == 200) {
            URL dataUrl = new URL(url, "/secure/mymotormouth.aspx");
            HttpURLConnection dataConnection = (HttpURLConnection) dataUrl.openConnection();
            dataConnection.setRequestProperty("Cookie", buildCookieString(cookies));
            InputStream dataInputStream = dataConnection.getInputStream();
            return dataInputStream;
        } else {
            return null;
        }
    }
public Transaction() throws Exception {
        Connection Conn = null;
        Statement Stmt = null;
        try {
            Class.forName("org.gjt.mm.mysql.Driver").newInstance();
            Conn = DriverManager.getConnection(DBUrl);
            Conn.setAutoCommit(true);
            Stmt = Conn.createStatement();
            try {
                Stmt.executeUpdate("DROP TABLE trans_test");
            } catch (SQLException sqlEx) {
            }
            Stmt.executeUpdate("CREATE TABLE trans_test (id int not null primary key, decdata double) type=BDB");
            Conn.setAutoCommit(false);
            Stmt.executeUpdate("INSERT INTO trans_test (id, decdata) VALUES (1, 21.0)");
            Stmt.executeUpdate("INSERT INTO trans_test (id, decdata) VALUES (2, 23.485115)");
            Conn.rollback();
            System.out.println("Roll Ok");
            ResultSet RS = Stmt.executeQuery("SELECT * from trans_test");
            if (!RS.next()) {
                System.out.println("Ok");
            } else {
                System.out.println("Rollback failed");
            }
            Stmt.executeUpdate("INSERT INTO trans_test (id, decdata) VALUES (2, 23.485115)");
            Stmt.executeUpdate("INSERT INTO trans_test (id, decdata) VALUES (1, 21.485115)");
            Conn.commit();
            RS = Stmt.executeQuery("SELECT * from trans_test where id=2");
            if (RS.next()) {
                System.out.println(RS.getDouble(2));
                System.out.println("Ok");
            } else {
                System.out.println("Rollback failed");
            }
        } catch (Exception ex) {
            throw ex;
        } finally {
            if (Stmt != null) {
                try {
                    Stmt.close();
                } catch (SQLException SQLEx) {
                }
            }
            if (Conn != null) {
                try {
                    Conn.close();
                } catch (SQLException SQLEx) {
                }
            }
        }
    }
public static String encrypt(String plaintext) throws Exception {
        MessageDigest md = null;
        try {
            md = MessageDigest.getInstance("SHA");
        } catch (NoSuchAlgorithmException e) {
            throw new Exception(e.getMessage());
        }
        md.update(plaintext.getBytes(Charset.defaultCharset()));
        byte raw[] = md.digest();
        String hash = (new BASE64Encoder()).encode(raw);
        return hash;
    }
public void testManageSources() throws Exception {
        this.getTestTool().manageSources(this.getTestSourcesDirectory());
        this.getTestTool().manageSources(this.getTestTool().getModules().getModule("Module"), this.getTestSourcesDirectory());
        final File implementationDirectory = this.getTestSourcesDirectory();
        this.getTestTool().manageSources(this.getTestTool().getModules().getImplementation("Implementation"), implementationDirectory);
        this.getTestTool().manageSources(this.getTestTool().getModules().getImplementation("Implementation"), implementationDirectory);
        final File specificationDirectory = this.getTestSourcesDirectory();
        this.getTestTool().manageSources(this.getTestTool().getModules().getSpecification("Specification"), specificationDirectory);
        this.getTestTool().manageSources(this.getTestTool().getModules().getSpecification("Specification"), specificationDirectory);
        IOUtils.copy(this.getClass().getResourceAsStream("IllegalImplementationSource.java.txt"), new FileOutputStream(new File(implementationDirectory, "Implementation.java")));
        IOUtils.copy(this.getClass().getResourceAsStream("IllegalSpecificationSource.java.txt"), new FileOutputStream(new File(specificationDirectory, "Specification.java")));
        try {
            this.getTestTool().manageSources(this.getTestTool().getModules().getImplementation("Implementation"), implementationDirectory);
            Assert.fail("Expected IOException not thrown.");
        } catch (IOException e) {
            Assert.assertNotNull(e.getMessage());
            System.out.println(e.toString());
        }
        try {
            this.getTestTool().manageSources(this.getTestTool().getModules().getSpecification("Specification"), specificationDirectory);
            Assert.fail("Expected IOException not thrown.");
        } catch (IOException e) {
            Assert.assertNotNull(e.getMessage());
            System.out.println(e.toString());
        }
        this.getTestTool().setProfile("DOES_NOT_EXIST");
        this.getTestTool().manageSources(this.getTestSourcesDirectory());
        this.getTestTool().manageSources(this.getTestTool().getModules().getModule("Module"), this.getTestSourcesDirectory());
        this.getTestTool().manageSources(this.getTestTool().getModules().getImplementation("Implementation"), this.getTestSourcesDirectory());
        this.getTestTool().manageSources(this.getTestTool().getModules().getSpecification("Specification"), this.getTestSourcesDirectory());
    }