semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public static String crypt(String strPassword, String strSalt) {
        try {
            StringTokenizer st = new StringTokenizer(strSalt, "$");
            st.nextToken();
            byte[] abyPassword = strPassword.getBytes();
            byte[] abySalt = st.nextToken().getBytes();
            MessageDigest _md = MessageDigest.getInstance("MD5");
            _md.update(abyPassword);
            _md.update(MAGIC.getBytes());
            _md.update(abySalt);
            MessageDigest md2 = MessageDigest.getInstance("MD5");
            md2.update(abyPassword);
            md2.update(abySalt);
            md2.update(abyPassword);
            byte[] abyFinal = md2.digest();
            for (int n = abyPassword.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 = abyPassword.length; i != 0; i >>>= 1) {
                if ((i & 1) == 1) _md.update(abyFinal, j, 1); else _md.update(abyPassword, j, 1);
            }
            StringBuffer sbPasswd = new StringBuffer();
            sbPasswd.append(MAGIC);
            sbPasswd.append(new String(abySalt));
            sbPasswd.append('$');
            abyFinal = _md.digest();
            for (int n = 0; n < 1000; n++) {
                MessageDigest md3 = MessageDigest.getInstance("MD5");
                if ((n & 1) != 0) md3.update(abyPassword); else md3.update(abyFinal);
                if ((n % 3) != 0) md3.update(abySalt);
                if ((n % 7) != 0) md3.update(abyPassword);
                if ((n & 1) != 0) md3.update(abyFinal); else md3.update(abyPassword);
                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();
        } catch (NoSuchAlgorithmException e) {
            return null;
        }
    }
public void writeData(String name, int items, int mznum, int mzscale, long tstart, long tdelta, int[] peaks) {
        PrintWriter file = getWriter(name + ".txt");
        file.println("999 9999");
        file.println("Doe, John");
        file.println("TEST Lab");
        if (mzscale == 1) file.println("PALMS Positive Ion Data"); else if (mzscale == -1) file.println("PALMS Negative Ion Data"); else file.println("PALMS GJIFJIGJ Ion Data");
        file.println("TEST Mission");
        file.println("1 1");
        file.println("1970 01 01 2008 07 09");
        file.println("0");
        file.println("TIME (UT SECONDS)");
        file.println(mznum + 4);
        for (int i = 0; i < mznum + 4; i++) file.println("1.0");
        for (int i = 0; i < mznum + 4; i++) file.println("9.9E29");
        file.println("TOTION total MCP signal (electron units)");
        file.println("HMASS high mass integral (fraction)");
        file.println("UNLIST (unlisted low mass peaks (fraction)");
        file.println("UFO unidentified peaks (fraction)");
        for (int i = 1; i <= mznum; i++) file.println("MS" + i + " (fraction)");
        int header2length = 13;
        file.println(header2length);
        for (int i = 0; i < header2length; i++) file.println("1.0");
        for (int i = 0; i < header2length; i++) file.println("9.9E29");
        file.println("AirCraftTime aircraft time (s)");
        file.println("INDEX index ()");
        file.println("SCAT scatter (V)");
        file.println("JMETER joule meter ()");
        file.println("ND neutral density (fraction)");
        file.println("SCALEA Mass scale intercept (us)");
        file.println("SCALEB mass scale slope (us)");
        file.println("NUMPKS number of peaks ()");
        file.println("CONF confidence (coded)");
        file.println("CAT preliminary category ()");
        file.println("AeroDiam aerodynamic diameter (um)");
        file.println("AeroDiam1p7 aero diam if density=1.7 (um)");
        file.println("TOTBACK total background subtracted (electron units)");
        file.println("0");
        file.println("0");
        String nothing = "0.000000";
        for (int i = 0; i < items; i++) {
            file.println(tstart + (tdelta * i));
            file.println(tstart + (tdelta * i) - 3);
            file.println(i + 1);
            for (int j = 0; j < 15; j++) file.println(Math.random());
            boolean peaked = false;
            for (int k = 1; k <= mznum; k++) {
                for (int j = 0; j < peaks.length && !peaked; j++) if (k == peaks[j]) {
                    double randData = (int) (1000000 * (j + 1));
                    file.println(randData / 1000000);
                    peaked = true;
                }
                if (!peaked) file.println(nothing);
                peaked = false;
            }
        }
        try {
            Scanner test = new Scanner(f);
            while (test.hasNext()) {
                System.out.println(test.nextLine());
            }
            System.out.println("test");
        } catch (Exception e) {
        }
        file.close();
    }
public static InputStream getPropertyFileInputStream(String propertyFileURLStr) {
        InputStream in = null;
        String errmsg = "Fatal error: Unable to open specified properties file: " + propertyFileURLStr;
        try {
            URL url = new URL(propertyFileURLStr);
            in = url.openStream();
        } catch (IOException e) {
            throw new IllegalArgumentException(errmsg);
        }
        return (in);
    }
private void createPropertyName(String objectID, String value, String propertyName, Long userID) throws JspTagException {
        rObject object = new rObject(new Long(objectID), userID);
        ClassProperty classProperty = new ClassProperty(propertyName, object.getClassName());
        String newValue = value;
        if (classProperty.getName().equals("Password")) {
            try {
                MessageDigest crypt = MessageDigest.getInstance("MD5");
                crypt.update(value.getBytes());
                byte digest[] = crypt.digest();
                StringBuffer hexString = new StringBuffer();
                for (int i = 0; i < digest.length; i++) {
                    hexString.append(hexDigit(digest[i]));
                }
                newValue = hexString.toString();
                crypt.reset();
            } catch (NoSuchAlgorithmException e) {
                System.err.println("jspShop: Could not get instance of MD5 algorithm. Please fix this!" + e.getMessage());
                e.printStackTrace();
                throw new JspTagException("Error crypting password!: " + e.getMessage());
            }
        }
        Properties properties = new Properties(new Long(objectID), userID);
        try {
            Property property = properties.create(classProperty.getID(), newValue);
            pageContext.setAttribute(getId(), property);
        } catch (CreateException e) {
            throw new JspTagException("Could not create PropertyValue, CreateException: " + e.getMessage());
        }
    }
private void createProperty(String objectID, String value, String propertyID, Long userID) throws JspTagException {
        ClassProperty classProperty = new ClassProperty(new Long(propertyID));
        String newValue = value;
        if (classProperty.getName().equals("Password")) {
            try {
                MessageDigest crypt = MessageDigest.getInstance("MD5");
                crypt.update(value.getBytes());
                byte digest[] = crypt.digest();
                StringBuffer hexString = new StringBuffer();
                for (int i = 0; i < digest.length; i++) {
                    hexString.append(hexDigit(digest[i]));
                }
                newValue = hexString.toString();
                crypt.reset();
            } catch (NoSuchAlgorithmException e) {
                System.err.println("jspShop: Could not get instance of MD5 algorithm. Please fix this!" + e.getMessage());
                e.printStackTrace();
                throw new JspTagException("Error crypting password!: " + e.getMessage());
            }
        }
        Properties properties = new Properties(new Long(objectID), userID);
        try {
            Property property = properties.create(new Long(propertyID), newValue);
            pageContext.setAttribute(getId(), property);
        } catch (CreateException e) {
            throw new JspTagException("Could not create PropertyValue, CreateException: " + e.getMessage());
        }
    }
public List<Datastream> getFiles(final String pFile) throws IOException {
        List<Datastream> tDatastreams = new ArrayList<Datastream>();
        new File(this.getTmpExtractDirName()).mkdir();
        ZipFile tZipFile = new ZipFile(pFile);
        Enumeration tEntries = tZipFile.entries();
        ZipEntry tEntry = null;
        File tFile = null;
        String tFileLocation = "";
        LocalDatastream tLocalDs = null;
        while (tEntries.hasMoreElements()) {
            tEntry = (ZipEntry) tEntries.nextElement();
            if (tEntry.isDirectory()) {
                continue;
            }
            tFileLocation = this.getTmpExtractDirName() + System.getProperty("file.separator") + tEntry.getName();
            tFile = new File(tFileLocation);
            LOG.debug("Saving " + tEntry.getName() + " to " + tFile.getPath());
            tFile.getParentFile().mkdirs();
            IOUtils.copy(tZipFile.getInputStream(tEntry), new FileOutputStream(tFile));
            tLocalDs = new LocalDatastream(tFile.getName().split("\\.")[0], FindMimeType.getMimeType(tFile.getName().split("\\.")[1]), tFileLocation);
            tLocalDs.setLabel(tEntry.getName());
            tDatastreams.add(tLocalDs);
        }
        return tDatastreams;
    }
public static String SHA1(String text) throws NoSuchAlgorithmException, UnsupportedEncodingException {
        MessageDigest md;
        md = MessageDigest.getInstance("SHA-1");
        byte[] sha1hash = new byte[40];
        md.update(text.getBytes("iso-8859-1"), 0, text.length());
        sha1hash = md.digest();
        return convertToHex(sha1hash);
    }
protected void configure() {
        Enumeration<URL> resources = null;
        try {
            resources = classLoader.getResources(resourceName);
        } catch (IOException e) {
            binder().addError(e.getMessage(), e);
            return;
        }
        int resourceCount = 0;
        while (resources.hasMoreElements()) {
            URL url = resources.nextElement();
            log.debug(url + " ...");
            try {
                InputStream stream = url.openStream();
                Properties props = new Properties();
                props.load(stream);
                resourceCount++;
                addComponentsFromProperties(props, classLoader);
            } catch (IOException e) {
                binder().addError(e.getMessage(), e);
            }
        }
        log.info("Added components from " + resourceCount + " resources.");
    }
public String upload() {
        System.out.println(imgFile);
        String destDir = "E:\\ganymede_workspace\\training01\\web\\user_imgs\\map_bg.jpg";
        FileOutputStream fos;
        try {
            fos = new FileOutputStream(new File(destDir));
            IOUtils.copy(new FileInputStream(imgFile), fos);
            IOUtils.closeQuietly(fos);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "show";
    }
private static void copy(File in, File out) throws IOException {
        if (!out.getParentFile().isDirectory()) out.getParentFile().mkdirs();
        FileChannel ic = new FileInputStream(in).getChannel();
        FileChannel oc = new FileOutputStream(out).getChannel();
        ic.transferTo(0, ic.size(), oc);
        ic.close();
        oc.close();
    }
public static String readFromUrl(String url) {
        URL url_ = null;
        URLConnection uc = null;
        BufferedReader in = null;
        StringBuilder str = new StringBuilder();
        try {
            url_ = new URL(url);
            uc = url_.openConnection();
            in = new BufferedReader(new InputStreamReader(uc.getInputStream()));
            String inputLine;
            while ((inputLine = in.readLine()) != null) str.append(inputLine);
            in.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return str.toString();
    }
private boolean handlePart(Part p) throws MessagingException, GetterException {
        String filename = p.getFileName();
        if (!p.isMimeType("multipart/*")) {
            String disp = p.getDisposition();
            if (disp == null || disp.equalsIgnoreCase(Part.ATTACHMENT)) {
                if (checkCriteria(p)) {
                    if (filename == null) filename = "Attachment" + attnum++;
                    if (result == null) {
                        try {
                            File f = File.createTempFile("amorph_pop3-", ".tmp");
                            f.deleteOnExit();
                            OutputStream os = new BufferedOutputStream(new FileOutputStream(f));
                            InputStream is = p.getInputStream();
                            int c;
                            while ((c = is.read()) != -1) os.write(c);
                            os.close();
                            result = new FileInputStream(f);
                            System.out.println("saved attachment to file: " + f.getAbsolutePath());
                            return true;
                        } catch (IOException ex) {
                            throw new GetterException(ex, "Failed to save attachment: " + ex);
                        }
                    }
                }
            }
        }
        return false;
    }
public final Matrix3D<E> read(final URL url) throws IOException {
        if (url == null) {
            throw new IllegalArgumentException("url must not be null");
        }
        InputStream inputStream = null;
        try {
            inputStream = url.openStream();
            return read(inputStream);
        } catch (IOException e) {
            throw e;
        } finally {
            MatrixIOUtils.closeQuietly(inputStream);
        }
    }
@Override
    public void sendData(String serverUrl, String fileName, String type, InputStream is) throws IOException {
        ClientSession clientSession = null;
        try {
            if (logger.isDebugEnabled()) {
                logger.debug("Connecting to " + serverUrl);
            }
            clientSession = (ClientSession) Connector.open(serverUrl);
            HeaderSet hsConnectReply = clientSession.connect(clientSession.createHeaderSet());
            if (hsConnectReply.getResponseCode() != ResponseCodes.OBEX_HTTP_OK) {
                throw new IOException("Connect Error " + hsConnectReply.getResponseCode());
            }
            HeaderSet hsOperation = clientSession.createHeaderSet();
            hsOperation.setHeader(HeaderSet.NAME, fileName);
            if (type != null) {
                hsOperation.setHeader(HeaderSet.TYPE, type);
            }
            hsOperation.setHeader(HeaderSet.LENGTH, new Long(is.available()));
            Operation po = clientSession.put(hsOperation);
            OutputStream os = po.openOutputStream();
            IOUtils.copy(is, os);
            os.flush();
            os.close();
            if (logger.isDebugEnabled()) {
                logger.debug("put responseCode " + po.getResponseCode());
            }
            po.close();
            HeaderSet hsDisconnect = clientSession.disconnect(null);
            if (logger.isDebugEnabled()) {
                logger.debug("disconnect responseCode " + hsDisconnect.getResponseCode());
            }
            if (hsDisconnect.getResponseCode() != ResponseCodes.OBEX_HTTP_OK) {
                throw new IOException("Send Error " + hsConnectReply.getResponseCode());
            }
        } finally {
            if (clientSession != null) {
                try {
                    clientSession.close();
                } catch (IOException ignore) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("IOException during clientSession.close()", ignore);
                    }
                }
            }
            clientSession = null;
        }
    }
public static String md5(String input) throws NoSuchAlgorithmException, UnsupportedEncodingException {
        StringBuffer result = new StringBuffer();
        MessageDigest md = MessageDigest.getInstance("MD5");
        md.update(input.getBytes("utf-8"));
        byte[] digest = md.digest();
        for (byte b : digest) {
            result.append(String.format("%02X ", b & 0xff));
        }
        return result.toString();
    }
protected Object getMethodKey(String methodName, Object[] args) {
        StringBuffer key = new StringBuffer(methodName.trim().replace(" ", ".")).append(".");
        for (Object o : args) {
            if (o != null) key.append(o.hashCode());
        }
        LOGGER.info("Generation key ->" + key.toString());
        try {
            MessageDigest messageDigest = MessageDigest.getInstance("SHA-512");
            messageDigest.reset();
            messageDigest.update(key.toString().getBytes(Charset.forName("UTF8")));
            final byte[] resultByte = messageDigest.digest();
            String hex = null;
            for (int i = 0; i < resultByte.length; i++) {
                hex = Integer.toHexString(0xFF & resultByte[i]);
                if (hex.length() < 2) {
                    key.append("0");
                }
                key.append(hex);
            }
        } catch (NoSuchAlgorithmException e) {
            LOGGER.severe("No hash generated for method key! " + StackTraceUtil.getStackTrace(e));
        }
        LOGGER.info("Generation key ->" + key.toString());
        return new String(key);
    }
private void extractByParsingHtml(String refererURL, String requestURL) throws MalformedURLException, IOException {
        URL url = new URL(refererURL);
        InputStream is = url.openStream();
        mRefererURL = refererURL;
        if (requestURL.startsWith("http://www.")) {
            mRequestURLWWW = requestURL;
            mRequestURL = "http://" + mRequestURLWWW.substring(11);
        } else {
            mRequestURL = requestURL;
            mRequestURLWWW = "http://www." + mRequestURL.substring(7);
        }
        Parser parser = (new HTMLEditorKit() {

            public Parser getParser() {
                return super.getParser();
            }
        }).getParser();
        InputStreamReader isr = new InputStreamReader(is);
        BufferedReader br = new BufferedReader(isr);
        String line = null;
        StringBuffer sb = new StringBuffer();
        while ((line = br.readLine()) != null) {
            sb.append(line);
        }
        StringReader sr = new StringReader(sb.toString());
        parser.parse(sr, new LinkbackCallback(), true);
        if (mStart != 0 && mEnd != 0 && mEnd > mStart) {
            mExcerpt = sb.toString().substring(mStart, mEnd);
            mExcerpt = Utilities.removeHTML(mExcerpt);
            if (mExcerpt.length() > mMaxExcerpt) {
                mExcerpt = mExcerpt.substring(0, mMaxExcerpt) + "...";
            }
        }
        if (mTitle.startsWith(">") && mTitle.length() > 1) {
            mTitle = mTitle.substring(1);
        }
    }
public String insertBuilding() {
        homeMap = homeMapDao.getHomeMapById(homeMap.getId());
        homeBuilding.setHomeMap(homeMap);
        Integer id = homeBuildingDao.saveHomeBuilding(homeBuilding);
        String dir = "E:\\ganymede_workspace\\training01\\web\\user_buildings\\";
        FileOutputStream fos;
        try {
            fos = new FileOutputStream(dir + id);
            IOUtils.copy(new FileInputStream(imageFile), fos);
            IOUtils.closeQuietly(fos);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return execute();
    }
public static void copyFile(File from, File to) throws Exception {
        if (!from.exists()) return;
        FileInputStream in = new FileInputStream(from);
        FileOutputStream out = new FileOutputStream(to);
        byte[] buffer = new byte[8192];
        int bytes_read;
        while (true) {
            bytes_read = in.read(buffer);
            if (bytes_read == -1) break;
            out.write(buffer, 0, bytes_read);
        }
        out.flush();
        out.close();
        in.close();
    }
public static void copyFile(File in, File out) throws EnhancedException {
        try {
            FileChannel sourceChannel = new FileInputStream(in).getChannel();
            FileChannel destinationChannel = new FileOutputStream(out).getChannel();
            sourceChannel.transferTo(0, sourceChannel.size(), destinationChannel);
            sourceChannel.close();
            destinationChannel.close();
        } catch (Exception e) {
            throw new EnhancedException("Could not copy file " + in.getAbsolutePath() + " to " + out.getAbsolutePath() + ".", e);
        }
    }
public static String loadURLToString(String url, String EOL) throws FileNotFoundException, IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader((new URL(url)).openStream()));
        String result = "";
        String str;
        while ((str = in.readLine()) != null) {
            result += str + EOL;
        }
        in.close();
        return result;
    }
public static String generate(String presentity, String eventPackage) {
        if (presentity == null || eventPackage == null) {
            return null;
        }
        String date = Long.toString(System.currentTimeMillis());
        try {
            MessageDigest md = MessageDigest.getInstance(HASH_ALGORITHM);
            md.update(presentity.getBytes());
            md.update(eventPackage.getBytes());
            md.update(date.getBytes());
            byte[] digest = md.digest();
            return toHexString(digest);
        } catch (NoSuchAlgorithmException e) {
            return null;
        }
    }
public static String getWebContent(String remoteUrl) {
        StringBuffer sb = new StringBuffer();
        try {
            java.net.URL url = new java.net.URL(remoteUrl);
            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
            String line;
            while ((line = in.readLine()) != null) {
                sb.append(line);
            }
            in.close();
        } catch (Exception e) {
            logger.error("获取远程网址内容失败 - " + remoteUrl, e);
        }
        return sb.toString();
    }