semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public static int executeUpdate(EOAdaptorChannel channel, String sql, boolean autoCommit) throws SQLException {
        int rowsUpdated;
        boolean wasOpen = channel.isOpen();
        if (!wasOpen) {
            channel.openChannel();
        }
        Connection conn = ((JDBCContext) channel.adaptorContext()).connection();
        try {
            Statement stmt = conn.createStatement();
            try {
                rowsUpdated = stmt.executeUpdate(sql);
                if (autoCommit) {
                    conn.commit();
                }
            } catch (SQLException ex) {
                if (autoCommit) {
                    conn.rollback();
                }
                throw new RuntimeException("Failed to execute the statement '" + sql + "'.", ex);
            } finally {
                stmt.close();
            }
        } finally {
            if (!wasOpen) {
                channel.closeChannel();
            }
        }
        return rowsUpdated;
    }
private Element getXmlFromGeoNetwork(String urlIn, Session userSession) throws FailedActionException {
        Element results = null;
        try {
            URL url = new URL(urlIn);
            URLConnection conn = url.openConnection();
            conn.setConnectTimeout(1000);
            String cookie = (String) userSession.getAttribute("usercookie.object");
            if (cookie != null) conn.setRequestProperty("Cookie", cookie);
            BufferedInputStream in = new BufferedInputStream(conn.getInputStream());
            try {
                results = Xml.loadStream(in);
            } finally {
                in.close();
            }
        } catch (Exception e) {
            throw new FailedActionException(FailedActionReason.SYSTEM_ERROR);
        }
        return results;
    }
private ArrayList<String> loadProperties(String filename) throws DevFailed, IOException {
        java.net.URL url = getClass().getResource(filename);
        if (url == null) {
            Except.throw_exception("LOAD_PROPERTY_FAILED", "URL for property file (" + filename + ") is null !", "PogoProperty.loadProperties()");
            return null;
        }
        InputStream is = url.openStream();
        BufferedReader br = new BufferedReader(new InputStreamReader(is));
        ArrayList<String> vs = new ArrayList<String>();
        String str;
        while ((str = br.readLine()) != null) {
            str = str.trim();
            if (!str.startsWith("#")) if (str.length() > 0) vs.add(str);
        }
        br.close();
        return vs;
    }
public void write(File file) throws Exception {
        if (medooFile != null) {
            if (!medooFile.renameTo(file)) {
                BufferedInputStream in = null;
                BufferedOutputStream out = null;
                try {
                    in = new BufferedInputStream(new FileInputStream(medooFile));
                    out = new BufferedOutputStream(new FileOutputStream(file));
                    IOUtils.copy(in, out);
                } finally {
                    if (in != null) {
                        try {
                            in.close();
                        } catch (IOException e) {
                        }
                    }
                    if (out != null) {
                        try {
                            out.close();
                        } catch (IOException e) {
                        }
                    }
                }
            }
        } else {
            throw new FileUploadException("Cannot write uploaded file to disk!");
        }
    }
private static String digest(String myinfo) {
        try {
            MessageDigest alga = MessageDigest.getInstance("SHA");
            alga.update(myinfo.getBytes());
            byte[] digesta = alga.digest();
            return byte2hex(digesta);
        } catch (Exception ex) {
            return myinfo;
        }
    }
