semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public static String getRolesString(HttpServletRequest hrequest, HttpServletResponse hresponse, String username, String servicekey) {
        String registerapp = SSOFilter.getRegisterapp();
        String u = SSOUtil.addParameter(registerapp + "/api/getroles", "username", username);
        u = SSOUtil.addParameter(u, "servicekey", servicekey);
        String roles = "";
        try {
            URL url = new URL(u);
            BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
            String line;
            while ((line = reader.readLine()) != null) {
                roles = line.trim();
            }
            reader.close();
        } catch (MalformedURLException e) {
            return null;
        } catch (IOException e) {
            return null;
        }
        if ("error".equals(roles)) {
            return "";
        }
        return roles.trim();
    }
static void conditionalCopyFile(File dst, File src) throws IOException {
        if (dst.equals(src)) return;
        if (!dst.isFile() || dst.lastModified() < src.lastModified()) {
            System.out.println("Copying " + src);
            InputStream is = new FileInputStream(src);
            OutputStream os = new FileOutputStream(dst);
            byte[] buf = new byte[8192];
            int len;
            while ((len = is.read(buf)) > 0) os.write(buf, 0, len);
            os.close();
            is.close();
        }
    }
public Resource createNew(String name, InputStream in, Long length, String contentType) throws IOException {
        File dest = new File(this.getRealFile(), name);
        LOGGER.debug("PUT?? - real file: " + this.getRealFile() + ",name: " + name);
        if (isOwner) {
            if (!".request".equals(name) && !".tokens".equals(name)) {
                FileOutputStream out = null;
                try {
                    out = new FileOutputStream(dest);
                    IOUtils.copy(in, out);
                } finally {
                    IOUtils.closeQuietly(out);
                }
            } else {
                if (ServerConfiguration.isDynamicSEL()) {
                } else {
                }
                FileOutputStream out = null;
                try {
                    out = new FileOutputStream(dest);
                    IOUtils.copy(in, out);
                } finally {
                    IOUtils.closeQuietly(out);
                }
            }
            return factory.resolveFile(this.host, dest);
        } else {
            LOGGER.error("User isn't owner of this folder");
            return null;
        }
    }
public String hash(String plainTextPassword) {
        try {
            MessageDigest digest = MessageDigest.getInstance(digestAlgorithm);
            digest.update(plainTextPassword.getBytes(charset));
            byte[] rawHash = digest.digest();
            return new String(org.jboss.seam.util.Hex.encodeHex(rawHash));
        } catch (NoSuchAlgorithmException e) {
            log.error("Digest algorithm #0 to calculate the password hash will not be supported.", digestAlgorithm);
            throw new RuntimeException(e);
        } catch (UnsupportedEncodingException e) {
            log.error("The Character Encoding #0 is not supported", charset);
            throw new RuntimeException(e);
        }
    }
private String hashString(String key) {
        MessageDigest digest;
        try {
            digest = java.security.MessageDigest.getInstance("MD5");
            digest.update(key.getBytes());
            byte[] hash = digest.digest();
            BigInteger bi = new BigInteger(1, hash);
            return String.format("%0" + (hash.length << 1) + "X", bi) + KERNEL_VERSION;
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            return "" + key.hashCode();
        }
    }
public int addPermissionsForUserAndAgenda(Integer userId, Integer agendaId, String permissions) throws TechnicalException {
        if (permissions == null) {
            throw new TechnicalException(new Exception(new Exception("Column 'permissions' cannot be null")));
        }
        Session session = null;
        Transaction transaction = null;
        try {
            session = HibernateUtil.getCurrentSession();
            transaction = session.beginTransaction();
            String query = "INSERT INTO j_user_agenda (userId, agendaId, permissions) VALUES(" + userId + "," + agendaId + ",\"" + permissions + "\")";
            Statement statement = session.connection().createStatement();
            int rowsUpdated = statement.executeUpdate(query);
            transaction.commit();
            return rowsUpdated;
        } catch (HibernateException ex) {
            if (transaction != null) transaction.rollback();
            throw new TechnicalException(ex);
        } catch (SQLException e) {
            if (transaction != null) transaction.rollback();
            throw new TechnicalException(e);
        }
    }
