semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public int deleteRecord(String uuid) throws SQLException, CatalogIndexException {
        Connection con = null;
        boolean autoCommit = true;
        PreparedStatement st = null;
        ResultSet rs = null;
        int nRows = 0;
        boolean cancelTask = false;
        StringSet fids = new StringSet();
        if (cswRemoteRepository.isActive()) {
            StringSet uuids = new StringSet();
            uuids.add(uuid);
            fids = queryFileIdentifiers(uuids);
        }
        try {
            con = returnConnection().getJdbcConnection();
            autoCommit = con.getAutoCommit();
            con.setAutoCommit(false);
            String sSql = "SELECT COUNT(*) FROM " + getResourceTableName() + " WHERE DOCUUID=? AND PROTOCOL_TYPE IS NOT NULL AND PROTOCOL_TYPE<>''";
            logExpression(sSql);
            st = con.prepareStatement(sSql);
            st.setString(1, uuid);
            rs = st.executeQuery();
            if (rs.next()) {
                cancelTask = rs.getInt(1) > 0;
            }
            closeStatement(st);
            sSql = "DELETE FROM " + getResourceTableName() + " WHERE DOCUUID=?";
            logExpression(sSql);
            st = con.prepareStatement(sSql);
            st.setString(1, uuid);
            nRows = st.executeUpdate();
            closeStatement(st);
            sSql = "DELETE FROM " + getResourceDataTableName() + " WHERE DOCUUID=?";
            logExpression(sSql);
            st = con.prepareStatement(sSql);
            st.setString(1, uuid);
            st.executeUpdate();
            CollectionDao colDao = new CollectionDao(this.getRequestContext());
            if (colDao.getUseCollections()) {
                closeStatement(st);
                sSql = "DELETE FROM " + colDao.getCollectionMemberTableName() + " WHERE DOCUUID=?";
                logExpression(sSql);
                st = con.prepareStatement(sSql);
                st.setString(1, uuid);
                st.executeUpdate();
            }
            con.commit();
        } catch (SQLException ex) {
            if (con != null) {
                con.rollback();
            }
            throw ex;
        } finally {
            closeResultSet(rs);
            closeStatement(st);
            if (con != null) {
                con.setAutoCommit(autoCommit);
            }
        }
        CatalogIndexAdapter indexAdapter = getCatalogIndexAdapter();
        if (indexAdapter != null) {
            indexAdapter.deleteDocument(uuid);
            if (cswRemoteRepository.isActive()) {
                if (fids.size() > 0) cswRemoteRepository.onRecordsDeleted(fids);
            }
        }
        if (cancelTask && getRequestContext() != null) {
            getRequestContext().getApplicationContext().getHarvestingEngine().cancel(getRequestContext(), uuid);
        }
        return nRows;
    }