@Override
    protected IProject createProject(String projectName, IProgressMonitor monitor) throws CoreException {
        monitor.beginTask(CheatSheetsPlugin.INSTANCE.getString("_UI_CreateJavaProject_message", new String[] { projectName }), 5);
        IProject project = super.createProject(projectName, new SubProgressMonitor(monitor, 1));
        if (project != null) {
            IProjectDescription description = project.getDescription();
            if (!description.hasNature(JavaCore.NATURE_ID)) {
                IJavaProject javaProject = JavaCore.create(project);
                if (javaProject != null) {
                    String[] natures = description.getNatureIds();
                    String[] javaNatures = new String[natures.length + 1];
                    System.arraycopy(natures, 0, javaNatures, 0, natures.length);
                    javaNatures[natures.length] = JavaCore.NATURE_ID;
                    description.setNatureIds(javaNatures);
                    project.setDescription(description, new SubProgressMonitor(monitor, 1));
                    IFolder sourceFolder = project.getFolder(SOURCE_FOLDER);
                    if (!sourceFolder.exists()) {
                        sourceFolder.create(true, true, new SubProgressMonitor(monitor, 1));
                    }
                    javaProject.setOutputLocation(project.getFolder(OUTPUT_FOLDER).getFullPath(), new SubProgressMonitor(monitor, 1));
                    IClasspathEntry[] entries = new IClasspathEntry[] { JavaCore.newSourceEntry(sourceFolder.getFullPath()), JavaCore.newContainerEntry(new Path("org.eclipse.jdt.launching.JRE_CONTAINER")) };
                    javaProject.setRawClasspath(entries, new SubProgressMonitor(monitor, 1));
                }
            }
        }
        monitor.done();
        return project;
    }
public static int[] bubbleSort(int... a) {
        boolean swapped;
        do {
            swapped = false;
            for (int i = 0; i < a.length - 1; i++) {
                if (a[i] > a[i + 1]) {
                    int tmp = a[i];
                    a[i] = a[i + 1];
                    a[i + 1] = tmp;
                    swapped = true;
                }
            }
        } while (swapped);
        return a;
    }
public InputStream resolve(String uri) throws SAJException {
        try {
            URI url = new URI(uri);
            InputStream stream = url.toURL().openStream();
            if (stream == null) throw new SAJException("URI " + uri + " can't be resolved");
            return stream;
        } catch (SAJException e) {
            throw e;
        } catch (Exception e) {
            throw new SAJException("Invalid uri to resolve " + uri, e);
        }
    }
public void moveRowUp(int row) throws FidoDatabaseException {
        try {
            Connection conn = null;
            Statement stmt = null;
            try {
                conn = fido.util.FidoDataSource.getConnection();
                conn.setAutoCommit(false);
                stmt = conn.createStatement();
                int max = findMaxRank(stmt);
                if ((row < 2) || (row > max)) throw new IllegalArgumentException("Row number not between 2 and " + max);
                stmt.executeUpdate("update WordClassifications set Rank = -1 where Rank = " + row);
                stmt.executeUpdate("update WordClassifications set Rank = " + row + " where Rank = " + (row - 1));
                stmt.executeUpdate("update WordClassifications set Rank = " + (row - 1) + " where Rank = -1");
                conn.commit();
            } catch (SQLException e) {
                if (conn != null) conn.rollback();
                throw e;
            } finally {
                if (stmt != null) stmt.close();
                if (conn != null) conn.close();
            }
        } catch (SQLException e) {
            throw new FidoDatabaseException(e);
        }
    }
public void moveRowDown(int row) throws FidoDatabaseException {
        try {
            Connection conn = null;
            Statement stmt = null;
            try {
                conn = fido.util.FidoDataSource.getConnection();
                conn.setAutoCommit(false);
                stmt = conn.createStatement();
                int max = findMaxRank(stmt);
                if ((row < 1) || (row > (max - 1))) throw new IllegalArgumentException("Row number not between 1 and " + (max - 1));
                stmt.executeUpdate("update WordClassifications set Rank = -1 where Rank = " + row);
                stmt.executeUpdate("update WordClassifications set Rank = " + row + " where Rank = " + (row + 1));
                stmt.executeUpdate("update WordClassifications set Rank = " + (row + 1) + " where Rank = -1");
                conn.commit();
            } catch (SQLException e) {
                if (conn != null) conn.rollback();
                throw e;
            } finally {
                if (stmt != null) stmt.close();
                if (conn != null) conn.close();
            }
        } catch (SQLException e) {
            throw new FidoDatabaseException(e);
        }
    }
