semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public void concatFiles() throws IOException {
        Writer writer = null;
        try {
            final File targetFile = new File(getTargetDirectory(), getTargetFile());
            targetFile.getParentFile().mkdirs();
            if (null != getEncoding()) {
                getLog().info("Writing aggregated file with encoding '" + getEncoding() + "'");
                writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(targetFile), getEncoding()));
            } else {
                getLog().info("WARNING: writing aggregated file with system encoding");
                writer = new FileWriter(targetFile);
            }
            for (File file : getFiles()) {
                Reader reader = null;
                try {
                    if (null != getEncoding()) {
                        getLog().info("Reading file " + file.getCanonicalPath() + " with encoding  '" + getEncoding() + "'");
                        reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), getEncoding()));
                    } else {
                        getLog().info("WARNING: Reading file " + file.getCanonicalPath() + " with system encoding");
                        reader = new FileReader(file);
                    }
                    IOUtils.copy(reader, writer);
                    final String delimiter = getDelimiter();
                    if (delimiter != null) {
                        writer.write(delimiter.toCharArray());
                    }
                } finally {
                    IOUtils.closeQuietly(reader);
                }
            }
        } finally {
            IOUtils.closeQuietly(writer);
        }
    }
public List<T_new> executeGet(HttpTransport transport, String targetUrl) throws HttpResponseException, IOException {
        HttpRequest req = transport.buildGetRequest();
        req.setUrl(targetUrl);
        NotifyFeed feed = req.execute().parseAs(NotifyFeed.class);
        if (feed.entry == null) {
            return Collections.emptyList();
        }
        List<T_new> results = new ArrayList<T_new>();
        for (NotifyEntry e : feed.entry) {
            StringBuilder buffer = new StringBuilder();
            if (e.id != null) {
                buffer.append(e.id);
            }
            buffer.append("@");
            if (e.updated != null) {
                buffer.append(e.updated.toStringRfc3339().substring(0, 19) + "Z");
            }
            Key key = Datastore.createKey(T_new.class, buffer.toString());
            T_new news = new T_new();
            news.setTitle(e.title);
            if (e.content != null) {
                news.setNewText(e.content.substring(0, Math.min(e.content.length(), 500)));
            }
            if (e.status != null && e.content == null) {
                news.setNewText(e.status);
            }
            if (e.updated != null) {
                news.setCreatedAt(new Date(e.updated.value));
            }
            news.setContentUrl(e.getAlternate());
            if (e.author != null) {
                news.setAuthor(e.author.name);
            }
            news.setKey(key);
            results.add(news);
        }
        return results;
    }
public static byte[] encrypt(String passphrase, byte[] data) throws Exception {
        byte[] dataTemp;
        try {
            Security.addProvider(new com.sun.crypto.provider.SunJCE());
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(passphrase.getBytes());
            DESKeySpec key = new DESKeySpec(md.digest());
            SecretKeySpec DESKey = new SecretKeySpec(key.getKey(), "DES");
            Cipher cipher = Cipher.getInstance("DES/ECB/PKCS5Padding");
            cipher.init(Cipher.ENCRYPT_MODE, DESKey);
            dataTemp = cipher.doFinal(data);
        } catch (Exception e) {
            throw e;
        }
        return dataTemp;
    }
public static byte[] decrypt(String passphrase, byte[] data) throws Exception {
        byte[] dataTemp;
        try {
            Security.addProvider(new com.sun.crypto.provider.SunJCE());
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(passphrase.getBytes());
            DESKeySpec key = new DESKeySpec(md.digest());
            SecretKeySpec DESKey = new SecretKeySpec(key.getKey(), "DES");
            Cipher cipher = Cipher.getInstance("DES/ECB/PKCS5Padding");
            cipher.init(Cipher.DECRYPT_MODE, DESKey);
            dataTemp = cipher.doFinal(data);
        } catch (Exception e) {
            throw e;
        }
        return dataTemp;
    }
