semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
private void loadOverrideProperties(String uri) {
        try {
            File f = new File(uri);
            Properties temp = new Properties();
            if (f.exists()) {
                info("Found config override file " + f.getAbsolutePath());
                try {
                    InputStream readStream = new BufferedInputStream(new FileInputStream(f));
                    try {
                        temp.load(readStream);
                    } finally {
                        readStream.close();
                    }
                } catch (IOException iex) {
                    warning("Error while loading override properties file; skipping.", iex);
                    return;
                }
            } else {
                InputStream in = null;
                try {
                    URL url = new URL(uri);
                    in = new BufferedInputStream(url.openStream());
                    info("Found config override URI " + uri);
                    temp.load(in);
                } catch (MalformedURLException e) {
                    warning("URI for override properties is malformed, skipping: " + uri);
                    return;
                } catch (IOException e) {
                    warning("Overridden properties could not be loaded from URI: " + uri, e);
                    return;
                } finally {
                    if (in != null) try {
                        in.close();
                    } catch (IOException e) {
                    }
                }
            }
            Enumeration elem = this.properties.keys();
            List lp = Collections.list(elem);
            Collections.sort(lp);
            Iterator iter = lp.iterator();
            int cnt = 0;
            while (iter.hasNext()) {
                String key = (String) iter.next();
                String val = temp.getProperty(key);
                if (val != null) {
                    this.properties.setProperty(key, val);
                    finer("  " + key + " -> " + val);
                    cnt++;
                }
            }
            finer("Configuration: " + cnt + " properties overridden from secondary properties file.");
            Enumeration allRead = temp.keys();
            List ap = Collections.list(allRead);
            Collections.sort(ap);
            iter = ap.iterator();
            cnt = 0;
            while (iter.hasNext()) {
                String key = (String) iter.next();
                String val = temp.getProperty(key);
                if (val != null) {
                    this.properties.setProperty(key, val);
                    finer("  (+)" + key + " -> " + val);
                    cnt++;
                }
            }
            finer("Configuration: " + cnt + " properties added from secondary properties file.");
        } catch (SecurityException e) {
            System.err.println(e.getLocalizedMessage());
        }
    }
private void extractSourceFiles(String jar) {
        JarInputStream in = null;
        BufferedOutputStream out = null;
        try {
            in = new JarInputStream(new FileInputStream(getProjectFile(jar)));
            JarEntry item;
            byte buffer[] = new byte[4096];
            int buflength;
            while ((item = in.getNextJarEntry()) != null) if (item.getName().startsWith(PREFIX) && (!item.getName().endsWith("/"))) {
                out = new BufferedOutputStream(new FileOutputStream(new File(dest, getFileName(item))));
                while ((buflength = in.read(buffer)) != -1) out.write(buffer, 0, buflength);
                howmany++;
                out.flush();
                out.close();
                out = null;
            }
        } catch (IOException ex) {
            System.out.println("Unable to parse file " + jar + ", reason: " + ex.getMessage());
        } finally {
            try {
                if (in != null) in.close();
            } catch (IOException ex) {
            }
            try {
                if (out != null) out.close();
            } catch (IOException ex) {
            }
        }
    }
public void actionPerformed(ActionEvent e) {
        if ("register".equals(e.getActionCommand())) {
            buttonClicked = "register";
            try {
                String data = URLEncoder.encode("ver", "UTF-8") + "=" + URLEncoder.encode(Double.toString(questVer), "UTF-8");
                data += "&" + URLEncoder.encode("name", "UTF-8") + "=" + URLEncoder.encode(name.getText(), "UTF-8");
                data += "&" + URLEncoder.encode("os", "UTF-8") + "=" + URLEncoder.encode(os.getText(), "UTF-8");
                data += "&" + URLEncoder.encode("jre", "UTF-8") + "=" + URLEncoder.encode(jre.getText(), "UTF-8");
                data += "&" + URLEncoder.encode("email", "UTF-8") + "=" + URLEncoder.encode(email.getText(), "UTF-8");
                data += "&" + URLEncoder.encode("key", "UTF-8") + "=" + URLEncoder.encode("Qr7SchF", "UTF-8");
                data += "&" + URLEncoder.encode("answers", "UTF-8") + "=" + URLEncoder.encode(Integer.toString(getAnswers()), "UTF-8");
                URL url = new URL("http://ubcdcreator.sourceforge.net/register.php");
                URLConnection conn = url.openConnection();
                conn.setDoInput(true);
                conn.setDoOutput(true);
                OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
                wr.write(data);
                wr.flush();
                BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
                String line;
                while ((line = rd.readLine()) != null) {
                }
                rd.close();
                wr.close();
            } catch (Exception ex) {
            }
            setVisible(false);
        } else if ("cancel".equals(e.getActionCommand())) {
            buttonClicked = "cancel";
            setVisible(false);
        } else if ("never".equals(e.getActionCommand())) {
            buttonClicked = "never";
            setVisible(false);
        }
    }
