semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public void alterarQuestaoMultiplaEscolha(QuestaoMultiplaEscolha q) throws SQLException {
        PreparedStatement stmt = null;
        String sql = "UPDATE multipla_escolha SET texto=?, gabarito=? WHERE id_questao=?";
        try {
            for (Alternativa alternativa : q.getAlternativa()) {
                stmt = conexao.prepareStatement(sql);
                stmt.setString(1, alternativa.getTexto());
                stmt.setBoolean(2, alternativa.getGabarito());
                stmt.setInt(3, q.getIdQuestao());
                stmt.executeUpdate();
                conexao.commit();
            }
        } catch (SQLException e) {
            conexao.rollback();
            throw e;
        }
    }
@Override
    public void excluir(QuestaoMultiplaEscolha q) throws Exception {
        PreparedStatement stmt = null;
        String sql = "DELETE FROM questao WHERE id_questao=?";
        try {
            stmt = conexao.prepareStatement(sql);
            stmt.setInt(1, q.getIdQuestao());
            stmt.executeUpdate();
            conexao.commit();
        } catch (SQLException e) {
            conexao.rollback();
            throw e;
        }
    }
public void openAndClose(ZKEntry zke, LinkedList toOpen, LinkedList toRemove) throws SQLException {
        conn.setAutoCommit(false);
        try {
            Statement stm = conn.createStatement();
            ResultSet rset = stm.executeQuery("SELECT now();");
            rset.next();
            Timestamp now = rset.getTimestamp("now()");
            for (int i = 0; i < toRemove.size(); i++) {
                Workitem wi = (Workitem) toRemove.get(i);
                rset = stm.executeQuery("SELECT intime, part FROM stampzk WHERE stampzkid = '" + wi.getStampZkId() + "';");
                rset.next();
                long diff = now.getTime() - rset.getLong("intime");
                float diffp = diff * rset.getFloat("part");
                stm.executeUpdate("UPDATE stampzk SET outtime='" + now.getTime() + "', diff='" + diff + "', diffp='" + diffp + "' WHERE stampzkid='" + wi.getStampZkId() + "';");
            }
            rset = stm.executeQuery("SELECT COUNT(*) FROM stampzk WHERE personalid='" + zke.getWorker().getPersonalId() + "' AND outtime='0';");
            rset.next();
            int count = rset.getInt("COUNT(*)") + toOpen.size();
            rset = stm.executeQuery("SELECT * FROM stampzk WHERE personalid='" + zke.getWorker().getPersonalId() + "' AND outtime='0';");
            while (rset.next()) {
                long diff = now.getTime() - rset.getLong("intime");
                float diffp = diff * rset.getFloat("part");
                int firstId = rset.getInt("firstid");
                if (firstId == 0) firstId = rset.getInt("stampzkid");
                Statement ust = conn.createStatement();
                ust.executeUpdate("UPDATE stampzk SET outtime='" + now.getTime() + "', diff='" + diff + "', diffp='" + diffp + "' WHERE stampzkid='" + rset.getInt("stampzkid") + "';");
                ust.executeUpdate("INSERT INTO stampzk SET zeitkid='" + rset.getInt("zeitkid") + "', personalid='" + zke.getWorker().getPersonalId() + "', funcsid='" + rset.getInt("funcsid") + "', part='" + (float) 1f / count + "', intime='" + now.getTime() + "', firstid='" + firstId + "';");
            }
            for (int i = 0; i < toOpen.size(); i++) {
                stm.executeUpdate("INSERT INTO stampzk SET zeitkid='" + zke.getZeitKId() + "', personalid='" + zke.getWorker().getPersonalId() + "', intime='" + now.getTime() + "', funcsid='" + ((Workitem) toOpen.get(i)).getWorkType() + "', part='" + (float) 1f / count + "';");
            }
        } catch (SQLException sqle) {
            conn.rollback();
            conn.setAutoCommit(true);
            throw sqle;
        }
        conn.commit();
        conn.setAutoCommit(true);
    }
