semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
@Override
    public String encryptPassword(String password) throws JetspeedSecurityException {
        if (securePasswords == false) {
            return password;
        }
        if (password == null) {
            return null;
        }
        try {
            if ("SHA-512".equals(passwordsAlgorithm)) {
                password = password + JetspeedResources.getString("aipo.encrypt_key");
                MessageDigest md = MessageDigest.getInstance(passwordsAlgorithm);
                md.reset();
                md.update(password.getBytes());
                byte[] hash = md.digest();
                StringBuffer sb = new StringBuffer();
                for (int i = 0; i < hash.length; i++) {
                    sb.append(Integer.toHexString((hash[i] >> 4) & 0x0F));
                    sb.append(Integer.toHexString(hash[i] & 0x0F));
                }
                return sb.toString();
            } else {
                MessageDigest md = MessageDigest.getInstance(passwordsAlgorithm);
                byte[] digest = md.digest(password.getBytes(ALEipConstants.DEF_CONTENT_ENCODING));
                ByteArrayOutputStream bas = new ByteArrayOutputStream(digest.length + digest.length / 3 + 1);
                OutputStream encodedStream = MimeUtility.encode(bas, "base64");
                encodedStream.write(digest);
                encodedStream.flush();
                encodedStream.close();
                return bas.toString();
            }
        } catch (Exception e) {
            logger.error("Unable to encrypt password." + e.getMessage(), e);
            return null;
        }
    }
public static String cryptografar(String senha) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(senha.getBytes());
            BigInteger hash = new BigInteger(1, md.digest());
            senha = hash.toString(16);
        } catch (NoSuchAlgorithmException ns) {
            ns.printStackTrace();
        }
        return senha;
    }
public Texture loadTexture(String file) throws IOException {
        URL imageUrl = urlFactory.makeUrl(file);
        Texture cached = textureLoader.getImageFromCache(imageUrl);
        if (cached != null) return cached;
        Image image;
        if (zip) {
            ZipInputStream zis = new ZipInputStream(url.openStream());
            ZipEntry entry;
            boolean found = false;
            while ((entry = zis.getNextEntry()) != null) {
                if (file.equals(entry.getName())) {
                    found = true;
                    break;
                }
            }
            if (!found) {
                throw new IOException("Cannot find file \"" + file + "\".");
            }
            int extIndex = file.lastIndexOf('.');
            if (extIndex == -1) {
                throw new IOException("Cannot parse file extension.");
            }
            String fileExt = file.substring(extIndex);
            image = TextureManager.loadImage(fileExt, zis, true);
        } else {
            image = TextureManager.loadImage(imageUrl, true);
        }
        return textureLoader.loadTexture(imageUrl, image);
    }
private static String getMD5(String phrase) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(phrase.getBytes());
            return asHexString(md.digest());
        } catch (Exception e) {
        }
        return "";
    }
private File copyFile(File currFile) throws IOException {
        String relativePath = currFile.getPath().substring(_distDir.length() + 1);
        File targetFile = new File(_installDir, relativePath);
        if (targetFile.exists()) {
            log(targetFile.getPath() + " already exists, skipping libcopy", Project.MSG_INFO);
            return targetFile;
        } else {
            if (!targetFile.getParentFile().exists()) {
                if (!targetFile.getParentFile().mkdirs()) {
                    log("Unable to create target dir tree for " + targetFile.getPath(), Project.MSG_ERR);
                    throw new IOException();
                }
            }
        }
        FileInputStream fis = null;
        FileOutputStream fos = null;
        try {
            fis = new FileInputStream(currFile);
        } catch (FileNotFoundException e) {
            log("Library from plugin manifest appears to have been deleted: " + currFile.getPath(), Project.MSG_ERR);
            throw new IOException();
        }
        try {
            fos = new FileOutputStream(targetFile);
        } catch (FileNotFoundException e) {
            log("Unable to create target file to write to: " + targetFile.getPath(), Project.MSG_ERR);
            throw new IOException();
        }
        BufferedInputStream bis = new BufferedInputStream(fis);
        BufferedOutputStream bos = new BufferedOutputStream(fos);
        int read = 0;
        byte[] buff = new byte[65536];
        boolean success = true;
        while (read != -1 && success) {
            try {
                read = bis.read(buff, 0, 65536);
            } catch (IOException e) {
                log("Read error whilst reading from: " + currFile.getPath(), Project.MSG_ERR);
                success = false;
            }
            if (read != -1 && success) {
                try {
                    bos.write(buff, 0, read);
                } catch (IOException e) {
                    log("Write error whilst writing to: " + targetFile.getPath(), Project.MSG_ERR);
                    success = false;
                }
            }
        }
        try {
            bis.close();
        } catch (IOException e) {
        }
        try {
            bos.close();
        } catch (IOException e) {
        }
        try {
            fis.close();
        } catch (IOException e) {
        }
        try {
            fos.close();
        } catch (IOException e) {
        }
        if (!success) {
            throw new IOException();
        }
        return targetFile;
    }