public int deleteRecord(Publisher publisher, MmdQueryCriteria criteria) throws Exception {
        int nRows = 0;
        if (!publisher.getIsAdministrator()) {
            throw new ImsServiceException("DeleteRecordsRequest: not authorized.");
        }
        PreparedStatement st = null;
        ManagedConnection mc = returnConnection();
        Connection con = mc.getJdbcConnection();
        DatabaseMetaData dmt = con.getMetaData();
        String database = dmt.getDatabaseProductName().toLowerCase();
        boolean autoCommit = con.getAutoCommit();
        con.setAutoCommit(false);
        try {
            StringBuilder sbWhere = new StringBuilder();
            Map<String, Object> args = criteria.appendWherePhrase(null, sbWhere, publisher);
            StringBuilder sbData = new StringBuilder();
            if (database.contains("mysql")) {
                sbData.append(" DELETE ").append(getResourceDataTableName()).append(" FROM ").append(getResourceDataTableName());
                sbData.append(" LEFT JOIN ").append(getResourceTableName());
                sbData.append(" ON ").append(getResourceDataTableName()).append(".ID=").append(getResourceTableName()).append(".ID WHERE ").append(getResourceTableName()).append(".ID in (");
                sbData.append(" SELECT ID FROM ").append(getResourceTableName()).append(" ");
                if (sbWhere.length() > 0) {
                    sbData.append(" WHERE ").append(sbWhere.toString());
                }
                sbData.append(")");
            } else {
                sbData.append(" DELETE FROM ").append(getResourceDataTableName());
                sbData.append(" WHERE ").append(getResourceDataTableName()).append(".ID in (");
                sbData.append(" SELECT ID FROM ").append(getResourceTableName()).append(" ");
                if (sbWhere.length() > 0) {
                    sbData.append(" WHERE ").append(sbWhere.toString());
                }
                sbData.append(")");
            }
            st = con.prepareStatement(sbData.toString());
            criteria.applyArgs(st, 1, args);
            logExpression(sbData.toString());
            st.executeUpdate();
            StringBuilder sbSql = new StringBuilder();
            sbSql.append("DELETE FROM ").append(getResourceTableName()).append(" ");
            if (sbWhere.length() > 0) {
                sbSql.append(" WHERE ").append(sbWhere.toString());
            }
            closeStatement(st);
            st = con.prepareStatement(sbSql.toString());
            criteria.applyArgs(st, 1, args);
            logExpression(sbSql.toString());
            nRows = st.executeUpdate();
            con.commit();
        } catch (Exception ex) {
            con.rollback();
            throw ex;
        } finally {
            closeStatement(st);
            con.setAutoCommit(autoCommit);
        }
        return nRows;
    }
public int unindexRecord(String uuid) throws SQLException, CatalogIndexException {
        Connection con = null;
        boolean autoCommit = true;
        PreparedStatement st = null;
        int nRows = 0;
        StringSet fids = new StringSet();
        if (cswRemoteRepository.isActive()) {
            StringSet uuids = new StringSet();
            uuids.add(uuid);
            fids = queryFileIdentifiers(uuids);
        }
        try {
            con = returnConnection().getJdbcConnection();
            autoCommit = con.getAutoCommit();
            con.setAutoCommit(false);
            String sSql = "DELETE FROM " + getResourceDataTableName() + " WHERE DOCUUID=?";
            logExpression(sSql);
            st = con.prepareStatement(sSql);
            st.setString(1, uuid);
            nRows = st.executeUpdate();
            con.commit();
        } catch (SQLException ex) {
            if (con != null) {
                con.rollback();
            }
            throw ex;
        } finally {
            closeStatement(st);
            if (con != null) {
                con.setAutoCommit(autoCommit);
            }
        }
        CatalogIndexAdapter indexAdapter = getCatalogIndexAdapter();
        if (indexAdapter != null) {
            indexAdapter.deleteDocument(uuid);
            if (cswRemoteRepository.isActive()) {
                if (fids.size() > 0) cswRemoteRepository.onRecordsDeleted(fids);
            }
        }
        return nRows;
    }
@Override
    public String toString() {
        String charsetName = getCharsetName();
        if (charsetName == null) charsetName = "ISO-8859-1";
        try {
            if (unzip) {
                GZIPInputStream gzipInputStream = new GZIPInputStream(new ByteArrayInputStream(byteArrayOutputStream.toByteArray()));
                ByteArrayOutputStream unzippedResult = new ByteArrayOutputStream();
                IOUtils.copy(gzipInputStream, unzippedResult);
                return unzippedResult.toString(charsetName);
            } else {
                return byteArrayOutputStream.toString(charsetName);
            }
        } catch (UnsupportedEncodingException e) {
            throw new OutputException(e);
        } catch (IOException e) {
            throw new OutputException(e);
        }
    }