protected void findPackages(Set<String> packages, ClassLoader classLoader) throws IOException {
        Enumeration<URL> resources = classLoader.getResources(META_INF_SERVICES);
        while (resources.hasMoreElements()) {
            URL url = resources.nextElement();
            String path = url.getPath();
            if (!visitedURIs.contains(path)) {
                visitedURIs.add(path);
                LOG.debug("Loading file {} to retrieve list of packages, from url: {}", META_INF_SERVICES, url);
                BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
                try {
                    while (true) {
                        String line = reader.readLine();
                        if (line == null) {
                            break;
                        }
                        line = line.trim();
                        if (line.startsWith("#") || line.length() == 0) {
                            continue;
                        }
                        tokenize(packages, line);
                    }
                } finally {
                    IOHelper.close(reader, null, LOG);
                }
            }
        }
    }
private void doDecrypt(boolean createOutput) throws IOException {
        FileInputStream input = null;
        FileOutputStream output = null;
        File tempOutput = null;
        try {
            input = new FileInputStream(infile);
            String cipherBaseFilename = basename(infile);
            byte[] magic = new byte[MAGIC.length];
            input.read(magic);
            for (int i = 0; i < MAGIC.length; i++) {
                if (MAGIC[i] != magic[i]) throw new IOException("Not a BORK file (bad magic number)");
            }
            short version = readShort(input);
            if (version / 1000 > VERSION / 1000) throw new IOException("File created by an incompatible future version: " + version + " > " + VERSION);
            String cipherName = readString(input);
            Cipher cipher = createCipher(cipherName, createSessionKey(password, cipherBaseFilename));
            CipherInputStream decryptedInput = new CipherInputStream(input, cipher);
            long headerCrc = Unsigned.promote(readInt(decryptedInput));
            decryptedInput.resetCRC();
            outfile = new File(outputDir, readString(decryptedInput));
            if (!createOutput || outfile.exists()) {
                skipped = true;
                return;
            }
            tempOutput = File.createTempFile("bork", null, outputDir);
            tempOutput.deleteOnExit();
            byte[] buffer = new byte[BUFFER_SIZE];
            output = new FileOutputStream(tempOutput);
            int bytesRead;
            while ((bytesRead = decryptedInput.read(buffer)) != -1) output.write(buffer, 0, bytesRead);
            output.close();
            output = null;
            if (headerCrc != decryptedInput.getCRC()) {
                outfile = null;
                throw new IOException("CRC mismatch: password is probably incorrect");
            }
            if (!tempOutput.renameTo(outfile)) throw new IOException("Failed to rename temp output file " + tempOutput + " to " + outfile);
            outfile.setLastModified(infile.lastModified());
        } finally {
            close(input);
            close(output);
            if (tempOutput != null) tempOutput.delete();
        }
    }
public static void zip(File mzml, File zipDestination) throws Exception {
        File preCompressionTmp = null;
        CompressionHandler comp = null;
        try {
            preCompressionTmp = new File(mzml.getName() + ".tmp");
            preCompressionTmp.createNewFile();
            if (!preCompressionTmp.canWrite()) {
                throw new Exception("Cannot write to temp file: " + preCompressionTmp.getAbsolutePath());
            }
            comp = new CompressionHandler();
            comp.compress(mzml, preCompressionTmp);
            comp.close();
            BufferedOutputStream bos = null;
            try {
                bos = new BufferedOutputStream(new FileOutputStream(zipDestination));
                bos.write(Util.convertIntToBytes(Util.getVersion()));
            } finally {
                try {
                    bos.flush();
                } catch (Exception nope) {
                }
                try {
                    bos.close();
                } catch (Exception nope) {
                }
            }
            GZIPOutputStream gos = null;
            BufferedInputStream bis = null;
            try {
                bis = new BufferedInputStream(new FileInputStream(preCompressionTmp));
                gos = new GZIPOutputStream(new FileOutputStream(zipDestination, true));
                final byte[] buffer = new byte[IO_BUFFER];
                int read = -1;
                while ((read = bis.read(buffer)) != -1) {
                    gos.write(buffer, 0, read);
                }
            } finally {
                try {
                    bis.close();
                } catch (Exception nope) {
                }
                try {
                    gos.flush();
                } catch (Exception nope) {
                }
                try {
                    gos.close();
                } catch (Exception nope) {
                }
            }
        } finally {
            try {
                comp.close();
            } catch (Exception nope) {
            }
            try {
                preCompressionTmp.delete();
            } catch (Exception nope) {
            }
        }
    }
