semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public static String md5Crypt(final byte[] key, final byte[] salt) throws NoSuchAlgorithmException {
        if (key == null || key.length == 0) {
            throw new IllegalArgumentException("Argument 'key' cannot be null or an empty array.");
        }
        if (salt == null || salt.length == 0) {
            throw new IllegalArgumentException("Argument 'salt' cannot be null or an empty array.");
        }
        final MessageDigest _md = MessageDigest.getInstance("MD5");
        _md.update(key);
        _md.update(MAGIC.getBytes());
        _md.update(salt);
        final MessageDigest md2 = MessageDigest.getInstance("MD5");
        md2.update(key);
        md2.update(salt);
        md2.update(key);
        byte[] abyFinal = md2.digest();
        for (int n = key.length; n > 0; n -= 16) {
            _md.update(abyFinal, 0, n > 16 ? 16 : n);
        }
        abyFinal = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
        for (int j = 0, i = key.length; i != 0; i >>>= 1) {
            if ((i & 1) == 1) _md.update(abyFinal, j, 1); else _md.update(key, j, 1);
        }
        final StringBuilder sbPasswd = new StringBuilder();
        sbPasswd.append(MAGIC);
        sbPasswd.append(new String(salt));
        sbPasswd.append('$');
        abyFinal = _md.digest();
        for (int n = 0; n < 1000; n++) {
            final MessageDigest md3 = MessageDigest.getInstance("MD5");
            if ((n & 1) != 0) {
                md3.update(key);
            } else {
                md3.update(abyFinal);
            }
            if ((n % 3) != 0) {
                md3.update(salt);
            }
            if ((n % 7) != 0) {
                md3.update(key);
            }
            if ((n & 1) != 0) {
                md3.update(abyFinal);
            } else {
                md3.update(key);
            }
            abyFinal = md3.digest();
        }
        int[] anFinal = new int[] { (abyFinal[0] & 0x7f) | (abyFinal[0] & 0x80), (abyFinal[1] & 0x7f) | (abyFinal[1] & 0x80), (abyFinal[2] & 0x7f) | (abyFinal[2] & 0x80), (abyFinal[3] & 0x7f) | (abyFinal[3] & 0x80), (abyFinal[4] & 0x7f) | (abyFinal[4] & 0x80), (abyFinal[5] & 0x7f) | (abyFinal[5] & 0x80), (abyFinal[6] & 0x7f) | (abyFinal[6] & 0x80), (abyFinal[7] & 0x7f) | (abyFinal[7] & 0x80), (abyFinal[8] & 0x7f) | (abyFinal[8] & 0x80), (abyFinal[9] & 0x7f) | (abyFinal[9] & 0x80), (abyFinal[10] & 0x7f) | (abyFinal[10] & 0x80), (abyFinal[11] & 0x7f) | (abyFinal[11] & 0x80), (abyFinal[12] & 0x7f) | (abyFinal[12] & 0x80), (abyFinal[13] & 0x7f) | (abyFinal[13] & 0x80), (abyFinal[14] & 0x7f) | (abyFinal[14] & 0x80), (abyFinal[15] & 0x7f) | (abyFinal[15] & 0x80) };
        to64(sbPasswd, anFinal[0] << 16 | anFinal[6] << 8 | anFinal[12], 4);
        to64(sbPasswd, anFinal[1] << 16 | anFinal[7] << 8 | anFinal[13], 4);
        to64(sbPasswd, anFinal[2] << 16 | anFinal[8] << 8 | anFinal[14], 4);
        to64(sbPasswd, anFinal[3] << 16 | anFinal[9] << 8 | anFinal[15], 4);
        to64(sbPasswd, anFinal[4] << 16 | anFinal[10] << 8 | anFinal[5], 4);
        to64(sbPasswd, anFinal[11], 2);
        return sbPasswd.toString();
    }
public static String computeMD5(InputStream input) {
        InputStream digestStream = null;
        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            digestStream = new DigestInputStream(input, md5);
            IOUtils.copy(digestStream, new NullOutputStream());
            return new String(Base64.encodeBase64(md5.digest()), "UTF-8");
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            IOUtils.closeQuietly(digestStream);
        }
    }
public static void writeToFile(InputStream input, File file, ProgressListener listener, long length) {
        OutputStream output = null;
        try {
            output = new CountingOutputStream(new FileOutputStream(file), listener, length);
            IOUtils.copy(input, output);
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            IOUtils.closeQuietly(input);
            IOUtils.closeQuietly(output);
        }
    }