public void delete(int row) throws FidoDatabaseException {
        try {
            Connection conn = null;
            Statement stmt = null;
            try {
                conn = fido.util.FidoDataSource.getConnection();
                conn.setAutoCommit(false);
                stmt = conn.createStatement();
                int max = findMaxRank(stmt);
                if ((row < 1) || (row > max)) throw new IllegalArgumentException("Row number not between 1 and " + max);
                stmt.executeUpdate("delete from WordClassifications where Rank = " + row);
                for (int i = row; i < max; ++i) stmt.executeUpdate("update WordClassifications set Rank = " + i + " where Rank = " + (i + 1));
                conn.commit();
            } catch (SQLException e) {
                if (conn != null) conn.rollback();
                throw e;
            } finally {
                if (stmt != null) stmt.close();
                if (conn != null) conn.close();
            }
        } catch (SQLException e) {
            throw new FidoDatabaseException(e);
        }
    }
public static synchronized String hash(String plaintext) {
        MessageDigest md;
        try {
            md = MessageDigest.getInstance("SHA");
        } catch (NoSuchAlgorithmException e) {
            return null;
        }
        try {
            md.update(plaintext.getBytes("UTF-8"));
        } catch (UnsupportedEncodingException e) {
            return null;
        }
        byte raw[] = md.digest();
        return (new BASE64Encoder()).encode(raw);
    }
public static int[] bubbleSortOtimizado(int... a) {
        boolean swapped;
        int n = a.length - 2;
        do {
            swapped = false;
            for (int i = 0; i <= n; i++) {
                if (a[i] > a[i + 1]) {
                    int tmp = a[i];
                    a[i] = a[i + 1];
                    a[i + 1] = tmp;
                    swapped = true;
                }
            }
            n = n - 1;
        } while (swapped);
        return a;
    }
@Nullable
    public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) {
        if (logger.isLoggable(Level.FINE)) {
            logger.fine("Try to resolve the resource with the public ID: " + publicId + ", system ID: " + systemId + " and baseURI " + baseURI + ".");
        }
        InputSource inputSource = null;
        try {
            inputSource = resolveIntern(publicId, systemId);
        } catch (IOException e) {
            logger.log(Level.SEVERE, "", e);
        }
        if (inputSource != null) {
            return new LSInputSAXWrapper(inputSource);
        }
        if (baseURI != null) {
            String resolved = baseURI.substring(0, baseURI.lastIndexOf('/') + 1) + systemId;
            try {
                URL url = new URL(resolved);
                url.openConnection().connect();
                if (logger.isLoggable(Level.FINE)) {
                    logger.fine("Resolve with help of baseURI to: " + resolved);
                }
                inputSource = new InputSource(resolved);
                return new LSInputSAXWrapper(inputSource);
            } catch (MalformedURLException e) {
            } catch (IOException e) {
            }
        }
        if (logger.isLoggable(Level.WARNING)) {
            logger.warning("Failed to resolve the resource with the public ID: " + publicId + ", system ID: " + systemId + " and baseURI " + baseURI + ".");
        }
        return null;
    }
private static void loadProperties(Properties props, String res, boolean warnIfNotFound) throws IOException {
        log.debug("Reading properties from resource " + res);
        URL url = ResourceFileStorageFactory.class.getResource(res);
        if (null == url) {
            if (warnIfNotFound) {
                log.warn("Resource " + res + " was not found");
            } else {
                log.debug("Resource " + res + " was not found");
            }
        } else {
            InputStream in = url.openStream();
            try {
                props.load(in);
            } finally {
                in.close();
            }
        }
    }