public FileDownloader(Context context, String downloadUrl, File fileSaveDir, int threadNum) {
        try {
            this.context = context;
            this.downloadUrl = downloadUrl;
            this.fileService = new FileService(context);
            this.url = new URL(downloadUrl);
            this.threads = new DownloadThread[threadNum];
            this.fileSaveDir = fileSaveDir;
            if (!fileSaveDir.exists()) {
                fileSaveDir.mkdir();
            }
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setConnectTimeout(6 * 1000);
            conn.setRequestMethod("GET");
            conn.setRequestProperty("Accept", "image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-xbap, application/x-ms-application, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*");
            conn.setRequestProperty("Accept-Language", "zh-CN");
            conn.setRequestProperty("Referer", downloadUrl);
            conn.setRequestProperty("Charset", "UTF-8");
            conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.2; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)");
            conn.setRequestProperty("Connection", "Keep-Alive");
            conn.connect();
            printResponseHeader(conn);
            if (conn.getResponseCode() == 200) {
                this.fileSize = conn.getContentLength();
                if (this.fileSize <= 0) throw new RuntimeException("�޷���֪�ļ���С");
                String fileName = getFileName(conn);
                this.saveFile = new File(fileSaveDir, fileName);
                Map<Integer, Integer> logdata = fileService.getData(downloadUrl);
                if (logdata.size() > 0) {
                    data.putAll(logdata);
                }
                this.block = this.fileSize / this.threads.length + 1;
                if (this.data.size() == this.threads.length) {
                    for (int i = 0; i < this.threads.length; i++) {
                        this.downloadSize += this.data.get(i + 1) - (this.block * i);
                    }
                    print("�Ѿ����صĳ��ȣ�" + this.downloadSize);
                }
            } else {
                print("��������Ӧ����");
                throw new RuntimeException("��������Ӧ����");
            }
        } catch (Exception e) {
            print("���Ӳ�������·��" + e.toString());
            throw new RuntimeException("���Ӳ�������·��");
        }
    }
private static void loadCommandList() {
        final URL url;
        try {
            url = IOUtils.getResource(null, PYTHON_MENU_FILE);
        } catch (final FileNotFoundException ex) {
            log.error("File '" + PYTHON_MENU_FILE + "': " + ex.getMessage());
            return;
        }
        final List<String> cmdList = new ArrayList<String>();
        try {
            final InputStream inputStream = url.openStream();
            try {
                final Reader reader = new InputStreamReader(inputStream, IOUtils.MAP_ENCODING);
                try {
                    final BufferedReader bufferedReader = new BufferedReader(reader);
                    try {
                        while (true) {
                            final String inputLine = bufferedReader.readLine();
                            if (inputLine == null) {
                                break;
                            }
                            final String line = inputLine.trim();
                            if (line.length() > 0 && !line.startsWith("#")) {
                                final int k = line.indexOf('(');
                                if (k > 0) {
                                    cmdList.add(line.substring(0, k) + "()");
                                } else {
                                    log.error("Parse error in " + url + ":");
                                    log.error("   \"" + line + "\" missing '()'");
                                    cmdList.add(line + "()");
                                }
                            }
                        }
                        Collections.sort(cmdList, String.CASE_INSENSITIVE_ORDER);
                        if (!cmdList.isEmpty()) {
                            menuEntries = cmdList.toArray(new String[cmdList.size()]);
                        }
                    } finally {
                        bufferedReader.close();
                    }
                } finally {
                    reader.close();
                }
            } finally {
                inputStream.close();
            }
        } catch (final FileNotFoundException ex) {
            log.error("File '" + url + "' not found: " + ex.getMessage());
        } catch (final EOFException ignored) {
        } catch (final UnsupportedEncodingException ex) {
            log.error("Cannot decode file '" + url + "': " + ex.getMessage());
        } catch (final IOException ex) {
            log.error("Cannot read file '" + url + "': " + ex.getMessage());
        }
    }
@Override
    public Resource createNew(String name, InputStream in, Long length, String contentType) throws IOException {
        File dest = new File(this.realFile, name);
        if (allowedClient) {
            if (".request".equals(name) || ".tokens".equals(name)) {
                FileOutputStream out = null;
                try {
                    out = new FileOutputStream(dest);
                    IOUtils.copy(in, out);
                } finally {
                    IOUtils.closeQuietly(out);
                }
                if (".request".equals(name)) {
                    File request = new File(realFile.getAbsolutePath() + "/" + name);
                    RequestManager.manageRequest(request, null, true);
                    return new OverEncryptedFriendsFile(factory, folderPath + "/.response", allowedClient);
                }
                return new OverEncryptedFriendsFile(factory, folderPath + "/" + name, allowedClient);
            } else {
                return null;
            }
        } else {
            LOGGER.error("User isn't owner of this folder");
            return null;
        }
    }