public static void copier(final File pFichierSource, final File pFichierDest) {
        FileChannel vIn = null;
        FileChannel vOut = null;
        try {
            vIn = new FileInputStream(pFichierSource).getChannel();
            vOut = new FileOutputStream(pFichierDest).getChannel();
            vIn.transferTo(0, vIn.size(), vOut);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (vIn != null) {
                try {
                    vIn.close();
                } catch (IOException e) {
                }
            }
            if (vOut != null) {
                try {
                    vOut.close();
                } catch (IOException e) {
                }
            }
        }
    }
private String signMethod() {
        String str = API.SHARED_SECRET;
        Vector<String> v = new Vector<String>(parameters.keySet());
        Collections.sort(v);
        for (String key : v) {
            str += key + parameters.get(key);
        }
        MessageDigest m = null;
        try {
            m = MessageDigest.getInstance("MD5");
            m.update(str.getBytes(), 0, str.length());
            return new BigInteger(1, m.digest()).toString(16);
        } catch (NoSuchAlgorithmException e) {
            return null;
        }
    }
public void setImage(java.awt.Image img) {
        if (imageName != null && imageName.length() > 0) {
            try {
                InputStream url = currentProject.getUrl(imageName).openStream();
                image = new org.eclipse.swt.graphics.Image(getDisplay(), url);
            } catch (IOException e) {
                e.printStackTrace();
            }
            Display.getDefault().asyncExec(new Runnable() {

                public void run() {
                    redraw();
                }
            });
        }
    }
private void work(String[] args) throws Exception {
        String dictLocation = CONTENT_URL;
        String cpeContentDirName = CONTENT_DIR;
        String fn = dictLocation.substring(dictLocation.lastIndexOf("/") + 1);
        File destFile = new File(cpeContentDirName + File.separator + fn);
        URL url = new URL(dictLocation);
        URLConnection conn = url.openConnection();
        conn.connect();
        long lmodifiedRemote = conn.getLastModified();
        boolean needToDownload = false;
        if (destFile.exists()) {
            System.out.println(destFile.getAbsolutePath() + " exists, check modification time");
            long lmodifiedLocal = destFile.lastModified();
            if (lmodifiedRemote > lmodifiedLocal) {
                System.out.println("Server file is newer, need to download");
                needToDownload = true;
            } else {
                System.out.println("Local version is newer, no need to download");
            }
        } else {
            System.out.println("Local version doesn't exist, need to download");
            needToDownload = true;
        }
        if (needToDownload) {
            InputStream is = conn.getInputStream();
            FileOutputStream fos = new FileOutputStream(destFile);
            byte[] buff = new byte[8192];
            int read = 0;
            while ((read = is.read(buff)) > 0) {
                fos.write(buff, 0, read);
            }
            fos.flush();
            fos.close();
            is.close();
        }
    }
public Resource get(URL serviceUrl, String resourceId) throws Exception {
        Resource resource = new Resource();
        String openurl = serviceUrl.toString() + "?url_ver=Z39.88-2004" + "&rft_id=" + URLEncoder.encode(resourceId, "UTF-8") + "&svc_id=" + SVCID_ADORE4;
        log.debug("OpenURL Request: " + openurl);
        URL url;
        try {
            url = new URL(openurl);
            HttpURLConnection huc = (HttpURLConnection) (url.openConnection());
            int code = huc.getResponseCode();
            if (code == 200) {
                InputStream is = huc.getInputStream();
                resource.setBytes(StreamUtil.getByteArray(is));
                resource.setContentType(huc.getContentType());
            } else {
                log.error("An error of type " + code + " occurred for " + url.toString());
                throw new Exception("Cannot get " + url.toString());
            }
        } catch (MalformedURLException e) {
            throw new Exception("A MalformedURLException occurred for " + openurl);
        } catch (IOException e) {
            throw new Exception("An IOException occurred attempting to connect to " + openurl);
        }
        return resource;
    }
