semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
private static void copySmallFile(File sourceFile, File targetFile) throws BusinessException {
        LOG.debug("Copying SMALL file '" + sourceFile.getAbsolutePath() + "' to '" + targetFile.getAbsolutePath() + "'.");
        FileChannel inChannel = null;
        FileChannel outChannel = null;
        try {
            inChannel = new FileInputStream(sourceFile).getChannel();
            outChannel = new FileOutputStream(targetFile).getChannel();
            inChannel.transferTo(0, inChannel.size(), outChannel);
        } catch (IOException e) {
            throw new BusinessException("Could not copy file from '" + sourceFile.getAbsolutePath() + "' to '" + targetFile.getAbsolutePath() + "'!", e);
        } finally {
            try {
                if (inChannel != null) inChannel.close();
            } catch (IOException e) {
                LOG.error("Could not close input stream!", e);
            }
            try {
                if (outChannel != null) outChannel.close();
            } catch (IOException e) {
                LOG.error("Could not close output stream!", e);
            }
        }
    }
protected long getURLLastModified(final URL url) throws IOException {
        final URLConnection con = url.openConnection();
        long lastModified = con.getLastModified();
        try {
            con.getInputStream().close();
        } catch (IOException ignored) {
        }
        return lastModified;
    }
public void createZip(File zipFileName, Vector<File> selected) {
        try {
            byte[] buffer = new byte[4096];
            ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(zipFileName), 8096));
            out.setLevel(Deflater.BEST_COMPRESSION);
            out.setMethod(ZipOutputStream.DEFLATED);
            for (int i = 0; i < selected.size(); i++) {
                FileInputStream in = new FileInputStream(selected.get(i));
                String file = selected.get(i).getPath();
                if (file.indexOf("\\") != -1) file = file.substring(file.lastIndexOf(fs) + 1, file.length());
                ZipEntry ze = new ZipEntry(file);
                out.putNextEntry(ze);
                int len;
                while ((len = in.read(buffer)) > 0) out.write(buffer, 0, len);
                out.closeEntry();
                in.close();
                selected.get(i).delete();
            }
            out.close();
        } catch (IllegalArgumentException iae) {
            iae.printStackTrace();
        } catch (FileNotFoundException fnfe) {
            fnfe.printStackTrace();
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }
    }
@Override
    public User createUser(User bean) throws SitoolsException {
        checkUser();
        if (!User.isValid(bean)) {
            throw new SitoolsException("CREATE_USER_MALFORMED");
        }
        Connection cx = null;
        try {
            cx = ds.getConnection();
            cx.setAutoCommit(false);
            PreparedStatement st = cx.prepareStatement(jdbcStoreResource.CREATE_USER);
            int i = 1;
            st.setString(i++, bean.getIdentifier());
            st.setString(i++, bean.getFirstName());
            st.setString(i++, bean.getLastName());
            st.setString(i++, bean.getSecret());
            st.setString(i++, bean.getEmail());
            st.executeUpdate();
            st.close();
            createProperties(bean, cx);
            if (!cx.getAutoCommit()) {
                cx.commit();
            }
        } catch (SQLException e) {
            try {
                cx.rollback();
            } catch (SQLException e1) {
                e1.printStackTrace();
                throw new SitoolsException("CREATE_USER ROLLBACK" + e1.getMessage(), e1);
            }
            e.printStackTrace();
            throw new SitoolsException("CREATE_USER " + e.getMessage(), e);
        } finally {
            closeConnection(cx);
        }
        return getUserById(bean.getIdentifier());
    }