private String readAboutText(String urlStr) {
        String text = null;
        try {
            URL url = this.getClass().getResource(urlStr);
            InputStreamReader reader = new InputStreamReader(url.openStream());
            StringWriter writer = new StringWriter();
            int character = reader.read();
            while (character != -1) {
                writer.write(character);
                character = reader.read();
            }
            text = writer.toString();
        } catch (IOException e) {
            e.printStackTrace();
            text = "<html><body><b>Author:</b><br>" + aAuthor + "<br>";
            text += "<a href=\"mailto:jhuwaldt@mac.com\">jhuwaldt@mac.com</a><br>";
            text += "<P ALIGN=CENTER><BR>" + aName + " comes with ABSOLUTELY NO WARRANTY;";
            text += "<BR>This is free software, and you are welcome to redistribute ";
            text += "it and it's source code under certain conditions.";
            text += "<BR>Source code is available at:";
            text += "<BR><a href=\"http://virtualhiker.sf.net/\">";
            text += "http://virtualhiker.sf.net/</a></P>";
            text += "</body></html>";
        }
        return text;
    }
public static boolean copyFile(final File inFile, final File outFile) {
        try {
            FileChannel ic = new FileInputStream(inFile).getChannel();
            FileChannel oc = new FileOutputStream(outFile).getChannel();
            ic.transferTo(0, ic.size(), oc);
            ic.close();
            oc.close();
            return true;
        } catch (IOException e) {
            SystemUtils.LOG.log(Level.INFO, "SystemUtils.copyFile() Exception while copy file " + inFile.getAbsolutePath() + " to " + outFile.getAbsolutePath(), e);
            return false;
        }
    }
public StringBuilder get(String q) {
        StringBuilder builder = new StringBuilder();
        try {
            URL url = new URL(q);
            URLConnection urlc = url.openConnection();
            BufferedInputStream buffer = new BufferedInputStream(urlc.getInputStream());
            int byteRead;
            while ((byteRead = buffer.read()) != -1) builder.append((char) byteRead);
            buffer.close();
        } catch (MalformedURLException ex) {
            JOptionPane.showMessageDialog(null, "Error " + ex.toString());
        } catch (IOException ex) {
            JOptionPane.showMessageDialog(null, "Error " + ex.toString());
        }
        return builder;
    }
public void elimina(Cliente cli) throws errorSQL, errorConexionBD {
        System.out.println("GestorCliente.elimina()");
        int id = cli.getId();
        String sql;
        Statement stmt = null;
        try {
            gd.begin();
            sql = "DELETE FROM cliente WHERE cod_cliente = '" + id + "'";
            System.out.println("Ejecutando: " + sql);
            stmt = gd.getConexion().createStatement();
            stmt.executeUpdate(sql);
            System.out.println("executeUpdate");
            gd.commit();
            System.out.println("commit");
            stmt.close();
        } catch (SQLException e) {
            gd.rollback();
            throw new errorSQL(e.toString());
        } catch (errorConexionBD e) {
            System.err.println("Error en GestorCliente.elimina(): " + e);
        } catch (errorSQL e) {
            System.err.println("Error en GestorCliente.elimina(): " + e);
        }
    }
