semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.listview);
        HttpGet request = new HttpGet(SERVICE_URI + "/json/getallpersons");
        request.setHeader("Accept", "application/json");
        request.setHeader("Content-type", "application/json");
        DefaultHttpClient httpClient = new DefaultHttpClient();
        String theString = new String("");
        try {
            HttpResponse response = httpClient.execute(request);
            HttpEntity responseEntity = response.getEntity();
            InputStream stream = responseEntity.getContent();
            BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
            StringBuilder builder = new StringBuilder();
            String line;
            while ((line = reader.readLine()) != null) {
                builder.append(line);
            }
            stream.close();
            theString = builder.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        Toast.makeText(this, theString + "\n", Toast.LENGTH_LONG).show();
    }
JSONResponse execute() throws ServerException, RtmApiException, IOException {
        HttpClient httpclient = new DefaultHttpClient();
        URI uri;
        try {
            uri = new URI(this.request.getUrl());
            HttpPost httppost = new HttpPost(uri);
            HttpResponse response = httpclient.execute(httppost);
            InputStream is = response.getEntity().getContent();
            try {
                StringBuilder sb = new StringBuilder();
                BufferedReader r = new BufferedReader(new InputStreamReader(new DoneHandlerInputStream(is)));
                for (String line = r.readLine(); line != null; line = r.readLine()) {
                    sb.append(line);
                }
                return new JSONResponse(sb.toString());
            } finally {
                is.close();
            }
        } catch (URISyntaxException e) {
            throw new RtmApiException(e.getMessage());
        } catch (ClientProtocolException e) {
            throw new RtmApiException(e.getMessage());
        }
    }
String test() throws ServerException, RtmApiException, IOException {
        HttpClient httpclient = new DefaultHttpClient();
        URI uri;
        try {
            uri = new URI(this.request.getUrl());
            HttpPost httppost = new HttpPost(uri);
            HttpResponse response = httpclient.execute(httppost);
            InputStream is = response.getEntity().getContent();
            StringBuilder sb = new StringBuilder();
            BufferedReader r = new BufferedReader(new InputStreamReader(new DoneHandlerInputStream(is)));
            for (String line = r.readLine(); line != null; line = r.readLine()) {
                sb.append(line);
            }
            return sb.toString();
        } catch (URISyntaxException e) {
            throw new RtmApiException(e.getMessage());
        } catch (ClientProtocolException e) {
            throw new RtmApiException(e.getMessage());
        }
    }
public void encryptPassword() {
        MessageDigest digest = null;
        try {
            digest = MessageDigest.getInstance("SHA");
        } catch (NoSuchAlgorithmException e) {
            System.out.print(e);
        }
        try {
            digest.update(passwordIn.getBytes("UTF-8"));
        } catch (UnsupportedEncodingException e) {
            System.out.println("cannot find char set for getBytes");
        }
        byte digestBytes[] = digest.digest();
        passwordHash = (new BASE64Encoder()).encode(digestBytes);
    }
public void addScanURL(final URL url) {
        if (url == null) throw new NullArgumentException();
        try {
            url.openConnection().connect();
        } catch (IOException e) {
            e.printStackTrace();
        }
        urlList.add(url);
    }
private FTPClient loginToSharedWorkspace() throws SocketException, IOException {
        FTPClient ftp = new FTPClient();
        ftp.connect(mSwarm.getHost(), mSharedWorkspacePort);
        if (!ftp.login(SHARED_WORKSPACE_LOGIN_NAME, mWorkspacePassword)) {
            throw new IOException("Unable to login to shared workspace.");
        }
        ftp.setFileType(FTPClient.BINARY_FILE_TYPE);
        return ftp;
    }
protected String encrypt(String text) throws Exception {
        MessageDigest md = MessageDigest.getInstance("SHA");
        md.update(text.getBytes("UTF-8"));
        byte raw[] = md.digest();
        String hash = (new BASE64Encoder()).encode(raw);
        return hash;
    }
