semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public static String hashNative(String password, String algorithm, String prefixKey, boolean useDefaultEncoding) {
        try {
            MessageDigest digest = MessageDigest.getInstance(algorithm);
            if (useDefaultEncoding) {
                digest.update(password.getBytes());
            } else {
                for (char c : password.toCharArray()) {
                    digest.update((byte) (c >> 8));
                    digest.update((byte) c);
                }
            }
            byte[] digestedPassword = digest.digest();
            BASE64Encoder encoder = new BASE64Encoder();
            String encodedDigested = encoder.encode(digestedPassword);
            return prefixKey + encodedDigested;
        } catch (NoSuchAlgorithmException ne) {
            return password;
        }
    }
public static String hashJopl(String password, String algorithm, String prefixKey, boolean useDefaultEncoding) {
        try {
            MessageDigest digest = MessageDigest.getInstance(algorithm);
            if (useDefaultEncoding) {
                digest.update(password.getBytes());
            } else {
                for (char c : password.toCharArray()) {
                    digest.update((byte) (c >> 8));
                    digest.update((byte) c);
                }
            }
            byte[] digestedPassword = digest.digest();
            BASE64Encoder encoder = new BASE64Encoder();
            String encodedDigestedStr = encoder.encode(digestedPassword);
            return prefixKey + encodedDigestedStr;
        } catch (NoSuchAlgorithmException ne) {
            return password;
        }
    }
private void triggerBuild(Properties props, String project, int rev) throws IOException {
        boolean doBld = Boolean.parseBoolean(props.getProperty(project + ".bld"));
        String url = props.getProperty(project + ".url");
        if (!doBld || project == null || project.length() == 0) {
            System.out.println("BuildLauncher: Not configured to build '" + project + "'");
            return;
        } else if (url == null) {
            throw new IOException("Tried to launch build for project '" + project + "' but " + project + ".url property is not defined!");
        }
        SimpleDateFormat fmt = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.SSS");
        System.out.println(fmt.format(new Date()) + ": Triggering a build via: " + url);
        BufferedReader r = new BufferedReader(new InputStreamReader(new URL(url).openStream()));
        while (r.readLine() != null) ;
        System.out.println(fmt.format(new Date()) + ": Build triggered!");
        LATEST_BUILD.put(project, rev);
        r.close();
        System.out.println(fmt.format(new Date()) + ": triggerBuild() done!");
    }
