semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public void rename(String virtualWiki, String oldTopicName, String newTopicName) throws Exception {
        Connection conn = DatabaseConnection.getConnection();
        try {
            boolean commit = false;
            conn.setAutoCommit(false);
            try {
                PreparedStatement pstm = conn.prepareStatement(STATEMENT_RENAME);
                try {
                    pstm.setString(1, newTopicName);
                    pstm.setString(2, oldTopicName);
                    pstm.setString(3, virtualWiki);
                    if (pstm.executeUpdate() == 0) throw new SQLException("Unable to rename topic " + oldTopicName + " on wiki " + virtualWiki);
                } finally {
                    pstm.close();
                }
                doUnlockTopic(conn, virtualWiki, oldTopicName);
                doRenameAllVersions(conn, virtualWiki, oldTopicName, newTopicName);
                commit = true;
            } finally {
                if (commit) conn.commit(); else conn.rollback();
            }
        } finally {
            conn.close();
        }
    }
public void testAuthentication() throws Exception {
        String host = "localhost";
        int port = 8080;
        URL url = new URL("http://" + host + ":" + port + "/");
        URLConnection connection = url.openConnection();
        InputStream in = connection.getInputStream();
        in.close();
        server.invoke(name, "stop", null, null);
        server.setAttribute(name, new Attribute("AuthenticationMethod", "basic"));
        server.invoke(name, "addAuthorization", new Object[] { "openjmx", "openjmx" }, new String[] { "java.lang.String", "java.lang.String" });
        server.invoke(name, "start", null, null);
        url = new URL("http://" + host + ":" + port + "/");
        connection = url.openConnection();
        in = connection.getInputStream();
        in.close();
        assertEquals(((HttpURLConnection) connection).getResponseCode(), 401);
        url = new URL("http://" + host + ":" + port + "/");
        connection = url.openConnection();
        connection.setRequestProperty("Authorization", "basic b3BlbmpteDpvcGVuam14");
        in = connection.getInputStream();
        in.close();
        server.invoke(name, "stop", null, null);
        server.setAttribute(name, new Attribute("AuthenticationMethod", "none"));
    }
@SuppressWarnings("unchecked")
    public List<Event> lookupFutureEvents(String groupIdentifier) throws GtugsException {
        StringBuilder json = new StringBuilder();
        String requestUrl = "http://api.meetup.com/events.json/?group_urlname=" + groupIdentifier + "&key=" + key;
        try {
            URL url = new URL(requestUrl.toString());
            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
            String inputLine;
            while ((inputLine = in.readLine()) != null) {
                json.append(inputLine);
            }
            in.close();
        } catch (IOException e) {
            throw new GtugsException(e);
        }
        List<Event> events = new ArrayList<Event>();
        JSONObject jsonObj = (JSONObject) JSONValue.parse(json.toString());
        JSONArray results = (JSONArray) jsonObj.get("results");
        for (int i = 0; i < results.size(); i++) {
            JSONObject result = (JSONObject) results.get(i);
            Event e = new Event();
            e.setAttendeeCount(Integer.parseInt((String) result.get("rsvpcount")));
            e.setCity((String) result.get("venue_city"));
            e.setDescription((String) result.get("description"));
            e.setLatitude(Double.parseDouble((String) result.get("venue_lat")));
            e.setLongitude(Double.parseDouble((String) result.get("venue_lon")));
            e.setName((String) result.get("name"));
            Date myDate = null;
            String time = (String) result.get("time");
            try {
                myDate = meetupDateFormat.parse(time);
                e.setStartTime(timeDateFormat.format(myDate));
                e.setEndTime(timeDateFormat.format(myDate));
                e.setStartDate(myDate);
                e.setEndDate(myDate);
                String tz = tzDateFormat.format(myDate);
                if (tz != null && tz.startsWith("+")) {
                    tz = tz.substring(1);
                }
                e.setTimeZone(Integer.toString(Integer.parseInt(tz) / 100));
            } catch (ParseException ex) {
                ex.printStackTrace();
                continue;
            }
            e.setState((String) result.get("venue_state"));
            StringBuilder addressBuilder = new StringBuilder();
            if (result.get("venue_address1") != null) {
                addressBuilder.append((String) result.get("venue_address1") + " ");
            }
            if (result.get("venue_address2") != null) {
                addressBuilder.append((String) result.get("venue_address2") + " ");
            }
            if (result.get("venue_address3") != null) {
                addressBuilder.append((String) result.get("venue_address3") + " ");
            }
            if (result.get("venue_address4") != null) {
                addressBuilder.append((String) result.get("venue_address4"));
            }
            e.setStreetAddress(addressBuilder.toString().trim());
            e.setZipCode((String) result.get("venue_zip"));
            e.setUrl((String) result.get("event_url"));
            events.add(e);
        }
        return events;
    }