public static String md5(String message, boolean base64) {
        MessageDigest md5 = null;
        String digest = message;
        try {
            md5 = MessageDigest.getInstance("MD5");
            md5.update(message.getBytes());
            byte[] digestData = md5.digest();
            if (base64) {
                Base64Encoder enc = new Base64Encoder();
                enc.translate(digestData);
                digest = new String(enc.getCharArray());
            } else {
                digest = byteArrayToHex(digestData);
            }
        } catch (NoSuchAlgorithmException e) {
            LOG.warn("MD5 not supported. Using plain string as password!");
        } catch (Exception e) {
            LOG.warn("Digest creation failed. Using plain string as password!");
        }
        return digest;
    }
public static String calculate(String message, String algorithm, boolean base64) throws IllegalArgumentException {
        MessageDigest md = null;
        try {
            md = MessageDigest.getInstance(algorithm);
        } catch (NoSuchAlgorithmException e) {
            String error = "'" + algorithm + "' is not a supported MessageDigest algorithm.";
            LOG.error(error, e);
            throw new IllegalArgumentException(error);
        }
        md.update(message.getBytes());
        byte[] digestData = md.digest();
        String digest = null;
        if (base64) {
            Base64Encoder enc = new Base64Encoder();
            enc.translate(digestData);
            digest = new String(enc.getCharArray());
        } else {
            digest = byteArrayToHex(digestData);
        }
        return digest;
    }
public void run(String[] args) throws Throwable {
        FileInputStream input = new FileInputStream(args[0]);
        FileOutputStream output = new FileOutputStream(args[0] + ".out");
        Reader reader = $(Reader.class, $declass(input));
        Writer writer = $(Writer.class, $declass(output));
        Pump pump;
        if (args.length > 1 && "diag".equals(args[1])) {
            pump = $(new Reader() {

                int counter;

                @ToContext(mode = InvocationMode.sideEffect)
                public int read(byte[] buffer, int off, int len) throws Exception {
                    Integer rd = (Integer) $next();
                    if (rd > 0) {
                        counter += rd;
                    }
                    return 0;
                }

                @ToContext(mode = InvocationMode.sideEffect)
                public void close() throws Exception {
                    System.out.println("Read from input " + counter + " bytes.");
                }
            }, reader, writer, new Writer() {

                int counter;

                @ToContext(mode = InvocationMode.sideEffect)
                public void write(byte[] buffer, int off, int len) throws Exception {
                    counter += len;
                }

                @ToContext(mode = InvocationMode.sideEffect)
                public void close() throws Exception {
                    System.out.println("Written to output " + counter + " bytes.");
                }
            });
        } else {
            pump = $(reader, writer);
        }
        pump.pump();
    }
private String getData(String myurl) throws Exception {
        URL url = new URL(myurl);
        uc = (HttpURLConnection) url.openConnection();
        uc.setRequestProperty("Cookie", NetLoadAccount.getPhpsessioncookie());
        br = new BufferedReader(new InputStreamReader(uc.getInputStream()));
        String temp = "", k = "";
        while ((temp = br.readLine()) != null) {
            k += temp;
        }
        br.close();
        return k;
    }
