semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public ResourceBundle newBundle(String baseName, Locale locale, String format, ClassLoader loader, boolean reload) throws IllegalAccessException, InstantiationException, IOException {
            if (baseName == null || locale == null || format == null || loader == null) throw new NullPointerException();
            ResourceBundle bundle = null;
            if (format.equals("user")) {
                String bundleName = toBundleName(baseName, locale);
                String resourceName = "file://" + config.getString(HOME) + "/" + bundleName + ".properties";
                InputStream stream = null;
                try {
                    URL url = new URL(resourceName);
                    if (url != null) {
                        URLConnection connection = url.openConnection();
                        if (connection != null) {
                            if (reload) {
                                connection.setUseCaches(false);
                            }
                            stream = connection.getInputStream();
                        }
                    }
                } catch (Throwable t) {
                }
                if (stream != null) {
                    BufferedInputStream bis = new BufferedInputStream(stream);
                    bundle = new UserResourceBundle(UTF8ClassLoader.readUTFStreamToEscapedASCII(bis), super.newBundle(baseName, locale, "java.properties", loader, reload));
                    bis.close();
                } else {
                    return super.newBundle(baseName, locale, "java.properties", loader, reload);
                }
            }
            return bundle;
        }
public void check() {
            statusBar.setStatusText(Labels.getLabel("state.retrievingVersion"));
            Runnable checkVersionCode = new Runnable() {

                public void run() {
                    BufferedReader reader = null;
                    String message = null;
                    int messageStyle = SWT.ICON_WARNING;
                    try {
                        URL url = new URL(Version.LATEST_VERSION_URL);
                        URLConnection conn = url.openConnection();
                        reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
                        String latestVersion = reader.readLine();
                        latestVersion = latestVersion.substring(latestVersion.indexOf(' ') + 1);
                        if (!Version.getVersion().equals(latestVersion)) {
                            message = Labels.getLabel("text.version.old");
                            message = message.replaceFirst("%LATEST", latestVersion);
                            message = message.replaceFirst("%VERSION", Version.getVersion());
                            messageStyle = SWT.ICON_QUESTION | SWT.YES | SWT.NO;
                        } else {
                            message = Labels.getLabel("text.version.latest");
                            messageStyle = SWT.ICON_INFORMATION;
                        }
                    } catch (Exception e) {
                        message = Labels.getLabel("exception.UserErrorException.version.latestFailed");
                        Logger.getLogger(getClass().getName()).log(Level.WARNING, message, e);
                    } finally {
                        try {
                            if (reader != null) reader.close();
                        } catch (IOException e) {
                        }
                        final String messageToShow = message;
                        final int messageStyleToShow = messageStyle;
                        Display.getDefault().asyncExec(new Runnable() {

                            public void run() {
                                statusBar.setStatusText(null);
                                MessageBox messageBox = new MessageBox(statusBar.getShell(), messageStyleToShow);
                                messageBox.setText(Version.getFullName());
                                messageBox.setMessage(messageToShow);
                                if (messageBox.open() == SWT.YES) {
                                    BrowserLauncher.openURL(Version.DOWNLOAD_URL);
                                }
                            }
                        });
                    }
                }
            };
            new Thread(checkVersionCode).start();
        }
public void run() {
                    BufferedReader reader = null;
                    String message = null;
                    int messageStyle = SWT.ICON_WARNING;
                    try {
                        URL url = new URL(Version.LATEST_VERSION_URL);
                        URLConnection conn = url.openConnection();
                        reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
                        String latestVersion = reader.readLine();
                        latestVersion = latestVersion.substring(latestVersion.indexOf(' ') + 1);
                        if (!Version.getVersion().equals(latestVersion)) {
                            message = Labels.getLabel("text.version.old");
                            message = message.replaceFirst("%LATEST", latestVersion);
                            message = message.replaceFirst("%VERSION", Version.getVersion());
                            messageStyle = SWT.ICON_QUESTION | SWT.YES | SWT.NO;
                        } else {
                            message = Labels.getLabel("text.version.latest");
                            messageStyle = SWT.ICON_INFORMATION;
                        }
                    } catch (Exception e) {
                        message = Labels.getLabel("exception.UserErrorException.version.latestFailed");
                        Logger.getLogger(getClass().getName()).log(Level.WARNING, message, e);
                    } finally {
                        try {
                            if (reader != null) reader.close();
                        } catch (IOException e) {
                        }
                        final String messageToShow = message;
                        final int messageStyleToShow = messageStyle;
                        Display.getDefault().asyncExec(new Runnable() {

                            public void run() {
                                statusBar.setStatusText(null);
                                MessageBox messageBox = new MessageBox(statusBar.getShell(), messageStyleToShow);
                                messageBox.setText(Version.getFullName());
                                messageBox.setMessage(messageToShow);
                                if (messageBox.open() == SWT.YES) {
                                    BrowserLauncher.openURL(Version.DOWNLOAD_URL);
                                }
                            }
                        });
                    }
                }