private IProject createCopyProject(IProject project, IWorkspace ws, IProgressMonitor pm) throws CoreException {
        pm.beginTask("Creating temp project", 1);
        final String pName = "translation_" + project.getName() + "_" + new Date().toString().replace(" ", "_").replace(":", "_");
        final IProgressMonitor npm = new NullProgressMonitor();
        final IPath destination = new Path(pName);
        project.copy(destination, false, npm);
        final IJavaProject oldJavaproj = JavaCore.create(project);
        final IClasspathEntry[] classPath = oldJavaproj.getRawClasspath();
        final IProject newProject = ResourcesPlugin.getWorkspace().getRoot().getProject("NewProjectName");
        final IProjectDescription desc = project.getDescription();
        desc.setNatureIds(new String[] { JavaCore.NATURE_ID });
        project.setDescription(desc, null);
        final IJavaProject javaproj = JavaCore.create(newProject);
        javaproj.setOutputLocation(project.getFullPath(), null);
        final List<IClasspathEntry> newClassPath = new ArrayList<IClasspathEntry>();
        for (final IClasspathEntry cEntry : newClassPath) {
            switch(cEntry.getContentKind()) {
                case IClasspathEntry.CPE_SOURCE:
                    System.out.println("Source folder " + cEntry.getPath());
                    break;
                default:
                    newClassPath.add(cEntry);
            }
        }
        javaproj.setRawClasspath(classPath, pm);
        final IProject newP = ws.getRoot().getProject(pName);
        return newP;
    }
public static void copyFile(File source, File dest) throws IOException {
        log.debug("Copy from {} to {}", source.getAbsoluteFile(), dest.getAbsoluteFile());
        FileInputStream fi = new FileInputStream(source);
        FileChannel fic = fi.getChannel();
        MappedByteBuffer mbuf = fic.map(FileChannel.MapMode.READ_ONLY, 0, source.length());
        fic.close();
        fi.close();
        fi = null;
        if (!dest.exists()) {
            String destPath = dest.getPath();
            log.debug("Destination path: {}", destPath);
            String destDir = destPath.substring(0, destPath.lastIndexOf(File.separatorChar));
            log.debug("Destination dir: {}", destDir);
            File dir = new File(destDir);
            if (!dir.exists()) {
                if (dir.mkdirs()) {
                    log.debug("Directory created");
                } else {
                    log.warn("Directory not created");
                }
            }
            dir = null;
        }
        FileOutputStream fo = new FileOutputStream(dest);
        FileChannel foc = fo.getChannel();
        foc.write(mbuf);
        foc.close();
        fo.close();
        fo = null;
        mbuf.clear();
        mbuf = null;
    }
private static FrameworkFactory getFrameworkFactory() throws Exception {
        URL url = Main.class.getClassLoader().getResource("META-INF/services/org.osgi.framework.launch.FrameworkFactory");
        if (url != null) {
            BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
            try {
                for (String s = br.readLine(); s != null; s = br.readLine()) {
                    s = s.trim();
                    if ((s.length() > 0) && (s.charAt(0) != '#')) {
                        return (FrameworkFactory) Class.forName(s).newInstance();
                    }
                }
            } finally {
                if (br != null) br.close();
            }
        }
        throw new Exception("Could not find framework factory.");
    }
public static String encryptPass(String pass) {
        String passEncrypt;
        MessageDigest md5 = null;
        try {
            md5 = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException ex) {
        }
        md5.update(pass.getBytes());
        BigInteger dis = new BigInteger(1, md5.digest());
        passEncrypt = dis.toString(16);
        return passEncrypt;
    }
public static String encryptPass2(String pass) throws UnsupportedEncodingException {
        String passEncrypt;
        MessageDigest md5 = null;
        try {
            md5 = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException ex) {
        }
        md5.update(pass.getBytes());
        String dis = new String(md5.digest(), 10);
        passEncrypt = dis.toString();
        return passEncrypt;
    }
void sortclasses() {
        int i, j;
        boolean domore;
        vclassptr = new int[numc];
        for (i = 0; i < numc; i++) vclassptr[i] = i;
        domore = true;
        while (domore == true) {
            domore = false;
            for (i = 0; i < numc - 1; i++) {
                if (vclassctr[vclassptr[i]] < vclassctr[vclassptr[i + 1]]) {
                    int temp = vclassptr[i];
                    vclassptr[i] = vclassptr[i + 1];
                    vclassptr[i + 1] = temp;
                    domore = true;
                }
            }
        }
    }