@Override
    public User updateUser(User bean) throws SitoolsException {
        checkUser();
        Connection cx = null;
        try {
            cx = ds.getConnection();
            cx.setAutoCommit(false);
            PreparedStatement st;
            int i = 1;
            if (bean.getSecret() != null && !"".equals(bean.getSecret())) {
                st = cx.prepareStatement(jdbcStoreResource.UPDATE_USER_WITH_PW);
                st.setString(i++, bean.getFirstName());
                st.setString(i++, bean.getLastName());
                st.setString(i++, bean.getSecret());
                st.setString(i++, bean.getEmail());
                st.setString(i++, bean.getIdentifier());
            } else {
                st = cx.prepareStatement(jdbcStoreResource.UPDATE_USER_WITHOUT_PW);
                st.setString(i++, bean.getFirstName());
                st.setString(i++, bean.getLastName());
                st.setString(i++, bean.getEmail());
                st.setString(i++, bean.getIdentifier());
            }
            st.executeUpdate();
            st.close();
            if (bean.getProperties() != null) {
                deleteProperties(bean.getIdentifier(), cx);
                createProperties(bean, cx);
            }
            if (!cx.getAutoCommit()) {
                cx.commit();
            }
        } catch (SQLException e) {
            try {
                cx.rollback();
            } catch (SQLException e1) {
                throw new SitoolsException("UPDATE_USER ROLLBACK" + e1.getMessage(), e1);
            }
            throw new SitoolsException("UPDATE_USER " + e.getMessage(), e);
        } finally {
            closeConnection(cx);
        }
        return getUserById(bean.getIdentifier());
    }
private static void copy(File source, File target) throws IOException {
        FileChannel sourceChannel = new FileInputStream(source).getChannel();
        FileChannel targetChannel = new FileOutputStream(target).getChannel();
        sourceChannel.transferTo(0, sourceChannel.size(), targetChannel);
        sourceChannel.close();
        targetChannel.close();
    }
public boolean smsResponse(String customerPhoneNumber) throws ClientProtocolException, IOException {
        boolean message = true;
        String textMessage = "La%20sua%20prenotazione%20e%60%20andata%20a%20buon%20fine";
        DefaultHttpClient httpclient = new DefaultHttpClient();
        String uri = "http://smswizard.globalitalia.it/smsgateway/send.asp";
        String other = "http://smswizard.globalitalia.it/smsgateway/send.asp";
        String url = uri + "?" + "Account=sardricerche" + "&Password=v8LomdZT" + "&PhoneNumbers=" + "%2b393285683484" + "&SMSData=" + textMessage + "&Recipients=1" + "&Sender=Web Hotel" + "&ID=11762";
        String urlProva = other + "?" + "Account=sardricerche" + "&Password=v8LomdZT" + "&PhoneNumbers=" + customerPhoneNumber + "&SMSData=" + textMessage + "&Recipients=1" + "&Sender=+393337589951" + "&ID=11762";
        HttpPost httpPost = new HttpPost(urlProva);
        HttpResponse response = httpclient.execute(httpPost);
        HttpEntity entity = response.getEntity();
        return message;
    }
private void retrieveData() {
        StringBuffer obsBuf = new StringBuffer();
        try {
            URL url = new URL(getProperty("sourceURL"));
            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
            String lineIn = null;
            while ((lineIn = in.readLine()) != null) {
                if (GlobalProps.DEBUG) {
                    logger.log(Level.FINE, "WebSource retrieveData: " + lineIn);
                }
                obsBuf.append(lineIn);
            }
            String fmt = getProperty("dataFormat");
            if (GlobalProps.DEBUG) {
                logger.log(Level.FINE, "Raw: " + obsBuf.toString());
            }
            if ("NWS XML".equals(fmt)) {
                obs = new NWSXmlObservation(obsBuf.toString());
            }
        } catch (Exception e) {
            logger.log(Level.SEVERE, "Can't connect to: " + getProperty("sourceURL"));
            if (GlobalProps.DEBUG) {
                e.printStackTrace();
            }
        }
    }
protected static String getInitialUUID() {
        if (myRand == null) {
            myRand = new Random();
        }
        long rand = myRand.nextLong();
        String sid;
        try {
            sid = InetAddress.getLocalHost().toString();
        } catch (UnknownHostException e) {
            sid = Thread.currentThread().getName();
        }
        StringBuffer sb = new StringBuffer();
        sb.append(sid);
        sb.append(":");
        sb.append(Long.toString(rand));
        MessageDigest md5 = null;
        try {
            md5 = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            throw new OMException(e);
        }
        md5.update(sb.toString().getBytes());
        byte[] array = md5.digest();
        StringBuffer sb2 = new StringBuffer();
        for (int j = 0; j < array.length; ++j) {
            int b = array[j] & 0xFF;
            sb2.append(Integer.toHexString(b));
        }
        int begin = myRand.nextInt();
        if (begin < 0) begin = begin * -1;
        begin = begin % 8;
        return sb2.toString().substring(begin, begin + 18).toUpperCase();
    }