private void buildBundle() {
        if (targetProject == null) {
            MessageDialog.openError(getShell(), "Error", "No target SPAB project selected!");
            return;
        }
        if (projectProcessDirSelector.getText().trim().length() == 0) {
            MessageDialog.openError(getShell(), "Error", "No process directory selected for project " + targetProject.getName() + "!");
            return;
        }
        deleteBundleFile();
        try {
            File projectDir = targetProject.getLocation().toFile();
            File projectProcessesDir = new File(projectDir, projectProcessDirSelector.getText());
            boolean bpmoCopied = IOUtils.copyProcessFilesSecure(getBPMOFile(), projectProcessesDir);
            boolean sbpelCopied = IOUtils.copyProcessFilesSecure(getSBPELFile(), projectProcessesDir);
            boolean xmlCopied = IOUtils.copyProcessFilesSecure(getBPEL4SWSFile(), projectProcessesDir);
            bundleFile = IOUtils.archiveBundle(projectDir, Activator.getDefault().getStateLocation().toFile());
            if (bpmoCopied) {
                new File(projectProcessesDir, getBPMOFile().getName()).delete();
            }
            if (sbpelCopied) {
                new File(projectProcessesDir, getSBPELFile().getName()).delete();
            }
            if (xmlCopied) {
                new File(projectProcessesDir, getBPEL4SWSFile().getName()).delete();
            }
        } catch (Throwable anyError) {
            LogManager.logError(anyError);
            MessageDialog.openError(getShell(), "Error", "Error building SPAB :\n" + anyError.getMessage());
            updateBundleUI();
            return;
        }
        bpmoFile = getBPMOFile();
        sbpelFile = getSBPELFile();
        xmlFile = getBPEL4SWSFile();
        updateBundleUI();
        getWizard().getContainer().updateButtons();
    }
public URLConnection getResourceConnection(String name) throws ResourceException {
        if (context == null) throw new ResourceException("There is no ServletContext to get the requested resource");
        URL url = null;
        try {
            url = context.getResource("/WEB-INF/scriptags/" + name);
            return url.openConnection();
        } catch (Exception e) {
            throw new ResourceException(String.format("Resource '%s' could not be found (url: %s)", name, url), e);
        }
    }
public void loadProperties() throws IOException {
        File file = new File(filename);
        URL url = file.toURI().toURL();
        Properties temp = new Properties();
        temp.load(url.openStream());
        Point2d start = new Point2d();
        Point2d end = new Point2d();
        if (temp.getProperty("StartX") != null) try {
            start.x = Double.valueOf(temp.getProperty("StartX"));
        } catch (Exception e) {
            System.out.println("Error loading StartX - leaving as default: " + e);
        }
        if (temp.getProperty("StartY") != null) try {
            start.y = Double.valueOf(temp.getProperty("StartY"));
        } catch (Exception e) {
            System.out.println("Error loading StartY - leaving as default: " + e);
        }
        if (temp.getProperty("EndX") != null) try {
            end.x = Double.valueOf(temp.getProperty("EndX"));
        } catch (Exception e) {
            System.out.println("Error loading EndX - leaving as default: " + e);
        }
        if (temp.getProperty("EndY") != null) try {
            end.y = Double.valueOf(temp.getProperty("EndY"));
        } catch (Exception e) {
            System.out.println("Error loading EndY - leaving as default: " + e);
        }
        initialline = new LineSegment2D(start, end);
        if (temp.getProperty("ReferenceImage") != null) try {
            referenceimage = Integer.valueOf(temp.getProperty("ReferenceImage"));
        } catch (Exception e) {
            System.out.println("Error loading ReferenceImage - leaving as default: " + e);
        }
    }
public void run(IAction action) {
        int style = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().getStyle();
        Shell shell = new Shell((style & SWT.MIRRORED) != 0 ? SWT.RIGHT_TO_LEFT : SWT.NONE);
        GraphicalViewer viewer = new ScrollingGraphicalViewer();
        viewer.createControl(shell);
        viewer.setEditDomain(new DefaultEditDomain(null));
        viewer.setRootEditPart(new ScalableFreeformRootEditPart());
        viewer.setEditPartFactory(new GraphicalPartFactory());
        viewer.setContents(getContents());
        viewer.flush();
        int printMode = new PrintModeDialog(shell).open();
        if (printMode == -1) return;
        PrintDialog dialog = new PrintDialog(shell, SWT.NULL);
        PrinterData data = dialog.open();
        if (data != null) {
            PrintGraphicalViewerOperation op = new PrintGraphicalViewerOperation(new Printer(data), viewer);
            op.setPrintMode(printMode);
            op.run(selectedFile.getName());
        }
    }
