semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public boolean isWebServerAvaliable(String url) {
        long inicial = new Date().getTime();
        HttpURLConnection connection = null;
        try {
            URL urlBase = urlBase = new URL(url);
            getLog().info("Verificando se WebServer esta no ar: " + urlBase.toString());
            connection = (HttpURLConnection) urlBase.openConnection();
            connection.connect();
        } catch (Exception e) {
            return false;
        } finally {
            try {
                getLog().info("Resposta do WebServer: " + connection.getResponseCode());
            } catch (IOException e) {
                e.printStackTrace();
                return false;
            }
            long tfinal = new Date().getTime();
            getLog().info("Tempo esperado: " + ((tfinal - inicial) / 1000) + " segundos!");
        }
        return true;
    }
public HashMap<String, String> prepareDataFile(String fileName) {
        File originalDataFile = new File(fileName);
        String tableName = new String();
        String line = new String();
        BufferedReader br;
        BufferedWriter bw;
        long recordsNumber;
        File tempDataFile;
        HashMap<String, String> tableFileMap = new HashMap<String, String>();
        String filePath = new String();
        try {
            br = new BufferedReader(new InputStreamReader(new FileInputStream(originalDataFile)));
            if (br.ready()) {
                if ((line = br.readLine()) != null) {
                    do {
                        tableName = "temp_" + getTableName(line);
                        tempDataFile = new File("./Data/" + tableName + ".txt");
                        tempDataFile.createNewFile();
                        tableFileMap.put(tableName, tempDataFile.getCanonicalPath());
                        recordsNumber = getRecordNumber(line);
                        bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(tempDataFile)));
                        for (long i = 0; i < recordsNumber; i++) {
                            bw.write(br.readLine() + "\r\n");
                        }
                        bw.close();
                    } while ((line = br.readLine()) != null);
                }
                br.close();
                return tableFileMap;
            }
        } catch (Exception e) {
            ExceptionHandler.handleExcptin(e);
        }
        return null;
    }
public void login(String a_username, String a_password) throws GB_SecurityException {
        Exception l_exception = null;
        try {
            if (clientFtp == null) {
                clientFtp = new FTPClient();
                clientFtp.connect("ftp://" + ftp);
            }
            boolean b = clientFtp.login(a_username, a_password);
            if (b) {
                username = a_username;
                password = a_password;
                return;
            }
        } catch (Exception ex) {
            l_exception = ex;
        }
        String l_msg = "Cannot login to ftp server with user [{1}], {2}";
        String[] l_replaces = new String[] { a_username, ftp };
        l_msg = STools.replace(l_msg, l_replaces);
        throw new GB_SecurityException(l_msg, l_exception);
    }
public Scene load(URL url) throws FileNotFoundException, IncorrectFormatException, ParsingErrorException {
        BufferedReader reader;
        if (baseUrl == null) setBaseUrlFromUrl(url);
        try {
            reader = new BufferedReader(new InputStreamReader(url.openStream()));
        } catch (IOException e) {
            throw new FileNotFoundException(e.getMessage());
        }
        fromUrl = true;
        return load(reader);
    }
Object execute(String method, Vector params) throws XmlRpcException, IOException {
            fault = false;
            long now = 0;
            if (XmlRpc.debug) {
                System.err.println("Client calling procedure '" + method + "' with parameters " + params);
                now = System.currentTimeMillis();
            }
            try {
                ByteArrayOutputStream bout = new ByteArrayOutputStream();
                if (buffer == null) {
                    buffer = new ByteArrayOutputStream();
                } else {
                    buffer.reset();
                }
                XmlWriter writer = new XmlWriter(buffer);
                writeRequest(writer, method, params);
                writer.flush();
                byte[] request = buffer.toByteArray();
                URLConnection con = url.openConnection();
                con.setDoInput(true);
                con.setDoOutput(true);
                con.setUseCaches(false);
                con.setAllowUserInteraction(false);
                con.setRequestProperty("Content-Length", Integer.toString(request.length));
                con.setRequestProperty("Content-Type", "text/xml");
                if (auth != null) {
                    con.setRequestProperty("Authorization", "Basic " + auth);
                }
                OutputStream out = con.getOutputStream();
                out.write(request);
                out.flush();
                out.close();
                InputStream in = con.getInputStream();
                parse(in);
            } catch (Exception x) {
                if (XmlRpc.debug) {
                    x.printStackTrace();
                }
                throw new IOException(x.getMessage());
            }
            if (fault) {
                XmlRpcException exception = null;
                try {
                    Hashtable f = (Hashtable) result;
                    String faultString = (String) f.get("faultString");
                    int faultCode = Integer.parseInt(f.get("faultCode").toString());
                    exception = new XmlRpcException(faultCode, faultString.trim());
                } catch (Exception x) {
                    throw new XmlRpcException(0, "Invalid fault response");
                }
                throw exception;
            }
            if (XmlRpc.debug) {
                System.err.println("Spent " + (System.currentTimeMillis() - now) + " in request");
            }
            return result;
        }