public static String md5Hash(String src) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(src.getBytes());
            return bytesArrayToHexString(md.digest());
        } catch (Exception e) {
            return null;
        }
    }
public void sendMessageToServer(String msg, Map<String, String> args, StringCallback cb, URLConstructor ctor) {
        try {
            int tmpPort = port;
            for (; tmpPort < port + 10; tmpPort++) {
                Socket tmpSock;
                try {
                    tmpSock = socketsManager.connect(new InetSocketAddress(host, port), 5000);
                    tmpSock.close();
                    break;
                } catch (IOException e) {
                }
            }
            Map<String, String> newArgs = new HashMap<String, String>(args);
            newArgs.put("_f", String.valueOf(System.currentTimeMillis()));
            String request = ctor.constructURL(msg, newArgs);
            HttpClient client = new SimpleLimeHttpClient();
            HttpGet get = new HttpGet("http://" + host + ":" + port + "/" + request);
            HttpProtocolParams.setVersion(client.getParams(), HttpVersion.HTTP_1_1);
            HttpResponse response = client.execute(get);
            String res = "";
            if (response.getEntity() != null) {
                String result;
                if (response.getEntity() != null) {
                    result = EntityUtils.toString(response.getEntity());
                } else {
                    result = null;
                }
                res = result;
            }
            cb.process(res);
        } catch (IOException e) {
            fail(e);
        } catch (HttpException e) {
            fail(e);
        } catch (URISyntaxException e) {
            fail(e);
        } catch (InterruptedException e) {
            fail(e);
        }
    }
private void getServiceReponse(String service, NameSpaceDefinition nsDefinition) throws Exception {
        Pattern pattern = Pattern.compile("(?i)(?:.*(xmlns(?:\\:\\w+)?=\\\"http\\:\\/\\/www\\.ivoa\\.net\\/.*" + service + "[^\\\"]*\\\").*)");
        pattern = Pattern.compile(".*xmlns(?::\\w+)?=(\"[^\"]*(?i)(?:" + service + ")[^\"]*\").*");
        logger.debug("read " + this.url + service);
        BufferedReader in = new BufferedReader(new InputStreamReader((new URL(this.url + service)).openStream()));
        String inputLine;
        BufferedWriter bfw = new BufferedWriter(new FileWriter(this.baseDirectory + service + ".xml"));
        boolean found = false;
        while ((inputLine = in.readLine()) != null) {
            if (!found) {
                Matcher m = pattern.matcher(inputLine);
                if (m.matches()) {
                    nsDefinition.init("xmlns:vosi=" + m.group(1));
                    found = true;
                }
            }
            bfw.write(inputLine + "\n");
        }
        in.close();
        bfw.close();
    }
private void setNodekeyInJsonResponse(String service) throws Exception {
        String filename = this.baseDirectory + service + ".json";
        Scanner s = new Scanner(new File(filename));
        PrintWriter fw = new PrintWriter(new File(filename + ".new"));
        while (s.hasNextLine()) {
            fw.println(s.nextLine().replaceAll("NODEKEY", this.key));
        }
        s.close();
        fw.close();
        (new File(filename + ".new")).renameTo(new File(filename));
    }
public static String calculateSHA1(String data, String key) throws NoSuchAlgorithmException, UnsupportedEncodingException {
        data += key;
        MessageDigest md;
        md = MessageDigest.getInstance("SHA-1");
        byte[] sha1hash = new byte[40];
        md.update(data.getBytes("iso-8859-1"), 0, data.length());
        sha1hash = md.digest();
        return convertToHex(sha1hash);
    }