private ArrayList<Stock> fetchStockData(Stock[] stocks) throws IOException {
        Log.d(TAG, "Fetching stock data from Yahoo");
        ArrayList<Stock> newStocks = new ArrayList<Stock>(stocks.length);
        if (stocks.length > 0) {
            StringBuilder sb = new StringBuilder();
            for (Stock stock : stocks) {
                sb.append(stock.getSymbol());
                sb.append('+');
            }
            sb.deleteCharAt(sb.length() - 1);
            String urlStr = "http://finance.yahoo.com/d/quotes.csv?f=sb2n&s=" + sb.toString();
            HttpClient client = new DefaultHttpClient();
            HttpGet request = new HttpGet(urlStr.toString());
            HttpResponse response = client.execute(request);
            BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
            String line = reader.readLine();
            int i = 0;
            Log.d(TAG, "Parsing stock data from Yahoo");
            while (line != null) {
                Log.d(TAG, "Parsing: " + line);
                String[] values = line.split(",");
                Stock stock = new Stock(stocks[i], stocks[i].getId());
                stock.setCurrentPrice(Double.parseDouble(values[1]));
                stock.setName(values[2]);
                Log.d(TAG, "Parsed Stock: " + stock);
                newStocks.add(stock);
                line = reader.readLine();
                i++;
            }
        }
        return newStocks;
    }
public static void copyFile(File sourceFile, File targetFile) throws IOException {
        if (sourceFile == null || targetFile == null) {
            throw new NullPointerException("Source file and target file must not be null");
        }
        File directory = targetFile.getParentFile();
        if (!directory.exists() && !directory.mkdirs()) {
            throw new IOException("Could not create directory '" + directory + "'");
        }
        InputStream inputStream = null;
        OutputStream outputStream = null;
        try {
            inputStream = new BufferedInputStream(new FileInputStream(sourceFile));
            outputStream = new BufferedOutputStream(new FileOutputStream(targetFile));
            try {
                byte[] buffer = new byte[32768];
                for (int readBytes = inputStream.read(buffer); readBytes > 0; readBytes = inputStream.read(buffer)) {
                    outputStream.write(buffer, 0, readBytes);
                }
            } catch (IOException ex) {
                targetFile.delete();
                throw ex;
            }
        } finally {
            if (inputStream != null) {
                try {
                    inputStream.close();
                } catch (IOException ex) {
                }
            }
            if (outputStream != null) {
                try {
                    outputStream.close();
                } catch (IOException ex) {
                }
            }
        }
    }
public static StringBuffer readURLText(URL url, StringBuffer errorText) {
        StringBuffer page = new StringBuffer("");
        String thisLine;
        try {
            BufferedReader source = new BufferedReader(new InputStreamReader(url.openStream()));
            while ((thisLine = source.readLine()) != null) {
                page.append(thisLine + "\n");
            }
            return page;
        } catch (Exception e) {
            return errorText;
        }
    }
public VeecheckResult performRequest(VeecheckVersion version, String uri) throws ClientProtocolException, IOException, IllegalStateException, SAXException {
        HttpClient client = new DefaultHttpClient();
        HttpParams params = client.getParams();
        HttpConnectionParams.setConnectionTimeout(params, CONNECTION_TIMEOUT);
        HttpConnectionParams.setSoTimeout(params, SO_TIMEOUT);
        HttpGet request = new HttpGet(version.substitute(uri));
        HttpResponse response = client.execute(request);
        HttpEntity entity = response.getEntity();
        try {
            StatusLine line = response.getStatusLine();
            if (line.getStatusCode() != 200) throw new IOException("Request failed: " + line.getReasonPhrase());
            Header header = response.getFirstHeader(HTTP.CONTENT_TYPE);
            Encoding encoding = identityEncoding(header);
            VeecheckResult handler = new VeecheckResult(version);
            Xml.parse(entity.getContent(), encoding, handler);
            return handler;
        } finally {
            entity.consumeContent();
        }
    }
