semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public String[] doGeoQuery(String query) throws IOException {
        String baseURL = "http://maps.google.com/maps/geo?output=csv&keyABQIAAAAct2NN7QKbyiMr1rfhB6UGBQn1DChMmG6tCCZd3aXbcL03vlL5hSUZpyoaGCXRwjbRTSBi0L89DeYeg&q=";
        URL url = new URL(baseURL + URLEncoder.encode(query, "UTF-8"));
        URLConnection connection = url.openConnection();
        StringBuffer buf = new StringBuffer();
        InputStream is = (InputStream) connection.getContent();
        int b = -1;
        while ((b = is.read()) != -1) {
            buf.append((char) b);
        }
        log.info("Geo Query " + url.toExternalForm() + " => " + buf.toString());
        return buf.toString().split(",");
    }
public static void main(String[] argv) {
        if (1 < argv.length) {
            File[] sources = Source(argv[0]);
            if (null != sources) {
                for (File src : sources) {
                    File[] targets = Target(src, argv);
                    if (null != targets) {
                        final long srclen = src.length();
                        try {
                            FileChannel source = new FileInputStream(src).getChannel();
                            try {
                                for (File tgt : targets) {
                                    FileChannel target = new FileOutputStream(tgt).getChannel();
                                    try {
                                        source.transferTo(0L, srclen, target);
                                    } finally {
                                        target.close();
                                    }
                                    System.out.printf("Updated %s\n", tgt.getPath());
                                    File[] deletes = Delete(src, tgt);
                                    if (null != deletes) {
                                        for (File del : deletes) {
                                            if (SVN) {
                                                if (SvnDelete(del)) System.out.printf("Deleted %s\n", del.getPath()); else System.out.printf("Failed to delete %s\n", del.getPath());
                                            } else if (del.delete()) System.out.printf("Deleted %s\n", del.getPath()); else System.out.printf("Failed to delete %s\n", del.getPath());
                                        }
                                    }
                                    if (SVN) SvnAdd(tgt);
                                }
                            } finally {
                                source.close();
                            }
                        } catch (Exception exc) {
                            exc.printStackTrace();
                            System.exit(1);
                        }
                    }
                }
                System.exit(0);
            } else {
                System.err.printf("Source file(s) not found in '%s'\n", argv[0]);
                System.exit(1);
            }
        } else {
            usage();
            System.exit(1);
        }
    }
