semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public static final String getUniqueId() {
        String digest = "";
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            String timeVal = "" + (System.currentTimeMillis() + 1);
            String localHost = "";
            ;
            try {
                localHost = InetAddress.getLocalHost().toString();
            } catch (UnknownHostException e) {
                log.error("Error trying to get localhost" + e.getMessage());
            }
            String randVal = "" + new Random().nextInt();
            String val = timeVal + localHost + randVal;
            md.reset();
            md.update(val.getBytes());
            digest = toHexString(md.digest());
        } catch (NoSuchAlgorithmException e) {
            log.error("Error trying to generate unique Id" + e.getMessage());
        }
        return digest;
    }
public void run(IAction action) {
        int style = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().getStyle();
        Shell shell = new Shell((style & SWT.MIRRORED) != 0 ? SWT.RIGHT_TO_LEFT : SWT.NONE);
        GraphicalViewer viewer = new ScrollingGraphicalViewer();
        viewer.createControl(shell);
        viewer.setEditDomain(new DefaultEditDomain(null));
        viewer.setRootEditPart(new ScalableFreeformRootEditPart());
        viewer.setEditPartFactory(new ProjectEditPartFactory());
        viewer.setContents(getContents());
        viewer.flush();
        int printMode = new PrintModeDialog(shell).open();
        if (printMode == -1) return;
        PrintDialog dialog = new PrintDialog(shell, SWT.NULL);
        PrinterData data = dialog.open();
        if (data != null) {
            PrintGraphicalViewerOperation op = new PrintGraphicalViewerOperation(new Printer(data), viewer);
            op.setPrintMode(printMode);
            op.run(selectedFile.getName());
        }
    }
public static String getHashCode(String text) throws UnsupportedEncodingException, NoSuchAlgorithmException {
        MessageDigest md;
        md = MessageDigest.getInstance("MD5");
        byte[] md5hash = new byte[32];
        md.update(text.getBytes("UTF-8"), 0, text.length());
        md5hash = md.digest();
        return convertToHex(md5hash);
    }
static String doHttp(String postURL, String text) {
        String returnValue = null;
        StringBuffer sb = new StringBuffer();
        sb.append("bsh.client=Remote");
        sb.append("&bsh.script=");
        sb.append(URLEncoder.encode(text));
        String formData = sb.toString();
        try {
            URL url = new URL(postURL);
            HttpURLConnection urlcon = (HttpURLConnection) url.openConnection();
            urlcon.setRequestMethod("POST");
            urlcon.setRequestProperty("Content-type", "application/x-www-form-urlencoded");
            urlcon.setDoOutput(true);
            urlcon.setDoInput(true);
            PrintWriter pout = new PrintWriter(new OutputStreamWriter(urlcon.getOutputStream(), "8859_1"), true);
            pout.print(formData);
            pout.flush();
            int rc = urlcon.getResponseCode();
            if (rc != HttpURLConnection.HTTP_OK) System.out.println("Error, HTTP response: " + rc);
            returnValue = urlcon.getHeaderField("Bsh-Return");
            BufferedReader bin = new BufferedReader(new InputStreamReader(urlcon.getInputStream()));
            String line;
            while ((line = bin.readLine()) != null) System.out.println(line);
            System.out.println("Return Value: " + returnValue);
        } catch (MalformedURLException e) {
            System.out.println(e);
        } catch (IOException e2) {
            System.out.println(e2);
        }
        return returnValue;
    }
public static String MD5(String text) throws NoSuchAlgorithmException, UnsupportedEncodingException {
        MessageDigest md;
        md = MessageDigest.getInstance("MD5");
        byte[] md5hash = new byte[32];
        md.update(text.getBytes("UTF-8"), 0, text.length());
        md5hash = md.digest();
        return convertToHex(md5hash);
    }