public static void copyFile(File sourceFile, File destFile) throws IOException {
        InputStream is = null;
        OutputStream os = null;
        try {
            is = new FileInputStream(sourceFile);
            os = new FileOutputStream(destFile);
            IOUtils.copy(is, os);
        } finally {
            try {
                if (os != null) os.close();
            } catch (Exception e) {
            }
            try {
                if (is != null) is.close();
            } catch (Exception e) {
            }
        }
    }
public static void copyWithClose(InputStream is, OutputStream os) throws IOException {
        try {
            IOUtils.copy(is, os);
        } catch (IOException ioe) {
            try {
                if (os != null) os.close();
            } catch (Exception e) {
            }
            try {
                if (is != null) is.close();
            } catch (Exception e) {
            }
        }
    }
public static Object fetchCached(String address, int hours) throws MalformedURLException, IOException {
        String cacheName = md5(address);
        checkAndCreateDirectoryIfNeeded();
        File r = new File(CACHELOCATION + cacheName);
        Date d = new Date();
        long limit = d.getTime() - (1000 * 60 * 60 * hours);
        if (!r.exists() || (hours != -1 && r.lastModified() < limit)) {
            InputStream is = (InputStream) fetch(address);
            FileOutputStream fos = new FileOutputStream(CACHELOCATION + cacheName);
            int nextChar;
            while ((nextChar = is.read()) != -1) fos.write((char) nextChar);
            fos.flush();
        }
        FileInputStream fis = new FileInputStream(CACHELOCATION + cacheName);
        return fis;
    }
public static Drawable fetchCachedDrawable(String url) throws MalformedURLException, IOException {
        Log.d(LOG_TAG, "Fetching cached : " + url);
        String cacheName = md5(url);
        checkAndCreateDirectoryIfNeeded();
        File r = new File(CACHELOCATION + cacheName);
        if (!r.exists()) {
            InputStream is = (InputStream) fetch(url);
            FileOutputStream fos = new FileOutputStream(CACHELOCATION + cacheName);
            int nextChar;
            while ((nextChar = is.read()) != -1) fos.write((char) nextChar);
            fos.flush();
        }
        FileInputStream fis = new FileInputStream(CACHELOCATION + cacheName);
        Drawable d = Drawable.createFromStream(fis, "src");
        return d;
    }