public SSLContext getSSLContext() throws IOException {
        try {
            URL url = getClass().getClassLoader().getResource(keyStoreFile);
            KeyStore keystore = KeyStore.getInstance(type.name());
            keystore.load(url.openStream(), keyPassword);
            KeyManagerFactory kmfactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
            kmfactory.init(keystore, keyPassword);
            KeyManager[] keymanagers = kmfactory.getKeyManagers();
            SSLContext sslcontext = SSLContext.getInstance(protocol.name());
            sslcontext.init(keymanagers, TRUST_MANAGER, null);
            return sslcontext;
        } catch (Exception e) {
            throw new IOException(e);
        }
    }
static void populateResources() throws BasicException {
        try {
            List<URL> templates = DatabaseValidator.listResources("/net/adrianromero/templates/" + Locale.getDefault().getLanguage());
            if (templates.size() == 0) {
                templates = DatabaseValidator.listResources("/net/adrianromero/templates/en");
            }
            for (URL url : templates) {
                String fileName = url.getFile();
                fileName = fileName.substring(fileName.lastIndexOf('/') + 1);
                if (fileName.endsWith(".xml") || fileName.endsWith(".txt")) {
                    Resource templateResource = new Resource(fileName.substring(0, fileName.length() - 4));
                    InputStream is = url.openStream();
                    StringBuffer strBuff = new StringBuffer();
                    BufferedReader br = new BufferedReader(new InputStreamReader(is));
                    String str;
                    while ((str = br.readLine()) != null) {
                        strBuff.append(str + "\n");
                    }
                    templateResource.setText(strBuff.toString());
                    templateResource.save();
                }
            }
        } catch (MalformedURLException e1) {
            logger.error("Unable to load templates", e1);
        } catch (IOException e1) {
            logger.error("Unable to load templates", e1);
        }
        String[][] images = new String[][] { { "default.user", "yast_sysadmin.png" }, { "default.product", "colorize.png" }, { "Window.Logo", "windowlogo.png" }, { "Image.Backarrow", "3backarrow.png" } };
        for (int i = 0; i < images.length; i++) {
            Image img = new Image();
            img.setBufferedImage(ImageUtils.readImage(DatabaseValidator.class.getResource("/net/adrianromero/images/" + images[i][1])));
            img.save();
            Property imgProperty = new Property(images[i][0]);
            imgProperty.setValue("" + img.getId());
            imgProperty.save();
        }
    }
public void serveResource(HTTPResource resource, HttpServletRequest request, HttpServletResponse response) throws java.io.IOException {
        Image image = (Image) resource;
        log.debug("Serving: " + image);
        URL url = image.getResourceURL();
        int idx = url.toString().lastIndexOf(".");
        String fn = image.getId() + url.toString().substring(idx);
        String cd = "filename=\"" + fn + "\"";
        response.setContentType(image.getContentType());
        log.debug("LOADING: " + url);
        IOUtil.copyData(response.getOutputStream(), url.openStream());
    }
private String readRDF() {
        try {
            FileReader fileStream = new FileReader(GeoModel.PATH_STORED_FILES + "rdfVersion.xml");
            BufferedReader readBuf = new BufferedReader(fileStream);
            StringBuilder contents = new StringBuilder();
            String line;
            while ((line = readBuf.readLine()) != null) {
                contents.append(line);
                contents.append(System.getProperty("line.separator"));
            }
            readBuf.close();
            return contents.toString();
        } catch (IOException e) {
            MessageViewer.infoMessage(mainFrame, "You are running a demo version using data files fetched from the web.\nResults cannot be saved.");
            mainFrame.setTitle(mainFrame.getTitle() + ". You are running a demo version using data files fetched from the web. Results cannot be saved.");
            URL urlRdf;
            try {
                urlRdf = new URL(GeoModel.URL_STORED_FILES + "rdfVersion.xml");
                URLConnection urlConnRdf = urlRdf.openConnection();
                BufferedReader urlReader = new BufferedReader(new InputStreamReader(urlConnRdf.getInputStream()));
                StringBuilder contents = new StringBuilder();
                String line;
                while ((line = urlReader.readLine()) != null) {
                    contents.append(line);
                    contents.append(System.getProperty("line.separator"));
                }
                urlReader.close();
                return contents.toString();
            } catch (Exception e1) {
                return null;
            }
        }
    }