private FTPClient connect() throws IOException {
        FTPClient client = null;
        Configuration conf = getConf();
        String host = conf.get("fs.ftp.host");
        int port = conf.getInt("fs.ftp.host.port", FTP.DEFAULT_PORT);
        String user = conf.get("fs.ftp.user." + host);
        String password = conf.get("fs.ftp.password." + host);
        client = new FTPClient();
        client.connect(host, port);
        int reply = client.getReplyCode();
        if (!FTPReply.isPositiveCompletion(reply)) {
            throw new IOException("Server - " + host + " refused connection on port - " + port);
        } else if (client.login(user, password)) {
            client.setFileTransferMode(FTP.BLOCK_TRANSFER_MODE);
            client.setFileType(FTP.BINARY_FILE_TYPE);
            client.setBufferSize(DEFAULT_BUFFER_SIZE);
        } else {
            throw new IOException("Login failed on server - " + host + ", port - " + port);
        }
        return client;
    }
public void copyFile(File a_fileSrc, File a_fileDest, boolean a_append) throws IOException {
        a_fileDest.getParentFile().mkdirs();
        FileInputStream in = null;
        FileOutputStream out = null;
        FileChannel fcin = null;
        FileChannel fcout = null;
        try {
            in = new FileInputStream(a_fileSrc);
            out = new FileOutputStream(a_fileDest, a_append);
            fcin = in.getChannel();
            fcout = out.getChannel();
            ByteBuffer buffer = ByteBuffer.allocate(16 * 1024);
            while (true) {
                buffer.clear();
                int r = fcin.read(buffer);
                if (r == -1) {
                    break;
                }
                buffer.flip();
                fcout.write(buffer);
            }
        } catch (IOException ex) {
            throw ex;
        } finally {
            if (in != null) {
                in.close();
            }
            if (out != null) {
                out.close();
            }
            if (fcin != null) {
                fcin.close();
            }
            if (fcout != null) {
                fcout.close();
            }
        }
    }
private ArrayList loadHTML(URL url) {
        ArrayList res = new ArrayList();
        try {
            URLConnection myCon = url.openConnection();
            BufferedReader in = new BufferedReader(new InputStreamReader(myCon.getInputStream()));
            String inputLine;
            while ((inputLine = in.readLine()) != null) {
                res.add(inputLine);
            }
            in.close();
        } catch (Exception e) {
            System.out.println("url> " + url);
        }
        return res;
    }
public static int fileCopy(String strSourceFilePath, String strDestinationFilePath, String strFileName) throws IOException {
        String SEPARATOR = System.getProperty("file.separator");
        File dir = new File(strSourceFilePath);
        if (!dir.exists()) dir.mkdirs();
        File realDir = new File(strDestinationFilePath);
        if (!realDir.exists()) realDir.mkdirs();
        FileInputStream fis = null;
        FileOutputStream fos = null;
        try {
            fis = new FileInputStream(new File(strSourceFilePath + SEPARATOR + strFileName));
            fos = new FileOutputStream(new File(strDestinationFilePath + SEPARATOR + strFileName));
            IOUtils.copy(fis, fos);
        } catch (Exception ex) {
            return -1;
        } finally {
            try {
                fos.close();
                fis.close();
            } catch (Exception ex2) {
            }
        }
        return 0;
    }