public static String toHash(String pw) throws Exception {
        final MessageDigest md5 = MessageDigest.getInstance("md5");
        md5.update(pw.getBytes("utf-8"));
        final byte[] result = md5.digest();
        return toHexString(result);
    }
public void run() {
        List<String> remoteVersions = new LinkedList<String>();
        for (String s : VERSION_URLS) {
            URL url = null;
            try {
                url = new URL(s);
            } catch (MalformedURLException e) {
                LogService.getGlobal().log("Cannot create update target url: " + e.getMessage(), LogService.ERROR);
            }
            if (url != null) {
                BufferedReader in = null;
                try {
                    in = new BufferedReader(new InputStreamReader(url.openStream()));
                    String remoteVersion = in.readLine();
                    if ((remoteVersion != null) && (remoteVersion.length() > 0) && (Character.isDigit(remoteVersion.charAt(0)))) {
                        remoteVersions.add(remoteVersion);
                    }
                } catch (IOException e) {
                    LogService.getGlobal().log("Not able to check for updates. Maybe no internet connection.", LogService.WARNING);
                } finally {
                    try {
                        if (in != null) in.close();
                    } catch (IOException e) {
                        throw new Error(e);
                    }
                }
            }
        }
        if (remoteVersions.size() > 0) {
            RapidMinerGUI.saveLastUpdateCheckDate();
        }
        Iterator<String> i = remoteVersions.iterator();
        VersionNumber newestVersion = getVersionNumber(Version.getLongVersion());
        while (i.hasNext()) {
            String remoteVersionString = i.next();
            if (remoteVersionString != null) {
                VersionNumber remoteVersion = getVersionNumber(remoteVersionString);
                if (isNewer(remoteVersion, newestVersion)) {
                    newestVersion = remoteVersion;
                }
            }
        }
        if ((newestVersion != null) && (isNewer(newestVersion, getVersionNumber(Version.getLongVersion())))) {
            JOptionPane.showMessageDialog(mainFrame, "New version of the RapidMiner Community Edition is available:" + Tools.getLineSeparator() + Tools.getLineSeparator() + "          RapidMiner " + newestVersion + Tools.getLineSeparator() + Tools.getLineSeparator() + "Please download it from:" + Tools.getLineSeparator() + "          http://www.rapidminer.com", "New RapidMiner version", JOptionPane.INFORMATION_MESSAGE);
        } else if (showFailureDialog) {
            JOptionPane.showMessageDialog(mainFrame, "No newer versions of the RapidMiner Community Edition available!", "RapidMiner CE is up to date", JOptionPane.INFORMATION_MESSAGE);
        }
    }
protected StringBuffer readURL(java.net.URL url) throws IOException {
        StringBuffer result = new StringBuffer(4096);
        InputStreamReader reader = new InputStreamReader(url.openStream());
        for (; ; ) {
            char portion[] = new char[4096];
            int numRead = reader.read(portion, 0, portion.length);
            if (numRead < 0) break;
            result.append(portion, 0, numRead);
        }
        dout("Read " + result.length() + " bytes.");
        return result;
    }
public static File copyToLibDirectory(final File file) throws FileNotFoundException, IOException {
        if (file == null || !file.exists()) {
            throw new FileNotFoundException();
        }
        File directory = new File("lib/");
        File dest = new File(directory, file.getName());
        File parent = dest.getParentFile();
        while (parent != null && !parent.equals(directory)) {
            parent = parent.getParentFile();
        }
        if (parent.equals(directory)) {
            return file;
        }
        FileChannel in = null;
        FileChannel out = null;
        try {
            in = new FileInputStream(file).getChannel();
            out = new FileOutputStream(dest).getChannel();
            in.transferTo(0, in.size(), out);
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                }
            }
            if (out != null) {
                try {
                    out.close();
                } catch (IOException e) {
                }
            }
        }
        return dest;
    }