public void actionPerformed(ActionEvent e) {
            String aboutText = "Slug application.";
            String aboutURL = System.getProperty(GateConstants.ABOUT_URL_JAVA_PROPERTY_NAME);
            boolean canShowInPane = false;
            if (aboutURL != null) {
                try {
                    URL url = new URL(aboutURL);
                    AboutPaneDialog dlg = new AboutPaneDialog(ShellSlacFrame.this, "Slug application about", true);
                    canShowInPane = dlg.setURL(url);
                    if (canShowInPane) {
                        dlg.setSize(300, 200);
                        dlg.setLocationRelativeTo(ShellSlacFrame.this);
                        dlg.setVisible(true);
                    } else {
                        BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
                        String line = "";
                        StringBuffer content = new StringBuffer();
                        do {
                            content.append(line);
                            line = reader.readLine();
                        } while (line != null);
                        if (content.length() != 0) {
                            aboutText = content.toString();
                        }
                    }
                } catch (Exception ex) {
                    if (DEBUG) {
                        ex.printStackTrace();
                    }
                }
            }
            if (!canShowInPane) JOptionPane.showMessageDialog(ShellSlacFrame.this, aboutText, "Slug application about", JOptionPane.INFORMATION_MESSAGE);
        }
public boolean extract(File f, String folder) {
        Enumeration entries;
        ZipFile zipFile;
        try {
            zipFile = new ZipFile(f);
            entries = zipFile.getEntries();
            while (entries.hasMoreElements()) {
                ZipArchiveEntry entry = (ZipArchiveEntry) entries.nextElement();
                if (entry == null) continue;
                String path = folder + "/" + entry.getName().replace('\\', '/');
                if (!entry.isDirectory()) {
                    File destFile = new File(path);
                    String parent = destFile.getParent();
                    if (parent != null) {
                        File parentFile = new File(parent);
                        if (!parentFile.exists()) {
                            parentFile.mkdirs();
                        }
                    }
                    copyInputStream(zipFile.getInputStream(entry), new BufferedOutputStream(new FileOutputStream(destFile)));
                }
            }
            zipFile.close();
        } catch (IOException ioe) {
            this.errMsg = ioe.getMessage();
            Malgn.errorLog("{Zip.unzip} " + ioe.getMessage());
            return false;
        }
        return true;
    }
protected void handleConnection(Socket server) throws IOException {
        OutputStream out = server.getOutputStream();
        PrintWriter pout = new PrintWriter(out, true);
        BufferedReader in = SocketUtil.getReader(server);
        String failureReason = null;
        int failureCode = 0;
        String httpVersion = "HTTP/1.0";
        String uri = null;
        String command = in.readLine();
        URL url = null;
        if (command != null) {
            StringTokenizer tokenizer = new StringTokenizer(command);
            if (tokenizer.countTokens() != 3) {
                failureCode = 400;
                failureReason = "Illformed Request-Line";
            } else {
                String method = tokenizer.nextToken();
                if (!method.equalsIgnoreCase("get")) {
                    failureCode = 501;
                    failureReason = "Only supports GET method";
                } else {
                    uri = tokenizer.nextToken();
                    httpVersion = tokenizer.nextToken();
                    try {
                        url = getURL(uri);
                    } catch (IOException e) {
                        failureCode = 404;
                        failureReason = "resource not found";
                    }
                }
            }
        } else {
            failureCode = 400;
            failureReason = "Null request";
        }
        if (url != null) {
            InputStream stream = null;
            try {
                URLConnection connection = url.openConnection();
                byte[] chunk = new byte[1024];
                int read = 0;
                pout.println(httpVersion + " 200 ");
                pout.println("Content-Type: " + connection.getContentType());
                pout.println("Content-Length: " + connection.getContentLength());
                pout.println("Content-Encoding: " + connection.getContentEncoding());
                pout.println();
                stream = connection.getInputStream();
                read = stream.read(chunk);
                while (read != -1) {
                    out.write(chunk, 0, read);
                    read = stream.read(chunk);
                }
            } catch (IOException e) {
                failureCode = 500;
                failureReason = "problem reading the resource content";
            } finally {
                if (stream != null) {
                    stream.close();
                }
            }
        } else {
            failureCode = 404;
            failureReason = "resource not found";
        }
        if (failureCode != 0) {
            pout.println(httpVersion + " " + failureCode + " " + failureReason);
            pout.println();
        }
        doDelay();
        server.close();
    }