public String read(String url) throws IOException {
        URL myurl = new URL(url);
        BufferedReader in = new BufferedReader(new InputStreamReader(myurl.openStream()));
        StringBuffer sb = new StringBuffer();
        String inputLine;
        while ((inputLine = in.readLine()) != null) sb.append(inputLine);
        in.close();
        return sb.toString();
    }
private void writeFile(String name, URL url) throws IOException {
        Location location = resourcesHome.resolve(name);
        InputStream input = url.openStream();
        OutputStream output = location.getOutputStream();
        try {
            byte buf[] = new byte[1024];
            int read;
            while (true) {
                read = input.read(buf);
                if (read == -1) break;
                output.write(buf, 0, read);
            }
        } finally {
            try {
                input.close();
            } finally {
                output.close();
            }
        }
    }
public static void copyOverWarFile() {
        System.out.println("Copy Over War File:");
        File dir = new File(theAppsDataDir);
        FileFilter ff = new WildcardFileFilter("*.war");
        if (dir.listFiles(ff).length == 0) {
            dir = new File(System.getProperty("user.dir") + "/war");
            if (dir.exists()) {
                File[] files = dir.listFiles(ff);
                for (File f : files) {
                    try {
                        File newFile = new File("" + theAppsDataDir + "/" + f.getName());
                        System.out.println("Creating new file \"" + f.getAbsolutePath() + "\"");
                        newFile.createNewFile();
                        InputStream fi = new FileInputStream(f);
                        OutputStream fo = new FileOutputStream(newFile);
                        IOUtils.copy(fi, fo);
                        moveUnzipAndExtract(newFile);
                    } catch (Exception ex) {
                        Logger.getLogger(AppDataDir.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            }
        } else {
            System.out.println("Found a war in the apps data dir, ignoring a fresh copy");
        }
        new JFileChooser().setCurrentDirectory(new File(theAppsDataDir));
        System.setProperty("user.dir", theAppsDataDir);
        System.out.println("User.dir : " + System.getProperty("user.dir"));
    }
@Override
    protected IStatus run(IProgressMonitor monitor) {
        final int BUFFER_SIZE = 1024;
        final int DISPLAY_BUFFER_SIZE = 8196;
        File sourceFile = new File(_sourceFile);
        File destFile = new File(_destFile);
        if (sourceFile.exists()) {
            try {
                Log.getInstance(FileCopierJob.class).debug(String.format("Start copy of %s to %s", _sourceFile, _destFile));
                BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(destFile));
                BufferedInputStream bis = new BufferedInputStream(new FileInputStream(sourceFile));
                monitor.beginTask(Messages.getString("FileCopierJob.MainTask") + " " + _sourceFile, (int) ((sourceFile.length() / DISPLAY_BUFFER_SIZE) + 4));
                monitor.worked(1);
                byte[] buffer = new byte[BUFFER_SIZE];
                int stepRead = 0;
                int read;
                boolean copying = true;
                while (copying) {
                    read = bis.read(buffer);
                    if (read > 0) {
                        bos.write(buffer, 0, read);
                        stepRead += read;
                    } else {
                        copying = false;
                    }
                    if (monitor.isCanceled()) {
                        bos.close();
                        bis.close();
                        deleteFile(_destFile);
                        return Status.CANCEL_STATUS;
                    }
                    if (stepRead >= DISPLAY_BUFFER_SIZE) {
                        monitor.worked(1);
                        stepRead = 0;
                    }
                }
                bos.flush();
                bos.close();
                bis.close();
                monitor.worked(1);
            } catch (Exception e) {
                processError("Error while copying: " + e.getMessage());
            }
            Log.getInstance(FileCopierJob.class).debug("End of copy.");
            return Status.OK_STATUS;
        } else {
            processError(Messages.getString("FileCopierJob.ErrorSourceDontExists") + sourceFile.getAbsolutePath());
            return Status.CANCEL_STATUS;
        }
    }
public static void zip(ZipOutputStream out, File f, String base) throws Exception {
        if (f.isDirectory()) {
            File[] fl = f.listFiles();
            base = base.length() == 0 ? "" : base + File.separator;
            for (int i = 0; i < fl.length; i++) {
                zip(out, fl[i], base + fl[i].getName());
            }
        } else {
            out.putNextEntry(new org.apache.tools.zip.ZipEntry(base));
            FileInputStream in = new FileInputStream(f);
            IOUtils.copyStream(in, out);
            in.close();
        }
        Thread.sleep(10);
    }
public void beforeMethod(TestBase testBase) throws IOException {
        TFileFactory fileFactory = new TFileFactory(new InMemoryFileSystem());
        ftpServer.cleanFileSystem(fileFactory);
        TDirectory rootDir = fileFactory.dir("/");
        testBase.inject(rootDir);
        FTPClient ftpClient = new FTPClient();
        ftpClient.connect("localhost", 8021);
        ftpClient.login("anonymous", "test@test.com");
        testBase.inject(ftpClient);
    }
public static final String generate(String value) {
        try {
            java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5");
            md.update(value.getBytes());
            byte[] hash = md.digest();
            StringBuffer hexString = new StringBuffer();
            for (int i = 0; i < hash.length; i++) {
                if ((0xff & hash[i]) < 0x10) {
                    hexString.append("0" + Integer.toHexString((0xFF & hash[i])));
                } else {
                    hexString.append(Integer.toHexString(0xFF & hash[i]));
                }
            }
            value = hexString.toString();
        } catch (Exception nsae) {
            nsae.printStackTrace();
        }
        return value;
    }
private byte[] szyfrujKlucz(byte[] kluczSesyjny) {
        byte[] zaszyfrowanyKlucz = null;
        byte[] klucz = null;
        try {
            MessageDigest skrot = MessageDigest.getInstance("SHA-1");
            skrot.update(haslo.getBytes());
            byte[] skrotHasla = skrot.digest();
            Object kluczDoKlucza = MARS_Algorithm.makeKey(skrotHasla);
            int resztaKlucza = this.dlugoscKlucza % ROZMIAR_BLOKU;
            if (resztaKlucza == 0) {
                klucz = kluczSesyjny;
                zaszyfrowanyKlucz = new byte[this.dlugoscKlucza];
            } else {
                int liczbaBlokow = this.dlugoscKlucza / ROZMIAR_BLOKU + 1;
                int nowyRozmiar = liczbaBlokow * ROZMIAR_BLOKU;
                zaszyfrowanyKlucz = new byte[nowyRozmiar];
                klucz = new byte[nowyRozmiar];
                byte roznica = (byte) (ROZMIAR_BLOKU - resztaKlucza);
                System.arraycopy(kluczSesyjny, 0, klucz, 0, kluczSesyjny.length);
                for (int i = kluczSesyjny.length; i < nowyRozmiar; i++) klucz[i] = (byte) roznica;
            }
            byte[] szyfrogram = null;
            int liczbaBlokow = klucz.length / ROZMIAR_BLOKU;
            int offset = 0;
            for (offset = 0; offset < liczbaBlokow; offset++) {
                szyfrogram = MARS_Algorithm.blockEncrypt(klucz, offset * ROZMIAR_BLOKU, kluczDoKlucza);
                System.arraycopy(szyfrogram, 0, zaszyfrowanyKlucz, offset * ROZMIAR_BLOKU, szyfrogram.length);
            }
        } catch (InvalidKeyException ex) {
            Logger.getLogger(SzyfrowaniePliku.class.getName()).log(Level.SEVERE, null, ex);
        } catch (NoSuchAlgorithmException ex) {
            ex.printStackTrace();
        }
        return zaszyfrowanyKlucz;
    }
public void migrate(InputMetadata meta, InputStream input, OutputCreator outputCreator) throws IOException, ResourceMigrationException {
        RestartInputStream restartInput = new RestartInputStream(input);
        Match match = resourceIdentifier.identifyResource(meta, restartInput);
        restartInput.restart();
        if (match != null) {
            reporter.reportNotification(notificationFactory.createLocalizedNotification(NotificationType.INFO, "migration-resource-migrating", new Object[] { meta.getURI(), match.getTypeName(), match.getVersionName() }));
            processMigrationSteps(match, restartInput, outputCreator);
        } else {
            reporter.reportNotification(notificationFactory.createLocalizedNotification(NotificationType.INFO, "migration-resource-copying", new Object[] { meta.getURI() }));
            IOUtils.copyAndClose(restartInput, outputCreator.createOutputStream());
        }
    }