semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public Object construct() {
                String fullName = lRegatta.getSaveDirectory() + lRegatta.getSaveName();
                System.out.println(MessageFormat.format(res.getString("MainMessageBackingUp"), new Object[] { fullName + BAK }));
                try {
                    FileInputStream fis = new FileInputStream(new File(fullName));
                    FileOutputStream fos = new FileOutputStream(new File(fullName + BAK));
                    int bufsize = 1024;
                    byte[] buffer = new byte[bufsize];
                    int n = 0;
                    while ((n = fis.read(buffer, 0, bufsize)) >= 0) fos.write(buffer, 0, n);
                    fos.flush();
                    fos.close();
                } catch (java.io.IOException ex) {
                    Util.showError(ex, true);
                }
                return null;
            }
private void fetchTree() throws IOException {
        String urlString = BASE_URL + TREE_URL + DATASET_URL + "&family=" + mFamily;
        URL url = new URL(urlString);
        BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
        String toParse = in.readLine();
        while (in.ready()) {
            String add = in.readLine();
            if (add == null) break;
            toParse += add;
        }
        if (toParse != null && !toParse.startsWith("No tree available")) mProteinTree = new PTree(this, toParse);
    }
public String retrieve(String url) {
        HttpGet getRequest = new HttpGet(url);
        try {
            HttpResponse getResponse = client.execute(getRequest);
            final int statusCode = getResponse.getStatusLine().getStatusCode();
            if (statusCode != HttpStatus.SC_OK) {
                Log.w(getClass().getSimpleName(), "Error " + statusCode + " for URL " + url);
                return null;
            }
            HttpEntity getResponseEntity = getResponse.getEntity();
            if (getResponseEntity != null) {
                return EntityUtils.toString(getResponseEntity);
            }
        } catch (IOException e) {
            getRequest.abort();
            Log.w(getClass().getSimpleName(), "Error for URL " + url, e);
        }
        return null;
    }
public InputStream retrieveStream(String url) {
        HttpGet getRequest = new HttpGet(url);
        try {
            HttpResponse getResponse = client.execute(getRequest);
            final int statusCode = getResponse.getStatusLine().getStatusCode();
            if (statusCode != HttpStatus.SC_OK) {
                Log.w(getClass().getSimpleName(), "Error " + statusCode + " for URL " + url);
                return null;
            }
            HttpEntity getResponseEntity = getResponse.getEntity();
            return getResponseEntity.getContent();
        } catch (IOException e) {
            getRequest.abort();
            Log.w(getClass().getSimpleName(), "Error for URL " + url, e);
        }
        return null;
    }
public static synchronized String getPageContent(String pageUrl) {
        URL url = null;
        InputStreamReader inputStreamReader = null;
        BufferedReader bufferedReader = null;
        String line = null;
        StringBuilder page = null;
        if (pageUrl == null || pageUrl.trim().length() == 0) {
            return null;
        } else {
            try {
                url = new URL(pageUrl);
                inputStreamReader = new InputStreamReader(url.openStream());
                bufferedReader = new BufferedReader(inputStreamReader);
                page = new StringBuilder();
                while ((line = bufferedReader.readLine()) != null) {
                    page.append(line);
                    page.append("\n");
                }
            } catch (IOException e) {
                logger.error("IOException", e);
            } catch (Exception e) {
                logger.error("Exception", e);
            } finally {
                try {
                    if (bufferedReader != null) {
                        bufferedReader.close();
                    }
                    if (inputStreamReader != null) {
                        inputStreamReader.close();
                    }
                } catch (IOException e) {
                    logger.error("IOException", e);
                } catch (Exception e) {
                    logger.error("Exception", e);
                }
            }
        }
        if (page == null) {
            return null;
        } else {
            return page.toString();
        }
    }
public static String hashMD5(String passw) {
        String passwHash = "";
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(passw.getBytes());
            byte[] result = md.digest();
            StringBuffer sb = new StringBuffer();
            for (int i = 0; i < result.length; i++) {
                String tmpStr = "0" + Integer.toHexString((0xff & result[i]));
                sb.append(tmpStr.substring(tmpStr.length() - 2));
            }
            passwHash = sb.toString();
        } catch (NoSuchAlgorithmException ecc) {
            log.error("Errore algoritmo " + ecc);
        }
        return passwHash;
    }