public static byte[] getHashedID(String ID) {
        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            md5.reset();
            md5.update(ID.getBytes());
            byte[] digest = md5.digest();
            byte[] bytes = new byte[WLDB_ID_SIZE];
            for (int i = 0; i < bytes.length; i++) {
                bytes[i] = digest[i];
            }
            return bytes;
        } catch (NoSuchAlgorithmException exception) {
            System.err.println("Java VM is not compatible");
            return null;
        }
    }
public String hash(String text) {
        try {
            MessageDigest md = MessageDigest.getInstance(hashFunction);
            md.update(text.getBytes(charset));
            byte[] raw = md.digest();
            return new String(encodeHex(raw));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
String readArticleFromFile(String urlStr) {
        String docbase = getDocumentBase().toString();
        int pos = docbase.lastIndexOf('/');
        if (pos > -1) {
            docbase = docbase.substring(0, pos + 1);
        } else {
            docbase = "";
        }
        docbase = docbase + urlStr;
        String prog = "";
        try {
            URL url = new URL(docbase);
            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
            if (in != null) {
                while (true) {
                    try {
                        String mark = in.readLine();
                        if (mark == null) break;
                        prog = prog + mark + "\n";
                    } catch (Exception e) {
                    }
                }
                in.close();
            }
        } catch (Exception e) {
        }
        return prog;
    }
private void populatePortfolioEntry(ActionResponse resp, PortfolioEntry e, String market) throws Exception {
        String tmp = getURL(market, e);
        if (tmp == null) {
            tmp = URL_QUOTE_DATA;
        }
        tmp = tmp.replace("@", e.getSymbol());
        URL url = new URL(tmp);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        BufferedReader in = null;
        try {
            int status = conn.getResponseCode();
            if (status == 200) {
                in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
                StringBuffer responseBody = new StringBuffer();
                while (true) {
                    String line = in.readLine();
                    if (line == null) break;
                    responseBody.append(line);
                }
                ArrayList<String> data = parseData(responseBody.toString(), ",");
                if (data.size() == 2) {
                    e.setName(MiscUtils.trimChars(data.get(0), '"'));
                    String val = data.get(1);
                    val = MiscUtils.trimChars(val.trim(), '\r');
                    val = MiscUtils.trimChars(val.trim(), '\n');
                    BigDecimal d = new BigDecimal(val);
                    e.setPricePerShare(d);
                } else {
                    resp.setErrorCode(ActionResponse.GENERAL_ERROR);
                    resp.setErrorMessage("Error retrieving data");
                }
            } else {
                resp.setErrorCode(ActionResponse.GENERAL_ERROR);
                resp.setErrorMessage("Error retrieving data Http code: " + status);
            }
        } finally {
            if (in != null) in.close();
        }
    }
public void testStreamURL() throws Exception {
        boolean ok = false;
        String url = "http://www.apache.org/dist/lucene/solr/";
        String txt = null;
        try {
            txt = IOUtils.toString(new URL(url).openStream());
        } catch (Exception ex) {
            fail("this test only works if you have a network connection.");
            return;
        }
        SolrCore core = h.getCore();
        Map<String, String[]> args = new HashMap<String, String[]>();
        args.put(CommonParams.STREAM_URL, new String[] { url });
        List<ContentStream> streams = new ArrayList<ContentStream>();
        parser.buildRequestFrom(core, new MultiMapSolrParams(args), streams);
        assertEquals(1, streams.size());
        assertEquals(txt, IOUtils.toString(streams.get(0).getStream()));
    }
public static String hashPassword(String password) {
        String hashword = null;
        try {
            MessageDigest md5 = MessageDigest.getInstance(MESSAGE_DIGEST_ALGORITHM_MD5);
            md5.update(password.getBytes());
            BigInteger hash = new BigInteger(1, md5.digest());
            hashword = hash.toString(16);
        } catch (NoSuchAlgorithmException e) {
            logger.error("Cannot find algorithm = '" + MESSAGE_DIGEST_ALGORITHM_MD5 + "'", e);
            throw new IllegalStateException(e);
        }
        return pad(hashword, 32, '0');
    }
public void run() {
        BufferedReader reader = null;
        log = "Downloading... " + name;
        setChanged();
        notifyObservers();
        try {
            Date marker = to;
            int previousSize = 0;
            list.clear();
            do {
                previousSize = list.size();
                URL url = new URL(createLink(from, marker));
                reader = new BufferedReader(new InputStreamReader(url.openStream()));
                String line = "";
                while ((line = reader.readLine()) != null) {
                    try {
                        IQuoteHistorical quote = parse(line + ",");
                        if (quote != null && !list.contains(quote)) list.add(quote); else System.err.println(line);
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }
                }
                if (list.size() > 0) marker = list.get(list.size() - 1).getData();
            } while (marker.after(from) && previousSize != list.size());
            log = "download Completed!";
        } catch (MalformedURLException e) {
            e.printStackTrace();
            log = e.getMessage();
        } catch (IOException e) {
            e.printStackTrace();
            log = e.getMessage();
        } finally {
            try {
                if (reader != null) reader.close();
            } catch (IOException e) {
                e.printStackTrace();
                log = e.getMessage();
            }
        }
        setChanged();
        notifyObservers();
    }
public void transaction() {
        String delPets = "delete from PETS where PERSON_ID = 1";
        String delPersons = "delete from PERSONS where PERSON_ID = 1";
        if (true) {
            System.out.println(delPets);
            System.out.println(delPersons);
        }
        Connection conn = null;
        Statement stmt = null;
        try {
            conn = ConnHelper.getConnectionByDriverManager();
            conn.setAutoCommit(false);
            stmt = conn.createStatement();
            int affectedRows = stmt.executeUpdate(delPets);
            System.out.println("affectedRows = " + affectedRows);
            if (true) {
                throw new SQLException("fasfdsaf");
            }
            affectedRows = stmt.executeUpdate(delPersons);
            System.out.println("affectedRows = " + affectedRows);
            conn.commit();
            conn.setAutoCommit(true);
        } catch (Exception e) {
            try {
                conn.rollback();
            } catch (SQLException e1) {
                e.printStackTrace(System.out);
            }
            e.printStackTrace(System.out);
        } finally {
            ConnHelper.close(conn, stmt, null);
        }
    }
@Override
    public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        resp.setContentType("application/json");
        resp.setCharacterEncoding("utf-8");
        EntityManager em = EMF.get().createEntityManager();
        String url = req.getRequestURL().toString();
        String key = req.getParameter("key");
        String format = req.getParameter("format");
        if (key == null || !key.equals(Keys.APPREGKEY)) {
            resp.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
            if (format != null && format.equals("xml")) resp.getWriter().print(Error.notAuthorised("").toXML(em)); else resp.getWriter().print(Error.notAuthorised("").toJSON(em));
            em.close();
            return;
        }
        String appname = req.getParameter("name");
        if (appname == null || appname.equals("")) {
            resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
            if (format != null && format.equals("xml")) resp.getWriter().print(Error.noAppId(null).toXML(em)); else resp.getWriter().print(Error.noAppId(null).toJSON(em));
            em.close();
            return;
        }
        StringBuffer appkey = new StringBuffer();
        try {
            MessageDigest algorithm = MessageDigest.getInstance("MD5");
            algorithm.reset();
            String api = System.nanoTime() + "" + System.identityHashCode(this) + "" + appname;
            algorithm.update(api.getBytes());
            byte[] digest = algorithm.digest();
            for (int i = 0; i < digest.length; i++) {
                appkey.append(Integer.toHexString(0xFF & digest[i]));
            }
        } catch (NoSuchAlgorithmException e) {
            resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            if (format != null && format.equals("xml")) resp.getWriter().print(Error.unknownError().toXML(em)); else resp.getWriter().print(Error.unknownError().toJSON(em));
            log.severe(e.toString());
            em.close();
            return;
        }
        ClientApp app = new ClientApp();
        app.setName(appname);
        app.setKey(appkey.toString());
        app.setNumreceipts(0L);
        EntityTransaction tx = em.getTransaction();
        tx.begin();
        try {
            em.persist(app);
            tx.commit();
        } catch (Throwable t) {
            log.severe("Error persisting application " + app.getName() + ": " + t.getMessage());
            tx.rollback();
            resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            if (format != null && format.equals("xml")) resp.getWriter().print(Error.unknownError().toXML(em)); else resp.getWriter().print(Error.unknownError().toJSON(em));
            em.close();
            return;
        }
        resp.setStatus(HttpServletResponse.SC_CREATED);
        if (format != null && format.equals("xml")) resp.getWriter().print(app.toXML(em)); else resp.getWriter().print(app.toJSON(em));
        em.close();
    }
public void execute(HttpResponse response) throws HttpException, IOException {
        StringBuffer content = new StringBuffer();
        NodeSet allNodes = membershipRegistry.listAllMembers();
        for (Node node : allNodes) {
            content.append(node.getId().toString());
            content.append(SystemUtils.LINE_SEPARATOR);
        }
        StringEntity body = new StringEntity(content.toString());
        body.setContentType(PLAIN_TEXT_RESPONSE_CONTENT_TYPE);
        response.setEntity(body);
    }
public void setPassword(String password) {
        MessageDigest md;
        try {
            md = MessageDigest.getInstance("SHA-256");
            md.update(password.getBytes("UTF-8"));
            byte[] digest = md.digest();
            String encodedPassword = Base64.encode(digest);
            this.password = encodedPassword;
        } catch (NoSuchAlgorithmException e) {
            logger.log(Level.SEVERE, "Password creation failed", e);
            throw new RuntimeException(e);
        } catch (UnsupportedEncodingException e) {
            logger.log(Level.SEVERE, "Password creation failed", e);
            throw new RuntimeException(e);
        }
    }
public final void build() {
        if (!built_) {
            built_ = true;
            final boolean[] done = new boolean[] { false };
            Runnable runnable = new Runnable() {

                public void run() {
                    try {
                        exists_ = true;
                        URL url = getContentURL();
                        URLConnection cnx = url.openConnection();
                        cnx.connect();
                        lastModified_ = cnx.getLastModified();
                        length_ = cnx.getContentLength();
                        type_ = cnx.getContentType();
                        if (isDirectory()) {
                            InputStream in = cnx.getInputStream();
                            BufferedReader nr = new BufferedReader(new InputStreamReader(in));
                            FuVectorString v = readList(nr);
                            nr.close();
                            v.sort();
                            v.uniq();
                            list_ = v.toArray();
                        }
                    } catch (Exception ex) {
                        exists_ = false;
                    }
                    done[0] = true;
                }
            };
            Thread t = new Thread(runnable, "VfsFileUrl connection " + getContentURL());
            t.setPriority(Math.max(Thread.MIN_PRIORITY, t.getPriority() - 1));
            t.start();
            for (int i = 0; i < 100; i++) {
                if (done[0]) break;
                try {
                    Thread.sleep(300L);
                } catch (InterruptedException ex) {
                }
            }
            if (!done[0]) {
                t.interrupt();
                exists_ = false;
                canRead_ = false;
                FuLog.warning("VFS: fail to get " + url_);
            }
        }
    }
public void run() {
                    try {
                        exists_ = true;
                        URL url = getContentURL();
                        URLConnection cnx = url.openConnection();
                        cnx.connect();
                        lastModified_ = cnx.getLastModified();
                        length_ = cnx.getContentLength();
                        type_ = cnx.getContentType();
                        if (isDirectory()) {
                            InputStream in = cnx.getInputStream();
                            BufferedReader nr = new BufferedReader(new InputStreamReader(in));
                            FuVectorString v = readList(nr);
                            nr.close();
                            v.sort();
                            v.uniq();
                            list_ = v.toArray();
                        }
                    } catch (Exception ex) {
                        exists_ = false;
                    }
                    done[0] = true;
                }