semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public int update(BusinessObject o) throws DAOException {
        int update = 0;
        Account acc = (Account) o;
        try {
            PreparedStatement pst = connection.prepareStatement(XMLGetQuery.getQuery("UPDATE_ACCOUNT"));
            pst.setString(1, acc.getName());
            pst.setString(2, acc.getAddress());
            pst.setInt(3, acc.getCurrency());
            pst.setInt(4, acc.getMainContact());
            pst.setBoolean(5, acc.isArchived());
            pst.setInt(6, acc.getId());
            update = pst.executeUpdate();
            if (update <= 0) {
                connection.rollback();
                throw new DAOException("Number of rows <= 0");
            } else if (update > 1) {
                connection.rollback();
                throw new DAOException("Number of rows > 1");
            }
            connection.commit();
        } catch (SQLException e) {
            Log.write(e.getMessage());
            throw new DAOException("A SQLException has occured");
        } catch (NullPointerException npe) {
            Log.write(npe.getMessage());
            throw new DAOException("Connection null");
        }
        return update;
    }
private void delete(Connection conn, int itemId) throws SQLException {
            Statement statement = null;
            try {
                conn.setAutoCommit(false);
                deleteComponents(conn, itemId);
                statement = conn.createStatement();
                StringBuffer sqlBuff = new StringBuffer("DELETE FROM ");
                sqlBuff.append(m_dbItemName);
                sqlBuff.append(" WHERE ");
                sqlBuff.append(m_dbItemIdFieldColName);
                sqlBuff.append(" = ");
                sqlBuff.append(Integer.toString(itemId));
                String sql = sqlBuff.toString();
                statement.executeUpdate(sql);
                conn.commit();
            } catch (SQLException ex) {
                try {
                    conn.rollback();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
                throw ex;
            } finally {
                if (statement != null) {
                    statement.close();
                }
            }
        }
void execute(Connection conn, Component parent, String context, final ProgressMonitor progressMonitor, ProgressWrapper progressWrapper) throws Exception {
            int noOfComponents = m_components.length;
            Statement statement = null;
            StringBuffer pmNoteBuf = new StringBuffer(m_update ? "Updating " : "Creating ");
            pmNoteBuf.append(m_itemNameAbbrev);
            pmNoteBuf.append(" ");
            pmNoteBuf.append(m_itemNameValue);
            final String pmNote = pmNoteBuf.toString();
            progressMonitor.setNote(pmNote);
            try {
                conn.setAutoCommit(false);
                int id = -1;
                if (m_update) {
                    statement = conn.createStatement();
                    String sql = getUpdateSql(noOfComponents, m_id);
                    statement.executeUpdate(sql);
                    id = m_id;
                    if (m_indexesChanged) deleteComponents(conn, id);
                } else {
                    PreparedStatement pStmt = getInsertPrepStmt(conn, noOfComponents);
                    pStmt.executeUpdate();
                    Integer res = DbCommon.getAutoGenId(parent, context, pStmt);
                    if (res == null) return;
                    id = res.intValue();
                }
                if (!m_update || m_indexesChanged) {
                    PreparedStatement insertCompPrepStmt = conn.prepareStatement(getInsertComponentPrepStmtSql());
                    for (int i = 0; i < noOfComponents; i++) {
                        createComponent(progressMonitor, m_components, pmNote, id, i, insertCompPrepStmt);
                    }
                }
                conn.commit();
                m_itemTable.getPrimaryId().setVal(m_item, id);
                m_itemCache.updateCache(m_item, id);
            } catch (SQLException ex) {
                try {
                    conn.rollback();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
                throw ex;
            } finally {
                if (statement != null) {
                    statement.close();
                }
            }
        }
private Document getXML(String artist) throws Exception {
        Document doc = null;
        URL url = new URL("http://" + disgogsUrl + "/artist/" + formatQuery(artist) + "?f=xml&api_key=" + apiKey[0]);
        HttpURLConnection uc = (HttpURLConnection) url.openConnection();
        uc.addRequestProperty("Accept-Encoding", "gzip");
        if (StaticObj.PROXY_ENABLED) {
            Properties systemSettings = System.getProperties();
            systemSettings.put("http.proxyHost", StaticObj.PROXY_URL);
            systemSettings.put("http.proxyPort", StaticObj.PROXY_PORT);
            System.setProperties(systemSettings);
            sun.misc.BASE64Encoder encoder = new sun.misc.BASE64Encoder();
            String encoded = new String(encoder.encode(new String(StaticObj.PROXY_USERNAME + ":" + StaticObj.PROXY_PASSWORD).getBytes()));
            uc.setRequestProperty("Proxy-Authorization", "Basic " + encoded);
        }
        BufferedReader ir = null;
        try {
            if (uc.getInputStream() != null) {
                InputStream _is = uc.getInputStream();
                GZIPInputStream _gzipIs = new GZIPInputStream(_is);
                InputStreamReader _isReader = new InputStreamReader(_gzipIs);
                ir = new BufferedReader(_isReader);
                SAXBuilder builder = new SAXBuilder();
                doc = builder.build(ir);
            }
        } catch (Exception e) {
            if (StaticObj.DEBUG) {
                LogManager.getInstance().getLogger().error(e);
                e.printStackTrace();
                System.out.println("No Data found!");
            }
        }
        return doc;
    }
public Document searchRelease(String id) throws Exception {
        Document doc = null;
        URL url = new URL("http://" + disgogsUrl + "/release/" + id + "?f=xml&api_key=" + apiKey[0]);
        HttpURLConnection uc = (HttpURLConnection) url.openConnection();
        uc.addRequestProperty("Accept-Encoding", "gzip");
        BufferedReader ir = null;
        if (uc.getInputStream() != null) {
            ir = new BufferedReader(new InputStreamReader(new GZIPInputStream(uc.getInputStream()), "ISO8859_1"));
            SAXBuilder builder = new SAXBuilder();
            doc = builder.build(ir);
        }
        return doc;
    }
@Override
    public void run() {
        YouTubeFeedParserHandler parserHandler = new YouTubeFeedParserHandler();
        SAXParserFactory spf = SAXParserFactory.newInstance();
        try {
            URL url = new URL(m_YouTubeFeedUrl);
            SAXParser sp = spf.newSAXParser();
            XMLReader xr = sp.getXMLReader();
            xr.setContentHandler(parserHandler);
            InputStream is = url.openStream();
            InputSource input = new InputSource(is);
            xr.parse(input);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (SAXException e) {
            e.printStackTrace();
        } catch (ParserConfigurationException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        resp.setContentType("text/html");
        String year = req.getParameter("year").toString();
        String round = req.getParameter("round").toString();
        resp.getWriter().println("<html><body>");
        resp.getWriter().println("Searching for : " + year + ", " + round + "<br/>");
        StringBuffer sb = new StringBuffer("http://www.dfb.de/bliga/bundes/archiv/");
        sb.append(year).append("/xml/blm_e_").append(round).append("_").append(year.substring(2, 4)).append(".xml");
        resp.getWriter().println(sb.toString() + "<br/><br/>");
        try {
            URL url = new URL(sb.toString());
            BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
            StringBuffer xml = new StringBuffer();
            String line;
            while ((line = reader.readLine()) != null) {
                xml.append(line);
            }
            Document document = DocumentHelper.parseText(xml.toString());
            List termine = document.selectNodes("//ergx/termin");
            int index = 1;
            for (Object termin : termine) {
                Element terminNode = (Element) termin;
                resp.getWriter().println("Termin " + index + " : " + terminNode.element("datum").getText() + "<br/>");
                resp.getWriter().println("Heim:" + terminNode.element("teama").getText() + "<br/>");
                resp.getWriter().println("Gast:" + terminNode.element("teamb").getText() + "<br/>");
                resp.getWriter().println("Ergebnis:" + terminNode.element("punkte_a").getText() + ":" + terminNode.element("punkte_b").getText() + "<br/>");
                resp.getWriter().println("<br/>");
                index++;
            }
            resp.getWriter().println();
            resp.getWriter().println("</body></html>");
            reader.close();
        } catch (MalformedURLException ex) {
            throw new RuntimeException(ex);
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        } catch (DocumentException ex) {
            throw new RuntimeException(ex);
        }
    }
public static void main(String[] args) throws Exception {
        DefaultHttpClient httpclient = new DefaultHttpClient();
        httpclient.getCredentialsProvider().setCredentials(new AuthScope("localhost", 80), new UsernamePasswordCredentials("username", "password"));
        BasicHttpContext localcontext = new BasicHttpContext();
        DigestScheme digestAuth = new DigestScheme();
        digestAuth.overrideParamter("realm", "some realm");
        digestAuth.overrideParamter("nonce", "whatever");
        localcontext.setAttribute("preemptive-auth", digestAuth);
        httpclient.addRequestInterceptor(new PreemptiveAuth(), 0);
        httpclient.addResponseInterceptor(new PersistentDigest());
        HttpHost targetHost = new HttpHost("localhost", 80, "http");
        HttpGet httpget = new HttpGet("/");
        System.out.println("executing request: " + httpget.getRequestLine());
        System.out.println("to target: " + targetHost);
        for (int i = 0; i < 3; i++) {
            HttpResponse response = httpclient.execute(targetHost, httpget, localcontext);
            HttpEntity entity = response.getEntity();
            System.out.println("----------------------------------------");
            System.out.println(response.getStatusLine());
            if (entity != null) {
                System.out.println("Response content length: " + entity.getContentLength());
                entity.consumeContent();
            }
        }
    }
public FTPClient getFTP(final Credentials credentials, final String remoteFile) throws NumberFormatException, SocketException, IOException, AccessDeniedException {
        String fileName = extractFilename(remoteFile);
        String fileDirectory = getPathName(remoteFile).substring(0, getPathName(remoteFile).indexOf(fileName));
        FTPClient ftp;
        ftp = new FTPClient();
        loadConfig();
        logger.info("FTP connection to: " + extractHostname(remoteFile));
        logger.info("FTP PORT: " + prop.getProperty("port"));
        ftp.connect(extractHostname(remoteFile), Integer.parseInt(prop.getProperty("port")));
        int reply = ftp.getReplyCode();
        if (!(FTPReply.isPositiveCompletion(reply))) {
            return null;
        }
        ftp.setFileTransferMode(org.apache.commons.net.ftp.FTP.BINARY_FILE_TYPE);
        ftp.setFileType(org.apache.commons.net.ftp.FTP.BINARY_FILE_TYPE);
        if (!ftp.login(credentials.getUserName(), credentials.getPassword())) {
            throw new AccessDeniedException(prop.getProperty("login_message"));
        }
        if (fileDirectory != null) {
            ftp.changeWorkingDirectory(fileDirectory);
        }
        return ftp;
    }
public static String encodeMD5(String param) throws Exception {
        MessageDigest digest = MessageDigest.getInstance("MD5");
        digest.update(param.getBytes());
        byte[] hash = digest.digest();
        char buf[] = new char[hash.length * 2];
        for (int i = 0, x = 0; i < hash.length; i++) {
            buf[x++] = HEX_CHARS[(hash[i] >>> 4) & 0xf];
            buf[x++] = HEX_CHARS[hash[i] & 0xf];
        }
        return String.valueOf(buf);
    }
private void reload() {
        if (xml != null) {
            try {
                String currentDate = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
                if (currentDate.equalsIgnoreCase(exchangeRateDate)) {
                    return;
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        XPath xpath = null;
        try {
            DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
            URLConnection conn = null;
            URL url = new URL("http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml");
            conn = url.openConnection();
            xml = docBuilder.parse(conn.getInputStream());
            xpath = XPathFactory.newInstance().newXPath();
            exchangeRateDate = xpath.evaluate("/Envelope/Cube/Cube/@time", xml);
            xpath = XPathFactory.newInstance().newXPath();
            NodeList currenciesNode = (NodeList) xpath.evaluate("/Envelope/Cube/Cube/Cube[@currency]", xml, XPathConstants.NODESET);
            currencies = new String[currenciesNode.getLength()];
            for (int i = 0; i < currencies.length; i++) {
                currencies[i] = currenciesNode.item(i).getAttributes().getNamedItem("currency").getTextContent();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
public String tranportRemoteUnitToLocalTempFile(String urlStr) throws UnitTransportException {
        URL url = null;
        File tempUnit = null;
        BufferedOutputStream bos = null;
        try {
            url = new URL(urlStr);
        } catch (MalformedURLException e1) {
            logger.error(String.format("The url [%s] is illegal.", urlStr), e1);
            throw new UnitTransportException(String.format("The url [%s] is illegal.", urlStr), e1);
        }
        URLConnection con = null;
        BufferedInputStream in = null;
        try {
            con = url.openConnection();
            in = new BufferedInputStream(con.getInputStream());
        } catch (IOException e) {
            logger.error(String.format("Can't open url [%s].", urlStr));
            throw new UnitTransportException(String.format("Can't open url [%s].", urlStr), e);
        } catch (Exception e) {
            logger.error(String.format("Unknown error. Maybe miss the username and password in url [%s].", urlStr), e);
            throw new UnitTransportException(String.format("Unknown error. Maybe miss the username and password in url [%s].", urlStr), e);
        }
        String unitName = urlStr.substring(urlStr.lastIndexOf('/') + 1);
        try {
            if (!StringUtils.isEmpty(unitName)) tempUnit = new File(CommonUtil.getTempDir(), unitName); else tempUnit = new File(CommonUtil.createTempFile());
        } catch (DeployToolException e) {
            logger.error(String.format("Can't get temp file [%s].", tempUnit));
            throw new UnitTransportException(String.format("Can't get temp file [%s].", tempUnit), e);
        }
        try {
            bos = new BufferedOutputStream(new FileOutputStream(tempUnit));
            logger.info(String.format("Use [%s] for ftp unit [%s].", tempUnit, urlStr));
        } catch (FileNotFoundException e) {
            logger.error(String.format("File [%s] don't exist.", tempUnit));
            throw new UnitTransportException(String.format("File [%s] don't exist.", tempUnit), e);
        }
        try {
            IOUtils.copy(in, bos);
            bos.flush();
        } catch (IOException e) {
            logger.error(String.format("Error when download [%s] to [%s].", urlStr, tempUnit), e);
            throw new UnitTransportException(String.format("Error when download [%s] to [%s].", urlStr, tempUnit), e);
        } finally {
            IOUtils.closeQuietly(bos);
            IOUtils.closeQuietly(in);
        }
        logger.info(String.format("Download unit to [%s].", tempUnit.getAbsolutePath()));
        return tempUnit.getAbsolutePath();
    }
public void setPage(String url) {
        System.out.println("SetPage(" + url + ")");
        if (url != null) {
            if (!url.startsWith("http://")) {
                url = "http://" + url;
            }
            boolean exists = false;
            for (int i = 0; i < urlComboBox.getItemCount(); i++) {
                if (((String) urlComboBox.getItemAt(i)).equals(url)) {
                    exists = true;
                    urlComboBox.setSelectedItem(url);
                }
            }
            if (!exists) {
                int i = urlComboBox.getSelectedIndex();
                if (i == -1 || urlComboBox.getItemCount() == 0) {
                    i = 0;
                } else {
                    i++;
                }
                urlComboBox.insertItemAt(url, i);
                urlComboBox.setSelectedItem(url);
            }
            boolean image = false;
            for (final String element : imageExtensions) {
                if (url.endsWith(element)) {
                    image = true;
                }
            }
            try {
                if (image) {
                    final String html = "<html><img src=\"" + url + "\"></html>";
                } else {
                    final String furl = url;
                    Runnable loadPage = new Runnable() {

                        public void run() {
                            try {
                                System.out.println("Setting page on Cobra");
                                SimpleHtmlRendererContext rendererContext = new SimpleHtmlRendererContext(htmlPanel, new SimpleUserAgentContext());
                                int nodeBaseEnd = furl.indexOf("/", 10);
                                if (nodeBaseEnd == -1) nodeBaseEnd = furl.length();
                                String nodeBase = furl.substring(0, nodeBaseEnd);
                                InputStream pageStream = new URL(furl).openStream();
                                BufferedReader pageStreamReader = new BufferedReader(new InputStreamReader(pageStream));
                                String pageContent = "";
                                String line;
                                while ((line = pageStreamReader.readLine()) != null) pageContent += line;
                                pageContent = borderImages(pageContent, nodeBase);
                                htmlPanel.setHtml(pageContent, furl, rendererContext);
                            } catch (Exception e) {
                                System.out.println("Error loading page " + furl + " : " + e);
                            }
                        }
                    };
                    new Thread(loadPage).start();
                }
            } catch (final Throwable exception) {
                System.out.println("Error in Browser.setPage(): " + exception);
            }
        }
    }
public void run() {
                            try {
                                System.out.println("Setting page on Cobra");
                                SimpleHtmlRendererContext rendererContext = new SimpleHtmlRendererContext(htmlPanel, new SimpleUserAgentContext());
                                int nodeBaseEnd = furl.indexOf("/", 10);
                                if (nodeBaseEnd == -1) nodeBaseEnd = furl.length();
                                String nodeBase = furl.substring(0, nodeBaseEnd);
                                InputStream pageStream = new URL(furl).openStream();
                                BufferedReader pageStreamReader = new BufferedReader(new InputStreamReader(pageStream));
                                String pageContent = "";
                                String line;
                                while ((line = pageStreamReader.readLine()) != null) pageContent += line;
                                pageContent = borderImages(pageContent, nodeBase);
                                htmlPanel.setHtml(pageContent, furl, rendererContext);
                            } catch (Exception e) {
                                System.out.println("Error loading page " + furl + " : " + e);
                            }
                        }
public static void copyFileToFile(File srcFile, File dstFile, boolean deleteOriginals, boolean forceDelete) throws FileNotFoundException, IOException {
        if (srcFile.exists() && srcFile.isFile()) {
            boolean copied = false;
            if (deleteOriginals && (!forceDelete || srcFile.canWrite())) {
                copied = srcFile.renameTo(dstFile);
            }
            if (!copied) {
                Throwable thrownException = null;
                File parent = dstFile.getParentFile();
                if (!parent.exists() && !parent.mkdirs()) {
                    throw new IOException("Failed to create the directory " + parent + ".");
                }
                FileInputStream in = new FileInputStream(srcFile);
                try {
                    FileChannel srcChannel = in.getChannel();
                    try {
                        FileOutputStream out = new FileOutputStream(dstFile);
                        try {
                            FileChannel dstChannel = out.getChannel();
                            try {
                                dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
                            } catch (Throwable t) {
                                thrownException = t;
                            } finally {
                                dstChannel.close();
                            }
                        } catch (Throwable t) {
                            if (thrownException == null) {
                                thrownException = t;
                            }
                        } finally {
                            out.close();
                        }
                    } catch (Throwable t) {
                        if (thrownException == null) {
                            thrownException = t;
                        }
                    } finally {
                        srcChannel.close();
                    }
                } catch (Throwable t) {
                    if (thrownException == null) {
                        thrownException = t;
                    }
                } finally {
                    try {
                        in.close();
                    } catch (IOException e) {
                        if (thrownException == null) {
                            thrownException = e;
                        }
                    }
                }
                if (deleteOriginals && (srcFile.canWrite() || forceDelete)) {
                    if (!srcFile.delete()) {
                        throw new IOException("Failed to delete " + srcFile + ".");
                    }
                }
                if (thrownException != null) {
                    if (thrownException instanceof IOException) {
                        throw (IOException) thrownException;
                    } else if (thrownException instanceof Error) {
                        throw (Error) thrownException;
                    } else {
                        throw (RuntimeException) thrownException;
                    }
                }
            }
        }
    }