public static void downloadFileFromHTTP(String address) {
        OutputStream out = null;
        URLConnection conn = null;
        InputStream in = null;
        int lastSlashIndex = address.lastIndexOf('/');
        if (!(lastSlashIndex >= 0 && lastSlashIndex < address.length() - 1)) {
            System.err.println("Could not figure out local file name for " + address);
        } else {
            try {
                String localFileName;
                if (!ZeroFileSettings.getDownloadFolder().equals("")) localFileName = ZeroFileSettings.getDownloadFolder() + "/" + address.substring(lastSlashIndex + 1).replace("%20", " "); else localFileName = System.getProperty("user.home") + "/" + address.substring(lastSlashIndex + 1).replace("%20", " ");
                URL url = new URL(address);
                out = new BufferedOutputStream(new FileOutputStream(localFileName));
                conn = url.openConnection();
                in = conn.getInputStream();
                byte[] buffer = new byte[1024];
                int numRead;
                long numWritten = 0;
                while ((numRead = in.read(buffer)) != -1) {
                    out.write(buffer, 0, numRead);
                    numWritten += numRead;
                }
            } catch (Exception exception) {
                exception.printStackTrace();
            } finally {
                try {
                    if (in != null) {
                        in.close();
                    }
                    if (out != null) {
                        out.close();
                    }
                } catch (IOException ioe) {
                    System.out.println(ioe);
                }
            }
        }
    }
public String encrypt(String password) {
        String encrypted_pass = "";
        ByteArrayOutputStream output = null;
        MessageDigest md = null;
        try {
            md = MessageDigest.getInstance("SHA");
            md.update(password.getBytes("UTF-8"));
            byte byte_array[] = md.digest();
            output = new ByteArrayOutputStream(byte_array.length);
            output.write(byte_array);
            encrypted_pass = output.toString("UTF-8");
            System.out.println("password: " + encrypted_pass);
        } catch (Exception e) {
            System.out.println("Exception thrown: " + e.getMessage());
        }
        return encrypted_pass;
    }
public void updateDBModel(Tasks task) throws Exception {
        task.setOperationName("Updating DB Model..");
        int localVersion = getLocalModelVersion();
        int currentVersion = 0;
        try {
            currentVersion = getModelVersion();
        } catch (SQLException e) {
            if (e.getErrorCode() != 1146) {
                throw e;
            }
        }
        boolean autoCommit = getConn().getAutoCommit();
        try {
            getConn().setAutoCommit(false);
            for (int version = currentVersion + 1; version <= localVersion; version++) {
                task.setStatus("Updating to version " + version);
                InputStream in = EDACCApp.class.getClassLoader().getResourceAsStream("edacc/resources/db_version/" + version + ".sql");
                if (in == null) {
                    throw new SQLQueryFileNotFoundException();
                }
                executeSqlScript(task, in);
                Statement st = getConn().createStatement();
                st.executeUpdate("INSERT INTO `Version` VALUES (" + version + ", NOW())");
                st.close();
            }
        } catch (Exception e) {
            getConn().rollback();
            throw e;
        } finally {
            getConn().setAutoCommit(autoCommit);
        }
    }
public static void decoupe(String input_file_path) {
        final int BUFFER_SIZE = 2000000;
        try {
            FileInputStream fr = new FileInputStream(input_file_path);
            byte[] cbuf = new byte[BUFFER_SIZE];
            int n_read = 0;
            int i = 0;
            boolean bContinue = true;
            while (bContinue) {
                n_read = fr.read(cbuf, 0, BUFFER_SIZE);
                if (n_read == -1) break;
                FileOutputStream fo = new FileOutputStream("f_" + ++i);
                fo.write(cbuf, 0, n_read);
                fo.close();
            }
            fr.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
private static String getSummaryText(File packageFile) {
        String retVal = null;
        Reader in = null;
        try {
            in = new FileReader(packageFile);
            StringWriter out = new StringWriter();
            IOUtils.copy(in, out);
            StringBuffer buf = out.getBuffer();
            int pos1 = buf.indexOf("<body>");
            int pos2 = buf.lastIndexOf("</body>");
            if (pos1 >= 0 && pos1 < pos2) {
                retVal = buf.substring(pos1 + 6, pos2);
            } else {
                retVal = "";
            }
        } catch (FileNotFoundException e) {
            LOG.error(e.getMessage(), e);
        } catch (IOException e) {
            LOG.error(e.getMessage(), e);
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    LOG.error(e.getMessage(), e);
                }
            }
        }
        return retVal;
    }