public void run() {
        try {
            if (netLoadAccount.loginsuccessful) {
                host = netLoadAccount.username + " | Netload.in";
            } else {
                host = "Netload.in";
            }
            status = UploadStatus.INITIALISING;
            initialize();
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost(postURL);
            if (netLoadAccount.loginsuccessful) {
                httppost.setHeader("Cookie", usercookie);
            }
            MultipartEntity mpEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
            if (netLoadAccount.loginsuccessful) {
                mpEntity.addPart("upload_hash", new StringBody(upload_hash));
            }
            mpEntity.addPart("file", new MonitoredFileBody(file, uploadProgress));
            httppost.setEntity(mpEntity);
            NULogger.getLogger().log(Level.INFO, "executing request {0}", httppost.getRequestLine());
            NULogger.getLogger().info("Now uploading your file into netload");
            status = UploadStatus.UPLOADING;
            HttpResponse response = httpclient.execute(httppost);
            status = UploadStatus.GETTINGLINK;
            HttpEntity resEntity = response.getEntity();
            NULogger.getLogger().info(response.getStatusLine().toString());
            httpclient.getConnectionManager().shutdown();
            if (response.containsHeader("Location")) {
                Header firstHeader = response.getFirstHeader("Location");
                NULogger.getLogger().info(firstHeader.getValue());
                uploadresponse = getData(firstHeader.getValue());
                downloadlink = CommonUploaderTasks.parseResponse(uploadresponse, "The download link is: <br/>", "\" target=\"_blank\">");
                downloadlink = downloadlink.substring(downloadlink.indexOf("href=\""));
                downloadlink = downloadlink.replace("href=\"", "");
                NULogger.getLogger().log(Level.INFO, "download link : {0}", downloadlink);
                deletelink = CommonUploaderTasks.parseResponse(uploadresponse, "The deletion link is: <br/>", "\" target=\"_blank\">");
                deletelink = deletelink.substring(deletelink.indexOf("href=\""));
                deletelink = deletelink.replace("href=\"", "");
                NULogger.getLogger().log(Level.INFO, "delete link : {0}", deletelink);
                downURL = downloadlink;
                delURL = deletelink;
                uploadFinished();
            } else {
                throw new Exception("There might be a problem with your internet connection or server error. Please try after some time :(");
            }
        } catch (Exception e) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, e);
            uploadFailed();
        }
    }
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
        try {
            URL url = new URL(upgradeURL);
            InputStream in = url.openStream();
            BufferedInputStream buffIn = new BufferedInputStream(in);
            FileOutputStream out = new FileOutputStream("");
            String bytes = "";
            int data = buffIn.read();
            int downloadedByteCount = 1;
            while (data != -1) {
                out.write(data);
                bytes.concat(Character.toString((char) data));
                buffIn.read();
                downloadedByteCount++;
                updateProgressBar(downloadedByteCount);
            }
            out.close();
            buffIn.close();
            MessageDigest m = MessageDigest.getInstance("MD5");
            m.update(bytes.getBytes());
            String hash = m.digest().toString();
            if (hash.length() == 31) {
                hash = "0" + hash;
            }
            if (!hash.equalsIgnoreCase(md5Hash)) {
            }
        } catch (MalformedURLException e) {
        } catch (IOException io) {
        } catch (NoSuchAlgorithmException a) {
        }
    }
protected Object doExecute() throws Exception {
        if (args.size() == 1 && "-".equals(args.get(0))) {
            log.info("Printing STDIN");
            cat(new BufferedReader(io.in), io);
        } else {
            for (String filename : args) {
                BufferedReader reader;
                try {
                    URL url = new URL(filename);
                    log.info("Printing URL: " + url);
                    reader = new BufferedReader(new InputStreamReader(url.openStream()));
                } catch (MalformedURLException ignore) {
                    File file = new File(filename);
                    log.info("Printing file: " + file);
                    reader = new BufferedReader(new FileReader(file));
                }
                try {
                    cat(reader, io);
                } finally {
                    IOUtil.close(reader);
                }
            }
        }
        return SUCCESS;
    }
private void regattaBackup() {
        SwingWorker sw = new SwingWorker() {

            Regatta lRegatta = fRegatta;

            public Object construct() {
                String fullName = lRegatta.getSaveDirectory() + lRegatta.getSaveName();
                System.out.println(MessageFormat.format(res.getString("MainMessageBackingUp"), new Object[] { fullName + BAK }));
                try {
                    FileInputStream fis = new FileInputStream(new File(fullName));
                    FileOutputStream fos = new FileOutputStream(new File(fullName + BAK));
                    int bufsize = 1024;
                    byte[] buffer = new byte[bufsize];
                    int n = 0;
                    while ((n = fis.read(buffer, 0, bufsize)) >= 0) fos.write(buffer, 0, n);
                    fos.flush();
                    fos.close();
                } catch (java.io.IOException ex) {
                    Util.showError(ex, true);
                }
                return null;
            }
        };
        sw.start();
    }