@Override
        protected String doInBackground(String... params) {
            try {
                final HttpParams param = new BasicHttpParams();
                HttpConnectionParams.setConnectionTimeout(param, 30000);
                HttpConnectionParams.setSoTimeout(param, 30000);
                DefaultHttpClient client = new DefaultHttpClient(param);
                HttpPost post = new HttpPost("http://www.google.com/loc/json");
                post.setEntity(new StringEntity(params[0]));
                if (DEBUG) Log.d("Location", params[0]);
                HttpResponse resp = client.execute(post);
                if (resp.getStatusLine().getStatusCode() == 200) {
                    HttpEntity entity = resp.getEntity();
                    String result = EntityUtils.toString(entity);
                    return result;
                } else {
                    if (isFirstLocation) {
                        requestGearsLocation(1);
                        isFirstLocation = false;
                        return RESULT_FIRST_FAILE;
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }
private static Properties getProperties(String propFilename, ClassLoader loader) {
        Properties properties = new Properties();
        try {
            URL url = Loader.getResource(loader, propFilename);
            properties.load(url.openStream());
        } catch (Exception e) {
            log.debug("Cannot find crypto property file: " + propFilename);
            throw new RuntimeException("CryptoFactory: Cannot load properties: " + propFilename);
        }
        return properties;
    }
private void work(int timeout) throws Exception {
        Thread.currentThread().setName("Update - " + mod.getName());
        if (mod.getUpdateCheckUrl() != null && mod.getUpdateDownloadUrl() != null) {
            URL url = new URL(mod.getUpdateCheckUrl().trim());
            URLConnection connection = url.openConnection();
            connection.setConnectTimeout(timeout);
            connection.setReadTimeout(timeout);
            BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            String str = in.readLine();
            in.close();
            if (str != null && !str.toLowerCase().trim().contains("error") && !str.toLowerCase().trim().contains("Error") && !Manager.getInstance().compareModsVersions(str, "*-" + mod.getVersion())) {
                InputStream is = new URL(mod.getUpdateDownloadUrl().trim()).openStream();
                file = new File(System.getProperty("java.io.tmpdir") + File.separator + new File(mod.getPath()).getName());
                FileOutputStream fos = new FileOutputStream(file, false);
                FileUtils.copyInputStream(is, fos);
                is.close();
                fos.flush();
                fos.close();
            }
        }
    }
public static void copy(String source, String dest) throws java.io.IOException {
        java.io.BufferedInputStream in = null;
        java.io.BufferedOutputStream out = null;
        try {
            in = new java.io.BufferedInputStream(new java.io.FileInputStream(source), 1000);
            out = new java.io.BufferedOutputStream(new java.io.FileOutputStream(dest), 1000);
            while (in.available() != 0) {
                out.write(in.read());
            }
        } catch (java.io.IOException e) {
            throw e;
        } finally {
            try {
                if (in != null) {
                    in.close();
                }
                if (out != null) {
                    out.close();
                }
            } catch (java.io.IOException E) {
            }
        }
    }
public static JSONObject getJSONData(String url) throws JSONException {
        JSONObject jObject = null;
        InputStream data = null;
        DefaultHttpClient httpClient = new DefaultHttpClient();
        URI uri;
        try {
            uri = new URI(url);
            HttpGet httpGet = new HttpGet(uri);
            HttpResponse response = httpClient.execute(httpGet);
            data = response.getEntity().getContent();
            String line;
            StringBuilder builder = new StringBuilder();
            BufferedReader reader;
            reader = new BufferedReader(new InputStreamReader(data), 8192);
            while ((line = reader.readLine()) != null) builder.append(line);
            reader.close();
            jObject = (JSONObject) new JSONTokener(builder.toString()).nextValue();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return jObject;
    }
public void extractImage(String input, String output, DjatokaDecodeParam params, IWriter w) throws DjatokaException {
        File in = null;
        String dest = output;
        if (input.equals(STDIN)) {
            try {
                in = File.createTempFile("tmp", ".jp2");
                input = in.getAbsolutePath();
                in.deleteOnExit();
                IOUtils.copyFile(new File(STDIN), in);
            } catch (IOException e) {
                logger.error("Unable to process image from " + STDIN + ": " + e.getMessage());
                throw new DjatokaException(e);
            }
        }
        BufferedImage bi = extractImpl.process(input, params);
        if (bi != null) {
            if (params.getScalingFactor() != 1.0 || params.getScalingDimensions() != null) bi = applyScaling(bi, params);
            if (params.getTransform() != null) bi = params.getTransform().run(bi);
            try {
                BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(new File(dest)));
                w.write(bi, os);
                os.close();
            } catch (FileNotFoundException e) {
                logger.error("Requested file was not found: " + dest);
                throw new DjatokaException(e);
            } catch (IOException e) {
                logger.error("Error attempting to close: " + dest);
                throw new DjatokaException(e);
            }
        }
        if (in != null) in.delete();
    }
public void extractImage(String input, OutputStream os, DjatokaDecodeParam params, IWriter w) throws DjatokaException {
        File in = null;
        if (input.equals(STDIN)) {
            try {
                in = File.createTempFile("tmp", ".jp2");
                input = in.getAbsolutePath();
                in.deleteOnExit();
                IOUtils.copyFile(new File(STDIN), in);
            } catch (IOException e) {
                logger.error("Unable to process image from " + STDIN + ": " + e.getMessage());
                throw new DjatokaException(e);
            }
        }
        BufferedImage bi = extractImpl.process(input, params);
        if (bi != null) {
            if (params.getScalingFactor() != 1.0 || params.getScalingDimensions() != null) bi = applyScaling(bi, params);
            if (params.getTransform() != null) bi = params.getTransform().run(bi);
            w.write(bi, os);
        }
        if (in != null) in.delete();
    }
protected void onSubmit() {
        try {
            Connection conn = ((JdbcRequestCycle) getRequestCycle()).getConnection();
            String sql = "insert into entry (author, accessibility) values(?,?)";
            PreparedStatement pstmt = conn.prepareStatement(sql);
            pstmt.setInt(1, userId);
            pstmt.setInt(2, accessibility.getId());
            pstmt.executeUpdate();
            ResultSet insertedEntryIdRs = pstmt.getGeneratedKeys();
            insertedEntryIdRs.next();
            int insertedEntryId = insertedEntryIdRs.getInt(1);
            sql = "insert into revisions (title, entry, content, tags," + " revision_remark) values(?,?,?,?,?)";
            PreparedStatement pstmt2 = conn.prepareStatement(sql);
            pstmt2.setString(1, getTitle());
            pstmt2.setInt(2, insertedEntryId);
            pstmt2.setString(3, getContent());
            pstmt2.setString(4, getTags());
            pstmt2.setString(5, "newly added");
            int insertCount = pstmt2.executeUpdate();
            if (insertCount > 0) {
                info("Successfully added one new record.");
            } else {
                conn.rollback();
                info("Addition of one new record failed.");
            }
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
    }
public void sortPlayersTurn() {
        Token tempT = new Token();
        Player tempP = new Player("test name", tempT);
        int tempN = 0;
        boolean exchangeMade = true;
        for (int i = 0; i < playerNum - 1 && exchangeMade; i++) {
            exchangeMade = false;
            for (int j = 0; j < playerNum - 1 - i; j++) {
                if (diceSum[j] < diceSum[j + 1]) {
                    tempP = players[j];
                    tempN = diceSum[j];
                    players[j] = players[j + 1];
                    diceSum[j] = diceSum[j + 1];
                    players[j + 1] = tempP;
                    diceSum[j + 1] = tempN;
                    exchangeMade = true;
                }
            }
        }
    }
private RssEvent getLastEvent() throws DocumentException, IOException {
        Document document = new SAXReader().read(url.openStream());
        Element item = document.getRootElement().element("channel").element("item");
        Date date = new Date();
        String dateStr = item.element("pubDate").getStringValue();
        try {
            date = dateFormat.parse(dateStr);
        } catch (ParseException e) {
            String message = MessageFormat.format("Unable to parse string \"{0}\" with pattern \"{1}\".", dateStr, FORMAT);
            logger.warn(message, e);
        }
        RssEvent event = new RssEvent(this, item.element("title").getStringValue(), item.element("link").getStringValue(), item.element("description").getStringValue(), item.element("author").getStringValue(), date);
        return event;
    }
private void downloadPhoto(File photo, String url) {
        try {
            HttpClient httpClient = new DefaultHttpClient();
            Log.v(TAG, "Dowloading photo from " + Server.URL + url);
            HttpGet request = new HttpGet(Server.URL + url);
            HttpResponse response = httpClient.execute(request);
            HttpEntity entity = response.getEntity();
            InputStream serverPhoto = entity.getContent();
            photo.createNewFile();
            FileOutputStream photoStream = new FileOutputStream(photo);
            byte[] buf = new byte[1024];
            int len;
            while ((len = serverPhoto.read(buf)) > 0) {
                photoStream.write(buf, 0, len);
            }
            photoStream.flush();
            photoStream.close();
        } catch (Exception e) {
            Log.e(TAG, e.getMessage());
        }
    }
private String calculatePassword(String string) {
        try {
            MessageDigest md5 = MessageDigest.getInstance("md5");
            md5.update(nonce.getBytes());
            md5.update(string.getBytes());
            return toHexString(md5.digest());
        } catch (NoSuchAlgorithmException e) {
            error("MD5 digest is no supported !!!", "ERROR");
            return null;
        }
    }
public static Dictionary loadManifestFrom(BaseData bundledata) throws BundleException {
        URL url = bundledata.getEntry(Constants.OSGI_BUNDLE_MANIFEST);
        if (url == null) return null;
        try {
            return Headers.parseManifest(url.openStream());
        } catch (IOException e) {
            throw new BundleException(NLS.bind(EclipseAdaptorMsg.ECLIPSE_DATA_ERROR_READING_MANIFEST, bundledata.getLocation()), e);
        }
    }
public Long processAddCompany(Company companyBean, Long holdingId) {
        PreparedStatement ps = null;
        DatabaseAdapter dbDyn = null;
        try {
            dbDyn = DatabaseAdapter.getInstance();
            CustomSequenceType seq = new CustomSequenceType();
            seq.setSequenceName("seq_WM_LIST_COMPANY");
            seq.setTableName("WM_LIST_COMPANY");
            seq.setColumnName("ID_FIRM");
            Long sequenceValue = dbDyn.getSequenceNextValue(seq);
            ps = dbDyn.prepareStatement("insert into WM_LIST_COMPANY (" + "	ID_FIRM, " + "	full_name, " + "	short_name, " + "	address, " + "	chief, " + "	buh, " + "	url, " + "	short_info, " + "   is_deleted" + ")values " + (dbDyn.getIsNeedUpdateBracket() ? "(" : "") + "	?," + "	?," + "	?," + "	?," + "	?," + "	?," + "	?," + "	?," + "   0 " + (dbDyn.getIsNeedUpdateBracket() ? ")" : ""));
            int num = 1;
            RsetTools.setLong(ps, num++, sequenceValue);
            ps.setString(num++, companyBean.getName());
            ps.setString(num++, companyBean.getShortName());
            ps.setString(num++, companyBean.getAddress());
            ps.setString(num++, companyBean.getCeo());
            ps.setString(num++, companyBean.getCfo());
            ps.setString(num++, companyBean.getWebsite());
            ps.setString(num++, companyBean.getInfo());
            int i1 = ps.executeUpdate();
            if (log.isDebugEnabled()) log.debug("Count of inserted records - " + i1);
            if (holdingId != null) {
                InternalDaoFactory.getInternalHoldingDao().setRelateHoldingCompany(dbDyn, holdingId, sequenceValue);
            }
            dbDyn.commit();
            return sequenceValue;
        } catch (Exception e) {
            try {
                if (dbDyn != null) dbDyn.rollback();
            } catch (Exception e001) {
            }
            String es = "Error add new company";
            log.error(es, e);
            throw new IllegalStateException(es, e);
        } finally {
            DatabaseManager.close(dbDyn, ps);
            dbDyn = null;
            ps = null;
        }
    }
public Long processAddCompany(Company companyBean, String userLogin, Long holdingId, AuthSession authSession) {
        if (authSession == null) {
            return null;
        }
        PreparedStatement ps = null;
        DatabaseAdapter dbDyn = null;
        try {
            dbDyn = DatabaseAdapter.getInstance();
            CustomSequenceType seq = new CustomSequenceType();
            seq.setSequenceName("seq_WM_LIST_COMPANY");
            seq.setTableName("WM_LIST_COMPANY");
            seq.setColumnName("ID_FIRM");
            Long sequenceValue = dbDyn.getSequenceNextValue(seq);
            ps = dbDyn.prepareStatement("insert into WM_LIST_COMPANY (" + "	ID_FIRM, " + "	full_name, " + "	short_name, " + "	address, " + "	telefon_buh, " + "	telefon_chief, " + "	chief, " + "	buh, " + "	fax, " + "	email, " + "	icq, " + "	short_client_info, " + "	url, " + "	short_info, " + "is_deleted" + ")" + (dbDyn.getIsNeedUpdateBracket() ? "(" : "") + " select " + "	?," + "	?," + "	?," + "	?," + "	?," + "	?," + "	?," + "	?," + "	?," + "	?," + "	?," + "	?," + "	?," + "	?,0 from WM_AUTH_USER " + "where USER_LOGIN=? " + (dbDyn.getIsNeedUpdateBracket() ? ")" : ""));
            int num = 1;
            RsetTools.setLong(ps, num++, sequenceValue);
            ps.setString(num++, companyBean.getName());
            ps.setString(num++, companyBean.getShortName());
            ps.setString(num++, companyBean.getAddress());
            ps.setString(num++, "");
            ps.setString(num++, "");
            ps.setString(num++, companyBean.getCeo());
            ps.setString(num++, companyBean.getCfo());
            ps.setString(num++, "");
            ps.setString(num++, "");
            RsetTools.setLong(ps, num++, null);
            ps.setString(num++, "");
            ps.setString(num++, companyBean.getWebsite());
            ps.setString(num++, companyBean.getInfo());
            ps.setString(num++, userLogin);
            int i1 = ps.executeUpdate();
            if (log.isDebugEnabled()) log.debug("Count of inserted records - " + i1);
            if (holdingId != null) {
                InternalDaoFactory.getInternalHoldingDao().setRelateHoldingCompany(dbDyn, holdingId, sequenceValue);
            }
            dbDyn.commit();
            return sequenceValue;
        } catch (Exception e) {
            try {
                if (dbDyn != null) dbDyn.rollback();
            } catch (Exception e001) {
            }
            String es = "Error add new company";
            log.error(es, e);
            throw new IllegalStateException(es, e);
        } finally {
            DatabaseManager.close(dbDyn, ps);
            dbDyn = null;
            ps = null;
        }
    }
public void processSaveCompany(Company companyBean, AuthSession authSession) {
        if (authSession == null) {
            return;
        }
        DatabaseAdapter dbDyn = null;
        PreparedStatement ps = null;
        try {
            dbDyn = DatabaseAdapter.getInstance();
            String sql = "UPDATE WM_LIST_COMPANY " + "SET " + "	full_name = ?, " + "	short_name = ?, " + "	address = ?, " + "	telefon_buh = ?, " + "	telefon_chief = ?, " + "	chief = ?, " + "	buh = ?, " + "	fax = ?, " + "	email = ?, " + "	icq = ?, " + "	short_client_info = ?, " + "	url = ?, " + "	short_info = ? " + "WHERE ID_FIRM = ? and ID_FIRM in ";
            switch(dbDyn.getFamaly()) {
                case DatabaseManager.MYSQL_FAMALY:
                    String idList = authSession.getGrantedCompanyId();
                    sql += " (" + idList + ") ";
                    break;
                default:
                    sql += "(select z1.ID_FIRM from v$_read_list_firm z1 where z1.user_login = ?)";
                    break;
            }
            ps = dbDyn.prepareStatement(sql);
            int num = 1;
            ps.setString(num++, companyBean.getName());
            ps.setString(num++, companyBean.getShortName());
            ps.setString(num++, companyBean.getAddress());
            ps.setString(num++, "");
            ps.setString(num++, "");
            ps.setString(num++, companyBean.getCeo());
            ps.setString(num++, companyBean.getCfo());
            ps.setString(num++, "");
            ps.setString(num++, "");
            RsetTools.setLong(ps, num++, null);
            ps.setString(num++, "");
            ps.setString(num++, companyBean.getWebsite());
            ps.setString(num++, companyBean.getInfo());
            RsetTools.setLong(ps, num++, companyBean.getId());
            switch(dbDyn.getFamaly()) {
                case DatabaseManager.MYSQL_FAMALY:
                    break;
                default:
                    ps.setString(num++, authSession.getUserLogin());
                    break;
            }
            int i1 = ps.executeUpdate();
            if (log.isDebugEnabled()) log.debug("Count of updated record - " + i1);
            dbDyn.commit();
        } catch (Exception e) {
            try {
                if (dbDyn != null) dbDyn.rollback();
            } catch (Exception e001) {
            }
            String es = "Error save company";
            log.error(es, e);
            throw new IllegalStateException(es, e);
        } finally {
            DatabaseManager.close(dbDyn, ps);
            dbDyn = null;
            ps = null;
        }
    }
public void processDeleteCompany(Company companyBean, AuthSession authSession) {
        if (authSession == null) {
            return;
        }
        DatabaseAdapter dbDyn = null;
        PreparedStatement ps = null;
        try {
            dbDyn = DatabaseAdapter.getInstance();
            if (companyBean.getId() == null) throw new IllegalArgumentException("companyId is null");
            String sql = "update WM_LIST_COMPANY set is_deleted = 1 " + "where  ID_FIRM = ? and ID_FIRM in ";
            switch(dbDyn.getFamaly()) {
                case DatabaseManager.MYSQL_FAMALY:
                    String idList = authSession.getGrantedCompanyId();
                    sql += " (" + idList + ") ";
                    break;
                default:
                    sql += "(select z1.ID_FIRM from v$_read_list_firm z1 where z1.user_login = ?)";
                    break;
            }
            ps = dbDyn.prepareStatement(sql);
            RsetTools.setLong(ps, 1, companyBean.getId());
            switch(dbDyn.getFamaly()) {
                case DatabaseManager.MYSQL_FAMALY:
                    break;
                default:
                    ps.setString(2, authSession.getUserLogin());
                    break;
            }
            int i1 = ps.executeUpdate();
            if (log.isDebugEnabled()) log.debug("Count of deleted records - " + i1);
            dbDyn.commit();
        } catch (Exception e) {
            try {
                if (dbDyn != null) dbDyn.rollback();
            } catch (Exception e001) {
            }
            String es = "Error delete company";
            log.error(es, e);
            throw new IllegalStateException(es, e);
        } finally {
            DatabaseManager.close(dbDyn, ps);
            dbDyn = null;
            ps = null;
        }
    }