public static String md5(String str) {
        try {
            MessageDigest digest = java.security.MessageDigest.getInstance("MD5");
            digest.update(str.getBytes());
            byte messageDigest[] = digest.digest();
            StringBuffer hexString = new StringBuffer();
            for (int i = 0; i < messageDigest.length; i++) hexString.append(Integer.toHexString(0xFF & messageDigest[i]));
            String md5 = hexString.toString();
            Log.v(FileUtil.class.getName(), md5);
            return md5;
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return "";
    }
private void copy(final File file) throws IOException {
        String targetFilename = targetFilename(file);
        FileInputStream fis = new FileInputStream(file);
        try {
            FileChannel source = fis.getChannel();
            try {
                FileOutputStream fos = new FileOutputStream(targetFilename);
                try {
                    FileChannel target = fos.getChannel();
                    try {
                        target.transferFrom(source, 0, source.size());
                    } finally {
                        target.close();
                    }
                } finally {
                    fos.close();
                }
            } finally {
                source.close();
            }
        } finally {
            fis.close();
        }
    }
public void run() {
        InputStreamReader in = null;
        OutputStreamWriter out = null;
        URL url = null;
        File net_file = null;
        long in_length = 0;
        progress_bar.setValue(0);
        progress_bar.setString("connecting!");
        progress_bar.setStringPainted(true);
        if (sync_host_path_name.length() > 0) {
            try {
                try {
                    if (protocol == Settings.protFTP) {
                        url = new URL("ftp://" + user_name + ":" + password + "@" + sync_host_path_name);
                        URLConnection connection = url.openConnection();
                        in = new InputStreamReader(connection.getInputStream());
                        in_length = connection.getContentLength();
                    } else {
                        net_file = new File(sync_host_path_name);
                        in = new InputStreamReader(new FileInputStream(net_file), "US-ASCII");
                        in_length = net_file.length();
                    }
                    progress_bar.setString("synchronising!");
                    EventMemory.get_instance(null).import_vCalendar(in, Math.max(in_length, 1), true, progress_bar);
                    in.close();
                } catch (Exception x) {
                    progress_bar.setString(x.getMessage());
                }
                progress_bar.setValue(0);
                progress_bar.setString("connecting!");
                if (protocol == Settings.protFTP) {
                    URLConnection connection = url.openConnection();
                    connection.setDoOutput(true);
                    out = new OutputStreamWriter(connection.getOutputStream(), "US-ASCII");
                } else if (protocol == Settings.protFile) {
                    out = new OutputStreamWriter(new FileOutputStream(net_file), "US-ASCII");
                }
                progress_bar.setString("writing!");
                int[] i = new int[EventMemory.get_instance(null).get_size()];
                for (int k = 0; k < i.length; k++) {
                    i[k] = k;
                }
                progress_bar.setStringPainted(true);
                EventMemory.get_instance(null).export_vCalendar(out, i, true, progress_bar, true);
                out.close();
                sync_dialog.sync_panel.unlock_input();
                sync_dialog.dispose();
            } catch (Exception e) {
                progress_bar.setString(e.getMessage());
                sync_dialog.sync_panel.unlock_input();
            }
        } else {
            progress_bar.setString("enter a valid URL!");
            sync_dialog.sync_panel.unlock_input();
        }
    }
public void run() {
        logger.info("downloading '" + url.toString() + "' to: " + dstFile.getAbsolutePath());
        Preferences prefs = Preferences.userRoot().node("gvsig.downloader");
        int timeout = prefs.getInt("timeout", 60000);
        DataOutputStream dos;
        try {
            DataInputStream is;
            OutputStreamWriter os = null;
            HttpURLConnection connection = null;
            if (url.getProtocol().equals("https")) {
                disableHttsValidation();
            }
            connection = (HttpURLConnection) url.openConnection();
            connection.setConnectTimeout(timeout);
            if (data != null) {
                connection.setRequestProperty("SOAPAction", "post");
                connection.setRequestMethod("POST");
                connection.setDoOutput(true);
                connection.setRequestProperty("Content-Type", "text/xml; charset=UTF-8");
                os = new OutputStreamWriter(connection.getOutputStream());
                os.write(data);
                os.flush();
                is = new DataInputStream(connection.getInputStream());
            } else {
                is = new DataInputStream(url.openStream());
            }
            dos = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(dstFile)));
            byte[] buffer = new byte[1024 * 4];
            long readed = 0;
            for (int i = is.read(buffer); !Utilities.getCanceled(groupID) && i > 0; i = is.read(buffer)) {
                dos.write(buffer, 0, i);
                readed += i;
            }
            if (os != null) {
                os.close();
            }
            dos.close();
            is.close();
            is = null;
            dos = null;
            if (Utilities.getCanceled(groupID)) {
                logger.warning("[RemoteServices] '" + url + "' CANCELED.");
                dstFile.delete();
                dstFile = null;
            } else {
                Utilities.addDownloadedURL(url, dstFile.getAbsolutePath());
            }
        } catch (Exception e) {
            e.printStackTrace();
            Utilities.downloadException = e;
        }
    }
