semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public void deleteUser(String userID) throws XregistryException {
        try {
            userID = Utils.canonicalizeDN(userID);
            Connection connection = context.createConnection();
            connection.setAutoCommit(false);
            try {
                PreparedStatement statement1 = connection.prepareStatement(DELETE_USER_SQL_MAIN);
                statement1.setString(1, userID);
                statement1.executeUpdate();
                PreparedStatement statement2 = connection.prepareStatement(DELETE_USER_SQL_DEPEND);
                statement2.setString(1, userID);
                statement2.executeUpdate();
                connection.commit();
                Collection<Group> groupList = groups.values();
                for (Group group : groupList) {
                    group.removeUser(userID);
                }
                log.info("Delete User " + userID);
            } catch (SQLException e) {
                connection.rollback();
                throw new XregistryException(e);
            } finally {
                context.closeConnection(connection);
            }
        } catch (SQLException e) {
            throw new XregistryException(e);
        }
    }
private void initialize() {
        StringBuffer license = new StringBuffer();
        URL url;
        InputStreamReader in;
        BufferedReader reader;
        String str;
        JTextArea textArea;
        JButton button;
        GridBagConstraints c;
        setTitle("Mibble License");
        setSize(600, 600);
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        getContentPane().setLayout(new GridBagLayout());
        url = getClass().getClassLoader().getResource("LICENSE.txt");
        if (url == null) {
            license.append("Couldn't locate license file (LICENSE.txt).");
        } else {
            try {
                in = new InputStreamReader(url.openStream());
                reader = new BufferedReader(in);
                while ((str = reader.readLine()) != null) {
                    if (!str.equals("")) {
                        license.append(str);
                    }
                    license.append("\n");
                }
                reader.close();
            } catch (IOException e) {
                license.append("Error reading license file ");
                license.append("(LICENSE.txt):\n\n");
                license.append(e.getMessage());
            }
        }
        textArea = new JTextArea(license.toString());
        textArea.setEditable(false);
        c = new GridBagConstraints();
        c.fill = GridBagConstraints.BOTH;
        c.weightx = 1.0d;
        c.weighty = 1.0d;
        c.insets = new Insets(4, 5, 4, 5);
        getContentPane().add(new JScrollPane(textArea), c);
        button = new JButton("Close");
        button.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                dispose();
            }
        });
        c = new GridBagConstraints();
        c.gridy = 1;
        c.anchor = GridBagConstraints.CENTER;
        c.insets = new Insets(10, 10, 10, 10);
        getContentPane().add(button, c);
    }
public void copyFilesIntoProject(HashMap<String, String> files) {
        Set<String> filenames = files.keySet();
        for (String key : filenames) {
            String realPath = files.get(key);
            if (key.equals("fw4ex.xml")) {
                try {
                    FileReader in = new FileReader(new File(realPath));
                    FileWriter out = new FileWriter(new File(project.getLocation() + "/" + bundle.getString("Stem") + STEM_FILE_EXETENSION));
                    int c;
                    while ((c = in.read()) != -1) out.write(c);
                    in.close();
                    out.close();
                } catch (FileNotFoundException e) {
                    Activator.getDefault().showMessage("File " + key + " not found... Error while moving files to the new project.");
                } catch (IOException ie) {
                    Activator.getDefault().showMessage("Error while moving " + key + " to the new project.");
                }
            } else {
                try {
                    FileReader in = new FileReader(new File(realPath));
                    FileWriter out = new FileWriter(new File(project.getLocation() + "/" + key));
                    int c;
                    while ((c = in.read()) != -1) out.write(c);
                    in.close();
                    out.close();
                } catch (FileNotFoundException e) {
                    Activator.getDefault().showMessage("File " + key + " not found... Error while moving files to the new project.");
                } catch (IOException ie) {
                    Activator.getDefault().showMessage("Error while moving " + key + " to the new project.");
                }
            }
        }
    }
private static void copy(File source, File target) throws IOException {
        InputStream is = null;
        OutputStream os = null;
        try {
            is = new BufferedInputStream(new FileInputStream(source));
            os = new BufferedOutputStream(new FileOutputStream(target));
            int b;
            while ((b = is.read()) > -1) os.write(b);
        } finally {
            try {
                if (is != null) is.close();
            } catch (IOException ignore) {
            }
            try {
                if (os != null) os.close();
            } catch (IOException ignore) {
            }
        }
    }
@Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String arg = req.getParameter("file");
        if (arg == null) {
            resp.sendError(404, "Missing 'file' Arg");
            return;
        }
        int mfid = NumberUtils.toInt(arg);
        Object sageFile = MediaFileAPI.GetMediaFileForID(mfid);
        if (sageFile == null) {
            resp.sendError(404, "Sage File not found " + mfid);
            return;
        }
        int seconds = NumberUtils.toInt(req.getParameter("ss"), -1);
        long offset = NumberUtils.toLong(req.getParameter("sb"), -1);
        if (seconds < 0 && offset < 0) {
            resp.sendError(501, "Missing 'ss' or 'sb' args");
            return;
        }
        int width = NumberUtils.toInt(req.getParameter("w"), 320);
        int height = NumberUtils.toInt(req.getParameter("h"), 320);
        File dir = new File(Phoenix.getInstance().getUserCacheDir(), "videothumb/" + mfid);
        if (!dir.exists()) {
            dir.mkdirs();
        }
        String prefix = "";
        if (offset > 0) {
            prefix = "O" + offset;
        } else {
            prefix = "S" + seconds;
        }
        File f = new File(dir, prefix + "_" + width + "_" + height + ".jpg").getCanonicalFile();
        if (!f.exists()) {
            try {
                generateThumbnailNew(sageFile, f, seconds, offset, width, height);
            } catch (Exception e) {
                e.printStackTrace();
                resp.sendError(503, "Failed to generate thumbnail\n " + e.getMessage());
                return;
            }
        }
        if (!f.exists()) {
            resp.sendError(404, "Missing File: " + f);
            return;
        }
        resp.setContentType("image/jpeg");
        resp.setContentLength((int) f.length());
        FileInputStream fis = null;
        try {
            fis = new FileInputStream(f);
            OutputStream os = resp.getOutputStream();
            IOUtils.copyLarge(fis, os);
            os.flush();
            fis.close();
        } catch (Throwable e) {
            log.error("Failed to send file: " + f);
            resp.sendError(500, "Failed to get file " + f);
        } finally {
            IOUtils.closeQuietly(fis);
        }
    }
public static void copy(String inputFile, String outputFile) throws EDITSException {
        try {
            FileReader in = new FileReader(inputFile);
            FileWriter out = new FileWriter(outputFile);
            int c;
            while ((c = in.read()) != -1) out.write(c);
            in.close();
            out.close();
        } catch (Exception e) {
            throw new EDITSException("Could not copy " + inputFile + " into " + outputFile + " because:\n" + e.getMessage());
        }
    }
public static void createModelZip(String filename, String tempdir) throws EDITSException {
        try {
            BufferedInputStream origin = null;
            FileOutputStream dest = new FileOutputStream(filename);
            ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(dest));
            int BUFFER = 2048;
            byte data[] = new byte[BUFFER];
            File f = new File(tempdir);
            for (File fs : f.listFiles()) {
                FileInputStream fi = new FileInputStream(fs.getAbsolutePath());
                origin = new BufferedInputStream(fi, BUFFER);
                ZipEntry entry = new ZipEntry(fs.getName());
                out.putNextEntry(entry);
                int count;
                while ((count = origin.read(data, 0, BUFFER)) != -1) out.write(data, 0, count);
                out.closeEntry();
                origin.close();
            }
            out.close();
        } catch (Exception e) {
            throw new EDITSException("Can not create a model in file " + filename + " from folder " + tempdir);
        }
    }
public static void unzipModel(String filename, String tempdir) throws EDITSException {
        try {
            BufferedOutputStream dest = null;
            FileInputStream fis = new FileInputStream(filename);
            int BUFFER = 2048;
            ZipInputStream zis = new ZipInputStream(new BufferedInputStream(fis));
            ZipEntry entry;
            while ((entry = zis.getNextEntry()) != null) {
                int count;
                byte data[] = new byte[BUFFER];
                FileOutputStream fos = new FileOutputStream(tempdir + entry.getName());
                dest = new BufferedOutputStream(fos, BUFFER);
                while ((count = zis.read(data, 0, BUFFER)) != -1) dest.write(data, 0, count);
                dest.flush();
                dest.close();
            }
            zis.close();
        } catch (Exception e) {
            throw new EDITSException("Can not expand model in \"" + tempdir + "\" because:\n" + e.getMessage());
        }
    }