public static void main(String[] args) {
        try {
            Object o = Naming.lookup("Server");
            IServer serverStub = (IServer) o;
            File srcDir = new File(args[0]);
            File dstDir = new File(args[1]);
            File[] srcFiles = srcDir.listFiles();
            long position = 0;
            for (File f : srcFiles) {
                if (f.isDirectory()) continue;
                try {
                    FileChannel srcChannel = new FileInputStream(f).getChannel();
                    String fileName = dstDir.getAbsolutePath() + System.getProperty("file.separator") + f.getName();
                    FileChannel dstChannel = new FileOutputStream(fileName).getChannel();
                    System.out.println("Coping " + fileName);
                    ByteBuffer buffer = ByteBuffer.allocate(65536);
                    int nr = 0;
                    srcChannel.position(nr);
                    nr = srcChannel.read(buffer);
                    while (nr > -1) {
                        buffer.flip();
                        byte[] bytes = new byte[buffer.limit()];
                        buffer.get(bytes);
                        position = serverStub.write(bytes, position);
                        buffer.clear();
                        nr = srcChannel.read(buffer);
                    }
                    System.out.println("Done ");
                    srcChannel.close();
                    dstChannel.close();
                } catch (IOException e) {
                }
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (RemoteException e) {
            e.printStackTrace();
        } catch (NotBoundException e) {
            e.printStackTrace();
        }
    }
private static boolean extractFromJarUsingClassLoader(String searchString, String filename, String destinationDirectory) {
        ClassLoader cl = null;
        try {
            Class clClass = Class.forName("com.simontuffs.onejar.JarClassLoader");
            Constructor[] constructor = clClass.getConstructors();
            cl = (ClassLoader) constructor[1].newInstance(ClassLoader.getSystemClassLoader());
            System.out.println("Loaded JarClassLoader. cl=" + cl.toString());
        } catch (Throwable e) {
            cl = ClassLoader.getSystemClassLoader();
        }
        URL liburl = cl.getResource(filename);
        if (liburl == null) {
            return false;
        }
        if (!destinationDirectory.endsWith(File.separator)) {
            destinationDirectory = destinationDirectory + File.separator;
        }
        try {
            File destFile = new File(destinationDirectory + filename);
            if (destFile.exists()) {
                destFile.delete();
            }
            InputStream is;
            is = liburl.openStream();
            OutputStream os = new FileOutputStream(destinationDirectory + filename);
            byte[] buf = new byte[4096];
            int cnt = is.read(buf);
            while (cnt > 0) {
                os.write(buf, 0, cnt);
                cnt = is.read(buf);
            }
            os.close();
            is.close();
            destFile.deleteOnExit();
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }
public String digest(String password, String digestType, String inputEncoding) throws CmsPasswordEncryptionException {
        MessageDigest md;
        String result;
        try {
            if (DIGEST_TYPE_PLAIN.equals(digestType.toLowerCase())) {
                result = password;
            } else if (DIGEST_TYPE_SSHA.equals(digestType.toLowerCase())) {
                byte[] salt = new byte[4];
                byte[] digest;
                byte[] total;
                if (m_secureRandom == null) {
                    m_secureRandom = SecureRandom.getInstance("SHA1PRNG");
                }
                m_secureRandom.nextBytes(salt);
                md = MessageDigest.getInstance(DIGEST_TYPE_SHA);
                md.reset();
                md.update(password.getBytes(inputEncoding));
                md.update(salt);
                digest = md.digest();
                total = new byte[digest.length + salt.length];
                System.arraycopy(digest, 0, total, 0, digest.length);
                System.arraycopy(salt, 0, total, digest.length, salt.length);
                result = new String(Base64.encodeBase64(total));
            } else {
                md = MessageDigest.getInstance(digestType);
                md.reset();
                md.update(password.getBytes(inputEncoding));
                result = new String(Base64.encodeBase64(md.digest()));
            }
        } catch (NoSuchAlgorithmException e) {
            CmsMessageContainer message = Messages.get().container(Messages.ERR_UNSUPPORTED_ALGORITHM_1, digestType);
            if (LOG.isErrorEnabled()) {
                LOG.error(message.key(), e);
            }
            throw new CmsPasswordEncryptionException(message, e);
        } catch (UnsupportedEncodingException e) {
            CmsMessageContainer message = Messages.get().container(Messages.ERR_UNSUPPORTED_PASSWORD_ENCODING_1, inputEncoding);
            if (LOG.isErrorEnabled()) {
                LOG.error(message.key(), e);
            }
            throw new CmsPasswordEncryptionException(message, e);
        }
        return result;
    }
@Test
    public void testHandleMessageInvalidSignature() throws Exception {
        KeyPair keyPair = MiscTestUtils.generateKeyPair();
        DateTime notBefore = new DateTime();
        DateTime notAfter = notBefore.plusYears(1);
        X509Certificate certificate = MiscTestUtils.generateCertificate(keyPair.getPublic(), "CN=Test", notBefore, notAfter, null, keyPair.getPrivate(), true, 0, null, null);
        ServletConfig mockServletConfig = EasyMock.createMock(ServletConfig.class);
        Map<String, String> httpHeaders = new HashMap<String, String>();
        HttpSession mockHttpSession = EasyMock.createMock(HttpSession.class);
        HttpServletRequest mockServletRequest = EasyMock.createMock(HttpServletRequest.class);
        EasyMock.expect(mockServletConfig.getInitParameter("AuditService")).andStubReturn(null);
        EasyMock.expect(mockServletConfig.getInitParameter("AuditServiceClass")).andStubReturn(AuditTestService.class.getName());
        EasyMock.expect(mockServletConfig.getInitParameter("SignatureService")).andStubReturn(null);
        EasyMock.expect(mockServletConfig.getInitParameter("SignatureServiceClass")).andStubReturn(SignatureTestService.class.getName());
        EasyMock.expect(mockServletRequest.getRemoteAddr()).andStubReturn("remote-address");
        MessageDigest messageDigest = MessageDigest.getInstance("SHA1");
        byte[] document = "hello world".getBytes();
        byte[] digestValue = messageDigest.digest(document);
        EasyMock.expect(mockHttpSession.getAttribute(SignatureDataMessageHandler.DIGEST_VALUE_SESSION_ATTRIBUTE)).andStubReturn(digestValue);
        EasyMock.expect(mockHttpSession.getAttribute(SignatureDataMessageHandler.DIGEST_ALGO_SESSION_ATTRIBUTE)).andStubReturn("SHA-1");
        SignatureDataMessage message = new SignatureDataMessage();
        message.certificateChain = new LinkedList<X509Certificate>();
        message.certificateChain.add(certificate);
        Signature signature = Signature.getInstance("SHA1withRSA");
        signature.initSign(keyPair.getPrivate());
        signature.update("foobar-document".getBytes());
        byte[] signatureValue = signature.sign();
        message.signatureValue = signatureValue;
        EasyMock.replay(mockServletConfig, mockHttpSession, mockServletRequest);
        AppletServiceServlet.injectInitParams(mockServletConfig, this.testedInstance);
        this.testedInstance.init(mockServletConfig);
        try {
            this.testedInstance.handleMessage(message, httpHeaders, mockServletRequest, mockHttpSession);
            fail();
        } catch (ServletException e) {
            LOG.debug("expected exception: " + e.getMessage());
            EasyMock.verify(mockServletConfig, mockHttpSession, mockServletRequest);
            assertNull(SignatureTestService.getSignatureValue());
            assertEquals("remote-address", AuditTestService.getAuditSignatureRemoteAddress());
            assertEquals(certificate, AuditTestService.getAuditSignatureClientCertificate());
        }
    }
public void read() throws IOException {
        if (log.isInfoEnabled()) {
            log.info("Reading the camera log, " + url);
        }
        final BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
        String line;
        int i = 0;
        try {
            while ((line = in.readLine()) != null) {
                i++;
                try {
                    final CameraLogRecord logDatum = new CameraLogRecord(line);
                    records.add(logDatum);
                } catch (LogParseException e) {
                    if (log.isInfoEnabled()) {
                        log.info("Bad record in " + url + " at line:" + i);
                    }
                }
            }
        } finally {
            in.close();
        }
        Collections.sort(records);
        if (log.isInfoEnabled()) {
            log.info("Finished reading the camera log, " + url);
        }
    }
private void initBanner() {
        for (int k = 0; k < 3; k++) {
            if (bannerImg == null) {
                int i = getRandomId();
                imageURL = NbBundle.getMessage(BottomContent.class, "URL_BannerImageLink", Integer.toString(i));
                bannerURL = NbBundle.getMessage(BottomContent.class, "URL_BannerLink", Integer.toString(i));
                HttpContext context = new BasicHttpContext();
                context.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
                HttpGet method = new HttpGet(imageURL);
                try {
                    HttpResponse response = ProxyManager.httpClient.execute(method, context);
                    HttpEntity entity = response.getEntity();
                    if (entity != null) {
                        bannerImg = new ImageIcon(ImageIO.read(entity.getContent()));
                        EntityUtils.consume(entity);
                    }
                } catch (IOException ex) {
                    bannerImg = null;
                } finally {
                    method.abort();
                }
            } else {
                break;
            }
        }
        if (bannerImg == null) {
            NotifyUtil.error("Banner Error", "Application could not get banner image. Please check your internet connection.", false);
        }
    }
public void mousePressed(MouseEvent e) {
            bannerLbl.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
            HttpContext context = new BasicHttpContext();
            context.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
            HttpGet method = new HttpGet(bannerURL);
            try {
                HttpResponse response = ProxyManager.httpClient.execute(method, context);
                HttpEntity entity = response.getEntity();
                HttpHost host = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
                HttpUriRequest request = (HttpUriRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST);
                String targetURL = host.toURI() + request.getURI();
                DesktopUtil.browseAndWarn(targetURL, bannerLbl);
                EntityUtils.consume(entity);
            } catch (Exception ex) {
                NotifyUtil.error("Banner Error", "Could not open the default web browser.", ex, false);
            } finally {
                method.abort();
            }
            bannerLbl.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        }
private DataSource loadSingleDataSource(ClassLoader contextLoader, URL url) throws IOException, DataSourceException {
        URI datasourceURI;
        OWLOntology datasourceOntology = null;
        URL baseURL = new URL(url.toString().replace("META-INF/artifact.properties", ""));
        Properties properties = new Properties();
        properties.load(url.openStream());
        String fileName = properties.get("db").toString() + ".owl";
        String pkg = properties.get("package").toString();
        datasourceURI = URI.create("http://" + properties.get("host").toString() + "/" + fileName);
        Set<Class> beans = new HashSet<Class>();
        if (baseURL.toString().startsWith("jar") && baseURL.toString().endsWith("!/")) {
            JarURLConnection jarConn = (JarURLConnection) baseURL.openConnection();
            Enumeration<JarEntry> entries = jarConn.getJarFile().entries();
            while (entries.hasMoreElements()) {
                JarEntry next = entries.nextElement();
                if (next.getName().startsWith(pkg.replace('.', '/')) && next.getName().endsWith(".class")) {
                    String fullClassName = next.getName().replace('/', '.').replace(".class", "");
                    try {
                        beans.add(contextLoader.loadClass(fullClassName));
                    } catch (ClassNotFoundException e) {
                        throw new DataSourceException("Unable to locate " + fullClassName + ".class", e);
                    }
                } else if (next.getName().equals(fileName)) {
                    String resName = next.getName();
                    URL owl = contextLoader.getResource(resName);
                    try {
                        datasourceOntology = OWLManager.createOWLOntologyManager().loadOntologyFromPhysicalURI(owl.toURI());
                    } catch (URISyntaxException e) {
                        throw new DataSourceException("Bad syntax converting url -> uri: " + owl.toString(), e);
                    } catch (OWLOntologyCreationException e) {
                        throw new DataSourceException("Couldn't create ontology from " + owl.toString(), e);
                    }
                }
            }
            if (beans.size() == 0) {
                throw new DataSourceException("Failed to load beans for the datasource at " + url);
            }
            if (datasourceOntology == null) {
                throw new DataSourceException("The datasource at " + url + " contains no ontology, or the ontology could not be loaded");
            }
            return new BeanModelDataSource(datasourceURI, datasourceOntology);
        } else {
            throw new DataSourceException("Unable to create a datasource, cannot load classes with the " + "given URL protocol (" + baseURL + ")");
        }
    }
private static byte[] finalizeStringHash(String loginHash) throws NoSuchAlgorithmException {
        MessageDigest md5Hasher;
        md5Hasher = MessageDigest.getInstance("MD5");
        md5Hasher.update(loginHash.getBytes());
        md5Hasher.update(LOGIN_FINAL_SALT);
        return md5Hasher.digest();
    }