public String getFeatureInfoHTML(Point3d GKposition, String[] layerIds, int featureCount) {
        String html = "";
        try {
            String request = null;
            if (version == VERSION_030) {
                org.gdi3d.xnavi.services.w3ds.x030.GetFeatureInfo getFeatureInfo = new org.gdi3d.xnavi.services.w3ds.x030.GetFeatureInfo(this.serviceEndPoint);
                request = getFeatureInfo.createRequest(GKposition, layerIds, featureCount);
            } else if (version == VERSION_040) {
                org.gdi3d.xnavi.services.w3ds.x040.GetFeatureInfo getFeatureInfo = new org.gdi3d.xnavi.services.w3ds.x040.GetFeatureInfo(this.serviceEndPoint);
                request = getFeatureInfo.createRequest(GKposition, layerIds, featureCount);
            } else if (version == VERSION_041) {
                org.gdi3d.xnavi.services.w3ds.x041.GetFeatureInfo getFeatureInfo = new org.gdi3d.xnavi.services.w3ds.x041.GetFeatureInfo(this.serviceEndPoint);
                request = getFeatureInfo.createRequest(GKposition, layerIds, featureCount);
            }
            if (Navigator.isVerbose()) System.out.println(request);
            URL url = new URL(request);
            int contentLength = -1;
            URLConnection urlc;
            urlc = url.openConnection();
            urlc.setReadTimeout(Navigator.TIME_OUT);
            if (getEncoding() != null) {
                urlc.setRequestProperty("Authorization", "Basic " + getEncoding());
            }
            urlc.connect();
            String content_type = urlc.getContentType();
            if (content_type.equalsIgnoreCase("text/html") || content_type.equalsIgnoreCase("text/html;charset=UTF-8")) {
                InputStream is = urlc.getInputStream();
                BufferedInputStream bis = new BufferedInputStream(is);
                StringBuffer sb = new StringBuffer();
                InputStreamReader isr = new InputStreamReader(bis);
                char chars[] = new char[10240];
                int len = 0;
                contentLength = 0;
                while ((len = isr.read(chars, 0, chars.length)) >= 0) {
                    sb.append(chars, 0, len);
                    contentLength += len;
                }
                chars = null;
                isr.close();
                bis.close();
                is.close();
                html = sb.toString();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return html;
    }
private String httpGet(String urlString, boolean postStatus) throws Exception {
        URL url;
        URLConnection conn;
        String answer = "";
        try {
            if (username.equals("") || password.equals("")) throw new AuthNotProvidedException();
            url = new URL(urlString);
            conn = url.openConnection();
            conn.setRequestProperty("Authorization", "Basic " + getAuthentificationString());
            if (postStatus) {
                conn.setDoOutput(true);
                conn.setUseCaches(false);
                conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
                DataOutputStream das = new DataOutputStream(conn.getOutputStream());
                String content = "status=" + URLEncoder.encode(statusMessage, "UTF-8") + "&source=" + URLEncoder.encode("sametimetwitterclient", "UTF-8");
                das.writeBytes(content);
                das.flush();
                das.close();
            }
            InputStream is = (InputStream) conn.getInputStream();
            BufferedReader br = new BufferedReader(new InputStreamReader(is));
            String line;
            while ((line = br.readLine()) != null) {
                answer += line + "\n";
            }
            br.close();
        } catch (FileNotFoundException ex) {
            System.out.println(ex.toString());
            throw new RuntimeException("Page not Found. Maybe Twitter-API has changed.");
        } catch (UnknownHostException ex) {
            System.out.println(ex.toString());
            throw new RuntimeException("Network connection problems. Could not find twitter.com");
        } catch (IOException ex) {
            System.out.println("IO-Exception");
            if (ex.getMessage().indexOf("401") > -1) {
                authenthicated = AUTH_BAD;
                throw new AuthNotAcceptedException();
            }
            System.out.println(ex.toString());
        }
        if (checkForError(answer) != null) {
            throw new RuntimeException(checkForError(answer));
        }
        authenthicated = AUTH_OK;
        return answer;
    }
public void updateDb(int scriptNumber) throws SQLException, IOException {
        String pathName = updatesPackage.replace(".", "/");
        InputStream in = getClass().getClassLoader().getResourceAsStream(pathName + "/" + scriptNumber + ".sql");
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        IOUtils.copy(in, out);
        String script = out.toString("UTF-8");
        String[] statements = script.split(";");
        for (String statement : statements) {
            getJdbcTemplate().execute(statement);
        }
    }
private final String createMD5(String pwd) throws Exception {
        MessageDigest md = (MessageDigest) MessageDigest.getInstance("MD5").clone();
        md.update(pwd.getBytes("UTF-8"));
        byte[] pd = md.digest();
        StringBuffer app = new StringBuffer();
        for (int i = 0; i < pd.length; i++) {
            String s2 = Integer.toHexString(pd[i] & 0xFF);
            app.append((s2.length() == 1) ? "0" + s2 : s2);
        }
        return app.toString();
    }
public static void copyFile(File source, File destination) throws IOException {
        FileChannel srcChannel = new FileInputStream(source).getChannel();
        FileChannel destChannel = new FileOutputStream(destination).getChannel();
        try {
            int maxCount = (64 * 1024 * 1024) - (32 * 1024);
            long size = srcChannel.size();
            long position = 0;
            while (position < size) {
                position += srcChannel.transferTo(position, maxCount, destChannel);
            }
        } finally {
            if (srcChannel != null) srcChannel.close();
            if (destChannel != null) destChannel.close();
        }
    }
public static String generateHash(String msg) throws NoSuchAlgorithmException {
        if (msg == null) {
            throw new IllegalArgumentException("Input string can not be null");
        }
        MessageDigest m = MessageDigest.getInstance("MD5");
        m.reset();
        m.update(msg.getBytes());
        byte[] digest = m.digest();
        BigInteger bigInt = new BigInteger(1, digest);
        String hashText = bigInt.toString(16);
        while (hashText.length() < 32) {
            hashText = "0" + hashText;
        }
        return hashText;
    }
public void run() {
        Pair p = null;
        try {
            while ((p = queue.pop()) != null) {
                GetMethod get = new GetMethod(p.getRemoteUri());
                try {
                    get.setFollowRedirects(true);
                    get.setRequestHeader("Mariner-Application", "prerenderer");
                    get.setRequestHeader("Mariner-DeviceName", deviceName);
                    int iGetResultCode = httpClient.executeMethod(get);
                    if (iGetResultCode != 200) {
                        throw new IOException("Got response code " + iGetResultCode + " for a request for " + p.getRemoteUri());
                    }
                    InputStream is = get.getResponseBodyAsStream();
                    File localFile = new File(deviceFile, p.getLocalUri());
                    localFile.getParentFile().mkdirs();
                    OutputStream os = new FileOutputStream(localFile);
                    IOUtils.copy(is, os);
                    os.close();
                } finally {
                    get.releaseConnection();
                }
            }
        } catch (Exception ex) {
            result = ex;
        }
    }
public List<AnalyzerResult> analyze(LWComponent c, boolean tryFallback) {
        List<AnalyzerResult> results = new ArrayList<AnalyzerResult>();
        try {
            URL url = new URL(DEFAULT_FLOW_URL + "?" + DEFAULT_INPUT + "=" + c.getLabel());
            if (flow != null) {
                url = new URL(flow.getUrl() + "?" + flow.getInputList().get(0) + "=" + getSpecFromComponent(c));
            }
            System.setProperty("javax.xml.parsers.SAXParserFactory", "org.apache.xerces.jaxp.SAXParserFactoryImpl");
            XMLDecoder decoder = new XMLDecoder(url.openStream());
            Map map = (Map) decoder.readObject();
            for (Object key : map.keySet()) {
                results.add(new AnalyzerResult(key.toString(), map.get(key).toString()));
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            VueUtil.alert("Can't Execute Flow on the node " + c.getLabel(), "Can't Execute Seasr flow");
        }
        return results;
    }
public List<AnalyzerResult> analyze(String urlString, boolean tryFallback) {
        List<AnalyzerResult> results = new ArrayList<AnalyzerResult>();
        try {
            URL url;
            if (flow == null) {
                url = new URL(DEFAULT_FLOW_URL + "?" + DEFAULT_INPUT + "=" + urlString);
            } else {
                url = new URL(flow.getUrl() + "?" + flow.getInputList().get(0) + "=" + urlString);
            }
            System.setProperty("javax.xml.parsers.SAXParserFactory", "org.apache.xerces.jaxp.SAXParserFactoryImpl");
            System.out.println("Executing: " + url.toString());
            XMLDecoder decoder = new XMLDecoder(url.openStream());
            Map map = (Map) decoder.readObject();
            for (Object key : map.keySet()) {
                results.add(new AnalyzerResult(key.toString(), map.get(key).toString()));
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            VueUtil.alert("Can't Execute Flow on the url " + urlString, "Can't Execute Seasr flow");
        }
        return results;
    }
private void readXML() throws IOException, SAXException {
        DocumentBuilder builder = null;
        try {
            builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        } catch (ParserConfigurationException ex) {
            throw new RuntimeException(ex);
        }
        InputSource source = new InputSource(url.openStream());
        document = builder.parse(source);
        Node n = document.getDocumentElement();
        String localName = n.getNodeName();
        int i = localName.indexOf(":");
        if (i > -1) {
            localName = localName.substring(i + 1);
        }
        if (localName.equals("Spase")) {
            type = TYPE_SPASE;
        } else if (localName.equals("Eventlist")) {
            type = TYPE_HELM;
        } else if (localName.equals("VOTABLE")) {
            type = TYPE_VOTABLE;
        } else {
            throw new IllegalArgumentException("Unsupported XML type, root node should be Spase or Eventlist");
        }
    }
private InputStream execute(String filter, String query) {
        client = new DefaultHttpClient();
        String url = getURL();
        String trenn = "?";
        if (filter != null) {
            url += trenn + "filter=" + filter;
            trenn = "&";
        }
        if (query != null) {
            url += trenn + "query=" + query;
        }
        HttpGet get = new HttpGet(url);
        System.out.println("get: " + url);
        try {
            HttpResponse response = client.execute(get);
            HttpEntity entity = response.getEntity();
            return entity.getContent();
        } catch (ClientProtocolException e) {
        } catch (IOException e) {
        }
        return null;
    }
public static boolean saveToTempFile(Context context, String filePath, DirType dirType, String tempSavePath, boolean secrete) {
        FileOutputStream fos = null;
        InputStream in = null;
        byte[] buffer = new byte[1024];
        int readLength = 0;
        boolean result = false;
        try {
            try {
                File f = new File(context.getFilesDir().getAbsolutePath() + File.separator + tempSavePath);
                if (f.exists()) {
                    context.deleteFile(tempSavePath);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            fos = context.openFileOutput(tempSavePath, Context.MODE_WORLD_READABLE);
            logger.error("tempfile:" + tempSavePath);
            if (dirType == DirType.assets) {
                AssetManager assetManager = context.getAssets();
                in = assetManager.open(filePath);
            } else if (dirType == DirType.file && Constant.getUpdateDataPath() != null) {
                in = new FileInputStream(Constant.getUpdateDataPath() + File.separator + filePath);
            } else if (dirType == DirType.sd && Constant.getSdPath() != null) {
                in = new FileInputStream(Constant.getSdPath() + File.separator + filePath);
            } else if (dirType == DirType.extSd && Constant.getExtSdPath() != null) {
                in = new FileInputStream(Constant.getExtSdPath() + File.separator + filePath);
            }
            if (in == null) {
                return false;
            }
            readLength = in.read(buffer);
            if (readLength >= ZipToFile.encrypLength && secrete) {
                byte[] encrypByte = new byte[ZipToFile.encrypLength];
                System.arraycopy(buffer, 0, encrypByte, 0, ZipToFile.encrypLength);
                byte[] temp = CryptionControl.getInstance().decryptECB(encrypByte, ZipToFile.rootKey);
                System.arraycopy(temp, 0, buffer, 0, ZipToFile.encrypLength);
            }
            while (readLength > 0) {
                fos.write(buffer, 0, readLength);
                fos.flush();
                readLength = in.read(buffer);
            }
            result = true;
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (fos != null) {
                try {
                    fos.flush();
                    fos.close();
                } catch (Exception e) {
                }
            }
            if (in != null) {
                try {
                    in.close();
                } catch (Exception e) {
                }
            }
        }
        return result;
    }
public static PersistencyParameters parse(String unitName) {
        URL[] persistenceUnits;
        try {
            persistenceUnits = Classpath.search("META-INF/", "persistence.xml");
        } catch (IOException e) {
            throw new Error(e);
        }
        Set classes = new HashSet();
        for (int i = 0; i < persistenceUnits.length; i++) {
            URL url = persistenceUnits[i];
            try {
                nu.xom.Builder b = new nu.xom.Builder(false);
                Document d = b.build(url.openStream());
                Nodes unitNodes = d.getRootElement().query("//p:persistence-unit", new XPathContext("p", "http://java.sun.com/xml/ns/persistence"));
                for (int j = 0; j < unitNodes.size(); j++) {
                    Node unitNode = unitNodes.get(j);
                    Element unitElt = ((Element) unitNode);
                    String uName = unitElt.getAttributeValue("name");
                    if (!uName.equals(unitName)) continue;
                    {
                        PersistencyParameters parameters = new PersistencyParameters();
                        Nodes classNodes = unitElt.query("//p:property", new XPathContext("p", "http://java.sun.com/xml/ns/persistence"));
                        for (int k = 0; k < classNodes.size(); k++) {
                            Node classNode = classNodes.get(k);
                            if (!(classNode instanceof Element)) continue;
                            Element classElt = (Element) classNode;
                            String elementName = classElt.getAttribute("name").getValue();
                            if (elementName.equals("eclipselink.jdbc.url")) {
                                String elementValue = classElt.getAttribute("value").getValue();
                                parameters.setJdbcUrl(elementValue);
                            } else if (elementName.equals("eclipselink.jdbc.user")) {
                                String elementValue = classElt.getAttribute("value").getValue();
                                parameters.setDBUserName(elementValue);
                            } else if (elementName.equals("eclipselink.jdbc.password")) {
                                String elementValue = classElt.getAttribute("value").getValue();
                                parameters.setDBPassword(elementValue);
                            } else if (elementName.equals("eclipselink.jdbc.driver")) {
                                String elementValue = classElt.getAttribute("value").getValue();
                                parameters.setDBDriverClassName(elementValue);
                            }
                        }
                        return parameters;
                    }
                }
            } catch (Exception x) {
                x.printStackTrace();
                throw new Error(x);
            }
        }
        return null;
    }
public static String SHA1(String text) throws NoSuchAlgorithmException {
        MessageDigest md = MessageDigest.getInstance("SHA-1");
        md.update(text.getBytes());
        byte byteData[] = md.digest();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < byteData.length; i++) {
            sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1));
        }
        StringBuilder hexString = new StringBuilder();
        for (int i = 0; i < byteData.length; i++) {
            String hex = Integer.toHexString(0xff & byteData[i]);
            if (hex.length() == 1) hexString.append('0');
            hexString.append(hex);
        }
        return hexString.toString();
    }
public static void copyFile(File source, File destination) throws IOException {
        FileChannel srcChannel = new FileInputStream(source).getChannel();
        FileChannel dstChannel = new FileOutputStream(destination).getChannel();
        dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
        srcChannel.close();
        dstChannel.close();
    }
public static String getEncryptedPassword(String clearTextPassword) {
        if (StringUtil.isEmpty(clearTextPassword)) return "";
        try {
            MessageDigest md = MessageDigest.getInstance("SHA-256");
            md.update(clearTextPassword.getBytes());
            return new sun.misc.BASE64Encoder().encode(md.digest());
        } catch (NoSuchAlgorithmException e) {
            _log.error("Failed to encrypt password.", e);
        }
        return "";
    }
public static String hashSourceCode(String source) {
        MessageDigest md;
        try {
            md = MessageDigest.getInstance("MD5");
            md.update(source.getBytes());
            return new sun.misc.BASE64Encoder().encode(md.digest());
        } catch (NoSuchAlgorithmException e) {
            _log.error("Failed to generate hashcode.", e);
        }
        return null;
    }
public void encryptFile(String originalFile, String encryptedFile, String password) throws Exception {
        CipherOutputStream out;
        InputStream in;
        Cipher cipher;
        SecretKey key;
        byte[] byteBuffer;
        cipher = Cipher.getInstance("DES");
        key = new SecretKeySpec(password.getBytes(), "DES");
        cipher.init(Cipher.ENCRYPT_MODE, key);
        in = new FileInputStream(originalFile);
        out = new CipherOutputStream(new FileOutputStream(encryptedFile), cipher);
        byteBuffer = new byte[1024];
        for (int n; (n = in.read(byteBuffer)) != -1; out.write(byteBuffer, 0, n)) ;
        in.close();
        out.close();
    }