semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public final synchronized boolean isValidLicenseFile() throws LicenseNotSetupException {
        if (!isSetup()) {
            throw new LicenseNotSetupException();
        }
        boolean returnValue = false;
        Properties properties = getLicenseFile();
        logger.debug("isValidLicenseFile: License to validate:");
        logger.debug(properties);
        StringBuffer validationStringBuffer = new StringBuffer();
        validationStringBuffer.append(LICENSE_KEY_KEY + ":" + properties.getProperty(LICENSE_KEY_KEY) + ",");
        validationStringBuffer.append(LICENSE_FILE_STATUS_KEY + ":" + properties.getProperty(LICENSE_FILE_STATUS_KEY) + ",");
        validationStringBuffer.append(LICENSE_FILE_USERS_KEY + ":" + properties.getProperty(LICENSE_FILE_USERS_KEY) + ",");
        validationStringBuffer.append(LICENSE_FILE_MAC_KEY + ":" + properties.getProperty(LICENSE_FILE_MAC_KEY) + ",");
        validationStringBuffer.append(LICENSE_FILE_HOST_NAME_KEY + ":" + properties.getProperty(LICENSE_FILE_HOST_NAME_KEY) + ",");
        validationStringBuffer.append(LICENSE_FILE_OFFSET_KEY + ":" + properties.getProperty(LICENSE_FILE_OFFSET_KEY) + ",");
        validationStringBuffer.append(LICENSE_FILE_EXP_DATE_KEY + ":" + properties.getProperty(LICENSE_FILE_EXP_DATE_KEY) + ",");
        validationStringBuffer.append(LICENSE_EXPIRES_KEY + ":" + properties.getProperty(LICENSE_EXPIRES_KEY));
        logger.debug("isValidLicenseFile: Validation String Buffer: " + validationStringBuffer.toString());
        String validationKey = (String) properties.getProperty(LICENSE_FILE_SHA_KEY);
        try {
            MessageDigest messageDigest = MessageDigest.getInstance("SHA-1");
            messageDigest.update(validationStringBuffer.toString().getBytes());
            String newValidation = Base64.encode(messageDigest.digest());
            if (newValidation.equals(validationKey)) {
                if (getMACAddress().equals(Settings.getInstance().getMACAddress())) {
                    returnValue = true;
                }
            }
        } catch (Exception exception) {
            System.out.println("Exception in LicenseInstanceVO.isValidLicenseFile");
        }
        return returnValue;
    }
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String senha = "";
        String email = request.getParameter("EmailLogin");
        try {
            MessageDigest messageDigest = MessageDigest.getInstance("MD5");
            messageDigest.update(request.getParameter("SenhaLogin").getBytes(), 0, request.getParameter("SenhaLogin").length());
            senha = new BigInteger(1, messageDigest.digest()).toString(16);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        Usuario usuario = UsuarioBll.getUsuarioByEmailAndSenha(email, senha);
        String redirect = request.getHeader("REFERER").replace("?msg=3", "").replace("&msg=3", "") + "?&msg=3";
        if (request.getHeader("REFERER").indexOf("?") != -1) {
            redirect = request.getHeader("REFERER").replace("?msg=3", "").replace("&msg=3", "") + "&msg=3";
        }
        if (usuario.getNome() != null) {
            HttpSession session = request.getSession();
            session.setAttribute("usuario", usuario);
            redirect = "index.jsp";
        }
        response.sendRedirect(redirect);
    }
public static void loadPlugins() {
        Logger.trace("Loading plugins");
        Enumeration<URL> urls = null;
        try {
            urls = Play.classloader.getResources("play.plugins");
        } catch (Exception e) {
        }
        while (urls != null && urls.hasMoreElements()) {
            URL url = urls.nextElement();
            Logger.trace("Found one plugins descriptor, %s", url);
            try {
                BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream(), "utf-8"));
                String line = null;
                while ((line = reader.readLine()) != null) {
                    String[] infos = line.split(":");
                    PlayPlugin plugin = (PlayPlugin) Play.classloader.loadClass(infos[1].trim()).newInstance();
                    Logger.trace("Loaded plugin %s", plugin);
                    plugin.index = Integer.parseInt(infos[0]);
                    plugins.add(plugin);
                }
            } catch (Exception ex) {
                Logger.error(ex, "Cannot load %s", url);
            }
        }
        Collections.sort(plugins);
        for (PlayPlugin plugin : new ArrayList<PlayPlugin>(plugins)) {
            plugin.onLoad();
        }
    }
