semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public boolean actualizarRondaActual(division div) {
        int intResult = 0;
        String sql = "UPDATE divisionxTorneo " + " SET rondaActual = " + div.getRondaActual() + " WHERE idDivisionxTorneo = " + div.getidDivision();
        try {
            connection = conexionBD.getConnection();
            connection.setAutoCommit(false);
            ps = connection.prepareStatement(sql);
            intResult = ps.executeUpdate();
            connection.commit();
        } catch (SQLException ex) {
            ex.printStackTrace();
            try {
                connection.rollback();
            } catch (SQLException exe) {
                exe.printStackTrace();
            }
        } finally {
            conexionBD.close(ps);
            conexionBD.close(connection);
        }
        return (intResult > 0);
    }
public boolean actualizarNumeroRondas(int idDivision, int numFechas) {
        int intResult = 0;
        String sql = "UPDATE divisionxTorneo " + " SET numFechas = " + numFechas + " WHERE idDivisionxTorneo = " + idDivision;
        try {
            connection = conexionBD.getConnection();
            connection.setAutoCommit(false);
            ps = connection.prepareStatement(sql);
            intResult = ps.executeUpdate();
            connection.commit();
        } catch (SQLException ex) {
            ex.printStackTrace();
            try {
                connection.rollback();
            } catch (SQLException exe) {
                exe.printStackTrace();
            }
        } finally {
            conexionBD.close(ps);
            conexionBD.close(connection);
        }
        return (intResult > 0);
    }
public static boolean copyFile(File source, File dest) throws IOException {
        int answer = JOptionPane.YES_OPTION;
        if (dest.exists()) {
            answer = JOptionPane.showConfirmDialog(null, "File " + dest.getAbsolutePath() + "\n already exists.  Overwrite?", "Warning", JOptionPane.YES_NO_OPTION);
        }
        if (answer == JOptionPane.NO_OPTION) return false;
        dest.createNewFile();
        InputStream in = null;
        OutputStream out = null;
        try {
            in = new FileInputStream(source);
            out = new FileOutputStream(dest);
            byte[] buf = new byte[1024];
            int len;
            while ((len = in.read(buf)) > 0) {
                out.write(buf, 0, len);
            }
            return true;
        } catch (Exception e) {
            return false;
        } finally {
            if (in != null) {
                in.close();
            }
            if (out != null) {
                out.close();
            }
        }
    }