protected synchronized void doLogin(long timeout, String eventMask) throws IOException, AuthenticationFailedException, TimeoutException {
        ChallengeAction challengeAction;
        ManagerResponse challengeResponse;
        String challenge;
        String key;
        LoginAction loginAction;
        ManagerResponse loginResponse;
        if (socket == null) {
            connect();
        }
        synchronized (protocolIdentifier) {
            if (protocolIdentifier.value == null) {
                try {
                    protocolIdentifier.wait(timeout);
                } catch (InterruptedException e) {
                    Thread.currentThread().interrupt();
                }
            }
            if (protocolIdentifier.value == null) {
                disconnect();
                if (reader != null && reader.getTerminationException() != null) {
                    throw reader.getTerminationException();
                } else {
                    throw new TimeoutException("Timeout waiting for protocol identifier");
                }
            }
        }
        challengeAction = new ChallengeAction("MD5");
        try {
            challengeResponse = sendAction(challengeAction);
        } catch (Exception e) {
            disconnect();
            throw new AuthenticationFailedException("Unable to send challenge action", e);
        }
        if (challengeResponse instanceof ChallengeResponse) {
            challenge = ((ChallengeResponse) challengeResponse).getChallenge();
        } else {
            disconnect();
            throw new AuthenticationFailedException("Unable to get challenge from Asterisk. ChallengeAction returned: " + challengeResponse.getMessage());
        }
        try {
            MessageDigest md;
            md = MessageDigest.getInstance("MD5");
            if (challenge != null) {
                md.update(challenge.getBytes());
            }
            if (password != null) {
                md.update(password.getBytes());
            }
            key = ManagerUtil.toHexString(md.digest());
        } catch (NoSuchAlgorithmException ex) {
            disconnect();
            throw new AuthenticationFailedException("Unable to create login key using MD5 Message Digest", ex);
        }
        loginAction = new LoginAction(username, "MD5", key, eventMask);
        try {
            loginResponse = sendAction(loginAction);
        } catch (Exception e) {
            disconnect();
            throw new AuthenticationFailedException("Unable to send login action", e);
        }
        if (loginResponse instanceof ManagerError) {
            disconnect();
            throw new AuthenticationFailedException(loginResponse.getMessage());
        }
        state = CONNECTED;
        logger.info("Successfully logged in");
        version = determineVersion();
        writer.setTargetVersion(version);
        logger.info("Determined Asterisk version: " + version);
        ConnectEvent connectEvent = new ConnectEvent(this);
        connectEvent.setProtocolIdentifier(getProtocolIdentifier());
        connectEvent.setDateReceived(DateUtil.getDate());
        fireEvent(connectEvent);
    }
public void run() {
            Shell shell = new Shell(display);
            shell.setLayout(new GridLayout(1, false));
            ERDiagramEditPartFactory editPartFactory = new ERDiagramEditPartFactory();
            viewer = new ScrollingGraphicalViewer();
            viewer.setControl(new FigureCanvas(shell));
            ScalableFreeformRootEditPart rootEditPart = new PagableFreeformRootEditPart(diagram);
            viewer.setRootEditPart(rootEditPart);
            viewer.setEditPartFactory(editPartFactory);
            viewer.setContents(diagram);
        }
public void getDownloadInfo() throws Exception {
        cl = new DefaultHttpClient();
        InfoAuthPromter hp = new InfoAuthPromter();
        cl.setCredentialsProvider(hp);
        head = new HttpHead(getURL());
        head.setHeader("User-Agent", "test");
        head.setHeader("Accept", "*/*");
        head.setHeader("Range", "bytes=0-");
        HttpResponse resp = cl.execute(head);
        log.debug("getDownloadInfo(url) - Status : " + resp.getStatusLine());
        System.out.println("----------------- RESPONSE HEADERS ------------------------");
        for (Header h : resp.getAllHeaders()) {
            System.out.println(h);
        }
        System.out.println("-----------------------------------------------------------\n");
        int code = resp.getStatusLine().getStatusCode();
        if (code == 401) {
            throw new Exception("HTTP Authentication Failed");
        }
        AuthManager.putAuth(getSite(), auth);
        setURL(head.getURI().toString());
        log.debug("Last url: " + head.getURI());
        Header hsize = resp.getFirstHeader("Content-Length");
        Header hmod = resp.getFirstHeader("Last-Modified");
        setSize(Long.parseLong(hsize.getValue()));
        setRangeEnd(getSize() - 1);
        setResumable(code == 206);
    }