private boolean downloadFile(Proxy proxy, URL url, File file) {
        try {
            URLConnection conn = null;
            if (null == proxy) {
                conn = url.openConnection();
            } else {
                conn = url.openConnection(proxy);
            }
            conn.connect();
            File destFile = new File(file.getAbsolutePath() + ".update");
            ;
            FileOutputStream fos = new FileOutputStream(destFile);
            byte[] buffer = new byte[2048];
            while (true) {
                int len = conn.getInputStream().read(buffer);
                if (len < 0) {
                    break;
                } else {
                    fos.write(buffer, 0, len);
                }
            }
            fos.close();
            file.delete();
            destFile.renameTo(file);
            return true;
        } catch (Exception e) {
            logger.error("Failed to get remote hosts file.", e);
        }
        return false;
    }
public static final String convertPassword(final String srcPwd) {
        StringBuilder out;
        MessageDigest md;
        byte[] byteValues;
        byte singleChar = 0;
        try {
            md = MessageDigest.getInstance("MD5");
            md.update(srcPwd.getBytes());
            byteValues = md.digest();
            if ((byteValues == null) || (byteValues.length <= 0)) {
                return null;
            }
            out = new StringBuilder(byteValues.length * 2);
            for (byte element : byteValues) {
                singleChar = (byte) (element & 0xF0);
                singleChar = (byte) (singleChar >>> 4);
                singleChar = (byte) (singleChar & 0x0F);
                out.append(PasswordConverter.ENTRIES[singleChar]);
                singleChar = (byte) (element & 0x0F);
                out.append(PasswordConverter.ENTRIES[singleChar]);
            }
            return out.toString();
        } catch (final NoSuchAlgorithmException e) {
            e.printStackTrace();
            return null;
        }
    }
public String report() {
        if (true) return "-";
        StringBuffer parameter = new StringBuffer("?");
        if (getRecord_ID() == 0) return "ID=0";
        if (getRecord_ID() == 1) {
            parameter.append("ISSUE=");
            HashMap htOut = get_HashMap();
            try {
                ByteArrayOutputStream bOut = new ByteArrayOutputStream();
                ObjectOutput oOut = new ObjectOutputStream(bOut);
                oOut.writeObject(htOut);
                oOut.flush();
                String hexString = Secure.convertToHexString(bOut.toByteArray());
                parameter.append(hexString);
            } catch (Exception e) {
                log.severe(e.getLocalizedMessage());
                return "New-" + e.getLocalizedMessage();
            }
        } else {
            try {
                parameter.append("RECORDID=").append(getRecord_ID());
                parameter.append("&DBADDRESS=").append(URLEncoder.encode(getDBAddress(), "UTF-8"));
                parameter.append("&COMMENTS=").append(URLEncoder.encode(getComments(), "UTF-8"));
            } catch (Exception e) {
                log.severe(e.getLocalizedMessage());
                return "Update-" + e.getLocalizedMessage();
            }
        }
        InputStreamReader in = null;
        String target = "http://dev1/wstore/issueReportServlet";
        try {
            StringBuffer urlString = new StringBuffer(target).append(parameter);
            URL url = new URL(urlString.toString());
            URLConnection uc = url.openConnection();
            in = new InputStreamReader(uc.getInputStream());
        } catch (Exception e) {
            String msg = "Cannot connect to http://" + target;
            if (e instanceof FileNotFoundException || e instanceof ConnectException) msg += "\nServer temporarily down - Please try again later"; else {
                msg += "\nCheck connection - " + e.getLocalizedMessage();
                log.log(Level.FINE, msg);
            }
            return msg;
        }
        return readResponse(in);
    }
public void doAction() throws MalformedURLException, IOException, Exception {
        URL url = new URL(CheckNewVersionAction.VERSION_FILE);
        InputStream is = url.openStream();
        byte[] buffer = Utils.loadBytes(is);
        is.close();
        String version = new String(buffer);
        if (version != null) {
            version = version.substring(0, version.lastIndexOf("\n") == -1 ? version.length() : version.lastIndexOf("\n"));
        }
        hasNewVersion = !DAOSystem.getSystem().getVersion().equals(version);
    }
public void sendResponse(DjdocRequest req, HttpServletResponse res) throws IOException {
        File file = (File) req.getResult();
        InputStream in = null;
        try {
            in = new FileInputStream(file);
            IOUtils.copy(in, res.getOutputStream());
        } finally {
            if (in != null) {
                in.close();
            }
        }
    }