public static String hashClientPassword(String algorithm, String password, String salt) throws IllegalArgumentException, DruidSafeRuntimeException {
        if (algorithm == null) {
            throw new IllegalArgumentException("THE ALGORITHM MUST NOT BE NULL");
        }
        if (password == null) {
            throw new IllegalArgumentException("THE PASSWORD MUST NOT BE NULL");
        }
        if (salt == null) {
            salt = "";
        }
        String result = null;
        try {
            MessageDigest md = MessageDigest.getInstance(algorithm);
            md.update(password.getBytes());
            md.update(salt.getBytes());
            result = SecurityHelper.byteArrayToHexString(md.digest());
        } catch (NoSuchAlgorithmException e) {
            throw new DruidSafeRuntimeException(e);
        }
        return result;
    }
public static Hashtable getNamingHashtable() {
        Hashtable namingHash = new Hashtable();
        URL url = AceTree.class.getResource("/org/rhwlab/snight/namesHash.txt");
        InputStream istream = null;
        try {
            istream = url.openStream();
            BufferedReader br = new BufferedReader(new InputStreamReader(istream));
            String s;
            while (br.ready()) {
                s = br.readLine();
                if (s.length() == 0) continue;
                String[] sa = s.split(",");
                namingHash.put(sa[0], sa[1]);
            }
            br.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return namingHash;
    }
public static void copyFile(String fileName, String dstPath) throws IOException {
        FileChannel sourceChannel = new FileInputStream(fileName).getChannel();
        FileChannel destinationChannel = new FileOutputStream(dstPath).getChannel();
        sourceChannel.transferTo(0, sourceChannel.size(), destinationChannel);
        sourceChannel.close();
        destinationChannel.close();
    }
private void gerarFaturamento() {
        int opt = Funcoes.mensagemConfirma(null, "Confirma o faturamento?");
        if (opt == JOptionPane.OK_OPTION) {
            StringBuilder insert = new StringBuilder();
            insert.append("INSERT INTO RPFATURAMENTO ");
            insert.append("(CODEMP, CODFILIAL, CODPED, CODITPED, ");
            insert.append("QTDFATURADO, VLRFATURADO, QTDPENDENTE, ");
            insert.append("PERCCOMISFAT, VLRCOMISFAT, DTFATURADO ) ");
            insert.append("VALUES");
            insert.append("(?,?,?,?,?,?,?,?,?,?)");
            PreparedStatement ps;
            int parameterIndex;
            try {
                for (int i = 0; i < tab.getNumLinhas(); i++) {
                    parameterIndex = 1;
                    ps = con.prepareStatement(insert.toString());
                    ps.setInt(parameterIndex++, AplicativoRep.iCodEmp);
                    ps.setInt(parameterIndex++, ListaCampos.getMasterFilial("RPFATURAMENTO"));
                    ps.setInt(parameterIndex++, txtCodPed.getVlrInteger());
                    ps.setInt(parameterIndex++, (Integer) tab.getValor(i, ETabNota.ITEM.ordinal()));
                    ps.setBigDecimal(parameterIndex++, (BigDecimal) tab.getValor(i, ETabNota.QTDFATURADA.ordinal()));
                    ps.setBigDecimal(parameterIndex++, (BigDecimal) tab.getValor(i, ETabNota.VLRFATURADO.ordinal()));
                    ps.setBigDecimal(parameterIndex++, (BigDecimal) tab.getValor(i, ETabNota.QDTPENDENTE.ordinal()));
                    ps.setBigDecimal(parameterIndex++, (BigDecimal) tab.getValor(i, ETabNota.PERCCOMIS.ordinal()));
                    ps.setBigDecimal(parameterIndex++, (BigDecimal) tab.getValor(i, ETabNota.VLRCOMIS.ordinal()));
                    ps.setDate(parameterIndex++, Funcoes.dateToSQLDate(Calendar.getInstance().getTime()));
                    ps.executeUpdate();
                }
                gerarFaturamento.setEnabled(false);
                gerarComissao.setEnabled(true);
                Funcoes.mensagemInforma(null, "Faturamento criado para pedido " + txtCodPed.getVlrInteger());
                con.commit();
            } catch (Exception e) {
                e.printStackTrace();
                Funcoes.mensagemErro(this, "Erro ao gerar faturamento!\n" + e.getMessage());
                try {
                    con.rollback();
                } catch (SQLException e1) {
                    e1.printStackTrace();
                }
            }
        }
    }
private void gerarComissao() {
        int opt = Funcoes.mensagemConfirma(null, "Confirma gerar comiss�es para o vendedor " + txtNomeVend.getVlrString().trim() + "?");
        if (opt == JOptionPane.OK_OPTION) {
            StringBuilder insert = new StringBuilder();
            insert.append("INSERT INTO RPCOMISSAO ");
            insert.append("(CODEMP, CODFILIAL, CODPED, CODITPED, ");
            insert.append("CODEMPVD, CODFILIALVD, CODVEND, VLRCOMISS ) ");
            insert.append("VALUES ");
            insert.append("(?,?,?,?,?,?,?,?)");
            PreparedStatement ps;
            int parameterIndex;
            boolean gerou = false;
            try {
                for (int i = 0; i < tab.getNumLinhas(); i++) {
                    if (((BigDecimal) tab.getValor(i, 8)).floatValue() > 0) {
                        parameterIndex = 1;
                        ps = con.prepareStatement(insert.toString());
                        ps.setInt(parameterIndex++, AplicativoRep.iCodEmp);
                        ps.setInt(parameterIndex++, ListaCampos.getMasterFilial("RPCOMISSAO"));
                        ps.setInt(parameterIndex++, txtCodPed.getVlrInteger());
                        ps.setInt(parameterIndex++, (Integer) tab.getValor(i, ETabNota.ITEM.ordinal()));
                        ps.setInt(parameterIndex++, AplicativoRep.iCodEmp);
                        ps.setInt(parameterIndex++, ListaCampos.getMasterFilial("RPVENDEDOR"));
                        ps.setInt(parameterIndex++, txtCodVend.getVlrInteger());
                        ps.setBigDecimal(parameterIndex++, (BigDecimal) tab.getValor(i, ETabNota.VLRCOMIS.ordinal()));
                        ps.executeUpdate();
                        gerou = true;
                    }
                }
                if (gerou) {
                    Funcoes.mensagemInforma(null, "Comiss�o gerada para " + txtNomeVend.getVlrString().trim());
                    txtCodPed.setText("0");
                    lcPedido.carregaDados();
                    carregaTabela();
                    con.commit();
                } else {
                    Funcoes.mensagemInforma(null, "N�o foi possiv�l gerar comiss�o!\nVerifique os valores das comiss�es dos itens.");
                }
            } catch (Exception e) {
                e.printStackTrace();
                Funcoes.mensagemErro(this, "Erro ao gerar comiss�o!\n" + e.getMessage());
                try {
                    con.rollback();
                } catch (SQLException e1) {
                    e1.printStackTrace();
                }
            }
        }
    }
public void testImageDataField() {
        PropertySet propertySet = fetchPropertySet();
        try {
            ImageDataField dataField = propertySet.getDataField(PropertySetTestStruct.TESTBLOCK_IMAGE, ImageDataField.class);
            URL url = getClass().getResource("JFire_Test.gif");
            if (url == null) return;
            InputStream in = url.openStream();
            try {
                dataField.loadStream(in, "JFire_Test.gif", "image/gif");
            } finally {
                in.close();
            }
        } catch (Exception e) {
            throw new RuntimeException("Setting image of ImageDataField failed", e);
        }
        try {
            propertySet.deflate();
            getPropertyManager().storePropertySet(propertySet, true, FETCH_GROUPS, FETCH_DEPTH);
        } catch (Exception e) {
            throw new RuntimeException("Storing PropertySet with ImageDataField failed", e);
        }
    }
public static boolean writeFile(HttpServletResponse resp, File reqFile) {
        boolean retVal = false;
        InputStream in = null;
        try {
            in = new BufferedInputStream(new FileInputStream(reqFile));
            IOUtils.copy(in, resp.getOutputStream());
            logger.debug("File successful written to servlet response: " + reqFile.getAbsolutePath());
        } catch (FileNotFoundException e) {
            logger.error("Resource not found: " + reqFile.getAbsolutePath());
        } catch (IOException e) {
            logger.error(String.format("Error while rendering [%s]: %s", reqFile.getAbsolutePath(), e.getMessage()), e);
        } finally {
            IOUtils.closeQuietly(in);
        }
        return retVal;
    }