public HttpURLConnection getURLConnection() throws IOException {
        HttpURLConnection conn = null;
        try {
            conn = (HttpURLConnection) _url.openConnection();
            conn.setUseCaches(false);
            conn.setRequestProperty("User-Agent", "WD-2.0");
            if (_doConditionalGET) {
                ResourceInfo ri = (ResourceInfo) conditionalGetTable().get(_url.toString());
                if (ri != null) {
                    if (ri.lastModified != null) {
                        conn.setRequestProperty("If-Modified-Since", ri.lastModified);
                    }
                    if (ri.etag != null) {
                        conn.setRequestProperty("If-None-Match", ri.etag);
                    }
                }
            }
            if (_username != null && _password != null) {
                String authenticationStr = _username + ":" + _password;
                String encodedAuthStr = Base64.encodeBytes(authenticationStr.getBytes());
                conn.setRequestProperty("Authorization", "Basic " + encodedAuthStr);
            }
            _httpResponseCode = conn.getResponseCode();
            if (_httpResponseCode == HttpURLConnection.HTTP_OK) {
                if (_doConditionalGET) {
                    ResourceInfo ri = new ResourceInfo();
                    ri.lastModified = conn.getHeaderField("Last-Modified");
                    ri.etag = conn.getHeaderField("ETag");
                    Hashtable table = conditionalGetTable();
                    table.put(_url.toString(), ri);
                    storeConditionalGetTable(table);
                }
            } else if (_httpResponseCode == HttpURLConnection.HTTP_NOT_MODIFIED) {
                _shouldGET = false;
            } else {
                Log.getInstance().write("Error getting url: " + _url + "\n" + "Error code: " + _httpResponseCode);
                _error = HTTP_NOT_OK;
                conn.disconnect();
                conn = null;
            }
        } catch (SocketException ex) {
            conn.disconnect();
            conn = null;
            _error = NETWORK_DOWN;
        }
        return conn;
    }
public void initFromXml(final String xmlFileName) throws java.net.MalformedURLException, ConfigurationException, IOException {
        if (xmlInitialized) {
            return;
        }
        templates = null;
        MergeTemplateWriter.setTokenList(getTokenProvider().getKnownTokens());
        java.net.URL url = new FileFinder().getUrl(getTokenProvider().getClass(), xmlFileName);
        InputStreamReader xmlFileReader = new InputStreamReader(url.openStream());
        KnownTemplates temps = MergeTemplateWriter.importFromXML(xmlFileReader);
        xmlFileReader.close();
        KnownTemplates.setDefaultInstance(temps);
        setTemplates(temps);
        setInitialized(true);
    }
public void init(File file) {
        InputStream is = null;
        ByteArrayOutputStream os = null;
        try {
            is = new FileInputStream(file);
            os = new ByteArrayOutputStream();
            IOUtils.copy(is, os);
        } catch (Throwable e) {
            throw new VisualizerEngineException("Unexcpected exception while reading MDF file", e);
        }
        if (simulationEngine != null) simulationEngine.stopSimulation();
        simulationEngine = new TrafficAsynchSimulationEngine();
        simulationEngine.init(MDFReader.read(os.toByteArray()));
        simulationEngineThread = null;
    }
public Vector _getSiteNames() {
        Vector _mySites = new Vector();
        boolean gotSites = false;
        while (!gotSites) {
            try {
                URL dataurl = new URL(getDocumentBase(), siteFile);
                BufferedReader readme = new BufferedReader(new InputStreamReader(new GZIPInputStream(dataurl.openStream())));
                while (true) {
                    String S = readme.readLine();
                    if (S == null) break;
                    StringTokenizer st = new StringTokenizer(S);
                    _mySites.addElement(st.nextToken());
                }
                gotSites = true;
            } catch (IOException e) {
                _mySites.removeAllElements();
                gotSites = false;
            }
        }
        return (_mySites);
    }