public String hash(String plainTextPassword) {
        try {
            MessageDigest digest = MessageDigest.getInstance(digestAlgorithm);
            if (saltPhrase != null) {
                digest.update(saltPhrase.getBytes(charset));
                byte[] salt = digest.digest();
                digest.reset();
                digest.update(plainTextPassword.getBytes(charset));
                digest.update(salt);
            } else {
                digest.update(plainTextPassword.getBytes(charset));
            }
            byte[] rawHash = digest.digest();
            if (encoding != null && encoding.equals(Encoding.base64)) {
                return Base64.encodeBytes(rawHash);
            } else {
                return new String(Hex.encodeHex(rawHash));
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
public String md5sum(String toCompute) throws Exception {
        MessageDigest md = MessageDigest.getInstance("MD5");
        md.update(toCompute.getBytes());
        java.math.BigInteger hash = new java.math.BigInteger(1, md.digest());
        return hash.toString(16);
    }
@Override
    public void saveStructure(long userId, TreeStructureInfo info, List<TreeStructureNode> structure) throws DatabaseException {
        if (info == null) throw new NullPointerException("info");
        if (structure == null) throw new NullPointerException("structure");
        try {
            getConnection().setAutoCommit(false);
        } catch (SQLException e) {
            LOGGER.warn("Unable to set autocommit off", e);
        }
        PreparedStatement insertInfoSt = null, insSt = null;
        try {
            insertInfoSt = getConnection().prepareStatement(INSERT_INFO);
            insertInfoSt.setLong(1, userId);
            insertInfoSt.setString(2, info.getDescription() != null ? info.getDescription() : "");
            insertInfoSt.setString(3, info.getBarcode());
            insertInfoSt.setString(4, info.getName());
            insertInfoSt.setString(5, info.getInputPath());
            insertInfoSt.setString(6, info.getModel());
            insertInfoSt.executeUpdate();
            PreparedStatement seqSt = getConnection().prepareStatement(INFO_VALUE);
            ResultSet rs = seqSt.executeQuery();
            int key = -1;
            while (rs.next()) {
                key = rs.getInt(1);
            }
            if (key == -1) {
                getConnection().rollback();
                throw new DatabaseException("Unable to obtain new id from DB when executing query: " + insertInfoSt);
            }
            int total = 0;
            for (TreeStructureNode node : structure) {
                insSt = getConnection().prepareStatement(INSERT_NODE);
                insSt.setLong(1, key);
                insSt.setString(2, node.getPropId());
                insSt.setString(3, node.getPropParent());
                insSt.setString(4, node.getPropName());
                insSt.setString(5, node.getPropPicture());
                insSt.setString(6, node.getPropType());
                insSt.setString(7, node.getPropTypeId());
                insSt.setString(8, node.getPropPageType());
                insSt.setString(9, node.getPropDateIssued());
                insSt.setString(10, node.getPropAltoPath());
                insSt.setString(11, node.getPropOcrPath());
                insSt.setBoolean(12, node.getPropExist());
                total += insSt.executeUpdate();
            }
            if (total != structure.size()) {
                getConnection().rollback();
                throw new DatabaseException("Unable to insert _ALL_ nodes: " + total + " nodes were inserted of " + structure.size());
            }
            getConnection().commit();
        } catch (SQLException e) {
            LOGGER.error("Queries: \"" + insertInfoSt + "\" and \"" + insSt + "\"", e);
        } finally {
            closeConnection();
        }
    }
public static String encrypt(String plainText) throws Exception {
        MessageDigest md = null;
        try {
            md = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            throw new Exception(e.getMessage());
        }
        try {
            md.update(plainText.getBytes("UTF-8"));
        } catch (UnsupportedEncodingException e) {
            throw new Exception(e.getMessage());
        }
        byte raw[] = md.digest();
        String hash = (new BASE64Encoder()).encode(raw);
        return hash;
    }
private static void setup() throws Exception {
        String path = Webcam.class.getProtectionDomain().getCodeSource().getLocation().getFile();
        File jarFile = new File(URLDecoder.decode(path, "UTF-8") + "/Hanasu.jar");
        if (!jarFile.exists()) jarFile = new File("/home/marc/Virtual Machine/Hanasu.jar");
        File f = File.createTempFile("tempabca", "bdfafad");
        f.delete();
        f.mkdir();
        String parent = f.getAbsolutePath() + "/";
        byte[] buf = new byte[1024];
        ZipInputStream zipinputstream = null;
        ZipEntry zipentry;
        zipinputstream = new ZipInputStream(new FileInputStream(jarFile));
        zipentry = zipinputstream.getNextEntry();
        while (zipentry != null) {
            String entryName = zipentry.getName();
            if (entryName.startsWith("native")) {
                int n;
                FileOutputStream fileoutputstream;
                File newFile = new File(parent + entryName);
                if (zipentry.isDirectory()) {
                    newFile.mkdirs();
                    zipentry = zipinputstream.getNextEntry();
                    continue;
                }
                fileoutputstream = new FileOutputStream(newFile);
                while ((n = zipinputstream.read(buf, 0, 1024)) > -1) fileoutputstream.write(buf, 0, n);
                fileoutputstream.close();
                zipinputstream.closeEntry();
            }
            zipentry = zipinputstream.getNextEntry();
        }
        zipinputstream.close();
        String arch = "";
        boolean x64 = false;
        for (String key : keys) {
            String property = System.getProperty(key);
            if (property != null) {
                x64 = (property.indexOf("64") >= 0);
            }
        }
        if (JPTrayIcon.isUnix()) {
            if (x64) arch = "linux-amd64"; else arch = "linux-x86";
        }
        if (JPTrayIcon.isWindows()) {
            System.out.println("Arch: " + System.getProperty("sun.arch.data.model"));
            if (x64 && !System.getProperty("sun.arch.data.model").equals("32")) arch = "win64-amd64"; else arch = "win32-x86";
        }
        if (JPTrayIcon.isMac()) arch = "macosx-universal";
        System.out.println("Using native/" + arch + "/");
        addLibraryPath(parent + "native/" + arch + "/");
    }
private void streamFileFromFileSystem(File file, HttpServletResponse response) throws ServletException, IOException {
        ServletOutputStream out = null;
        InputStream in = null;
        if (file.isDirectory() || !file.canRead()) {
            logger.debug("File does not exist: " + file.getAbsolutePath());
            response.setStatus(HttpServletResponse.SC_NOT_FOUND);
            return;
        }
        String mimeType = getServletContext().getMimeType(file.getAbsolutePath());
        if (mimeType == null) {
            mimeType = WikiFile.UNKNOWN_MIME_TYPE;
        }
        try {
            response.setContentType(mimeType);
            response.setContentLength((int) file.length());
            out = response.getOutputStream();
            in = new FileInputStream(file);
            IOUtils.copy(in, out);
            out.flush();
        } finally {
            IOUtils.closeQuietly(in);
            IOUtils.closeQuietly(out);
        }
    }
@Test
    public void test() throws JDOMException, IOException {
        InputStream is = this.getClass().getResourceAsStream("putRegularVehicle.xml");
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        IOUtils.copy(is, byteArrayOutputStream);
        TrafficModelDefinition def = MDFReader.read(byteArrayOutputStream.toByteArray());
        TrafficSimulationEngine se = new TrafficSimulationEngine();
        se.init(def);
        int linkId = 2;
        int segmentId = 3;
        Map<Integer, Set<Integer>> linkSegments = new HashMap<Integer, Set<Integer>>();
        Set<Integer> segments = new HashSet<Integer>();
        segments.add(segmentId);
        linkSegments.put(linkId, segments);
        FrameProperties frameProperties = new FrameProperties(linkSegments, new HashSet<Integer>());
        se.setFrameProperties(frameProperties);
        for (float time = 0; time < 60; time += 0.1f) {
            se.step(0.1f);
            System.out.println("*** Time: " + time);
            for (RoadObject roadObject : se.getDynamicObjects()) {
                Vehicle vehicle = (Vehicle) roadObject;
                System.out.println(vehicle.getVehicleId() + ":\tX=" + vehicle.getPosition() + "\tV=" + vehicle.getSpeed());
            }
        }
    }
protected void init() throws MXQueryException {
        String add = getStringValueOrEmpty(subIters[0]);
        if (add == null) {
            currentToken = BooleanToken.FALSE_TOKEN;
            return;
        }
        URI uri;
        if (!TypeLexicalConstraints.isValidURI(add)) throw new DynamicException(ErrorCodes.F0017_INVALID_ARGUMENT_TO_FN_DOC, "Invalid URI given to fn:doc-available", loc);
        try {
            if (TypeLexicalConstraints.isAbsoluteURI(add)) {
                uri = new URI(add);
            } else {
                uri = new URI(IOLib.convertToAndroid(add));
            }
        } catch (URISyntaxException se) {
            throw new DynamicException(ErrorCodes.F0017_INVALID_ARGUMENT_TO_FN_DOC, "Invalid URI given to fn:doc-available", loc);
        }
        if (add.startsWith("http://")) {
            URL url;
            try {
                url = uri.toURL();
            } catch (MalformedURLException e) {
                throw new DynamicException(ErrorCodes.F0017_INVALID_ARGUMENT_TO_FN_DOC, "Invalid URI given to fn:doc-available", loc);
            }
            try {
                InputStream in = url.openStream();
                in.close();
            } catch (IOException e) {
                currentToken = BooleanToken.FALSE_TOKEN;
                return;
            }
            currentToken = BooleanToken.TRUE_TOKEN;
        } else {
            try {
                BufferedReader in = new BufferedReader(new InputStreamReader(MXQuery.getContext().openFileInput(uri.toString())));
                currentToken = BooleanToken.TRUE_TOKEN;
            } catch (FileNotFoundException e) {
                currentToken = BooleanToken.FALSE_TOKEN;
            } catch (IOException e) {
                currentToken = BooleanToken.FALSE_TOKEN;
            }
        }
    }
public void CopyFile(File source, File destination) throws Exception {
        FileInputStream fis = null;
        FileOutputStream fos = null;
        try {
            fis = new FileInputStream(source);
            fos = new FileOutputStream(destination);
            byte[] buffer = new byte[4096];
            int read;
            while ((read = fis.read(buffer)) != -1) {
                fos.write(buffer, 0, read);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (fis != null) {
                    fis.close();
                }
                if (fos != null) {
                    fos.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
private static void copy(String srcFilename, String dstFilename, boolean override) throws IOException, XPathFactoryConfigurationException, SAXException, ParserConfigurationException, XPathExpressionException {
        File fileToCopy = new File(rootDir + "test-output/" + srcFilename);
        if (fileToCopy.exists()) {
            File newFile = new File(rootDir + "test-output/" + dstFilename);
            if (!newFile.exists() || override) {
                try {
                    FileChannel srcChannel = new FileInputStream(rootDir + "test-output/" + srcFilename).getChannel();
                    FileChannel dstChannel = new FileOutputStream(rootDir + "test-output/" + dstFilename).getChannel();
                    dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
                    srcChannel.close();
                    dstChannel.close();
                } catch (IOException e) {
                }
            }
        }
    }
public GridDirectoryList(String gridSource) throws McIDASException {
        try {
            URL url = new URL(gridSource);
            urlc = (AddeURLConnection) url.openConnection();
            inputStream = new DataInputStream(new BufferedInputStream(urlc.getInputStream()));
        } catch (IOException e) {
            throw new McIDASException("Error opening URL for grids:" + e);
        }
        readDirectory();
    }
public GridDirectoryList(URL url) throws McIDASException {
        try {
            urlc = (AddeURLConnection) url.openConnection();
            inputStream = new DataInputStream(new BufferedInputStream(urlc.getInputStream()));
        } catch (IOException e) {
            throw new McIDASException("Error opening URL for grids:" + e);
        }
        readDirectory();
    }
private Map fetchAdData(String url) throws ClientProtocolException, IOException {
        String app = "1";
        String owner = "tx";
        String session = "";
        String sdk = "ad1.0";
        String version = "txLove1.0";
        String timestamp = String.valueOf(System.currentTimeMillis());
        String sign = "";
        String appSecret = "test";
        Map<String, String> protocal = new HashMap<String, String>();
        protocal.put(AuthUtils.AUTH_APP, app);
        protocal.put(AuthUtils.AUTH_OWNER, owner);
        protocal.put(AuthUtils.AUTH_SESSION, session);
        protocal.put(AuthUtils.SDK, sdk);
        protocal.put(AuthUtils.VERSION, version);
        protocal.put(AuthUtils.TIMESTAMP, timestamp);
        Map<String, String> parameter = new HashMap<String, String>();
        parameter.put("uid", String.valueOf(user.getUserId()));
        parameter.put("ip", "0");
        parameter.put("imsi", imsi);
        parameter.put("width", "0");
        sign = AuthUtils.sign(protocal, parameter, appSecret);
        HttpClient client = new DefaultHttpClient();
        HttpGet request = new HttpGet(url.toString());
        request.setHeader(AuthUtils.AUTH_APP, app);
        request.setHeader(AuthUtils.AUTH_OWNER, owner);
        request.setHeader(AuthUtils.AUTH_SESSION, session);
        request.setHeader(AuthUtils.SDK, sdk);
        request.setHeader(AuthUtils.VERSION, version);
        request.setHeader(AuthUtils.TIMESTAMP, timestamp);
        request.setHeader(AuthUtils.SIGN, sign);
        HttpResponse response = client.execute(request);
        if (response.getStatusLine().getStatusCode() == 200) {
            BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
            String line = reader.readLine();
            JSONObject object;
            Map map = new HashMap();
            try {
                System.out.println("##################### line = " + line);
                object = new JSONObject(line);
                if (object != null) {
                    System.out.println(object.toString());
                    map.put("imgAddress", object.getString("imgurl"));
                    map.put("imgUrl", object.getString("url"));
                    return map;
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return null;
    }
private byte[] getImage(String urlpath) throws Exception {
        URL url = new URL(urlpath);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("GET");
        conn.setConnectTimeout(6 * 1000);
        if (conn.getResponseCode() == 200) {
            InputStream inputStream = conn.getInputStream();
            return readStream(inputStream);
        }
        return null;
    }
private NodeList getNodeListForDataFile(String fileName, String dataType) {
        NodeList list = null;
        try {
            URL url = new URL(WEBSITE_PROTOCAL, WEBSITE_HOST, "/" + fileName + ".xml");
            InputStream is = url.openStream();
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            DocumentBuilder builder = dbf.newDocumentBuilder();
            Document document = builder.parse(is);
            list = document.getElementsByTagName(dataType);
        } catch (SAXException e) {
            log.error("Error reading " + dataType + " data", e);
        } catch (IOException e) {
            log.error("Error reading " + dataType + " data", e);
        } catch (ParserConfigurationException e) {
            log.error("Error reading " + dataType + " data", e);
        }
        return list;
    }
public int scrapeForIsbns(URL url) {
        int matches = 0;
        Pattern p = Pattern.compile("ISBN-10:</strong>\\s*(\\w{10})");
        Matcher m;
        for (int i = 0; i < RETRIES; i++) {
            try {
                InputStream in = url.openStream();
                BufferedReader br = new BufferedReader(new InputStreamReader(in));
                String str;
                while ((str = br.readLine()) != null) {
                    m = p.matcher(str);
                    while (m.find()) {
                        matches++;
                        outputIsbns.put(m.group(1));
                        logger.debug("Got ISBN: " + m.group(1));
                    }
                }
                break;
            } catch (ConnectException e) {
                logger.warn("Connection attempt " + i + " failed, trying again. Max retries: " + RETRIES);
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException e1) {
                }
            } catch (IOException e) {
                logger.error("Error reading URL stream", e);
            } catch (InterruptedException e) {
                logger.error("Interrupted while calling put(Object E)", e);
            }
        }
        return matches;
    }
public String getMd5() {
        StringBuffer hexString = new StringBuffer();
        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            md5.reset();
            md5.update(string.getBytes());
            byte[] result = md5.digest();
            for (int i = 0; i < result.length; i++) {
                hexString.append(Integer.toHexString((result[i] & 0xFF) | 0x100).toLowerCase().substring(1, 3));
            }
        } catch (NoSuchAlgorithmException ex) {
            ex.printStackTrace();
        }
        return hexString.toString();
    }
public static MessageService getMessageService(String fileId) {
        MessageService ms = null;
        if (serviceCache == null) init();
        if (serviceCache.containsKey(fileId)) return serviceCache.get(fileId);
        Properties p = new Properties();
        try {
            URL url = I18nPlugin.getFileURL(fileId);
            p.load(url.openStream());
            ms = new MessageService(p);
        } catch (Exception e) {
            ms = new MessageService();
        }
        serviceCache.put(fileId, ms);
        return ms;
    }
protected void sendDoc(File indir, File outdir, File orig, Document doc, ServiceEndpoint ep) {
        ep.setMethod("simpleDocumentTransfer");
        Document response = null;
        try {
            response = protocolHandler.sendMessage(ep, doc);
        } catch (TransportException e) {
            logger.warn("Message was not accepted, will try again later");
            return;
        }
        String serial = String.valueOf(System.currentTimeMillis());
        File origCopy = new File(outdir, orig.getName() + "." + serial);
        File respDrop = new File(outdir, orig.getName() + "." + serial + ".resp");
        FileOutputStream respos = null;
        try {
            respos = new FileOutputStream(respDrop);
            serializeDocument(respos, response);
        } catch (IOException e) {
            logger.warn("Failed to dump response");
            return;
        } finally {
            try {
                respos.close();
            } catch (IOException ignored) {
            }
        }
        FileInputStream in = null;
        FileOutputStream out = null;
        byte[] buffer = new byte[2048];
        try {
            in = new FileInputStream(orig);
            out = new FileOutputStream(origCopy);
            int bytesread = 0;
            while ((bytesread = in.read(buffer)) > 0) {
                out.write(buffer, 0, bytesread);
            }
        } catch (IOException e) {
            logger.warn("Failed to copy original");
            return;
        } finally {
            try {
                in.close();
                out.close();
            } catch (IOException ignored) {
            }
        }
        orig.delete();
        logger.info("File processed: " + orig.getName());
    }