public static void initStaticStuff() {
        Enumeration<URL> urls = null;
        try {
            urls = Play.class.getClassLoader().getResources("play.static");
        } catch (Exception e) {
        }
        while (urls != null && urls.hasMoreElements()) {
            URL url = urls.nextElement();
            try {
                BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream(), "utf-8"));
                String line = null;
                while ((line = reader.readLine()) != null) {
                    try {
                        Class.forName(line);
                    } catch (Exception e) {
                        System.out.println("! Cannot init static : " + line);
                    }
                }
            } catch (Exception ex) {
                Logger.error(ex, "Cannot load %s", url);
            }
        }
    }
private static <T> Collection<T> loadFromServices(Class<T> interf) throws Exception {
        ClassLoader classLoader = DSServiceLoader.class.getClassLoader();
        Enumeration<URL> e = classLoader.getResources("META-INF/services/" + interf.getName());
        Collection<T> services = new ArrayList<T>();
        while (e.hasMoreElements()) {
            URL url = e.nextElement();
            InputStream is = url.openStream();
            try {
                BufferedReader r = new BufferedReader(new InputStreamReader(is, "UTF-8"));
                while (true) {
                    String line = r.readLine();
                    if (line == null) {
                        break;
                    }
                    int comment = line.indexOf('#');
                    if (comment >= 0) {
                        line = line.substring(0, comment);
                    }
                    String name = line.trim();
                    if (name.length() == 0) {
                        continue;
                    }
                    Class<?> clz = Class.forName(name, true, classLoader);
                    Class<? extends T> impl = clz.asSubclass(interf);
                    Constructor<? extends T> ctor = impl.getConstructor();
                    T svc = ctor.newInstance();
                    services.add(svc);
                }
            } finally {
                is.close();
            }
        }
        return services;
    }
static void linkBlocks(File from, File to, int oldLV) throws IOException {
        if (!from.isDirectory()) {
            if (from.getName().startsWith(COPY_FILE_PREFIX)) {
                IOUtils.copyBytes(new FileInputStream(from), new FileOutputStream(to), 16 * 1024, true);
            } else {
                if (oldLV >= PRE_GENERATIONSTAMP_LAYOUT_VERSION) {
                    to = new File(convertMetatadataFileName(to.getAbsolutePath()));
                }
                HardLink.createHardLink(from, to);
            }
            return;
        }
        if (!to.mkdir()) throw new IOException("Cannot create directory " + to);
        String[] blockNames = from.list(new java.io.FilenameFilter() {

            public boolean accept(File dir, String name) {
                return name.startsWith(BLOCK_SUBDIR_PREFIX) || name.startsWith(BLOCK_FILE_PREFIX) || name.startsWith(COPY_FILE_PREFIX);
            }
        });
        for (int i = 0; i < blockNames.length; i++) linkBlocks(new File(from, blockNames[i]), new File(to, blockNames[i]), oldLV);
    }
private void copy(FileInfo inputFile, FileInfo outputFile) {
        try {
            FileReader in = new FileReader(inputFile.file);
            FileWriter out = new FileWriter(outputFile.file);
            int c;
            while ((c = in.read()) != -1) out.write(c);
            in.close();
            out.close();
            outputFile.file.setLastModified(inputFile.lastModified);
        } catch (IOException e) {
        }
    }