public byte[] getBytesFromUrl(String url) {
        try {
            HttpGet get = new HttpGet(url);
            HttpResponse response = this.getHttpClient().execute(get);
            HttpEntity entity = response.getEntity();
            if (entity == null) {
                throw new RuntimeException("response body was empty");
            }
            return EntityUtils.toByteArray(entity);
        } catch (RuntimeException ex) {
            throw ex;
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
    }
public String get(String url) {
        try {
            HttpGet get = new HttpGet(url);
            HttpResponse response = this.getHttpClient().execute(get);
            HttpEntity entity = response.getEntity();
            if (entity == null) {
                throw new RuntimeException("response body was empty");
            }
            return EntityUtils.toString(entity);
        } catch (RuntimeException ex) {
            throw ex;
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
    }
public TestReport runImpl() throws Exception {
        String parser = XMLResourceDescriptor.getXMLParserClassName();
        DocumentFactory df = new SAXDocumentFactory(GenericDOMImplementation.getDOMImplementation(), parser);
        File f = (new File(testFileName));
        URL url = f.toURL();
        Document doc = df.createDocument(null, rootTag, url.toString(), url.openStream());
        Element e = doc.getElementById(targetId);
        if (e == null) {
            DefaultTestReport report = new DefaultTestReport(this);
            report.setErrorCode(ERROR_GET_ELEMENT_BY_ID_FAILED);
            report.addDescriptionEntry(ENTRY_KEY_ID, targetId);
            report.setPassed(false);
            return report;
        }
        Document otherDocument = df.createDocument(null, rootTag, url.toString(), url.openStream());
        DocumentFragment docFrag = otherDocument.createDocumentFragment();
        try {
            docFrag.appendChild(doc.getDocumentElement());
        } catch (DOMException ex) {
            return reportSuccess();
        }
        DefaultTestReport report = new DefaultTestReport(this);
        report.setErrorCode(ERROR_EXCEPTION_NOT_THROWN);
        report.setPassed(false);
        return report;
    }
public static ChannelIF addChannel(String url) throws Exception {
        ChannelIF channel = null;
        try {
            channel = FeedParser.parse(new ChannelBuilder(), url);
            if (channel.getLocation() == null) channel.setLocation(new URL(url));
        } catch (ParseException e) {
            InputStream is = new URL(url).openStream();
            InputStreamReader reader = new InputStreamReader(is);
            channel = FeedParser.parse(new ChannelBuilder(), reader);
            reader.close();
            is.close();
            if (channel.getLocation() == null) channel.setLocation(new URL(url));
        }
        DAOChannel.addChannel(channel);
        DAOFavicon.addFaviconForChannel(channel);
        return channel;
    }
public static void main(String[] arg) throws IOException {
        XmlPullParserFactory PULL_PARSER_FACTORY;
        try {
            PULL_PARSER_FACTORY = XmlPullParserFactory.newInstance(System.getProperty(XmlPullParserFactory.PROPERTY_NAME), null);
            PULL_PARSER_FACTORY.setNamespaceAware(true);
            DasParser dp = new DasParser(PULL_PARSER_FACTORY);
            URL url = new URL("http://www.ebi.ac.uk/das-srv/uniprot/das/uniprot/features?segment=P05067");
            InputStream in = url.openStream();
            BufferedReader br = new BufferedReader(new InputStreamReader(in));
            String aLine, xml = "";
            while ((aLine = br.readLine()) != null) {
                xml += aLine;
            }
            WritebackDocument wbd = dp.parse(xml);
            System.out.println("FIN" + wbd);
        } catch (XmlPullParserException xppe) {
            throw new IllegalStateException("Fatal Exception thrown at initialisation.  Cannot initialise the PullParserFactory required to allow generation of the DAS XML.", xppe);
        }
    }