public void logging() throws Fault {
        final InterceptorWrapper wrap = new InterceptorWrapper(message);
        final LoggingMessage buffer = new LoggingMessage("Inbound Message\n----------------------------");
        String encoding = (String) wrap.getEncoding();
        if (encoding != null) {
            buffer.getEncoding().append(encoding);
        }
        Object headers = wrap.getProtocolHeaders();
        if (headers != null) {
            buffer.getHeader().append(headers);
        }
        InputStream is = (InputStream) wrap.getContent(InputStream.class);
        if (is != null) {
            CachedOutputStream bos = new CachedOutputStream();
            try {
                IOUtils.copy(is, bos);
                bos.flush();
                is.close();
                this.message.setContent(InputStream.class, bos.getInputStream());
                if (bos.getTempFile() != null) {
                    logger.error("\nMessage (saved to tmp file):\n");
                    logger.error("Filename: " + bos.getTempFile().getAbsolutePath() + "\n");
                }
                if (bos.size() > limit) {
                    logger.error("(message truncated to " + limit + " bytes)\n");
                }
                bos.writeCacheTo(buffer.getPayload(), limit);
                bos.close();
            } catch (IOException e) {
                throw new Fault(e);
            }
        }
        logger.debug(buffer.getPayload().toString().replaceAll("\r\n|\n|\r", ""));
    }
public InputStream getResourceAsStream(String name) {
        if (debug >= 2) log("getResourceAsStream(" + name + ")");
        InputStream stream = null;
        stream = findLoadedResource(name);
        if (stream != null) {
            if (debug >= 2) log("  --> Returning stream from cache");
            return (stream);
        }
        if (delegate) {
            if (debug >= 3) log("  Delegating to parent classloader");
            ClassLoader loader = parent;
            if (loader == null) loader = system;
            stream = loader.getResourceAsStream(name);
            if (stream != null) {
                if (debug >= 2) log("  --> Returning stream from parent");
                return (stream);
            }
        }
        if (debug >= 3) log("  Searching local repositories");
        URL url = findResource(name);
        if (url != null) {
            if (debug >= 2) log("  --> Returning stream from local");
            try {
                return (url.openStream());
            } catch (IOException e) {
                log("url.openStream(" + url.toString() + ")", e);
                return (null);
            }
        }
        if (!delegate) {
            if (debug >= 3) log("  Delegating to parent classloader");
            ClassLoader loader = parent;
            if (loader == null) loader = system;
            stream = loader.getResourceAsStream(name);
            if (stream != null) {
                if (debug >= 2) log("  --> Returning stream from parent");
                return (stream);
            }
        }
        if (debug >= 2) log("  --> Resource not found, returning null");
        return (null);
    }
public static boolean insert(final Departamento ObjDepartamento) {
        int result = 0;
        final Connection c = DBConnection.getConnection();
        PreparedStatement pst = null;
        if (c == null) {
            return false;
        }
        try {
            c.setAutoCommit(false);
            final String sql = "insert into departamento " + "(nome, sala, telefone, id_orgao)" + " values (?, ?, ?, ?)";
            pst = c.prepareStatement(sql);
            pst.setString(1, ObjDepartamento.getNome());
            pst.setString(2, ObjDepartamento.getSala());
            pst.setString(3, ObjDepartamento.getTelefone());
            pst.setInt(4, (ObjDepartamento.getOrgao()).getCodigo());
            result = pst.executeUpdate();
            c.commit();
        } catch (final SQLException e) {
            try {
                c.rollback();
            } catch (final SQLException e1) {
                e1.printStackTrace();
            }
            System.out.println("[DepartamentoDAO.insert] Erro ao inserir -> " + e.getMessage());
        } finally {
            DBConnection.closePreparedStatement(pst);
            DBConnection.closeConnection(c);
        }
        if (result > 0) {
            return true;
        } else {
            return false;
        }
    }
public static boolean update(Departamento objDepartamento) {
        int result = 0;
        Connection c = DBConnection.getConnection();
        PreparedStatement pst = null;
        if (c == null) {
            return false;
        }
        try {
            c.setAutoCommit(false);
            String sql = "update departamento set nome = ?, sala = ?, telefone = ?, id_orgao = ? where id_departamento= ?";
            pst = c.prepareStatement(sql);
            pst.setString(1, objDepartamento.getNome());
            pst.setString(2, objDepartamento.getSala());
            pst.setString(3, objDepartamento.getTelefone());
            pst.setLong(4, (objDepartamento.getOrgao()).getCodigo());
            pst.setInt(5, objDepartamento.getCodigo());
            result = pst.executeUpdate();
            c.commit();
        } catch (SQLException e) {
            try {
                c.rollback();
            } catch (SQLException e1) {
                e1.printStackTrace();
            }
            System.out.println("[DepartamentoDAO.update] Erro ao atualizar -> " + e.getMessage());
        } finally {
            DBConnection.closePreparedStatement(pst);
            DBConnection.closeConnection(c);
        }
        if (result > 0) {
            return true;
        } else {
            return false;
        }
    }
