semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
private static void loadEmoticons() {
        emoticons = new Hashtable();
        URL url = ChatPanel.class.getResource("/resources/text/emoticon.properties");
        BufferedReader br = null;
        try {
            br = new BufferedReader(new InputStreamReader(url.openStream()));
            String line = null;
            while ((line = br.readLine()) != null) {
                if (line.trim().length() == 0 || line.charAt(0) == '#') continue;
                int i0 = line.indexOf('=');
                if (i0 != -1) {
                    String key = line.substring(0, i0).trim();
                    String value = line.substring(i0 + 1).trim();
                    value = StringUtil.replaceString(value, "\\n", "\n");
                    URL eUrl = ChatPanel.class.getResource("/resources/emoticon/" + value);
                    if (eUrl != null) emoticons.put(key, new ImageIcon(eUrl));
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (br != null) {
                try {
                    br.close();
                } catch (Exception e) {
                }
            }
        }
    }
private void copy(File fin, File fout) throws IOException {
        FileOutputStream out = new FileOutputStream(fout);
        FileInputStream in = new FileInputStream(fin);
        byte[] buf = new byte[2048];
        int read = in.read(buf);
        while (read > 0) {
            out.write(buf, 0, read);
            read = in.read(buf);
        }
        in.close();
        out.close();
    }
@Override
    public void incluir(Casa_festas casa_festas) throws Exception {
        Connection connection = criaConexao(false);
        String sql = "insert into casa_festas ? as idlocal, ? as area, ? as realiza_cerimonia, ? as tipo_principal, ? as idgrupo;";
        String sql2 = "SELECT MAX(idlocal) FROM Local";
        PreparedStatement stmt = null;
        PreparedStatement stmt2 = null;
        ResultSet rs = null;
        try {
            stmt = connection.prepareStatement(sql);
            stmt2 = connection.prepareStatement(sql2);
            rs = stmt2.executeQuery();
            stmt.setInt(1, rs.getInt("max"));
            stmt.setDouble(2, casa_festas.getArea());
            stmt.setBoolean(3, casa_festas.getRealizaCerimonias());
            stmt.setBoolean(4, casa_festas.getTipoPrincipal());
            stmt.setInt(5, casa_festas.getIdGrupo());
            int retorno = stmt.executeUpdate();
            if (retorno == 0) {
                connection.rollback();
                throw new SQLException("Ocorreu um erro inesperado no momento de inserir dados de cliente no banco!");
            }
            connection.commit();
        } catch (SQLException e) {
            connection.rollback();
            throw e;
        } finally {
            try {
                stmt.close();
                stmt2.close();
                rs.close();
                this.fechaConexao();
            } catch (SQLException e) {
                throw e;
            }
        }
    }
public String getContent(URL url) {
        Logger.getLogger(this.getClass().getName()).log(Level.INFO, "getting content from " + url.toString());
        String content = "";
        try {
            URLConnection httpc;
            httpc = url.openConnection();
            httpc.setDoInput(true);
            httpc.connect();
            BufferedReader in = new BufferedReader(new InputStreamReader(httpc.getInputStream()));
            String line = "";
            while ((line = in.readLine()) != null) {
                content = content + line;
            }
            in.close();
        } catch (IOException e) {
            Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, "Problem writing to " + url, e);
        }
        return content;
    }
public String setContent(URL url, String inputdata) {
        String content = "";
        try {
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setDoOutput(true);
            connection.setRequestMethod("POST");
            connection.connect();
            OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream());
            out.write(inputdata);
            out.flush();
            BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            String strLine = "";
            while ((strLine = in.readLine()) != null) {
                content = content + strLine;
            }
            in.close();
            out.close();
        } catch (IOException e) {
            Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, "Problem writing to " + url + " content " + inputdata, e);
        }
        return content;
    }
public static final int executeSql(final Connection conn, final String sql, final boolean rollback) throws SQLException {
        if (null == sql) return 0;
        Statement stmt = null;
        try {
            stmt = conn.createStatement();
            final int updated = stmt.executeUpdate(sql);
            return updated;
        } catch (final SQLException e) {
            if (rollback) conn.rollback();
            throw e;
        } finally {
            closeAll(null, stmt, null);
        }
    }