private boolean authenticate(String reply) {
        String user = reply.substring(0, reply.indexOf(" "));
        String resp = reply.substring(reply.indexOf(" ") + 1);
        if (!module.users.contains(user)) {
            error = "so such user " + user;
            return false;
        }
        try {
            LineNumberReader secrets = new LineNumberReader(new FileReader(module.secretsFile));
            String line;
            while ((line = secrets.readLine()) != null) {
                if (line.startsWith(user + ":")) {
                    MessageDigest md4 = MessageDigest.getInstance("BrokenMD4");
                    md4.update(new byte[4]);
                    md4.update(line.substring(line.indexOf(":") + 1).getBytes("US-ASCII"));
                    md4.update(challenge.getBytes("US-ASCII"));
                    String hash = Util.base64(md4.digest());
                    if (hash.equals(resp)) {
                        secrets.close();
                        return true;
                    }
                }
            }
            secrets.close();
        } catch (Exception e) {
            logger.fatal(e.toString());
            error = "server configuration error";
            return false;
        }
        error = "authentication failure for module " + module.name;
        return false;
    }
public void copy(File source, File dest) throws IOException {
        System.out.println("copy " + source + " -> " + dest);
        FileInputStream in = new FileInputStream(source);
        try {
            FileOutputStream out = new FileOutputStream(dest);
            try {
                byte[] buf = new byte[1024];
                int len = 0;
                while ((len = in.read(buf)) > 0) out.write(buf, 0, len);
            } finally {
                out.close();
            }
        } finally {
            in.close();
        }
    }
public static void copyFile(File src, File dest) throws IOException {
        log.debug("Copying file: '" + src + "' to '" + dest + "'");
        FileChannel srcChannel = new FileInputStream(src).getChannel();
        FileChannel dstChannel = new FileOutputStream(dest).getChannel();
        dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
        srcChannel.close();
        dstChannel.close();
    }
private static void addFolderToZip(File folder, ZipOutputStream zip, String baseName) throws IOException {
        File[] files = folder.listFiles();
        for (File file : files) {
            if (file.isDirectory()) {
                String name = file.getAbsolutePath().substring(baseName.length());
                ZipEntry zipEntry = new ZipEntry(name + "/");
                zip.putNextEntry(zipEntry);
                zip.closeEntry();
                addFolderToZip(file, zip, baseName);
            } else {
                String name = file.getAbsolutePath().substring(baseName.length());
                ZipEntry zipEntry = new ZipEntry(updateFilename(name));
                zip.putNextEntry(zipEntry);
                IOUtils.copy(new FileInputStream(file), zip);
                zip.closeEntry();
            }
        }
    }
private String copyImageFile(String urlString, String filePath) {
        FileOutputStream destination = null;
        File destination_file = null;
        String inLine;
        String dest_name = "";
        byte[] buffer;
        int bytes_read;
        int last_offset = 0;
        int offset = 0;
        InputStream imageFile = null;
        try {
            URL url = new URL(urlString);
            imageFile = url.openStream();
            dest_name = url.getFile();
            offset = 0;
            last_offset = 0;
            offset = dest_name.indexOf('/', offset + 1);
            while (offset > -1) {
                last_offset = offset + 1;
                offset = dest_name.indexOf('/', offset + 1);
            }
            dest_name = filePath + File.separator + dest_name.substring(last_offset);
            destination_file = new File(dest_name);
            if (destination_file.exists()) {
                if (destination_file.isFile()) {
                    if (!destination_file.canWrite()) {
                        System.out.println("FileCopy: destination " + "file is unwriteable: " + dest_name);
                    }
                    System.out.println("File " + dest_name + " already exists. File will be overwritten.");
                } else {
                    System.out.println("FileCopy: destination " + "is not a file: " + dest_name);
                }
            } else {
                File parentdir = parent(destination_file);
                if (!parentdir.exists()) {
                    System.out.println("FileCopy: destination " + "directory doesn't exist: " + dest_name);
                }
                if (!parentdir.canWrite()) {
                    System.out.println("FileCopy: destination " + "directory is unwriteable: " + dest_name);
                }
            }
            destination = new FileOutputStream(dest_name);
            buffer = new byte[1024];
            while (true) {
                bytes_read = imageFile.read(buffer);
                if (bytes_read == -1) break;
                destination.write(buffer, 0, bytes_read);
            }
        } catch (MalformedURLException ex) {
            System.out.println("Bad URL " + urlString);
        } catch (IOException ex) {
            System.out.println(" IO error: " + ex.getMessage());
        } finally {
            if (imageFile != null) {
                try {
                    imageFile.close();
                } catch (IOException e) {
                }
            }
            if (destination != null) {
                try {
                    destination.close();
                } catch (IOException e) {
                }
            }
        }
        return (dest_name);
    }