public void setPilot(PilotData pilotData) throws UsernameNotValidException {
        try {
            if (pilotData.username.trim().equals("") || pilotData.password.trim().equals("")) throw new UsernameNotValidException(1, "Username or password missing");
            PreparedStatement psta;
            if (pilotData.id == 0) {
                psta = jdbc.prepareStatement("INSERT INTO pilot " + "(name, address1, address2, zip, city, state, country, birthdate, " + "pft_theory, pft, medical, passenger, instructor, loc_language, " + "loc_country, loc_variant, username, password, id) " + "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,pilot_id_seq.nextval)");
            } else {
                psta = jdbc.prepareStatement("UPDATE pilot SET " + "name = ?, address1 = ?, address2 = ?, " + "zip = ?, city = ?, state = ?, country = ?, birthdate = ?, pft_theory = ?," + "pft = ?, medical = ?, passenger = ?, instructor = ?, loc_language = ?, " + "loc_country = ?, loc_variant = ?, username = ?, password = ? " + "WHERE id = ?");
            }
            psta.setString(1, pilotData.name);
            psta.setString(2, pilotData.address1);
            psta.setString(3, pilotData.address2);
            psta.setString(4, pilotData.zip);
            psta.setString(5, pilotData.city);
            psta.setString(6, pilotData.state);
            psta.setString(7, pilotData.country);
            if (pilotData.birthdate != null) psta.setLong(8, pilotData.birthdate.getTime()); else psta.setNull(8, java.sql.Types.INTEGER);
            if (pilotData.pft_theory != null) psta.setLong(9, pilotData.pft_theory.getTime()); else psta.setNull(9, java.sql.Types.INTEGER);
            if (pilotData.pft != null) psta.setLong(10, pilotData.pft.getTime()); else psta.setNull(10, java.sql.Types.INTEGER);
            if (pilotData.medical != null) psta.setLong(11, pilotData.medical.getTime()); else psta.setNull(11, java.sql.Types.INTEGER);
            if (pilotData.passenger) psta.setString(12, "Y"); else psta.setString(12, "N");
            if (pilotData.instructor) psta.setString(13, "Y"); else psta.setString(13, "N");
            psta.setString(14, pilotData.loc_language);
            psta.setString(15, pilotData.loc_country);
            psta.setString(16, pilotData.loc_variant);
            psta.setString(17, pilotData.username);
            psta.setString(18, pilotData.password);
            if (pilotData.id != 0) {
                psta.setInt(19, pilotData.id);
            }
            psta.executeUpdate();
            jdbc.commit();
        } catch (SQLException sql) {
            jdbc.rollback();
            sql.printStackTrace();
            throw new UsernameNotValidException(2, "Username allready exist");
        }
    }
protected void loadResourceLocations() {
        try {
            for (String path : resourceLocations) {
                if (path.startsWith("${") && path.endsWith("}")) {
                    int start = path.indexOf('{') + 1;
                    int end = path.indexOf('}');
                    String key = path.substring(start, end).trim();
                    if (key.equals(ApplicationConstants.RESOURCE_SQL_LOCATION_PROP_NAME)) path = AdminHelper.getRepository().getURI("sql"); else path = AdminHelper.getRepository().getSetupApplicationProperties().get(key);
                    log.debug(key + "=" + path);
                }
                FileObject fo = VFSUtils.resolveFile(path);
                if (fo.exists()) {
                    URL url = fo.getURL();
                    url.openConnection();
                    if (fastDeploy) {
                        if (log.isDebugEnabled()) {
                            log.debug("Fast deploy : " + url);
                            AdminSqlQueryFactory builder = null;
                            for (DirectoryListener listener : scanner.getDirectoryListeners()) {
                                if (listener instanceof AdminSqlQueryFactory) {
                                    builder = (AdminSqlQueryFactory) listener;
                                }
                            }
                            File file = new File(url.getFile());
                            fastDeploy(file, builder);
                        }
                    }
                    scanner.addScanURL(url);
                }
            }
        } catch (Exception e) {
        }
    }