private File createWorkingCopy(File _originalRawDataFile) {
            File fOriginalRawDataFile = _originalRawDataFile;
            File fWorkingCopy;
            System.gc();
            try {
                fWorkingCopy = File.createTempFile("MZmine", null);
                FileChannel sourceChannel = new FileInputStream(fOriginalRawDataFile).getChannel();
                FileChannel destinationChannel = new FileOutputStream(fWorkingCopy).getChannel();
                long sourceChannelPos = 0;
                long sourceChannelSize = sourceChannel.size();
                long maxReadSize = 5 * 1024 * 1024;
                long targetChannelPos = 0;
                while (sourceChannelPos < sourceChannelSize) {
                    long transferAmount = maxReadSize;
                    if (transferAmount > (sourceChannelSize - sourceChannelPos)) {
                        transferAmount = sourceChannelSize - sourceChannelPos;
                    }
                    sourceChannel.transferTo(sourceChannelPos, transferAmount, destinationChannel);
                    sourceChannelPos += transferAmount;
                }
                sourceChannel.close();
                destinationChannel.close();
            } catch (Exception ekse) {
                Logger.put("NODE WORKER THREAD: ERROR - Failed to create working copy!");
                Logger.put(ekse.toString());
                return null;
            }
            return fWorkingCopy;
        }
public static String getOriginalWSDL(String wsdlURL) {
        try {
            URL url = new URL(wsdlURL);
            java.net.HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            InputStream input = conn.getInputStream();
            final int BUFFERSIZE = 4096;
            byte[] buffer = new byte[BUFFERSIZE];
            OutputStream output = new ByteArrayOutputStream();
            while (true) {
                int read = input.read(buffer);
                if (read == -1) {
                    break;
                }
                output.write(buffer, 0, read);
            }
            output.close();
            input.close();
            conn.disconnect();
            String s = output.toString();
            return s;
        } catch (Exception e) {
            return null;
        }
    }
private String getMD5(String password) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(password.getBytes());
            byte[] data = md.digest();
            return convertToHex(data);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return null;
    }
private static void updateLeapSeconds() throws IOException, MalformedURLException, NumberFormatException {
        URL url = new URL("http://cdf.gsfc.nasa.gov/html/CDFLeapSeconds.txt");
        InputStream in;
        try {
            in = url.openStream();
        } catch (IOException ex) {
            url = LeapSecondsConverter.class.getResource("CDFLeapSeconds.txt");
            in = url.openStream();
            System.err.println("Using local copy of leap seconds!!!");
        }
        BufferedReader r = new BufferedReader(new InputStreamReader(in));
        String s = "";
        leapSeconds = new ArrayList(50);
        withoutLeapSeconds = new ArrayList(50);
        String lastLine = s;
        while (s != null) {
            s = r.readLine();
            if (s == null) {
                System.err.println("Last leap second read from " + url + " " + lastLine);
                continue;
            }
            if (s.startsWith(";")) {
                continue;
            }
            String[] ss = s.trim().split("\\s+", -2);
            if (ss[0].compareTo("1972") < 0) {
                continue;
            }
            int iyear = Integer.parseInt(ss[0]);
            int imonth = Integer.parseInt(ss[1]);
            int iday = Integer.parseInt(ss[2]);
            int ileap = (int) (Double.parseDouble(ss[3]));
            double us2000 = TimeUtil.createTimeDatum(iyear, imonth, iday, 0, 0, 0, 0).doubleValue(Units.us2000);
            leapSeconds.add(Long.valueOf(((long) us2000) * 1000L - 43200000000000L + (long) (ileap - 32) * 1000000000));
            withoutLeapSeconds.add(us2000);
        }
        leapSeconds.add(Long.MAX_VALUE);
        withoutLeapSeconds.add(Double.MAX_VALUE);
        lastUpdateMillis = System.currentTimeMillis();
    }
static String encodeEmailAsUserId(String email) {
        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            md5.update(email.toLowerCase().getBytes());
            StringBuilder builder = new StringBuilder();
            builder.append("1");
            for (byte b : md5.digest()) {
                builder.append(String.format("%02d", new Object[] { Integer.valueOf(b & 0xFF) }));
            }
            return builder.toString().substring(0, 20);
        } catch (NoSuchAlgorithmException ex) {
        }
        return "";
    }