private void innerJob(String inFrom, String inTo, String line, Map<String, Match> result) throws UnsupportedEncodingException, IOException {
        String subline = line.substring(line.indexOf(inTo) + inTo.length());
        String tempStr = subline.substring(subline.indexOf(inFrom) + inFrom.length(), subline.indexOf(inTo));
        String inURL = "http://goal.2010worldcup.163.com/data/match/general/" + tempStr.substring(tempStr.indexOf("/") + 1) + ".xml";
        URL url = new URL(inURL);
        BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream(), "utf-8"));
        String inLine = null;
        String scoreFrom = "score=\"";
        String homeTo = "\" side=\"Home";
        String awayTo = "\" side=\"Away";
        String goalInclud = "Stat";
        String playerFrom = "playerId=\"";
        String playerTo = "\" position=";
        String timeFrom = "time=\"";
        String timeTo = "\" period";
        String teamFinish = "</Team>";
        boolean homeStart = false;
        boolean awayStart = false;
        while ((inLine = reader.readLine()) != null) {
            if (inLine.indexOf(teamFinish) != -1) {
                homeStart = false;
                awayStart = false;
            }
            if (inLine.indexOf(homeTo) != -1) {
                result.get(key).setHomeScore(inLine.substring(inLine.indexOf(scoreFrom) + scoreFrom.length(), inLine.indexOf(homeTo)));
                homeStart = true;
            }
            if (homeStart && inLine.indexOf(goalInclud) != -1) {
                MatchEvent me = new MatchEvent();
                me.setPlayerName(getPlayerName(inLine.substring(inLine.indexOf(playerFrom) + playerFrom.length(), inLine.indexOf(playerTo))));
                me.setTime(inLine.substring(inLine.indexOf(timeFrom) + timeFrom.length(), inLine.indexOf(timeTo)));
                result.get(key).getHomeEvents().add(me);
            }
            if (inLine.indexOf(awayTo) != -1) {
                result.get(key).setAwayScore(inLine.substring(inLine.indexOf(scoreFrom) + scoreFrom.length(), inLine.indexOf(awayTo)));
                awayStart = true;
            }
            if (awayStart && inLine.indexOf(goalInclud) != -1) {
                MatchEvent me = new MatchEvent();
                me.setPlayerName(getPlayerName(inLine.substring(inLine.indexOf(playerFrom) + playerFrom.length(), inLine.indexOf(playerTo))));
                me.setTime(inLine.substring(inLine.indexOf(timeFrom) + timeFrom.length(), inLine.indexOf(timeTo)));
                result.get(key).getAwayEvents().add(me);
            }
        }
        reader.close();
    }
private void innerJob(String inURL, String matchId, Map<String, Match> result) throws UnsupportedEncodingException, IOException {
        URL url = new URL(inURL);
        BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream(), "utf-8"));
        String inLine = null;
        String scoreFrom = "score=\"";
        String homeTo = "\" side=\"Home";
        String awayTo = "\" side=\"Away";
        String goalInclud = "Stat";
        String playerFrom = "playerId=\"";
        String playerTo = "\" position=";
        String timeFrom = "time=\"";
        String timeTo = "\" period";
        String teamFinish = "</Team>";
        boolean homeStart = false;
        boolean awayStart = false;
        while ((inLine = reader.readLine()) != null) {
            if (inLine.indexOf(teamFinish) != -1) {
                homeStart = false;
                awayStart = false;
            }
            if (inLine.indexOf(homeTo) != -1) {
                result.get(matchId).setHomeScore(inLine.substring(inLine.indexOf(scoreFrom) + scoreFrom.length(), inLine.indexOf(homeTo)));
                homeStart = true;
            }
            if (homeStart && inLine.indexOf(goalInclud) != -1) {
                MatchEvent me = new MatchEvent();
                me.setPlayerName(getPlayerName(inLine.substring(inLine.indexOf(playerFrom) + playerFrom.length(), inLine.indexOf(playerTo))));
                me.setTime(inLine.substring(inLine.indexOf(timeFrom) + timeFrom.length(), inLine.indexOf(timeTo)));
                List<MatchEvent> mes = result.get(matchId).getHomeEvents();
                boolean exist = false;
                for (MatchEvent _me : mes) {
                    if (_me.getPlayerName().equals(me.getPlayerName()) && _me.getTime().equals(me.getTime())) {
                        exist = true;
                        break;
                    }
                }
                if (!exist) {
                    mes.add(me);
                }
            }
            if (inLine.indexOf(awayTo) != -1) {
                result.get(matchId).setAwayScore(inLine.substring(inLine.indexOf(scoreFrom) + scoreFrom.length(), inLine.indexOf(awayTo)));
                awayStart = true;
            }
            if (awayStart && inLine.indexOf(goalInclud) != -1) {
                MatchEvent me = new MatchEvent();
                me.setPlayerName(getPlayerName(inLine.substring(inLine.indexOf(playerFrom) + playerFrom.length(), inLine.indexOf(playerTo))));
                me.setTime(inLine.substring(inLine.indexOf(timeFrom) + timeFrom.length(), inLine.indexOf(timeTo)));
                List<MatchEvent> mes = result.get(matchId).getAwayEvents();
                boolean exist = false;
                for (MatchEvent _me : mes) {
                    if (_me.getPlayerName().equals(me.getPlayerName()) && _me.getTime().equals(me.getTime())) {
                        exist = true;
                        break;
                    }
                }
                if (!exist) {
                    mes.add(me);
                }
            }
        }
        reader.close();
    }