public void run() {
        try {
            URL read = null;
            if (_readURL.indexOf("?") >= 0) {
                read = new URL(_readURL + "&id=" + _id);
            } else {
                read = new URL(_readURL + "?id=" + _id);
            }
            while (_keepGoing) {
                String line;
                while ((line = _in.readLine()) != null) {
                    ConnectionHandlerLocal.DEBUG("< " + line);
                    _linesRead++;
                    _listener.incomingMessage(line);
                }
                if (_linesRead == 0) {
                    shutdown(true);
                    return;
                }
                if (_keepGoing) {
                    URLConnection urlConn = read.openConnection();
                    urlConn.setUseCaches(false);
                    _in = new DataInputStream(urlConn.getInputStream());
                    _linesRead = 0;
                }
            }
            System.err.println("HttpReaderThread: stopping gracefully.");
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            shutdown(true);
        }
    }
private void initialize() {
            List providers = new ArrayList();
            while (this.urls.hasMoreElements()) {
                URL url = (URL) this.urls.nextElement();
                try {
                    BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream(), "UTF-8"));
                    String line = null;
                    while ((line = reader.readLine()) != null) {
                        String provider = uncommentLine(line).trim();
                        if (provider != null && provider.length() > 0) {
                            providers.add(provider);
                        }
                    }
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            this.iterator = providers.iterator();
        }
public NodeId generateTopicId(String topicName) {
        MessageDigest md = null;
        try {
            md = MessageDigest.getInstance("SHA");
        } catch (NoSuchAlgorithmException e) {
            System.err.println("No SHA support!");
        }
        if (m_ready) System.out.println("Scribe is ready at" + getNodeId() + " , topic is " + topicName);
        md.update(topicName.getBytes());
        byte[] digest = md.digest();
        NodeId newId = new NodeId(digest);
        return newId;
    }
private static Properties loadPropertiesFromClasspath(String path) {
        Enumeration<URL> locations;
        Properties props = new Properties();
        try {
            locations = Thread.currentThread().getContextClassLoader().getResources(path);
            while (locations.hasMoreElements()) {
                URL url = locations.nextElement();
                InputStream in = url.openStream();
                props.load(in);
                in.close();
                logger.config("Load properties from " + url);
            }
        } catch (IOException e) {
            logger.log(Level.SEVERE, "load properties from classpath \"" + path + "\" failed", e);
        }
        return props;
    }
public static void copyResource(String args) {
        try {
            URL url = copyURL.class.getResource(args);
            InputStream is = url.openStream();
            System.out.flush();
            FileOutputStream fos = null;
            fos = new FileOutputStream(System.getProperty("user.home") + "/JavaCPC/" + args);
            int oneChar, count = 0;
            while ((oneChar = is.read()) != -1) {
                fos.write(oneChar);
                count++;
            }
            is.close();
            fos.close();
        } catch (MalformedURLException e) {
            System.err.println(e.toString());
        } catch (IOException e) {
            System.err.println(e.toString());
        }
    }
private String determineGuardedHtml() {
        StringBuffer buf = new StringBuffer();
        if (m_guardedButtonPresent) {
            buf.append("\n<span id='" + getHtmlIdPrefix() + PUSH_PAGE_SUFFIX + "' style='display:none'>\n");
            String location = m_guardedHtmlLocation != null ? m_guardedHtmlLocation : (String) Config.getProperty(Config.PROP_PRESENTATION_DEFAULT_GUARDED_HTML_LOCATION);
            String html = (String) c_guardedHtmlCache.get(location);
            if (html == null) {
                if (log.isDebugEnabled()) log.debug(this.NAME + ".determineGuardedHtml: Reading the Guarded Html Fragment: " + location);
                URL url = getUrl(location);
                if (url != null) {
                    BufferedReader in = null;
                    try {
                        in = new BufferedReader(new InputStreamReader(url.openStream()));
                        StringBuffer buf1 = new StringBuffer();
                        String line = null;
                        while ((line = in.readLine()) != null) {
                            buf1.append(line);
                            buf1.append('\n');
                        }
                        html = buf1.toString();
                    } catch (IOException e) {
                        log.warn(this.NAME + ".determineGuardedHtml: Failed to read the Guarded Html Fragment: " + location, e);
                    } finally {
                        try {
                            if (in != null) in.close();
                        } catch (IOException ex) {
                            log.warn(this.NAME + ".determineGuardedHtml: Failed to close the Guarded Html Fragment: " + location, ex);
                        }
                    }
                } else {
                    log.warn("Failed to read the Guarded Html Fragment: " + location);
                }
                if (html == null) html = "Transaction in Progress";
                c_guardedHtmlCache.put(location, html);
            }
            buf.append(html);
            buf.append("\n</span>\n");
        }
        return buf.toString();
    }