public String calculateDigest(String str) {
        StringBuffer s = new StringBuffer();
        try {
            MessageDigest md = MessageDigest.getInstance("SHA-1");
            md.update(str.getBytes());
            byte[] digest = md.digest();
            for (byte d : digest) {
                s.append(Integer.toHexString((int) (d & 0xff)));
            }
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return s.toString();
    }
public static void copy(File toCopy, File dest) throws IOException {
        FileInputStream src = new FileInputStream(toCopy);
        FileOutputStream out = new FileOutputStream(dest);
        try {
            while (src.available() > 0) {
                out.write(src.read());
            }
        } finally {
            src.close();
            out.close();
        }
    }
private void copyFile(File source, File target) throws IOException {
        FileChannel srcChannel = new FileInputStream(source).getChannel();
        FileChannel dstChannel = new FileOutputStream(target).getChannel();
        dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
        srcChannel.close();
        dstChannel.close();
    }
protected void writeSnapshot(final String message, final String details) {
        try {
            URL url = proxyAddress == null ? new URL(url_spec) : new URL("http", proxyAddress, proxyPort, url_spec);
            LOG.info("connect to " + url);
            URLConnection connection = url.openConnection();
            connection.setDoOutput(true);
            HttpQueryWriter out = new HttpQueryWriter(connection.getOutputStream());
            out.addParameter("error", message);
            out.addParameter("trace", details);
            out.close();
            InputStream in = connection.getInputStream();
            int c;
            StringBuffer result = new StringBuffer();
            while ((c = in.read()) != -1) {
                result.append((char) c);
            }
            LOG.info(result);
            in.close();
        } catch (UnknownHostException e) {
            LOG.info("could not find host (unknown host) to submit log to");
        } catch (IOException e) {
            LOG.debug("i/o problem submitting log", e);
        }
    }
@Override
    public String toString() {
        if (byteArrayOutputStream == null) return "<Unparsed binary data: Content-Type=" + getHeader("Content-Type") + " >";
        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 boolean loadURL(URL url) {
        try {
            _properties.load(url.openStream());
            Argo.log.info("Configuration loaded from " + url + "\n");
            return true;
        } catch (Exception e) {
            if (_canComplain) Argo.log.warn("Unable to load configuration " + url + "\n");
            _canComplain = false;
            return false;
        }
    }
@Override
        public void run() {
            try {
                for (int r = 0; r < this.requestCount; r++) {
                    HttpGet httpget = new HttpGet("/");
                    HttpResponse response = this.httpclient.execute(this.target, httpget, this.context);
                    this.count++;
                    ManagedClientConnection conn = (ManagedClientConnection) this.context.getAttribute(ExecutionContext.HTTP_CONNECTION);
                    this.context.setAttribute("r" + r, conn.getState());
                    HttpEntity entity = response.getEntity();
                    if (entity != null) {
                        entity.consumeContent();
                    }
                }
            } catch (Exception ex) {
                this.exception = ex;
            }
        }
public Fen_Download_FlameRobin() {
        super();
        initialize();
        long HeureDebut = System.currentTimeMillis();
        long HeureActuelle;
        String urlsetup = "http://downloads.sourceforge.net/project/autobackupbysim/tools/flamerobin-0.9.2-1-setup.exe";
        int erreurOuverture = 0;
        InputStream input = null;
        String cheminFichier = "";
        File fichier;
        FileOutputStream writeFile = null;
        try {
            URL url = new URL(urlsetup);
            URLConnection connection = url.openConnection();
            final int fileLength = connection.getContentLength();
            if ((fileLength == -1) || (fileLength == 0)) {
                System.out.println("Invalide URL or file.");
                erreurOuverture++;
            }
            input = connection.getInputStream();
            String fileName = url.getFile().substring(url.getFile().lastIndexOf('/') + 1);
            if (fileName.contains("%20") == true) {
                fileName = fileName.replaceAll("%20", " ");
            }
            if (fileName.contains("&amp;") == true) {
                fileName = fileName.replaceAll("&amp;", " and ");
            }
            cheminFichier = GestionRepertoire.RecupRepTravail() + "\\" + fileName;
            jLabel1.setText(" Fichier en cours : " + fileName);
            fichier = new File(cheminFichier);
            writeFile = new FileOutputStream(cheminFichier);
            byte[] buffer = new byte[4096 * 1024];
            int read;
            while ((read = input.read(buffer)) > 0) {
                writeFile.write(buffer, 0, read);
                long TailleEncours = fichier.length();
                int progressionEnCours = (int) ((100 * (TailleEncours + 1)) / fileLength);
                HeureActuelle = System.currentTimeMillis();
                long Vitesse = (long) (TailleEncours / (HeureActuelle - HeureDebut));
                jLabel1.setText("T�l�chargement du fichier , Vitesse Actuelle : " + Vitesse + " Ko/s");
                jProgressBar.setValue(progressionEnCours);
                jProgressBar.setString(progressionEnCours + " %");
            }
            writeFile.flush();
        } catch (IOException e) {
            System.out.println("Error while trying to download the file.");
            e.printStackTrace();
        } finally {
            try {
                if (erreurOuverture == 0) {
                    writeFile.close();
                    input.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        String cmdExecuteSetup = ("cmd /c \"" + cheminFichier + "\" /silent");
        Runtime r = Runtime.getRuntime();
        Process p = null;
        try {
            p = r.exec(cmdExecuteSetup);
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            p.waitFor();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
protected Element downloadAndVerify(Element gElem) throws CacheException {
        try {
            String url = XMLHelper.GetChildText(gElem, "originalLocation");
            String id = XMLHelper.GetChildText(gElem, "id");
            URLConnection urlC = new URL(url).openConnection();
            String gElemStr = XMLHelper.ToString(gElem);
            int index = gElemStr.indexOf("</generator>");
            String cachedFileName = downloadInternal(urlC);
            gElemStr = gElemStr.substring(0, index) + "<location>" + cachedFileName + "</location>" + gElemStr.substring(index);
            index = gElemStr.indexOf("</generator>");
            gElemStr = gElemStr.substring(0, index) + "<downloadTime>" + System.currentTimeMillis() + "</downloadTime>" + gElemStr.substring(index);
            genHash.put(id, gElemStr);
            writeFile(genHash, genFileName);
            return XMLHelper.GetRootElement(gElemStr);
        } catch (Exception e) {
            throw new CacheException(e);
        }
    }
public String plainStringToMD5(String input) {
        MessageDigest md = null;
        byte[] byteHash = null;
        StringBuffer resultString = new StringBuffer();
        try {
            md = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            System.exit(-1);
        }
        md.reset();
        md.update(input.getBytes());
        byteHash = md.digest();
        for (int i = 0; i < byteHash.length; i++) {
            resultString.append(Integer.toHexString(0xFF & byteHash[i]));
        }
        return (resultString.toString());
    }
public RSClassLoader(Map<String, byte[]> classes, URL source) {
        try {
            CodeSource codeSource = new CodeSource(source, (CodeSigner[]) null);
            domain = new ProtectionDomain(codeSource, getPermissions());
            this.classes = classes;
            String s = getClass().getResource("RSClassLoader.class").toString();
            s = s.replace("bot/RSClassLoader.class", "client/RandomAccessFile.class");
            URL url = new URL(s);
            InputStream is = null;
            try {
                ByteArrayOutputStream bos = new ByteArrayOutputStream(5000);
                is = new BufferedInputStream(url.openStream());
                byte[] buff = new byte[1024];
                int len = -1;
                while ((len = is.read(buff)) != -1) bos.write(buff, 0, len);
                byte[] data = bos.toByteArray();
                this.classes.put("org.rsbot.client.RandomAccessFile", data);
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                if (is != null) is.close();
            }
        } catch (final Exception ignored) {
        }
    }
public static String getCoordinates(String city) throws MalformedURLException, IOException, ParserConfigurationException, SAXException {
        String url = "http://ws.geonames.org/search?q=" + city + "&maxRows=1&lang=it&username=lorenzo.abram";
        URLConnection conn = new URL(url).openConnection();
        InputStream response = conn.getInputStream();
        GeonamesHandler handler = new GeonamesHandler();
        SAXParserFactory factory = SAXParserFactory.newInstance();
        SAXParser parser = factory.newSAXParser();
        parser.parse(response, handler);
        return handler.getCoord();
    }
public static String getWikiPage(String city) throws MalformedURLException, IOException, ParserConfigurationException, SAXException {
        String url = "http://api.geonames.org/wikipediaSearch?q=" + city + "&maxRows=1&lang=it&username=lorenzo.abram";
        URLConnection conn = new URL(url).openConnection();
        InputStream response = conn.getInputStream();
        GeonamesHandler handler = new GeonamesHandler();
        SAXParserFactory factory = SAXParserFactory.newInstance();
        SAXParser parser = factory.newSAXParser();
        parser.parse(response, handler);
        return handler.getUrl();
    }
public static String convetToSignature(Map<String, String> keyVal, String apiSecret) {
        if (keyVal == null || apiSecret == null || keyVal.size() <= 0 || apiSecret.trim().equals("")) {
            throw new IllegalArgumentException("keyVal or api secret is not valid. Please Check it again.");
        }
        Iterator<Entry<String, String>> iterator = keyVal.entrySet().iterator();
        StringBuffer rslt = new StringBuffer();
        byte[] signature = null;
        while (iterator.hasNext()) {
            Entry<String, String> entry = iterator.next();
            rslt.append(entry.getKey());
            rslt.append("=");
            rslt.append(entry.getValue());
        }
        rslt.append(apiSecret);
        try {
            MessageDigest md5 = MessageDigest.getInstance(HASHING_METHOD);
            md5.reset();
            md5.update(rslt.toString().getBytes());
            rslt.delete(0, rslt.length());
            signature = md5.digest();
            for (int i = 0; i < signature.length; i++) {
                String hex = Integer.toHexString(0xff & signature[i]);
                if (hex.length() == 1) {
                    rslt.append('0');
                }
                rslt.append(hex);
            }
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return rslt.toString();
    }
@Override
    public String fetchURL(String urlString) throws ServiceException {
        try {
            URL url = new URL(urlString);
            BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
            String content = "";
            String line;
            while ((line = reader.readLine()) != null) {
                content += line + "\n";
            }
            reader.close();
            return content;
        } catch (MalformedURLException e) {
            throw new ServiceException(e.getMessage());
        } catch (IOException e) {
            throw new ServiceException(e.getMessage());
        }
    }
public String saveFile(URL url) {
        String newUrlToReturn = url.toString();
        try {
            String directory = Util.appendDirPath(targetDirectory, OBJ_REPOSITORY);
            String category = url.openConnection().getContentType();
            category = category.substring(0, category.indexOf("/"));
            String fileUrl = Util.transformUrlToPath(url.toString());
            directory = Util.appendDirPath(directory, category);
            directory = Util.appendDirPath(directory, fileUrl);
            String objectFileName = url.toString().substring(url.toString().lastIndexOf('/') + 1);
            BufferedInputStream in = new java.io.BufferedInputStream(url.openStream());
            File dir = new File(directory);
            if (!dir.exists()) {
                dir.mkdirs();
            }
            File file = new File(Util.appendDirPath(dir.getPath(), objectFileName));
            FileOutputStream fos = new FileOutputStream(file);
            BufferedOutputStream bout = new BufferedOutputStream(fos, 1024);
            byte data[] = new byte[1024];
            int count;
            while ((count = in.read(data, 0, 1024)) != -1) {
                bout.write(data, 0, count);
            }
            bout.close();
            fos.close();
            in.close();
            newUrlToReturn = Util.getRelativePath(file.getAbsolutePath(), targetDirectory);
        } catch (IOException e) {
            return newUrlToReturn;
        }
        return newUrlToReturn;
    }
public static Collection<String> readXML(Bundle declaringBundle, URL url) throws XmlPullParserException {
        try {
            return readXML(declaringBundle, url.openStream());
        } catch (IOException e) {
            throw new XmlPullParserException("Could not open \"" + url + "\" got exception:" + e.getLocalizedMessage());
        }
    }
public void genDropSchema(DiagramModel diagramModel, boolean foreignKeys) {
        try {
            con.setAutoCommit(false);
            stmt = con.createStatement();
            Collection boxes = diagramModel.getBoxes();
            BoxModel box;
            String sqlQuery;
            if (foreignKeys) {
                for (Iterator x = boxes.iterator(); x.hasNext(); ) {
                    box = (BoxModel) x.next();
                    if (!box.isAbstractDef()) {
                        dropForeignKeys(box);
                    }
                }
            }
            int counter = 0;
            for (Iterator x = boxes.iterator(); x.hasNext(); ) {
                box = (BoxModel) x.next();
                if (!box.isAbstractDef()) {
                    sqlQuery = sqlDropTable(box);
                    System.out.println(sqlQuery);
                    try {
                        stmt.executeUpdate(sqlQuery);
                        counter++;
                    } catch (SQLException e) {
                        String tableName = box.getName();
                        System.out.println("// Problem while dropping table " + tableName + " : " + e.getMessage());
                        String msg = Para.getPara().getText("tableNotDropped") + " -- " + tableName;
                        this.informUser(msg);
                    }
                }
            }
            con.commit();
            if (counter > 0) {
                String msg = Para.getPara().getText("schemaDropped") + " -- " + counter + " " + Para.getPara().getText("tables");
                this.informUser(msg);
            } else {
                this.informUser(Para.getPara().getText("schemaNotDropped"));
            }
        } catch (SQLException e) {
            System.out.println(e.getMessage() + " // Problem with the JDBC schema generation! ");
            try {
                con.rollback();
                this.informUser(Para.getPara().getText("schemaNotDropped"));
            } catch (SQLException e1) {
                System.out.println(e1.getMessage() + " // Problem with the connection rollback! ");
            }
        } finally {
            try {
                con.setAutoCommit(true);
                stmt.close();
            } catch (SQLException e1) {
                System.out.println(e1.getMessage() + " // Problem with the connection disconnect! ");
            }
        }
    }