public void initGet() throws Exception {
        cl = new DefaultHttpClient();
        GetAuthPromter hp = new GetAuthPromter();
        cl.setCredentialsProvider(hp);
        get = new HttpGet(getURL());
        get.setHeader("User-Agent", "test");
        get.setHeader("Accept", "*/*");
        get.setHeader("Range", "bytes=" + getPosition() + "-" + getRangeEnd());
        HttpResponse resp = cl.execute(get);
        ent = resp.getEntity();
        setInputStream(ent.getContent());
    }
protected static void copyDeleting(File source, File dest) throws ErrorCodeException {
        byte[] buf = new byte[8 * 1024];
        FileInputStream in = null;
        try {
            in = new FileInputStream(source);
            try {
                FileOutputStream out = new FileOutputStream(dest);
                try {
                    int count;
                    while ((count = in.read(buf)) >= 0) out.write(buf, 0, count);
                } finally {
                    out.close();
                }
            } finally {
                in.close();
            }
        } catch (IOException e) {
            throw new ErrorCodeException(e);
        }
    }
private final Node openConnection(String connection) throws JTweetException {
        try {
            URL url = new URL(connection);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.connect();
            BufferedInputStream reader = new BufferedInputStream(conn.getInputStream());
            if (builder == null) {
                builder = factory.newDocumentBuilder();
            }
            document = builder.parse(reader);
            reader.close();
            conn.disconnect();
        } catch (Exception e) {
            throw new JTweetException(e);
        }
        return document.getFirstChild();
    }
private void _scanForMetaData(URL _url) throws java.io.IOException {
        if (DEBUG.Enabled) System.out.println(this + " _scanForMetaData: xml props " + mXMLpropertyList);
        if (DEBUG.Enabled) System.out.println("*** Opening connection to " + _url);
        markAccessAttempt();
        Properties metaData = scrapeHTMLmetaData(_url.openConnection(), 2048);
        if (DEBUG.Enabled) System.out.println("*** Got meta-data " + metaData);
        markAccessSuccess();
        String title = metaData.getProperty("title");
        if (title != null && title.length() > 0) {
            setProperty("title", title);
            title = title.replace('\n', ' ').trim();
            setTitle(title);
        }
        try {
            setByteSize(Integer.parseInt((String) getProperty("contentLength")));
        } catch (Exception e) {
        }
    }
public int updateuser(User u) {
        int i = 0;
        Connection conn = null;
        PreparedStatement pm = null;
        try {
            conn = Pool.getConnection();
            conn.setAutoCommit(false);
            pm = conn.prepareStatement("update user set username=?,passwd=?,existstate=?,management=? where userid=?");
            pm.setString(1, u.getUsername());
            pm.setString(2, u.getPasswd());
            pm.setInt(3, u.getExiststate());
            pm.setInt(4, u.getManagement());
            pm.setString(5, u.getUserid());
            i = pm.executeUpdate();
            conn.commit();
            Pool.close(pm);
            Pool.close(conn);
        } catch (Exception e) {
            e.printStackTrace();
            try {
                conn.rollback();
            } catch (SQLException e1) {
                e1.printStackTrace();
            }
            Pool.close(pm);
            Pool.close(conn);
        } finally {
            Pool.close(pm);
            Pool.close(conn);
        }
        return i;
    }
public static InputStream getInputStream(URL url) throws IOException {
        if (url.getProtocol().equals("resource")) {
            Resources res = SpeakReceiver._context.getResources();
            String resname = url.getFile();
            resname = resname.split("\\.[a-z0-9]{3}")[0];
            int id = res.getIdentifier(resname, "raw", "com.l1ghtm4n.text2speech");
            if (id == 0) {
                throw new NotFoundException();
            } else return res.openRawResource(id);
        } else {
            return url.openStream();
        }
    }