public static boolean copy(File src, File dest) {
        boolean result = true;
        String files[] = null;
        if (src.isDirectory()) {
            files = src.list();
            result = dest.mkdir();
        } else {
            files = new String[1];
            files[0] = "";
        }
        if (files == null) {
            files = new String[0];
        }
        for (int i = 0; (i < files.length) && result; i++) {
            File fileSrc = new File(src, files[i]);
            File fileDest = new File(dest, files[i]);
            if (fileSrc.isDirectory()) {
                result = copy(fileSrc, fileDest);
            } else {
                FileChannel ic = null;
                FileChannel oc = null;
                try {
                    ic = (new FileInputStream(fileSrc)).getChannel();
                    oc = (new FileOutputStream(fileDest)).getChannel();
                    ic.transferTo(0, ic.size(), oc);
                } catch (IOException e) {
                    log.error(sm.getString("expandWar.copy", fileSrc, fileDest), e);
                    result = false;
                } finally {
                    if (ic != null) {
                        try {
                            ic.close();
                        } catch (IOException e) {
                        }
                    }
                    if (oc != null) {
                        try {
                            oc.close();
                        } catch (IOException e) {
                        }
                    }
                }
            }
        }
        return result;
    }
public TextureData newTextureData(GLProfile glp, URL url, int internalFormat, int pixelFormat, boolean mipmap, String fileSuffix) throws IOException {
            InputStream stream = new BufferedInputStream(url.openStream());
            try {
                return newTextureData(glp, stream, internalFormat, pixelFormat, mipmap, fileSuffix);
            } finally {
                stream.close();
            }
        }
private void loadTrustAnchors(final String keystoreLocation) {
        LOG.debug("keystore location: " + keystoreLocation);
        try {
            if (keystoreLocation == null) {
                throw new NullPointerException("No TrustAnchor KeyStore name is set");
            }
            InputStream keyStoreStream = null;
            if (new File(keystoreLocation).exists()) {
                keyStoreStream = new FileInputStream(keystoreLocation);
            } else if (new File("../trust1.keystore").exists()) {
                keyStoreStream = new FileInputStream(new File("../trust1.keystore"));
            } else if (new File("trust1.keystore").exists()) {
                keyStoreStream = new FileInputStream(new File("../trust1.keystore"));
            } else {
                URL url = Thread.currentThread().getContextClassLoader().getResource("trust1.keystore");
                if (url != null) keyStoreStream = new BufferedInputStream(url.openStream());
            }
            KeyStore ks = KeyStore.getInstance(trustStoreType);
            ks.load(keyStoreStream, trustStorePassword.toCharArray());
            Enumeration<String> aliases = ks.aliases();
            while (aliases.hasMoreElements()) {
                String alias = aliases.nextElement();
                LOG.debug("inspecting alias " + alias);
                if (ks.entryInstanceOf(alias, KeyStore.TrustedCertificateEntry.class)) {
                    LOG.debug("Adding TrustAnchor: " + ((X509Certificate) ks.getCertificate(alias)).getSubjectX500Principal().getName());
                    TrustAnchor ta = new TrustAnchor((X509Certificate) (ks.getCertificate(alias)), null);
                    this.trustAnchors.add(ta);
                }
            }
        } catch (Exception ex) {
            LOG.error("Error loading TrustAnchors", ex);
            this.trustAnchors = null;
        }
    }