@Override
    public Reader openReader(final Charset charset) throws LocatorException {
        try {
            if (charset != null) {
                return new InputStreamReader(url.openStream(), charset);
            }
            return new InputStreamReader(url.openStream());
        } catch (final IOException e) {
            throw new LocatorException("Failed to read from URL: " + url, e);
        }
    }
@Override
    public void readMessages(final Messages messages) throws LocatorException {
        try {
            final InputStream in = url.openStream();
            try {
                final Properties properties = new Properties();
                properties.load(in);
                messages.add(locale, properties);
            } finally {
                in.close();
            }
        } catch (final IOException e) {
            throw new LocatorException("Failed to read messages from URL: " + url, e);
        }
    }
private static List runITQLQuery(String itqlQuery) throws Exception {
        String escapedItqlQuery = URLEncoder.encode(itqlQuery, "UTF-8");
        String url = "http://" + Config.getProperty("FEDORA_SOAP_HOST") + ":" + Config.getProperty("FEDORA_SOAP_ACCESS_PORT") + "/fedora/risearch?type=tuples" + "&lang=iTQL" + "&format=CSV" + "&distinct=on" + "&stream=on" + "&query=" + escapedItqlQuery;
        logger.debug("url for risearch query: " + url);
        URL urlObject = new URL(url);
        HttpURLConnection con = (HttpURLConnection) urlObject.openConnection();
        BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()));
        logger.debug("response code: " + con.getResponseCode());
        if (con.getResponseCode() != 200 && con.getResponseCode() != 302) {
            throw new FedoraAccessException("Could not access the risearch service at url: " + url);
        }
        ArrayList arrayList = new ArrayList();
        String inputLine;
        int counter = 0;
        while ((inputLine = br.readLine()) != null) {
            logger.debug("reading line:" + inputLine);
            if (inputLine.indexOf("<html>") >= 0) {
                logger.error("problem quering the relationship");
                throw new Exception("Problem querying relationships; probably a bad ITQL query:" + itqlQuery);
            }
            if (counter >= 1 && inputLine.indexOf("/") >= 0 && inputLine.trim().length() > 0) {
                logger.debug("adding line:" + inputLine);
                inputLine = inputLine.substring(inputLine.indexOf("/") + 1);
                arrayList.add(inputLine);
                logger.debug("found relationship to item: " + inputLine);
            }
            counter++;
        }
        br.close();
        logger.debug("num relationships found: " + arrayList.size());
        return arrayList;
    }
private InputStream getPageStream(String query) throws MalformedURLException, IOException {
        URL url = new URL(baseUrl + query + "&rhtml=no");
        URLConnection connection = url.openConnection();
        connection.connect();
        InputStream in = connection.getInputStream();
        BufferedInputStream bis = new BufferedInputStream(in);
        return bis;
    }
public static Search Search(String searchString) throws Exception {
        Uri.Builder builder = new Uri.Builder();
        builder.scheme("http");
        builder.authority("www.goodreads.com");
        builder.path("search/search");
        builder.appendQueryParameter("format", "xml");
        builder.appendQueryParameter("key", _ConsumerKey);
        builder.appendQueryParameter("q", searchString);
        HttpClient httpClient = new DefaultHttpClient();
        HttpGet getSearchResponse = new HttpGet(builder.build().toString());
        HttpResponse searchResponse = httpClient.execute(getSearchResponse);
        Response searchResponseData = ResponseParser.parse(searchResponse.getEntity().getContent());
        return searchResponseData.get_Search();
    }