public synchronized void download(URL url, File file) throws IOException {
        reset();
        MessageDigest digest;
        try {
            digest = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }
        InputStream in = url.openConnection(proxy).getInputStream();
        byte[] buffer = new byte[2048];
        BufferedOutputStream bos = file == null ? null : new BufferedOutputStream(new FileOutputStream(file), buffer.length);
        try {
            int size;
            while ((size = in.read(buffer, 0, buffer.length)) != -1) {
                if (this.isCancelled()) break;
                if (bos != null) bos.write(buffer, 0, size);
                if (size > 0) {
                    digest.update(buffer, 0, size);
                    this.length += size;
                    progress();
                }
            }
        } finally {
            if (bos != null) {
                bos.flush();
                bos.close();
            }
        }
        if (!cancelled) this.checkSum = CheckSum.toString(digest.digest());
    }
public static String eventHash(String eventstr) {
        try {
            if (md == null) {
                md = MessageDigest.getInstance("MD5");
            }
            md.update(eventstr.getBytes("utf-8"));
            byte[] theDigest = md.digest();
            return new BASE64Encoder().encode(theDigest);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return null;
    }
public SWORDEntry ingestDepost(final DepositCollection pDeposit, final ServiceDocument pServiceDocument) throws SWORDException {
        try {
            ZipFileAccess tZipFile = new ZipFileAccess(super.getTempDir());
            LOG.debug("copying file");
            String tZipTempFileName = super.getTempDir() + "uploaded-file.tmp";
            IOUtils.copy(pDeposit.getFile(), new FileOutputStream(tZipTempFileName));
            Datastream tDatastream = new LocalDatastream(super.getGenericFileName(pDeposit), this.getContentType(), tZipTempFileName);
            _datastreamList.add(tDatastream);
            _datastreamList.addAll(tZipFile.getFiles(tZipTempFileName));
            int i = 0;
            boolean found = false;
            for (i = 0; i < _datastreamList.size(); i++) {
                if (_datastreamList.get(i).getId().equalsIgnoreCase("mets")) {
                    found = true;
                    break;
                }
            }
            if (found) {
                SAXBuilder tBuilder = new SAXBuilder();
                _mets = new METSObject(tBuilder.build(((LocalDatastream) _datastreamList.get(i)).getPath()));
                LocalDatastream tLocalMETSDS = (LocalDatastream) _datastreamList.remove(i);
                new File(tLocalMETSDS.getPath()).delete();
                _datastreamList.add(_mets.getMETSDs());
                _datastreamList.addAll(_mets.getMetadataDatastreams());
            } else {
                throw new SWORDException("Couldn't find a METS document in the zip file, ensure it is named mets.xml or METS.xml");
            }
            SWORDEntry tEntry = super.ingestDepost(pDeposit, pServiceDocument);
            tZipFile.removeLocalFiles();
            return tEntry;
        } catch (IOException tIOExcpt) {
            String tMessage = "Couldn't retrieve METS from deposit: " + tIOExcpt.toString();
            LOG.error(tMessage);
            tIOExcpt.printStackTrace();
            throw new SWORDException(tMessage, tIOExcpt);
        } catch (JDOMException tJDOMExcpt) {
            String tMessage = "Couldn't build METS from deposit: " + tJDOMExcpt.toString();
            LOG.error(tMessage);
            tJDOMExcpt.printStackTrace();
            throw new SWORDException(tMessage, tJDOMExcpt);
        }
    }
public String new2Password(String passwd) {
        try {
            MessageDigest md = MessageDigest.getInstance("SHA-1");
            String clearPassword = passwd;
            md.update(clearPassword.getBytes());
            byte[] digestedPassword = md.digest();
            return new String(digestedPassword);
        } catch (java.security.NoSuchAlgorithmException e) {
            System.out.println("MD5 doesn't exist");
            System.out.println(e.toString());
            return null;
        }
    }
public static String md5It(String data) {
        MessageDigest digest;
        String output = "";
        try {
            digest = java.security.MessageDigest.getInstance("MD5");
            digest.update(data.getBytes());
            byte[] hash = digest.digest();
            for (byte b : hash) {
                output = output + String.format("%02X", b);
            }
        } catch (NoSuchAlgorithmException ex) {
            Logger.getLogger(Authenticator.class.getName()).log(Level.SEVERE, null, ex);
        }
        return output;
    }
public static void main(String[] args) throws Exception {
        long start = System.currentTimeMillis();
        XSLTBuddy buddy = new XSLTBuddy();
        buddy.parseArgs(args);
        XSLTransformer transformer = new XSLTransformer();
        if (buddy.templateDir != null) {
            transformer.setTemplateDir(buddy.templateDir);
        }
        FileReader xslReader = new FileReader(buddy.xsl);
        Templates xslTemplate = transformer.getXSLTemplate(buddy.xsl, xslReader);
        for (Enumeration e = buddy.params.keys(); e.hasMoreElements(); ) {
            String key = (String) e.nextElement();
            transformer.addParam(key, buddy.params.get(key));
        }
        Reader reader = null;
        if (buddy.src == null) {
            reader = new StringReader(XSLTBuddy.BLANK_XML);
        } else {
            reader = new FileReader(buddy.src);
        }
        if (buddy.out == null) {
            String result = transformer.doTransform(reader, xslTemplate, buddy.xsl);
            buddy.getLogger().info("\n\nXSLT Result:\n\n" + result + "\n");
        } else {
            File file = new File(buddy.out);
            File dir = file.getParentFile();
            if (dir != null) {
                dir.mkdirs();
            }
            FileWriter writer = new FileWriter(buddy.out);
            transformer.doTransform(reader, xslTemplate, buddy.xsl, writer);
            writer.flush();
            writer.close();
        }
        buddy.getLogger().info("Transform done successfully in " + (System.currentTimeMillis() - start) + " milliseconds");
    }
protected void setRankOrder() {
        this.rankOrder = new int[values.length];
        for (int i = 0; i < rankOrder.length; i++) {
            rankOrder[i] = i;
            assert (!Double.isNaN(values[i]));
        }
        for (int i = rankOrder.length - 1; i >= 0; i--) {
            boolean swapped = false;
            for (int j = 0; j < i; j++) if (values[rankOrder[j]] < values[rankOrder[j + 1]]) {
                int r = rankOrder[j];
                rankOrder[j] = rankOrder[j + 1];
                rankOrder[j + 1] = r;
            }
        }
    }
private byte[] getCharImage(long chrId) {
        byte[] imgData = null;
        try {
            URL url = new URL("http://img.eve.is/serv.asp?s=256&c=" + chrId);
            URLConnection conn = url.openConnection();
            InputStream is = conn.getInputStream();
            ByteArrayOutputStream os = new ByteArrayOutputStream();
            int data;
            try {
                while ((data = is.read()) >= 0) {
                    os.write(data);
                }
            } finally {
                is.close();
            }
            imgData = os.toByteArray();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return imgData;
    }
private static boolean isRemoteFileExist(String url) {
        InputStream in = null;
        try {
            HttpURLConnection conn = (HttpURLConnection) (new URL(url)).openConnection();
            in = conn.getInputStream();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (in != null) {
            return true;
        } else {
            return false;
        }
    }
private static RemoteFile getRemoteFile(String url) {
        long size = 0;
        String realUrl = "";
        try {
            HttpURLConnection conn = (HttpURLConnection) (new URL(url)).openConnection();
            size = conn.getContentLength();
            realUrl = conn.getURL().toString();
            conn.disconnect();
        } catch (Exception e) {
            e.printStackTrace();
        }
        RemoteFile rf = new RemoteFile(size, realUrl);
        return rf;
    }
public byte[] downloadAttachmentContent(Attachment issueAttachment) throws IOException {
        byte[] result = null;
        URL url = new URL(issueAttachment.getContentURL());
        BufferedReader inputReader = null;
        try {
            inputReader = new BufferedReader(new InputStreamReader(url.openStream()));
            StringBuilder contentBuilder = new StringBuilder();
            String line;
            while ((line = inputReader.readLine()) != null) {
                contentBuilder.append(line);
            }
            result = contentBuilder.toString().getBytes();
        } finally {
            if (inputReader != null) {
                inputReader.close();
            }
        }
        return result;
    }
public void close() throws IOException {
            output.flush();
            output.close();
            FTPClient client = new FTPClient();
            if (server == null) {
                throw new IOException("FTP_SERVER property is missing");
            } else {
                if (port != null) {
                    client.connect(server, Integer.parseInt(port));
                } else {
                    client.connect(server);
                }
            }
            if (username != null) {
                logger.debug("log in as specified user");
                client.login(username, password);
            } else {
                logger.debug("log in as anonymous");
                client.login("anonymous", this.getClass().getName());
            }
            if (binaery) {
                logger.debug("use binaery mode");
                client.setFileType(FTP.BINARY_FILE_TYPE);
            } else {
                logger.debug("use ascii mode");
                client.setFileType(FTP.ASCII_FILE_TYPE);
            }
            client.enterLocalPassiveMode();
            logger.debug("store file on server: " + tempFile + " under name: " + file);
            InputStream stream = new FileInputStream(tempFile);
            String dir = file.substring(0, file.lastIndexOf("/")) + "/";
            String split[] = dir.split("/");
            String last = "";
            logger.debug("creating dir: " + dir);
            for (int i = 0; i < split.length; i++) {
                last = last + "/" + split[i];
                logger.debug(last + " --> " + client.makeDirectory(last));
            }
            logger.debug("storing file: " + file);
            client.deleteFile(file);
            client.storeFile(file, stream);
            client.disconnect();
            tempFile.delete();
            try {
                FTPSource source = new FTPSource();
                source.configure(properties);
                source.setIdentifier(file);
                if (source.exist()) {
                    logger.debug("done");
                } else {
                    throw new IOException("can't find file I just wrote, something went wrong!");
                }
            } catch (ConfigurationException e) {
                throw new IOException(e.getMessage());
            }
        }
@Test
    public void testGetResource_FileOutsideOfClasspath() throws Exception {
        File temp = File.createTempFile("dozerfiletest", ".txt");
        temp.deleteOnExit();
        String resourceName = "file:" + temp.getAbsolutePath();
        URL url = loader.getResource(resourceName);
        assertNotNull("URL should not be null", url);
        InputStream is = url.openStream();
        assertNotNull("input stream should not be null", is);
    }
protected static String fileName2md5(String input) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.reset();
            md.update(input.getBytes("iso-8859-1"));
            byte[] byteHash = md.digest();
            md.reset();
            StringBuffer resultString = new StringBuffer();
            for (int i = 0; i < byteHash.length; i++) {
                resultString.append(Integer.toHexString(0xFF & byteHash[i]));
            }
            return (resultString.toString());
        } catch (Exception ex) {
            Logger.error(ex.getClass() + " " + ex.getMessage());
            for (int i = 0; i < ex.getStackTrace().length; i++) Logger.error("     " + ex.getStackTrace()[i].toString());
            ex.printStackTrace();
        }
        return String.valueOf(Math.random() * Long.MAX_VALUE);
    }
public void startImport(ActionEvent evt) {
        final PsiExchange psiExchange = PsiExchangeFactory.createPsiExchange(IntactContext.getCurrentInstance().getSpringContext());
        for (final URL url : urlsToImport) {
            try {
                if (log.isInfoEnabled()) log.info("Importing: " + url);
                psiExchange.importIntoIntact(url.openStream());
            } catch (IOException e) {
                handleException(e);
                return;
            }
        }
        addInfoMessage("File successfully imported", Arrays.asList(urlsToImport).toString());
    }
@Override
    public void run() {
        try {
            FileChannel out = new FileOutputStream(outputfile).getChannel();
            long pos = 0;
            status.setText("Slučovač: Proces slučování spuštěn.. Prosím čekejte..");
            for (int i = 1; i <= noofparts; i++) {
                FileChannel in = new FileInputStream(originalfilename.getAbsolutePath() + "." + String.format("%03d", i)).getChannel();
                status.setText("Slučovač: Slučuji část " + i + "..");
                this.splitsize = in.size();
                out.transferFrom(in, pos, splitsize);
                pos += splitsize;
                in.close();
                if (deleteOnFinish) new File(originalfilename + String.format(".%03d", i)).delete();
                pb.setValue(100 * i / noofparts);
            }
            out.close();
            status.setText("Slučovač: Hotovo..");
            JOptionPane.showMessageDialog(null, "Sloučeno!", "Slučovač", JOptionPane.INFORMATION_MESSAGE);
        } catch (Exception e) {
        }
    }
String getLocation(Class clazz) {
        try {
            java.net.URL url = clazz.getProtectionDomain().getCodeSource().getLocation();
            String location = url.toString();
            if (location.startsWith("jar")) {
                url = ((java.net.JarURLConnection) url.openConnection()).getJarFileURL();
                location = url.toString();
            }
            if (location.startsWith("file")) {
                java.io.File file = new java.io.File(url.getFile());
                return file.getAbsolutePath();
            } else {
                return url.toString();
            }
        } catch (Throwable t) {
        }
        return Messages.getMessage("happyClientUnknownLocation");
    }
private void initialize() {
        if (!initialized) {
            if (context.getJavadocLinks() != null) {
                for (String url : context.getJavadocLinks()) {
                    if (!url.endsWith("/")) {
                        url += "/";
                    }
                    StringWriter writer = new StringWriter();
                    try {
                        IOUtils.copy(new URL(url + "package-list").openStream(), writer);
                    } catch (Exception e) {
                        e.printStackTrace();
                        continue;
                    }
                    StringTokenizer tokenizer2 = new StringTokenizer(writer.toString());
                    while (tokenizer2.hasMoreTokens()) {
                        javadocByPackage.put(tokenizer2.nextToken(), url);
                    }
                }
            }
            initialized = true;
        }
    }
public ContentPackage resolveItem() {
        URL url;
        try {
            url = new URL(itembankURL + "/" + deposit.get("http://www.caret.cam.ac.uk/minibix/metadata/ticket"));
            return new ContentPackage(url.openStream());
        } catch (MalformedURLException e1) {
            e1.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
public void addButtons() {
        BufferedImage bufImage = null;
        BufferedImage bufImage1 = null;
        for (int i = 0; i < urls.size(); i++) {
            String url = (String) urls.elementAt(i);
            if (url.contains(java.util.ResourceBundle.getBundle("com/jjcp/resources/Strings").getString("IHERETRIEVEDOCUMENT"))) {
                return;
            }
            try {
                URL url1 = new URL(url);
                URLConnection conn = null;
                conn = url1.openConnection();
                InputStream in = conn.getInputStream();
                in.close();
                bufImage = ImageIO.read(url1);
                bufImage1 = resizeAnImage(bufImage, 0.25);
                ImageIcon icon = new ImageIcon(bufImage1);
                ImageButton imageButton = new ImageButton(icon, this, i);
                imageButton.setIndex(i);
                jPanel1.add(imageButton);
                jPanel1.setPreferredSize(new Dimension(imageButton.getWidth() * urls.size(), imageButton.getHeight() + 20));
            } catch (Exception exception) {
                exception.printStackTrace();
            }
        }
        this.setVisible(true);
        this.repaint();
    }
@Override
        void execute(Connection conn, Component parent, String context, ProgressMonitor progressBar, ProgressWrapper progressWrapper) throws Exception {
            Statement statement = null;
            try {
                conn.setAutoCommit(false);
                statement = conn.createStatement();
                String deleteSql = getDeleteSql(m_compositionId);
                statement.executeUpdate(deleteSql);
                conn.commit();
                s_compostionCache.delete(new Integer(m_compositionId));
            } catch (SQLException ex) {
                try {
                    conn.rollback();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
                throw ex;
            } finally {
                if (statement != null) {
                    statement.close();
                }
            }
        }
protected URLConnection openConnection(URL url) throws IOException {
        log.log(Level.FINE, url.toString());
        MSServletRequest urlManager = new MSServletRequest(url);
        MicroServlet servlet = getServlet(urlManager);
        return (new MSConnection(url, servlet, urlManager));
    }