public static int fileUpload(long lngFileSize, InputStream inputStream, String strFilePath, String strFileName) throws IOException {
        String SEPARATOR = System.getProperty("file.separator");
        if (lngFileSize > (10 * 1024 * 1024)) {
            return -1;
        }
        InputStream is = null;
        FileOutputStream fos = null;
        try {
            File dir = new File(strFilePath);
            if (!dir.exists()) dir.mkdirs();
            is = inputStream;
            fos = new FileOutputStream(new File(strFilePath + SEPARATOR + strFileName));
            IOUtils.copy(is, fos);
        } catch (Exception ex) {
            return -2;
        } finally {
            try {
                fos.close();
                is.close();
            } catch (Exception ex2) {
            }
        }
        return 0;
    }
private void checkForNewVersion() {
        try {
            org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(net.xan.taskstack.TaskStackApp.class).getContext().getResourceMap(NewTaskDialog.class);
            String versionUrl = resourceMap.getString("Application.versionFileUrl");
            long startTime = System.currentTimeMillis();
            System.out.println("Retrieving version file from\n" + versionUrl);
            URL url = new URL(versionUrl);
            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
            String str;
            while ((str = in.readLine()) != null) {
                if (str.startsWith("LastVersion")) {
                    String remoteVersion = str.substring(str.indexOf("=") + 1);
                    String localVersion = resourceMap.getString("Application.version");
                    System.out.println("Version file found");
                    System.out.println("Local version: " + localVersion);
                    System.out.println("Remote version: " + remoteVersion);
                    if (remoteVersion.compareTo(localVersion) > 0) {
                        askDownloadNewVersion(remoteVersion, localVersion);
                    }
                    break;
                }
            }
            long endTime = System.currentTimeMillis();
            System.out.println("Elapsed time " + (endTime - startTime) + "ms");
            in.close();
        } catch (MalformedURLException e) {
            System.err.println(e.getMessage());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
private void loadURL(URL url, String username, String password, JLabel statusDialogMBLabel) throws IOException {
        URLConnection connection = url.openConnection();
        if (username != null && !username.equals("")) {
            if (password == null) {
                password = "";
            }
            String encoding = new sun.misc.BASE64Encoder().encode(new String(username + ":" + password).getBytes());
            connection.setRequestProperty("Authorization", "Basic " + encoding);
        }
        BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
        String inputLine;
        this.tmpVRMLFile = File.createTempFile("xnavi-", null, null);
        System.out.println("Created tmp file: " + this.tmpVRMLFile.getAbsolutePath());
        FileWriter fw = new FileWriter(this.tmpVRMLFile);
        long bytesInFile = this.tmpVRMLFile.length();
        double sizeInMB = ((double) bytesInFile) / (1024.0 * 1024.0);
        String response = "";
        while ((inputLine = in.readLine()) != null) {
            response = inputLine + "\n";
            fw.write(response);
            fw.flush();
            if (statusDialogMBLabel != null) {
                bytesInFile = this.tmpVRMLFile.length();
                sizeInMB = ((double) bytesInFile) / (1024.0 * 1024.0);
                sizeInMB *= 100.0;
                sizeInMB = (double) ((int) sizeInMB);
                sizeInMB /= 100.0;
                statusDialogMBLabel.setText(sizeInMB + " MB");
                statusDialogMBLabel.repaint();
            }
        }
        fw.close();
        System.out.println("Wrote file " + this.tmpVRMLFile.getAbsolutePath());
    }
public static void copyFile(File source, File target) throws Exception {
        if (source == null || target == null) {
            throw new IllegalArgumentException("The arguments may not be null.");
        }
        try {
            FileChannel srcChannel = new FileInputStream(source).getChannel();
            FileChannel dtnChannel = new FileOutputStream(target).getChannel();
            srcChannel.transferTo(0, srcChannel.size(), dtnChannel);
            srcChannel.close();
            dtnChannel.close();
        } catch (Exception e) {
            String message = "Unable to copy file '" + source.getName() + "' to '" + target.getName() + "'.";
            logger.error(message, e);
            throw new Exception(message, e);
        }
    }
protected GraphicalViewer createGraphicalViewer(Composite parent) {
        GraphicalViewer viewer = new ScrollingGraphicalViewer();
        viewer.createControl(parent);
        viewer.getControl().setBackground(parent.getBackground());
        viewer.setRootEditPart(new ScalableFreeformRootEditPart());
        GraphicalViewerKeyHandler graphicalViewerKeyHandler = new GraphicalViewerKeyHandler(viewer);
        KeyHandler parentKeyHandler = graphicalViewerKeyHandler.setParent(getCommonKeyHandler());
        viewer.setKeyHandler(parentKeyHandler);
        getEditDomain().addViewer(viewer);
        getSite().setSelectionProvider(viewer);
        ContextMenuProvider provider = new TestContextMenuProvider(viewer, getActionRegistry());
        viewer.setContextMenu(provider);
        getSite().registerContextMenu("cubicTestPlugin.editor.contextmenu", provider, viewer);
        viewer.addDropTargetListener(new DataEditDropTargetListner(((IFileEditorInput) getEditorInput()).getFile().getProject(), viewer));
        viewer.addDropTargetListener(new FileTransferDropTargetListener(viewer));
        viewer.setEditPartFactory(getEditPartFactory());
        viewer.setContents(getContent());
        return viewer;
    }
public static String do_checksum(String data) throws NoSuchAlgorithmException {
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        StringBuffer strbuf = new StringBuffer();
        md5.update(data.getBytes(), 0, data.length());
        byte[] digest = md5.digest();
        for (int i = 0; i < digest.length; i++) {
            strbuf.append(toHexString(digest[i]));
        }
        return strbuf.toString();
    }
public void SetRoles(Connection conn, User user, String[] roles) throws NpsException {
        if (!IsSysAdmin() && !IsLocalAdmin()) throw new NpsException(ErrorHelper.ACCESS_NOPRIVILEGE);
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        try {
            String sql = "delete from userrole where userid=?";
            pstmt = conn.prepareStatement(sql);
            pstmt.setString(1, user.id);
            pstmt.executeUpdate();
            if (roles != null && roles.length > 0) {
                try {
                    pstmt.close();
                } catch (Exception e1) {
                }
                sql = "insert into userrole(userid,roleid) values(?,?)";
                pstmt = conn.prepareStatement(sql);
                for (int i = 0; i < roles.length; i++) {
                    if (roles[i] != null && roles[i].length() > 0) {
                        pstmt.setString(1, user.GetId());
                        pstmt.setString(2, roles[i]);
                        pstmt.executeUpdate();
                    }
                }
            }
            try {
                pstmt.close();
            } catch (Exception e1) {
            }
            if (user.roles_by_name != null) user.roles_by_name.clear();
            if (user.roles_by_id != null) user.roles_by_id.clear();
            if (roles != null && roles.length > 0) {
                sql = "select b.* from UserRole a,Role b where a.roleid = b.id and a.userid=?";
                pstmt = conn.prepareStatement(sql);
                pstmt.setString(1, user.id);
                rs = pstmt.executeQuery();
                while (rs.next()) {
                    if (user.roles_by_name == null) user.roles_by_name = new Hashtable();
                    if (user.roles_by_id == null) user.roles_by_id = new Hashtable();
                    user.roles_by_name.put(rs.getString("name"), rs.getString("id"));
                    user.roles_by_id.put(rs.getString("id"), rs.getString("name"));
                }
            }
        } catch (Exception e) {
            try {
                conn.rollback();
            } catch (Exception e1) {
            }
            nps.util.DefaultLog.error(e);
        } finally {
            if (rs != null) try {
                rs.close();
            } catch (Exception e) {
            }
            if (pstmt != null) try {
                pstmt.close();
            } catch (Exception e1) {
            }
        }
    }
public static String post(String url, Map params, String line_delimiter) {
        String response = "";
        try {
            URL _url = new URL(url);
            URLConnection conn = _url.openConnection();
            conn.setDoOutput(true);
            OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
            String postdata = "";
            int mapsize = params.size();
            Iterator keyValue = params.entrySet().iterator();
            for (int i = 0; i < mapsize; i++) {
                Map.Entry entry = (Map.Entry) keyValue.next();
                String key = (String) entry.getKey();
                String value = (String) entry.getValue();
                if (i > 0) postdata += "&";
                postdata += URLEncoder.encode(key, "UTF-8") + "=" + URLEncoder.encode(value, "UTF-8");
            }
            wr.write(postdata);
            wr.flush();
            BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            String line;
            while ((line = rd.readLine()) != null) response += line + line_delimiter;
            wr.close();
            rd.close();
        } catch (Exception e) {
            System.err.println(e);
        }
        return response;
    }
public void testPreparedStatement0009() throws Exception {
        Connection cx = getConnection();
        dropTable("#t0009");
        Statement stmt = cx.createStatement();
        stmt.executeUpdate("create table #t0009 " + "  (i  integer  not null,      " + "   s  char(10) not null)      ");
        cx.setAutoCommit(false);
        PreparedStatement pStmt = cx.prepareStatement("insert into #t0009 values (?, ?)");
        int rowsToAdd = 8;
        final String theString = "abcdefghijklmnopqrstuvwxyz";
        int count = 0;
        for (int i = 1; i <= rowsToAdd; i++) {
            pStmt.setInt(1, i);
            pStmt.setString(2, theString.substring(0, i));
            count += pStmt.executeUpdate();
        }
        assertTrue(count == rowsToAdd);
        cx.rollback();
        stmt = cx.createStatement();
        ResultSet rs = stmt.executeQuery("select s, i from #t0009");
        assertNotNull(rs);
        count = 0;
        while (rs.next()) {
            count++;
            assertTrue(rs.getString(1).trim().length() == rs.getInt(2));
        }
        assertTrue(count == 0);
        cx.commit();
        rowsToAdd = 6;
        count = 0;
        for (int i = 1; i <= rowsToAdd; i++) {
            pStmt.setInt(1, i);
            pStmt.setString(2, theString.substring(0, i));
            count += pStmt.executeUpdate();
        }
        assertTrue(count == rowsToAdd);
        cx.commit();
        rs = stmt.executeQuery("select s, i from #t0009");
        count = 0;
        while (rs.next()) {
            count++;
            assertTrue(rs.getString(1).trim().length() == rs.getInt(2));
        }
        assertTrue(count == rowsToAdd);
        cx.commit();
        cx.setAutoCommit(true);
    }
public void testTransactions0010() throws Exception {
        Connection cx = getConnection();
        dropTable("#t0010");
        Statement stmt = cx.createStatement();
        stmt.executeUpdate("create table #t0010 " + "  (i  integer  not null,      " + "   s  char(10) not null)      ");
        cx.setAutoCommit(false);
        PreparedStatement pStmt = cx.prepareStatement("insert into #t0010 values (?, ?)");
        int rowsToAdd = 8;
        final String theString = "abcdefghijklmnopqrstuvwxyz";
        int count = 0;
        for (int i = 1; i <= rowsToAdd; i++) {
            pStmt.setInt(1, i);
            pStmt.setString(2, theString.substring(0, i));
            count += pStmt.executeUpdate();
        }
        assertTrue(count == rowsToAdd);
        cx.rollback();
        stmt = cx.createStatement();
        ResultSet rs = stmt.executeQuery("select s, i from #t0010");
        assertNotNull(rs);
        count = 0;
        while (rs.next()) {
            count++;
            assertTrue(rs.getString(1).trim().length() == rs.getInt(2));
        }
        assertTrue(count == 0);
        cx.commit();
        rowsToAdd = 6;
        for (int j = 1; j <= 2; j++) {
            count = 0;
            for (int i = 1; i <= rowsToAdd; i++) {
                pStmt.setInt(1, i + ((j - 1) * rowsToAdd));
                pStmt.setString(2, theString.substring(0, i));
                count += pStmt.executeUpdate();
            }
            assertTrue(count == rowsToAdd);
            cx.commit();
        }
        rs = stmt.executeQuery("select s, i from #t0010");
        count = 0;
        while (rs.next()) {
            count++;
            int i = rs.getInt(2);
            if (i > rowsToAdd) i -= rowsToAdd;
            assertTrue(rs.getString(1).trim().length() == i);
        }
        assertTrue(count == (2 * rowsToAdd));
        cx.commit();
        cx.setAutoCommit(true);
    }