private String getPlayerName(String id) throws UnsupportedEncodingException, IOException {
        String result = "";
        Map<String, String> players = (Map<String, String>) sc.getAttribute("players");
        if (players.containsKey(id)) {
            result = players.get(id);
            System.out.println("skip name:" + result);
        } else {
            String palyerURL = "http://goal.2010worldcup.163.com/player/" + id + ".html";
            URL url = new URL(palyerURL);
            BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream(), "utf-8"));
            String line = null;
            String nameFrom = "英文名:";
            String nameTo = "</dd>";
            while ((line = reader.readLine()) != null) {
                if (line.indexOf(nameFrom) != -1) {
                    result = line.substring(line.indexOf(nameFrom) + nameFrom.length(), line.indexOf(nameTo));
                    break;
                }
            }
            reader.close();
            players.put(id, result);
        }
        return result;
    }
@Override
        public void run() {
            try {
                IOUtils.copy(_is, processOutStr);
            } catch (final IOException ioe) {
                proc.destroy();
            } finally {
                IOUtils.closeQuietly(_is);
                IOUtils.closeQuietly(processOutStr);
            }
        }
public void compressFile(String filePath) {
        String outPut = filePath + ".zip";
        try {
            FileInputStream in = new FileInputStream(filePath);
            GZIPOutputStream out = new GZIPOutputStream(new FileOutputStream(outPut));
            byte[] buffer = new byte[4096];
            int bytes_read;
            while ((bytes_read = in.read(buffer)) != -1) out.write(buffer, 0, bytes_read);
            in.close();
            out.close();
        } catch (Exception c) {
            c.printStackTrace();
        }
    }
public void load(URL urlin) throws IOException {
        index = hs.getDoIndex();
        loaded = false;
        url = urlin;
        int c, i;
        htmlDocLength = 0;
        HtmlReader in = new HtmlReader(new InputStreamReader(url.openStream(), charset));
        try {
            if (debug >= 2) System.out.print("Loading " + urlin.toString() + " ... ");
            while ((c = in.read()) >= 0) {
                htmlDoc[htmlDocLength++] = (char) (c);
                if (htmlDocLength == htmlDocMaxLength) {
                    char[] newHtmlDoc = new char[2 * htmlDocMaxLength];
                    System.arraycopy(htmlDoc, 0, newHtmlDoc, 0, htmlDocMaxLength);
                    htmlDocMaxLength = 2 * htmlDocMaxLength;
                    htmlDoc = newHtmlDoc;
                }
            }
            if (debug >= 2) System.out.println("done.");
        } catch (ArrayIndexOutOfBoundsException aioobe) {
            if (debug >= 1) System.out.println("Error, reading file into memory (too big) - skipping " + urlin.toString());
            loaded = false;
            return;
        }
        in.close();
        fetchURLpos = 0;
        dumpPos = 0;
        dumpLastChar = SPACE;
        loaded = true;
        frameset = false;
        titledone = false;
        headdone = false;
        checkhead = false;
        checkbody = false;
    }
private static Reader getReader(String fname) throws IOException {
        InputStream is;
        if (isUrl(fname)) {
            URL url = new URL(fname);
            is = url.openStream();
        } else {
            is = new FileInputStream(fname);
        }
        if (fname.endsWith(".zip")) {
            is = new ZipInputStream(is);
        } else if (fname.endsWith(".gz") || fname.endsWith(".gzip")) {
            is = new GZIPInputStream(is);
        }
        return new InputStreamReader(is);
    }