public InputStream getStream(Hashtable<String, String> pValue) throws IOException {
        List<NameValuePair> nvps = new ArrayList<NameValuePair>();
        Enumeration<String> enm = pValue.keys();
        String key;
        while (enm.hasMoreElements()) {
            key = enm.nextElement();
            nvps.add(new BasicNameValuePair(key, pValue.get(key)));
        }
        httpPost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
        HttpResponse response = httpclient.execute(httpPost);
        HttpEntity entity = response.getEntity();
        return entity.getContent();
    }
public int fileUpload(File pFile, String uploadName, Hashtable pValue) throws Exception {
        int res = 0;
        MultipartEntity reqEntity = new MultipartEntity();
        if (uploadName != null) {
            FileBody bin = new FileBody(pFile);
            reqEntity.addPart(uploadName, bin);
        }
        Enumeration<String> enm = pValue.keys();
        String key;
        while (enm.hasMoreElements()) {
            key = enm.nextElement();
            reqEntity.addPart(key, new StringBody("" + pValue.get(key)));
        }
        httpPost.setEntity(reqEntity);
        HttpResponse response = httpclient.execute(httpPost);
        HttpEntity resEntity = response.getEntity();
        res = response.getStatusLine().getStatusCode();
        close();
        return res;
    }
public static String generate(String source) {
        byte[] SHA = new byte[20];
        String SHADigest = "";
        try {
            MessageDigest digest = MessageDigest.getInstance("SHA-1");
            digest.update(source.getBytes());
            SHA = digest.digest();
            for (int i = 0; i < SHA.length; i++) SHADigest += (char) SHA[i];
        } catch (NoSuchAlgorithmException e) {
            System.out.println("NO SUCH ALGORITHM EXCEPTION: " + e.getMessage());
        }
        return SHADigest;
    }
@JiveScriptCommand(help = "Load and executes a JiveScript file")
    public void load(String path) throws JiveScriptException, IOException {
        loading = true;
        JivesScene.setActiveScene(null);
        boolean allowScripting = JiveScriptEngine.allowScripting;
        JiveScriptEngine.allowScripting = true;
        JiveScriptEngine.FILENAME = null;
        URL url = new URL(path);
        InputStream fis = url.openStream();
        if (fis == null) {
            throw new IOException("Unable to open file at path " + path);
        }
        BufferedReader br = new BufferedReader(new InputStreamReader(fis));
        script = "";
        String line;
        while ((line = br.readLine()) != null) {
            script = script.concat(line) + Log.LINE_SEPARATOR;
        }
        eval(script);
        if (JiveScriptEngine.FILENAME == null) {
            String filename = path.substring(path.lastIndexOf(File.separatorChar) + 1);
            JiveScriptEngine.FILENAME = filename;
        }
        JiveScriptEngine.MD5 = DigestUtils.md5Hex(script.toString().getBytes());
        NetworkImplementorIntf networkImplementor = Jives.getNetwork();
        Object[] config = (Object[]) networkImplementor.getConnectionState(NetworkImplementorIntf.CONNECTIONSTATE_ALL);
        boolean internet = (Boolean) config[NetworkImplementorIntf.CONNECTIONSTATE_INTERNET];
        if (internet) {
            echo("Starting network on the internet");
        } else {
            boolean ipv6 = (Boolean) config[NetworkImplementorIntf.CONNECTIONSTATE_IPV6];
            String connection = (String) config[NetworkImplementorIntf.CONNECTIONSTATE_RENDEZVOUS_IPV4] + ":" + (Integer) config[NetworkImplementorIntf.CONNECTIONSTATE_RENDEZVOUS_IPV4_PORT];
            if (ipv6) {
                connection = (String) networkImplementor.getConnectionState(NetworkImplementorIntf.CONNECTIONSTATE_RENDEZVOUS_IPV6) + ":" + (Integer) networkImplementor.getConnectionState(NetworkImplementorIntf.CONNECTIONSTATE_RENDEZVOUS_IPV6_PORT);
            }
            echo("Starting network on " + connection);
        }
        networkImplementor.startNetwork(JiveScriptEngine.FILENAME, JiveScriptEngine.MD5);
        fis.close();
        if (JiveScriptEngine.allowScripting && !allowScripting) {
            JiveScriptEngine.allowScripting = allowScripting;
        }
        loading = false;
    }