public static Book GetReviewsForBook(String bookId, int page) throws Exception {
        Uri.Builder builder = new Uri.Builder();
        builder.scheme("http");
        builder.authority("www.goodreads.com");
        builder.path("book/show");
        builder.appendQueryParameter("key", _ConsumerKey);
        builder.appendQueryParameter("page", Integer.toString(page));
        builder.appendQueryParameter("id", bookId);
        builder.appendQueryParameter("format", "xml");
        HttpClient httpClient = new DefaultHttpClient();
        HttpGet getRequest = new HttpGet(builder.build().toString());
        if (get_IsAuthenticated()) {
            _Consumer.sign(getRequest);
        }
        HttpResponse response = httpClient.execute(getRequest);
        Response responseData = ResponseParser.parse(response.getEntity().getContent());
        return responseData.get_Book();
    }
public static Book GetReviewsForBook(String bookId, int page, int rating) throws Exception {
        Uri.Builder builder = new Uri.Builder();
        builder.scheme("http");
        builder.authority("www.goodreads.com");
        builder.path("book/show");
        builder.appendQueryParameter("key", _ConsumerKey);
        builder.appendQueryParameter("page", Integer.toString(page));
        builder.appendQueryParameter("rating", Integer.toString(rating));
        builder.appendQueryParameter("id", bookId);
        HttpClient httpClient = new DefaultHttpClient();
        HttpGet getRequest = new HttpGet(builder.build().toString());
        if (get_IsAuthenticated()) {
            _Consumer.sign(getRequest);
        }
        HttpResponse response = httpClient.execute(getRequest);
        Response responseData = ResponseParser.parse(response.getEntity().getContent());
        return responseData.get_Book();
    }
public static Author GetBooksByAuthor(String authorId, int page) throws Exception {
        Uri.Builder builder = new Uri.Builder();
        builder.scheme("http");
        builder.authority("www.goodreads.com");
        builder.path("author/list/" + authorId + ".xml");
        builder.appendQueryParameter("key", _ConsumerKey);
        builder.appendQueryParameter("page", Integer.toString(page));
        HttpClient httpClient = new DefaultHttpClient();
        HttpGet getResponse = new HttpGet(builder.build().toString());
        HttpResponse response = httpClient.execute(getResponse);
        Response responseData = ResponseParser.parse(response.getEntity().getContent());
        return responseData.get_Author();
    }
private String getFullScreenUrl() {
        progressDown.setIndeterminate(true);
        System.out.println("Har: " + ytUrl);
        String u = ytUrl;
        URLConnection conn = null;
        String line = null;
        String data = "";
        String fullUrl = "";
        try {
            URL url = new URL(u);
            conn = url.openConnection();
            conn.setDoOutput(true);
            BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            while ((line = rd.readLine()) != null) {
                if (line.contains("fullscreenUrl")) {
                    data = line.trim();
                }
            }
            rd.close();
            System.out.println(data);
            int start = 0;
            String[] lines = data.split("&");
            String[] tmp = null;
            String video_id = null;
            String t = null;
            String title = null;
            for (int i = 0; i < lines.length; i++) {
                if (lines[i].startsWith("video_id=")) {
                    tmp = lines[i].split("=");
                    video_id = tmp[1];
                }
                if (lines[i].startsWith("t=")) {
                    tmp = lines[i].split("=");
                    t = tmp[1];
                }
                if (lines[i].startsWith("title=")) {
                    tmp = lines[i].split("=");
                    title = tmp[1].substring(0, (tmp[1].length() - 2));
                }
                System.out.println(lines[i]);
            }
            System.out.println("So we got...");
            System.out.println("video_id: " + video_id);
            System.out.println("t: " + t);
            System.out.println("title: " + title);
            ytTitle = title;
            fullUrl = "http://www.youtube.com/get_video.php?video_id=" + video_id + "&t=" + t;
        } catch (Exception e) {
            System.err.println("Error: " + e.getLocalizedMessage());
        }
        progressDown.setIndeterminate(false);
        return fullUrl;
    }