public static String encripta(String senha) throws GCIException {
        LOGGER.debug(INICIANDO_METODO + "encripta(String)");
        try {
            MessageDigest digest = MessageDigest.getInstance("MD5");
            digest.update(senha.getBytes());
            BASE64Encoder encoder = new BASE64Encoder();
            return encoder.encode(digest.digest());
        } catch (NoSuchAlgorithmException e) {
            LOGGER.fatal(e.getMessage(), e);
            throw new GCIException(e);
        } finally {
            LOGGER.debug(FINALIZANDO_METODO + "encripta(String)");
        }
    }
public static String descripta(String senha) throws GCIException {
        LOGGER.debug(INICIANDO_METODO + "descripta(String)");
        try {
            MessageDigest digest = MessageDigest.getInstance("MD5");
            digest.update(senha.getBytes());
            BASE64Encoder encoder = new BASE64Encoder();
            return encoder.encode(digest.digest());
        } catch (NoSuchAlgorithmException e) {
            LOGGER.fatal(e.getMessage(), e);
            throw new GCIException(e);
        } finally {
            LOGGER.debug(FINALIZANDO_METODO + "descripta(String)");
        }
    }
private InputStream classpathStream(String path) {
        InputStream in = null;
        URL url = getClass().getClassLoader().getResource(path);
        if (url != null) {
            try {
                in = url.openStream();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return in;
    }
public void loadExistingAntlibs(ClassLoader classLoader) {
        URL antlibUrl;
        URI antlibUri;
        try {
            Enumeration<URL> resources = classLoader == null ? ClassLoader.getSystemResources(antLibsResource) : classLoader.getResources(antLibsResource);
            while (resources.hasMoreElements()) {
                URL url = resources.nextElement();
                InputStream stream = url.openStream();
                BufferedReader reader = new BufferedReader(new InputStreamReader(stream, "UTF-8"));
                for (String line = reader.readLine(); line != null; line = reader.readLine()) {
                    String pkg = line.trim();
                    URI uri = URI.create("antlib:" + pkg);
                    URI resource2antlib = URI.create(antLibsResource2root + pkg.replace('.', '/') + (pkg.isEmpty() ? "" : "/") + "antlib.xml");
                    antlibUri = NetUtils.resolve(url.toURI(), resource2antlib);
                    try {
                        antlibUrl = antlibUri.toURL();
                    } catch (IllegalArgumentException e) {
                        System.err.println("base uri: " + url);
                        System.err.println("relativepath: " + resource2antlib);
                        System.err.println("target uri: " + antlibUri);
                        throw new RuntimeException(antlibUri.toString(), e);
                    }
                    loadAntLib(antlibUrl, uri);
                }
                reader.close();
                stream.close();
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        } catch (URISyntaxException e) {
            throw new RuntimeException(e);
        }
    }
public HttpResponse fetch(HttpServletRequest request) throws IOException {
        GUI = SwingUI.getApplicatoin();
        DefaultHttpClient httpclient = new DefaultHttpClient();
        CookieSpecFactory csf = new CookieSpecFactory() {

            public CookieSpec newInstance(HttpParams params) {
                return new BrowserCompatSpec() {

                    @Override
                    public void validate(Cookie cookie, CookieOrigin origin) throws MalformedCookieException {
                    }
                };
            }
        };
        if (Helper.useProxy()) {
            HttpHost proxy = new HttpHost(Helper.getProxyServer(), Helper.getProxyPort());
            httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
        }
        httpclient.getCookieSpecs().register("easy", csf);
        httpclient.getParams().setParameter(ClientPNames.COOKIE_POLICY, "easy");
        String currentRemoteGAEHost = Helper.getRemoteServer();
        try {
            HttpUriRequest httpRequest = createRequest(request);
            addHeader(request, httpRequest);
            HttpResponse response = httpclient.execute(httpRequest);
            if (response.getStatusLine().getStatusCode() == HttpStatus.SC_FORBIDDEN) {
                challengeProxy(currentRemoteGAEHost);
            }
            logger.info(Helper.count.incrementAndGet() + " Response received from " + request.getRequestURL().toString() + ", status is " + response.getStatusLine());
            GUI.updateFetchCount();
            return response;
        } catch (ClientProtocolException e) {
            logger.error("Fetch ClientProtocol Error", e);
            throw e;
        } catch (IOException e) {
            logger.error("Fetch IO Error", e);
            throw e;
        }
    }