protected void validate(long googcmId, long reservePrice, String description, String category, int days, String status, String title, byte[] imgBytes) throws PortalException, SystemException {
        if (Validator.isNull(description)) throw new AuctionDescriptionException(); else if (Validator.isNull(title)) throw new AuctionTitleException(); else if (Validator.isNull(category)) throw new CategoryIdException();
        if (googcmId < 1000000000l | googcmId > 999999999999999l) throw new AuctionGoogCMIdException();
        long imgMaxSize = 1048576l;
        if ((imgBytes == null) || (imgBytes.length > ((int) imgMaxSize))) throw new AuctionImageSizeException();
        if (days != 3 & days != 7 & days != 10) throw new AuctionEndeDateException();
        if ((reservePrice < 0) || (reservePrice > 10000)) throw new AuctionReservePriceException();
        try {
            URL url = new URL("https://checkout.google.com/api/checkout/v2/checkoutForm/Merchant/" + googcmId);
            URLConnection conn = url.openConnection();
            BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            boolean sellerExists = true;
            String line;
            while ((line = rd.readLine()) != null) {
                if (line.contains("" + googcmId)) {
                    throw new AuctionGoogCMAccountException();
                }
            }
            rd.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
private static String webService(String strUrl) {
        StringBuffer buffer = new StringBuffer();
        try {
            URL url = new URL(strUrl);
            InputStream input = url.openStream();
            String sCurrentLine = "";
            InputStreamReader read = new InputStreamReader(input, "utf-8");
            BufferedReader l_reader = new java.io.BufferedReader(read);
            while ((sCurrentLine = l_reader.readLine()) != null) {
                buffer.append(sCurrentLine);
            }
            return buffer.toString();
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
public TapdocContextImpl(Registry registry, FileObject javaDom, List<String> javadocLinks, List<String> libraryLocations, FileObject outputDirectory, List<String> tapdocLinks, DocumentGenerator documentGenerator) {
        this.registry = registry;
        this.documentGenerator = documentGenerator;
        try {
            if (javaDom == null) {
                javaDom = outputDirectory.resolveFile("tapdoc-javadom.xml");
            }
            if (!javaDom.exists()) {
                javaDom.createFile();
                javaDom.close();
                IOUtils.copy(new StringReader("<?xml version=\"1.0\" encoding=\"UTF-8\"?><tapdoc-javadom></tapdoc-javadom>"), javaDom.getContent().getOutputStream());
            }
            this.javaDom = javaDom;
            this.javadocLinks = javadocLinks;
            this.tapdocLinks = tapdocLinks;
            this.libraryLocations = libraryLocations;
            this.outputDirectory = outputDirectory;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
public BasePolicy(String flaskPath) throws Exception {
        SWIGTYPE_p_p_policy p_p_pol = apol.new_policy_t_p_p();
        if (!flaskPath.endsWith("/")) flaskPath += "/";
        File tmpPolConf = File.createTempFile("tmpBasePolicy", ".conf");
        BufferedWriter tmpPolFile = new BufferedWriter(new FileWriter(tmpPolConf));
        BufferedReader secClassFile = new BufferedReader(new FileReader(flaskPath + "security_classes"));
        int bufSize = 1024;
        char[] buffer = new char[bufSize];
        int read;
        while ((read = secClassFile.read(buffer)) > 0) {
            tmpPolFile.write(buffer, 0, read);
        }
        secClassFile.close();
        BufferedReader sidsFile = new BufferedReader(new FileReader(flaskPath + "initial_sids"));
        while ((read = sidsFile.read(buffer)) > 0) {
            tmpPolFile.write(buffer, 0, read);
        }
        sidsFile.close();
        BufferedReader axxVecFile = new BufferedReader(new FileReader(flaskPath + "access_vectors"));
        while ((read = axxVecFile.read(buffer)) > 0) {
            tmpPolFile.write(buffer, 0, read);
        }
        axxVecFile.close();
        tmpPolFile.write("attribute ricka; \ntype rick_t; \nrole rick_r types rick_t; \nuser rick_u roles rick_r;\nsid kernel      rick_u:rick_r:rick_t\nfs_use_xattr ext3 rick_u:rick_r:rick_t;\ngenfscon proc /  rick_u:rick_r:rick_t\n");
        tmpPolFile.flush();
        tmpPolFile.close();
        if (apol.open_policy(tmpPolConf.getAbsolutePath(), p_p_pol) == 0) {
            Policy = apol.policy_t_p_p_value(p_p_pol);
            if (Policy == null) {
                throw new Exception("Failed to allocate memory for policy_t struct.");
            }
            tmpPolConf.delete();
        } else {
            throw new IOException("Failed to open/parse base policy file: " + tmpPolConf.getAbsolutePath());
        }
    }
public static String hexHash(Object obj) {
        String toHash = obj.toString();
        try {
            MessageDigest dg = MessageDigest.getInstance("MD5");
            dg.update(toHash.getBytes("UTF-8"));
            return bytesToHex(dg.digest());
        } catch (Exception e) {
            throw new RuntimeException("Error while hashing string: " + toHash, e);
        }
    }
public static IBiopaxModel read(URL url) throws ReactionException, IOException {
        IBiopaxModel model = null;
        InputStream in = null;
        try {
            in = url.openStream();
            model = read(in);
        } catch (IOException e) {
            LOGGER.error("Unable to read from URL " + url, e);
        } finally {
            if (in != null) in.close();
        }
        return model;
    }
public static List importSymbol(Report report, Symbol symbol, TradingDate startDate, TradingDate endDate) throws IOException {
        List quotes = new ArrayList();
        String URLString = constructURL(symbol, startDate, endDate);
        QuoteFilter filter = new YahooQuoteFilter(symbol);
        PreferencesManager.ProxyPreferences proxyPreferences = PreferencesManager.loadProxySettings();
        try {
            URL url = new URL(URLString);
            InputStreamReader input = new InputStreamReader(url.openStream());
            BufferedReader bufferedInput = new BufferedReader(input);
            String line = bufferedInput.readLine();
            while (line != null) {
                line = bufferedInput.readLine();
                if (line != null) {
                    try {
                        Quote quote = filter.toQuote(line);
                        quotes.add(quote);
                        verify(report, quote);
                    } catch (QuoteFormatException e) {
                        report.addError(Locale.getString("YAHOO") + ":" + symbol + ":" + Locale.getString("ERROR") + ": " + e.getMessage());
                    }
                }
            }
            bufferedInput.close();
        } catch (BindException e) {
            DesktopManager.showErrorMessage(Locale.getString("UNABLE_TO_CONNECT_ERROR", e.getMessage()));
            throw new IOException();
        } catch (ConnectException e) {
            DesktopManager.showErrorMessage(Locale.getString("UNABLE_TO_CONNECT_ERROR", e.getMessage()));
            throw new IOException();
        } catch (UnknownHostException e) {
            DesktopManager.showErrorMessage(Locale.getString("UNKNOWN_HOST_ERROR", e.getMessage()));
            throw new IOException();
        } catch (NoRouteToHostException e) {
            DesktopManager.showErrorMessage(Locale.getString("DESTINATION_UNREACHABLE_ERROR", e.getMessage()));
            throw new IOException();
        } catch (MalformedURLException e) {
            DesktopManager.showErrorMessage(Locale.getString("INVALID_PROXY_ERROR", proxyPreferences.host, proxyPreferences.port));
            throw new IOException();
        } catch (FileNotFoundException e) {
            report.addError(Locale.getString("YAHOO") + ":" + symbol + ":" + Locale.getString("ERROR") + ": " + Locale.getString("NO_QUOTES_FOUND"));
        } catch (IOException e) {
            DesktopManager.showErrorMessage(Locale.getString("ERROR_DOWNLOADING_QUOTES"));
            throw new IOException();
        }
        return quotes;
    }
public static String encodeMD5(String input) {
        MessageDigest md = null;
        byte[] byteHash = null;
        StringBuffer resultString = new StringBuffer();
        try {
            md = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            System.out.println("NoSuchAlgorithmException caught!");
            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());
    }
@Override
    public DownloadObject download() throws IOException {
        final HttpGet findLink = new HttpGet(url.toString());
        final HttpResponse response = this.client.execute(findLink);
        final String body = IOUtil.getString(response);
        LinkTag linkTag = null;
        try {
            linkTag = HtmlParserUtil.findLink(MegaUploadDownloader.DOWNLOAD_LINK_PATTERN, body);
        } catch (ParserException e) {
        }
        if (linkTag != null) {
            String link = linkTag.extractLink();
            final String filename = IOUtil.getBaseName(link).trim();
            link = link.replaceAll("&#[0-9]*;", "_");
            final URL url = new URL(link);
            final String newLink = link.replaceAll(Pattern.quote(IOUtil.getBaseName(url.getPath())), URLEncoder.encode(IOUtil.getBaseName(url.getPath()), "UTF-8"));
            final HttpGet download = new HttpGet(newLink);
            final HttpResponse downloadResponse = this.client.execute(download);
            final HttpEntity downloadEntity = downloadResponse.getEntity();
            final long filesize = downloadEntity.getContentLength();
            return createObject(downloadEntity.getContent(), filename, filesize);
        } else {
            throw new RuntimeException("No download link.");
        }
    }
@Override
    public DaeScene loadScene(URL url) throws IOException, IncorrectFormatException, ParsingErrorException {
        NullArgumentException.check(url);
        boolean baseURLWasNull = setBaseURLFromModelURL(url);
        DaeScene scene = loadScene(url.openStream());
        if (baseURLWasNull) {
            popBaseURL();
        }
        return (scene);
    }
public boolean connect() {
        if (connectStatus > -1) return (connectStatus == 1);
        connectStatus = 0;
        try {
            URL url = new URL(getURL());
            m_connection = (HttpURLConnection) url.openConnection();
            m_connection.connect();
            processHeaders();
            m_inputStream = m_connection.getInputStream();
        } catch (MalformedURLException e) {
            newError("connect failed", e, true);
        } catch (IOException e) {
            newError("connect failed", e, true);
        }
        return (connectStatus == 1);
    }
public String getHtmlSource(String url) {
        StringBuffer codeBuffer = null;
        BufferedReader in = null;
        URLConnection uc = null;
        try {
            uc = new URL(url).openConnection();
            uc.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows XP; DigExt)");
            in = new BufferedReader(new InputStreamReader(uc.getInputStream(), "utf-8"));
            codeBuffer = new StringBuffer();
            String tempCode = "";
            while ((tempCode = in.readLine()) != null) {
                codeBuffer.append(tempCode).append("\n");
            }
            in.close();
            tempCode = null;
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (null != in) in = null;
            if (null != uc) uc = null;
        }
        return codeBuffer.toString();
    }
public void init() throws Exception {
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        int code = conn.getResponseCode();
        if (code != 200) throw new IOException("Error fetching robots.txt; respose code is " + code);
        BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        String buff;
        StringBuilder builder = new StringBuilder();
        while ((buff = reader.readLine()) != null) builder.append(buff);
        parseRobots(builder.toString());
    }
private static void copyFile(File f) {
        try {
            String baseName = baseDir.getCanonicalPath();
            String fullPath = f.getCanonicalPath();
            String nameSufix = fullPath.substring(baseName.length() + 1);
            File destFile = new File(FileDestDir, nameSufix);
            destFile.getParentFile().mkdirs();
            destFile.createNewFile();
            FileChannel fromChannel = new FileInputStream(f).getChannel();
            FileChannel toChannel = new FileOutputStream(destFile).getChannel();
            fromChannel.transferTo(0, fromChannel.size(), toChannel);
            fromChannel.close();
            toChannel.close();
            destFile.setLastModified(f.lastModified());
        } catch (Exception e) {
            System.err.println(e.getMessage());
        }
    }
public ProductListByCatHandler(int cathegory, int langId) {
        try {
            URL url = new URL("http://eiffel.itba.edu.ar/hci/service/Catalog.groovy?method=GetProductListByCategory&category_id=" + cathegory + "&language_id=" + langId);
            URLConnection urlc = url.openConnection();
            urlc.setDoOutput(false);
            urlc.setAllowUserInteraction(false);
            BufferedReader br = new BufferedReader(new InputStreamReader(urlc.getInputStream()));
            String str;
            StringBuffer sb = new StringBuffer();
            while ((str = br.readLine()) != null) {
                sb.append(str);
                sb.append("\n");
            }
            br.close();
            String response = sb.toString();
            if (response == null) {
                return;
            }
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            DocumentBuilder db = dbf.newDocumentBuilder();
            InputSource is = new InputSource();
            is.setCharacterStream(new StringReader(response));
            Document dom = db.parse(is);
            NodeList nl = dom.getElementsByTagName("product");
            for (int i = 0; i < nl.getLength(); i++) {
                Element nodes = (Element) nl.item(i);
                String id = nodes.getAttribute("id").toString();
                NodeList name = nodes.getElementsByTagName("name");
                NodeList rank2 = nodes.getElementsByTagName("sales_rank");
                NodeList price = nodes.getElementsByTagName("price");
                NodeList url2 = nodes.getElementsByTagName("image_url");
                String nameS = getCharacterDataFromElement((Element) name.item(0));
                String rank2S = getCharacterDataFromElement((Element) rank2.item(0));
                String priceS = getCharacterDataFromElement((Element) price.item(0));
                String url2S = getCharacterDataFromElement((Element) url2.item(0));
                list.add(new ProductShort(id, nameS, rank2S, priceS, url2S));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
private void sendMessages() {
        Configuration conf = Configuration.getInstance();
        for (int i = 0; i < errors.size(); i++) {
            String msg = null;
            synchronized (this) {
                msg = errors.get(i);
                if (DEBUG) System.out.println(msg);
                errors.remove(i);
            }
            if (!conf.getCustomerFeedback()) continue;
            if (conf.getApproveCustomerFeedback()) {
                ConfirmCustomerFeedback dialog = new ConfirmCustomerFeedback(JOptionPane.getFrameForComponent(SqlTablet.getInstance()), msg);
                if (dialog.getResult() == ConfirmCustomerFeedback.Result.NO) continue;
            }
            try {
                URL url = new URL("http://www.sqltablet.com/beta/bug.php");
                URLConnection urlc = url.openConnection();
                urlc.setDoOutput(true);
                urlc.setDoOutput(true);
                urlc.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
                DataOutputStream out = new DataOutputStream(urlc.getOutputStream());
                String lines[] = msg.split("\n");
                for (int l = 0; l < lines.length; l++) {
                    String line = (l > 0 ? "&line" : "line") + l + "=";
                    line += URLEncoder.encode(lines[l], "UTF-8");
                    out.write(line.getBytes());
                }
                out.flush();
                out.close();
                BufferedReader in = new BufferedReader(new InputStreamReader(urlc.getInputStream()));
                String line;
                while ((line = in.readLine()) != null) {
                    if (DEBUG) System.out.println("RemoteLogger : " + line + "\n");
                }
                in.close();
            } catch (MalformedURLException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        PrintWriter out = response.getWriter();
        response.setContentType("text/html");
        HttpSession session = request.getSession();
        String session_id = session.getId();
        File session_fileDir = new File(destinationDir + java.io.File.separator + session_id);
        session_fileDir.mkdir();
        DiskFileItemFactory fileItemFactory = new DiskFileItemFactory();
        fileItemFactory.setSizeThreshold(1 * 1024 * 1024);
        fileItemFactory.setRepository(tmpDir);
        ServletFileUpload uploadHandler = new ServletFileUpload(fileItemFactory);
        String pathToFile = new String();
        try {
            List items = uploadHandler.parseRequest(request);
            Iterator itr = items.iterator();
            while (itr.hasNext()) {
                FileItem item = (FileItem) itr.next();
                if (item.isFormField()) {
                    ;
                } else {
                    pathToFile = getServletContext().getRealPath("/") + "files" + java.io.File.separator + session_id;
                    File file = new File(pathToFile + java.io.File.separator + item.getName());
                    item.write(file);
                    getContents(file, pathToFile);
                    ComtorStandAlone.setMode(Mode.CLOUD);
                    Comtor.start(pathToFile);
                }
            }
            try {
                File reportFile = new File(pathToFile + java.io.File.separator + "comtorReport.txt");
                String reportURLString = AWSServices.storeReportS3(reportFile, session_id).toString();
                if (reportURLString.startsWith("https")) reportURLString = reportURLString.replaceFirst("https", "http");
                String requestURL = request.getRequestURL().toString();
                String url = requestURL.substring(0, requestURL.lastIndexOf("/"));
                out.println("<html><head/><body>");
                out.println("<a href=\"" + url + "\">Return to home</a>&nbsp;&nbsp;");
                out.println("<a href=\"" + reportURLString + "\">Report URL</a><br/><hr/>");
                Scanner scan = new Scanner(reportFile);
                out.println("<pre>");
                while (scan.hasNextLine()) out.println(scan.nextLine());
                out.println("</pre><hr/>");
                out.println("<a href=\"" + url + "\">Return to home</a>&nbsp;&nbsp;");
                out.println("<a href=\"" + reportURLString + "\">Report URL</a><br/>");
                out.println("</body></html>");
            } catch (Exception ex) {
                System.err.println(ex);
            }
        } catch (FileUploadException ex) {
            System.err.println("Error encountered while parsing the request" + ex);
        } catch (Exception ex) {
            System.err.println("Error encountered while uploading file" + ex);
        }
    }
@Override
    public void setDocumentSpace(DocumentSpace space) {
        for (Document doc : space) {
            File result = new File(parent, doc.getName());
            if (doc instanceof XMLDOMDocument) {
                new PlainXMLDocumentWriter(result).writeDocument(doc);
            } else if (doc instanceof BinaryDocument) {
                BinaryDocument bin = (BinaryDocument) doc;
                try {
                    IOUtils.copy(bin.getContent().getInputStream(), new FileOutputStream(result));
                } catch (IOException e) {
                    throw ManagedIOException.manage(e);
                }
            } else {
                System.err.println("Unkown Document type");
            }
        }
    }