public void actionPerformed(ActionEvent ae) {
        if (ae.getSource() == jbutton) {
            try {
                String toservlet = "http://localhost:8080/direto-project/arquivos/teste.odt";
                URL servleturl = new URL(toservlet);
                URLConnection servletconnection = servleturl.openConnection();
                servletconnection.setDoInput(true);
                servletconnection.setDoOutput(true);
                servletconnection.setUseCaches(false);
                servletconnection.setDefaultUseCaches(false);
                DataInputStream inputFromClient = new DataInputStream(servletconnection.getInputStream());
                inputFromClient.readByte();
                OutputStream fos = new FileOutputStream("/home/danillo/arquivo_carregado.odt");
                byte[] buf = new byte[1024];
                int bytesread;
                while ((bytesread = inputFromClient.read(buf)) > -1) {
                    fos.write(buf, 0, bytesread);
                }
                inputFromClient.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
public JTree createTree() {
        DefaultMutableTreeNode top = new DefaultMutableTreeNode("Contents");
        DefaultMutableTreeNode[] nodeLevels = new DefaultMutableTreeNode[0];
        URL url = ResourceManager.getResource("tree.txt");
        try {
            InputStream is = url.openStream();
            InputStreamReader isr = new InputStreamReader(is);
            BufferedReader reader = new BufferedReader(isr);
            String line = reader.readLine();
            int numLevels = 0;
            if (line != null) {
                while (line.startsWith("#")) line = reader.readLine();
                numLevels = Integer.parseInt(line);
                line = reader.readLine();
                nodeLevels = new DefaultMutableTreeNode[numLevels + 1];
                nodeLevels[0] = top;
            }
            while (line != null) {
                if (!line.startsWith("#")) {
                    int level = Integer.parseInt(line.substring(0, 1));
                    line = line.substring(line.indexOf(",") + 1);
                    String nodeDescription = line.substring(0, line.indexOf(","));
                    String nodeURL = line.substring(line.indexOf(",") + 1, line.length());
                    nodeLevels[level] = new DefaultMutableTreeNode(new HelpTopic(nodeDescription, nodeURL));
                    nodeLevels[level - 1].add(nodeLevels[level]);
                }
                line = reader.readLine();
            }
        } catch (IOException e) {
            showErrorDialog("Unable to read resource tree.txt", true);
        } catch (NumberFormatException nfe) {
            showErrorDialog("Invalid format tree.txt", true);
        }
        return new JTree(top) {

            public java.awt.Insets getInsets() {
                return new java.awt.Insets(5, 5, 5, 5);
            }
        };
    }
private static void copyFile(String src, String dest) throws IOException {
        File destFile = new File(dest);
        if (destFile.exists()) {
            destFile.delete();
        }
        FileChannel srcChannel = new FileInputStream(src).getChannel();
        FileChannel dstChannel = new FileOutputStream(dest).getChannel();
        dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
        srcChannel.close();
        dstChannel.close();
    }
public static String encryption(String oldPass) {
        MessageDigest md = null;
        try {
            md = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException ex) {
            ex.printStackTrace();
        }
        md.update(oldPass.getBytes());
        byte b[] = md.digest();
        int i;
        StringBuffer buf = new StringBuffer();
        for (int offset = 0; offset < b.length; offset++) {
            i = b[offset];
            if (i < 0) {
                i += 256;
            }
            if (i < 16) {
                buf.append("0");
            }
            buf.append(Integer.toHexString(i));
        }
        String pass32 = buf.toString();
        return pass32;
    }
private void copy(File source, File destination) {
        if (!destination.exists()) {
            destination.mkdir();
        }
        File files[] = source.listFiles();
        if (files != null) {
            for (int i = 0; i < files.length; i++) {
                if (files[i].isDirectory()) {
                    copy(files[i], new File(destination, files[i].getName()));
                } else {
                    try {
                        FileChannel srcChannel = new FileInputStream(files[i]).getChannel();
                        FileChannel dstChannel = new FileOutputStream(new File(destination, files[i].getName())).getChannel();
                        dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
                        srcChannel.close();
                        dstChannel.close();
                    } catch (IOException ioe) {
                        log.error("Could not write to " + destination.getAbsolutePath(), ioe);
                    }
                }
            }
        }
    }