public synchronized String getEncryptedPassword(String plaintext, String algorithm) throws NoSuchAlgorithmException, UnsupportedEncodingException {
        MessageDigest md = null;
        md = MessageDigest.getInstance(algorithm);
        md.update(plaintext.getBytes("UTF-8"));
        return bytesToHexString(md.digest());
    }
public String calcMD5(String sequence) {
        MessageDigest md5 = null;
        try {
            md5 = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        md5.update(sequence.toString().toUpperCase().getBytes());
        BigInteger md5hash = new BigInteger(1, md5.digest());
        String sequence_md5 = md5hash.toString(16);
        while (sequence_md5.length() < 32) {
            sequence_md5 = "0" + sequence_md5;
        }
        return sequence_md5;
    }
private PrecomputedAnimatedModel loadPrecomputedModel_(URL url) {
        if (precompCache.containsKey(url.toExternalForm())) {
            return (precompCache.get(url.toExternalForm()).copy());
        }
        TextureLoader.getInstance().getTexture("");
        List<SharedGroup> frames = new ArrayList<SharedGroup>();
        Map<String, Animation> animations = new Hashtable<String, Animation>();
        if (url.toExternalForm().endsWith(".amo")) {
            try {
                BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
                String objFileName = reader.readLine();
                objFileName = url.toExternalForm().substring(0, url.toExternalForm().lastIndexOf("/")) + "/" + objFileName;
                frames = loadOBJFrames(objFileName);
                String line;
                while ((line = reader.readLine()) != null) {
                    StringTokenizer tokenizer = new StringTokenizer(line);
                    String animName = tokenizer.nextToken();
                    int from = Integer.valueOf(tokenizer.nextToken());
                    int to = Integer.valueOf(tokenizer.nextToken());
                    tokenizer.nextToken();
                    animations.put(animName, new Animation(animName, from, to));
                }
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        } else {
            frames = loadOBJFrames(url.toExternalForm());
        }
        PrecomputedAnimatedModel precompModel = new PrecomputedAnimatedModel(frames, animations);
        precompCache.put(url.toExternalForm(), precompModel);
        return (precompModel);
    }
@Override
    public OBJModel loadModel(URL url, String skin) throws IOException, IncorrectFormatException, ParsingErrorException {
        boolean baseURLWasNull = setBaseURLFromModelURL(url);
        OBJModel model = loadModel(url.openStream(), skin);
        if (baseURLWasNull) {
            popBaseURL();
        }
        return (model);
    }
public synchronized List<AnidbSearchResult> getAnimeTitles() throws Exception {
        URL url = new URL("http", host, "/api/animetitles.dat.gz");
        ResultCache cache = getCache();
        @SuppressWarnings("unchecked") List<AnidbSearchResult> anime = (List) cache.getSearchResult(null, Locale.ROOT);
        if (anime != null) {
            return anime;
        }
        Pattern pattern = Pattern.compile("^(?!#)(\\d+)[|](\\d)[|]([\\w-]+)[|](.+)$");
        Map<Integer, String> primaryTitleMap = new HashMap<Integer, String>();
        Map<Integer, Map<String, String>> officialTitleMap = new HashMap<Integer, Map<String, String>>();
        Map<Integer, Map<String, String>> synonymsTitleMap = new HashMap<Integer, Map<String, String>>();
        Scanner scanner = new Scanner(new GZIPInputStream(url.openStream()), "UTF-8");
        try {
            while (scanner.hasNextLine()) {
                Matcher matcher = pattern.matcher(scanner.nextLine());
                if (matcher.matches()) {
                    int aid = Integer.parseInt(matcher.group(1));
                    String type = matcher.group(2);
                    String language = matcher.group(3);
                    String title = matcher.group(4);
                    if (type.equals("1")) {
                        primaryTitleMap.put(aid, title);
                    } else if (type.equals("2") || type.equals("4")) {
                        Map<Integer, Map<String, String>> titleMap = (type.equals("4") ? officialTitleMap : synonymsTitleMap);
                        Map<String, String> languageTitleMap = titleMap.get(aid);
                        if (languageTitleMap == null) {
                            languageTitleMap = new HashMap<String, String>();
                            titleMap.put(aid, languageTitleMap);
                        }
                        languageTitleMap.put(language, title);
                    }
                }
            }
        } finally {
            scanner.close();
        }
        anime = new ArrayList<AnidbSearchResult>(primaryTitleMap.size());
        for (Entry<Integer, String> entry : primaryTitleMap.entrySet()) {
            Map<String, String> localizedTitles = new HashMap<String, String>();
            if (synonymsTitleMap.containsKey(entry.getKey())) {
                localizedTitles.putAll(synonymsTitleMap.get(entry.getKey()));
            }
            if (officialTitleMap.containsKey(entry.getKey())) {
                localizedTitles.putAll(officialTitleMap.get(entry.getKey()));
            }
            anime.add(new AnidbSearchResult(entry.getKey(), entry.getValue(), localizedTitles));
        }
        return cache.putSearchResult(null, Locale.ROOT, anime);
    }
public static String getHashText(String plainText, String algorithm) throws NoSuchAlgorithmException {
        MessageDigest mdAlgorithm = MessageDigest.getInstance(algorithm);
        mdAlgorithm.update(plainText.getBytes());
        byte[] digest = mdAlgorithm.digest();
        StringBuffer hexString = new StringBuffer();
        for (int i = 0; i < digest.length; i++) {
            plainText = Integer.toHexString(0xFF & digest[i]);
            if (plainText.length() < 2) {
                plainText = "0" + plainText;
            }
            hexString.append(plainText);
        }
        return hexString.toString();
    }
public static void copy(String fromFileName, String toFileName) throws IOException {
        File fromFile = new File(fromFileName);
        File toFile = new File(toFileName);
        FileInputStream from = null;
        FileOutputStream to = null;
        try {
            from = new FileInputStream(fromFile);
            to = new FileOutputStream(toFile);
            byte[] buffer = new byte[4096];
            int bytesRead;
            while ((bytesRead = from.read(buffer)) != -1) to.write(buffer, 0, bytesRead);
        } finally {
            from.close();
            to.close();
        }
    }
public static void unzipFile(File zipFile, File destFile, boolean removeSrcFile) throws Exception {
        ZipInputStream zipinputstream = new ZipInputStream(new FileInputStream(zipFile));
        ZipEntry zipentry = zipinputstream.getNextEntry();
        int BUFFER_SIZE = 4096;
        while (zipentry != null) {
            String entryName = zipentry.getName();
            log.info("<<<<<< ZipUtility.unzipFile - Extracting: " + zipentry.getName());
            File newFile = null;
            if (destFile.isDirectory()) newFile = new File(destFile, entryName); else newFile = destFile;
            if (zipentry.isDirectory() || entryName.endsWith(File.separator + ".")) {
                newFile.mkdirs();
            } else {
                ByteBuffer buffer = ByteBuffer.allocate(BUFFER_SIZE);
                byte[] bufferArray = buffer.array();
                FileUtilities.createDirectory(newFile.getParentFile());
                FileChannel destinationChannel = new FileOutputStream(newFile).getChannel();
                while (true) {
                    buffer.clear();
                    int lim = zipinputstream.read(bufferArray);
                    if (lim == -1) break;
                    buffer.flip();
                    buffer.limit(lim);
                    destinationChannel.write(buffer);
                }
                destinationChannel.close();
                zipinputstream.closeEntry();
            }
            zipentry = zipinputstream.getNextEntry();
        }
        zipinputstream.close();
        if (removeSrcFile) {
            if (zipFile.exists()) zipFile.delete();
        }
    }
public String md5Encode(String pass) {
        MessageDigest md = null;
        try {
            md = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        md.update(pass.getBytes());
        byte[] result = md.digest();
        return new String(result);
    }
public void load(URL url) throws IOException {
        ResourceLocator locator = null;
        try {
            locator = new RelativeResourceLocator(url);
        } catch (URISyntaxException use) {
            throw new IllegalArgumentException("Bad URL: " + use);
        }
        ResourceLocatorTool.addResourceLocator(ResourceLocatorTool.TYPE_TEXTURE, locator);
        InputStream stream = null;
        try {
            stream = url.openStream();
            if (stream == null) {
                throw new IOException("Failed to load materials file '" + url + "'");
            }
            logger.fine("Loading materials from '" + url + "'...");
            load(stream);
        } finally {
            if (stream != null) stream.close();
            ResourceLocatorTool.removeResourceLocator(ResourceLocatorTool.TYPE_TEXTURE, locator);
            locator = null;
        }
    }
public MetaService() {
        super();
        URL url = this.getClass().getResource(Resource);
        if (null != url) {
            this.location = url;
            String value = null;
            try {
                InputStream in = url.openStream();
                try {
                    value = (new java.io.DataInputStream(in).readLine());
                    if (null != value) {
                        value = value.trim();
                        if (1 > value.length()) value = null;
                    }
                } finally {
                    in.close();
                }
            } catch (IOException exc) {
                exc.printStackTrace();
            }
            this.value = value;
        } else {
            this.location = null;
            this.value = null;
        }
    }
public static void saveNetFile(String destUrl, String fileName) throws IOException {
        FileOutputStream fos = null;
        BufferedInputStream bis = null;
        HttpURLConnection httpUrl = null;
        int BUFFER_SIZE = 2048;
        URL url = null;
        byte[] buf = new byte[BUFFER_SIZE];
        int size = 0;
        url = new URL(destUrl);
        httpUrl = (HttpURLConnection) url.openConnection();
        httpUrl.connect();
        bis = new BufferedInputStream(httpUrl.getInputStream());
        java.io.File dest = new java.io.File(fileName).getParentFile();
        if (!dest.exists()) dest.mkdirs();
        fos = new FileOutputStream(fileName);
        while ((size = bis.read(buf)) != -1) fos.write(buf, 0, size);
        fos.close();
        bis.close();
        httpUrl.disconnect();
    }
public static boolean copy(InputStream is, File file) {
        try {
            FileOutputStream fos = new FileOutputStream(file);
            IOUtils.copy(is, fos);
            is.close();
            fos.close();
            return true;
        } catch (Exception e) {
            System.err.println(e.getMessage());
            return false;
        }
    }
public static void copy(File from, File to, CopyMode mode) throws IOException {
        if (!from.exists()) {
            IllegalArgumentException e = new IllegalArgumentException("Source doesn't exist: " + from.getCanonicalFile());
            log.throwing("Utils", "copy", e);
            throw e;
        }
        if (from.isFile()) {
            if (!to.canWrite()) {
                IllegalArgumentException e = new IllegalArgumentException("Cannot write to target location: " + to.getCanonicalFile());
                log.throwing("Utils", "copy", e);
                throw e;
            }
        }
        if (to.exists()) {
            if ((mode.val & CopyMode.OverwriteFile.val) != CopyMode.OverwriteFile.val) {
                IllegalArgumentException e = new IllegalArgumentException("Target already exists: " + to.getCanonicalFile());
                log.throwing("Utils", "copy", e);
                throw e;
            }
            if (to.isDirectory()) {
                if ((mode.val & CopyMode.OverwriteFolder.val) != CopyMode.OverwriteFolder.val) {
                    IllegalArgumentException e = new IllegalArgumentException("Target is a folder: " + to.getCanonicalFile());
                    log.throwing("Utils", "copy", e);
                    throw e;
                } else to.delete();
            }
        }
        if (from.isFile()) {
            FileChannel in = new FileInputStream(from).getChannel();
            FileLock inLock = in.lock();
            FileChannel out = new FileOutputStream(to).getChannel();
            FileLock outLock = out.lock();
            try {
                in.transferTo(0, (int) in.size(), out);
            } finally {
                inLock.release();
                outLock.release();
                in.close();
                out.close();
            }
        } else {
            to.mkdirs();
            File[] contents = to.listFiles();
            for (File file : contents) {
                File newTo = new File(to.getCanonicalPath() + "/" + file.getName());
                copy(file, newTo, mode);
            }
        }
    }
public void writeToFile(File out) throws IOException, DocumentException {
        FileChannel inChannel = new FileInputStream(pdf_file).getChannel();
        FileChannel outChannel = new FileOutputStream(out).getChannel();
        try {
            inChannel.transferTo(0, inChannel.size(), outChannel);
        } catch (IOException e) {
            throw e;
        } finally {
            if (inChannel != null) inChannel.close();
            if (outChannel != null) outChannel.close();
        }
    }
public static String getServerVersion() throws IOException {
        URL url;
        url = new URL(CHECKVERSIONURL);
        HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
        httpURLConnection.setDoInput(true);
        httpURLConnection.setDoOutput(false);
        httpURLConnection.setUseCaches(false);
        httpURLConnection.setRequestMethod("GET");
        httpURLConnection.connect();
        InputStream in = httpURLConnection.getInputStream();
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        IOUtils.copy(in, out);
        out.flush();
        IOUtils.closeQuietly(in);
        IOUtils.closeQuietly(out);
        String buffer;
        String[] lines;
        String version = "";
        buffer = out.toString();
        lines = StringUtils.split(buffer);
        for (int i = 0; i < lines.length; i++) {
            if (lines[i].startsWith("version=")) {
                version = lines[i].substring(8).trim();
                break;
            }
        }
        return version;
    }
public static String getHash(String password, String salt) {
        try {
            MessageDigest messageDigest = null;
            messageDigest = MessageDigest.getInstance(SHA_512);
            messageDigest.reset();
            messageDigest.update(salt.getBytes("UTF-8"));
            messageDigest.update(password.getBytes("UTF-8"));
            byte[] input = messageDigest.digest();
            for (int i = 0; i < 1000; i++) {
                messageDigest.reset();
                input = messageDigest.digest(input);
            }
            Formatter formatter = new Formatter();
            for (byte i : input) {
                formatter.format("%02x", i);
            }
            return formatter.toString();
        } catch (NoSuchAlgorithmException e) {
            return "";
        } catch (UnsupportedEncodingException e) {
            return "";
        }
    }
public void copy(final File source, final File target) throws FileSystemException {
        LogHelper.logMethod(log, toObjectString(), "copy(), source = " + source + ", target = " + target);
        FileChannel sourceChannel = null;
        FileChannel targetChannel = null;
        try {
            sourceChannel = new FileInputStream(source).getChannel();
            targetChannel = new FileOutputStream(target).getChannel();
            sourceChannel.transferTo(0L, sourceChannel.size(), targetChannel);
            log.info("Copied " + source + " to " + target);
        } catch (FileNotFoundException e) {
            throw new FileSystemException("Unexpected FileNotFoundException while copying a file", e);
        } catch (IOException e) {
            throw new FileSystemException("Unexpected IOException while copying a file", e);
        } finally {
            if (sourceChannel != null) {
                try {
                    sourceChannel.close();
                } catch (IOException e) {
                    log.error("IOException during source channel close after copy", e);
                }
            }
            if (targetChannel != null) {
                try {
                    targetChannel.close();
                } catch (IOException e) {
                    log.error("IOException during target channel close after copy", e);
                }
            }
        }
    }
void downloadImage(String filename, File imageFile) throws Exception {
        String URL = Constants.IMAGE_URL + "/" + filename;
        SiteResponse response = stratSite.getResponse(URL);
        InputStream inputStream = response.getInputStream();
        OutputStream outputStream = new FileOutputStream(imageFile);
        IOUtils.copy(inputStream, outputStream);
    }