public String hash(String senha) {
        String result = "";
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(senha.getBytes());
            byte[] hashMd5 = md.digest();
            for (int i = 0; i < hashMd5.length; i++) result += Integer.toHexString((((hashMd5[i] >> 4) & 0xf) << 4) | (hashMd5[i] & 0xf));
        } catch (NoSuchAlgorithmException ex) {
            Logger.getInstancia().log(TipoLog.ERRO, ex);
        }
        return result;
    }
public static boolean doExecuteSQL(String sql) {
        session = currentSession();
        Connection conn = session.connection();
        PreparedStatement ps = null;
        try {
            conn.setAutoCommit(false);
            log("[SmsManager] sql:" + sql);
            ps = conn.prepareStatement(sql);
            ps.executeUpdate();
            conn.commit();
            conn.setAutoCommit(true);
            return true;
        } catch (SQLException e) {
            e.printStackTrace();
            try {
                conn.rollback();
            } catch (SQLException e1) {
                e1.printStackTrace();
            }
            return false;
        } finally {
            if (conn != null) try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            if (ps != null) {
                try {
                    ps.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
            closeHibernateSession();
        }
    }
public static boolean doExecuteBatchSQL(List<String> sql) {
        session = currentSession();
        Connection conn = session.connection();
        PreparedStatement ps = null;
        try {
            conn.setAutoCommit(false);
            Iterator iter = sql.iterator();
            while (iter.hasNext()) {
                String sqlstr = (String) iter.next();
                log("[SmsManager] doing sql:" + sqlstr);
                ps = conn.prepareStatement(sqlstr);
                ps.executeUpdate();
            }
            conn.commit();
            conn.setAutoCommit(true);
            return true;
        } catch (SQLException e) {
            e.printStackTrace();
            try {
                conn.rollback();
            } catch (SQLException e1) {
                e1.printStackTrace();
            }
            return false;
        } finally {
            if (conn != null) try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            if (ps != null) {
                try {
                    ps.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
            closeHibernateSession();
        }
    }
public void init() {
        System.out.println("Init applet...");
        int port = Integer.parseInt(getParameter("port"));
        int useUDP = Integer.parseInt(getParameter("udp"));
        boolean bUseUDP = false;
        if (useUDP > 0) bUseUDP = true;
        m_strWorld = getParameter("world");
        m_strHost = this.getCodeBase().getHost();
        try {
            new EnvironmentMap(getParameter("vrwmap"));
        } catch (Throwable t) {
            System.out.println(t.getMessage());
        }
        URL urlExperiment = null;
        InputStream expStream = null;
        try {
            String strPathExperiment = getParameter("experiment");
            if (strPathExperiment.length() > 0) {
                urlExperiment = new URL(getCodeBase(), strPathExperiment);
                expStream = urlExperiment.openStream();
            }
        } catch (java.net.MalformedURLException e) {
            System.out.println("Couldn't open url experiment: badly specified URL " + e.getMessage());
        } catch (Throwable t) {
            System.out.println("Couldn't open url experiment: " + t.getMessage());
        }
        try {
            System.out.println("Creating client, logging to " + m_strWorld);
            m_VRWClient = new VRWClient(m_strHost, port, true, bUseUDP);
            m_VRWClient.setInApplet(true);
            m_VRWClient.login(m_strWorld);
        } catch (java.io.IOException e) {
            System.out.println("IOException creating the VRWClient");
        }
        try {
            jsobj = JSObject.getWindow(this);
        } catch (Throwable t) {
            System.out.println("Exception getting Java Script Interface: " + t.getMessage());
        }
        refApplet = this;
        m_frmVRWConsole = new VRWConsoleFrame();
        m_frmVRWConsole.setTitle("VRW Client Console");
        m_frmVRWConsole.pack();
        m_frmVRWConsole.setSize(Math.max(300, m_frmVRWConsole.getSize().width), Math.max(200, m_frmVRWConsole.getSize().height));
        if (expStream != null) {
            System.out.println("Passing experiment stream to VRWConsoleFrame");
            m_frmVRWConsole.loadExperiment(expStream);
        }
        m_frmVRWConsole.setVisible(true);
    }