semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
private static void addFile(File file, ZipArchiveOutputStream zaos) throws IOException {
        String filename = null;
        filename = file.getName();
        ZipArchiveEntry zae = new ZipArchiveEntry(filename);
        zae.setSize(file.length());
        zaos.putArchiveEntry(zae);
        FileInputStream fis = new FileInputStream(file);
        IOUtils.copy(fis, zaos);
        zaos.closeArchiveEntry();
    }
public static List<String> unZip(File tarFile, File directory) throws IOException {
        List<String> result = new ArrayList<String>();
        InputStream inputStream = new FileInputStream(tarFile);
        ZipArchiveInputStream in = new ZipArchiveInputStream(inputStream);
        ZipArchiveEntry entry = in.getNextZipEntry();
        while (entry != null) {
            OutputStream out = new FileOutputStream(new File(directory, entry.getName()));
            IOUtils.copy(in, out);
            out.close();
            result.add(entry.getName());
            entry = in.getNextZipEntry();
        }
        in.close();
        return result;
    }
public int[] sort() {
        boolean t = true;
        int temp = 0;
        int[] mas = new int[N];
        Random rand = new Random();
        for (int i = 0; i < N; i++) {
            mas[i] = rand.nextInt(10) + 1;
        }
        while (t) {
            t = false;
            for (int i = 0; i < mas.length - 1; i++) {
                if (mas[i] > mas[i + 1]) {
                    temp = mas[i];
                    mas[i] = mas[i + 1];
                    mas[i + 1] = temp;
                    t = true;
                }
            }
        }
        return mas;
    }
public static String encrypt(String key) {
        MessageDigest md5 = null;
        try {
            md5 = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        md5.update(key.getBytes());
        byte hash[] = md5.digest();
        StringBuffer buffer = new StringBuffer();
        for (int i = 0; i < hash.length; i++) {
            String temp = Integer.toHexString(0xFF & hash[i]);
            if (temp.length() == 1) temp = "0" + temp;
            buffer.append(temp);
        }
        return buffer.toString();
    }
public static void insertTableData(Connection dest, TableMetaData tableMetaData) throws Exception {
        PreparedStatement ps = null;
        try {
            dest.setAutoCommit(false);
            String sql = "INSERT INTO " + tableMetaData.getSchema() + "." + tableMetaData.getTableName() + " (";
            for (String columnName : tableMetaData.getColumnsNames()) {
                sql += columnName + ",";
            }
            sql = sql.substring(0, sql.length() - 1);
            sql += ") VALUES (";
            for (String columnName : tableMetaData.getColumnsNames()) {
                sql += "?" + ",";
            }
            sql = sql.substring(0, sql.length() - 1);
            sql += ")";
            IOHelper.writeInfo(sql);
            ps = dest.prepareStatement(sql);
            for (Row r : tableMetaData.getData()) {
                try {
                    int param = 1;
                    for (String columnName : tableMetaData.getColumnsNames()) {
                        if (dest instanceof OracleConnection) {
                            if (tableMetaData.getColumnsTypes().get(columnName).equalsIgnoreCase("BLOB")) {
                                BLOB blob = new BLOB((OracleConnection) dest, (byte[]) r.getRowData().get(columnName));
                                ((OraclePreparedStatement) ps).setBLOB(param, blob);
                            } else if (tableMetaData.getColumnsTypes().get(columnName).equalsIgnoreCase("CLOB")) {
                                ((OraclePreparedStatement) ps).setStringForClob(param, (String) r.getRowData().get(columnName));
                            } else if (tableMetaData.getColumnsTypes().get(columnName).equalsIgnoreCase("LONG")) {
                                ps.setBytes(param, (byte[]) r.getRowData().get(columnName));
                            }
                        } else {
                            IOHelper.writeInfo(columnName + " = " + r.getRowData().get(columnName));
                            ps.setObject(param, r.getRowData().get(columnName));
                        }
                        param++;
                    }
                    if (ps.executeUpdate() != 1) {
                        dest.rollback();
                        updateTableData(dest, tableMetaData, r);
                    }
                } catch (Exception ex) {
                    try {
                        dest.rollback();
                        updateTableData(dest, tableMetaData, r);
                    } catch (Exception ex2) {
                        IOHelper.writeError("Error in update " + sql, ex2);
                    }
                }
                ps.clearParameters();
            }
            dest.commit();
            dest.setAutoCommit(true);
        } finally {
            if (ps != null) ps.close();
        }
    }
public static void updateTableData(Connection dest, TableMetaData tableMetaData) throws Exception {
        PreparedStatement ps = null;
        try {
            dest.setAutoCommit(false);
            String sql = "UPDATE " + tableMetaData.getSchema() + "." + tableMetaData.getTableName() + " SET ";
            for (String columnName : tableMetaData.getColumnsNames()) {
                sql += columnName + " = ? ,";
            }
            sql = sql.substring(0, sql.length() - 1);
            sql += " WHERE ";
            for (String pkColumnName : tableMetaData.getPkColumns()) {
                sql += pkColumnName + " = ? AND ";
            }
            sql = sql.substring(0, sql.length() - 4);
            ps = dest.prepareStatement(sql);
            for (Row r : tableMetaData.getData()) {
                int param = 1;
                for (String columnName : tableMetaData.getColumnsNames()) {
                    if (dest instanceof OracleConnection) {
                        if (tableMetaData.getColumnsTypes().get(columnName).equalsIgnoreCase("BLOB")) {
                            BLOB blob = new BLOB((OracleConnection) dest, (byte[]) r.getRowData().get(columnName));
                            ((OraclePreparedStatement) ps).setBLOB(param, blob);
                        } else if (tableMetaData.getColumnsTypes().get(columnName).equalsIgnoreCase("CLOB")) {
                            ((OraclePreparedStatement) ps).setStringForClob(param, (String) r.getRowData().get(columnName));
                        } else if (tableMetaData.getColumnsTypes().get(columnName).equalsIgnoreCase("LONG")) {
                            ps.setBytes(param, (byte[]) r.getRowData().get(columnName));
                        }
                    } else {
                        ps.setObject(param, r.getRowData().get(columnName));
                    }
                    param++;
                }
                for (String pkColumnName : tableMetaData.getPkColumns()) {
                    ps.setObject(param, r.getRowData().get(pkColumnName));
                    param++;
                }
                if (ps.executeUpdate() != 1) {
                    dest.rollback();
                    throw new Exception();
                }
                ps.clearParameters();
            }
            dest.commit();
            dest.setAutoCommit(true);
        } finally {
            if (ps != null) ps.close();
        }
    }
public static void updateTableData(Connection dest, TableMetaData tableMetaData, Row r) throws Exception {
        PreparedStatement ps = null;
        try {
            dest.setAutoCommit(false);
            String sql = "UPDATE " + tableMetaData.getSchema() + "." + tableMetaData.getTableName() + " SET ";
            for (String columnName : tableMetaData.getColumnsNames()) {
                sql += columnName + " = ? ,";
            }
            sql = sql.substring(0, sql.length() - 1);
            sql += " WHERE ";
            for (String pkColumnName : tableMetaData.getPkColumns()) {
                sql += pkColumnName + " = ? AND ";
            }
            sql = sql.substring(0, sql.length() - 4);
            System.out.println("UPDATE: " + sql);
            ps = dest.prepareStatement(sql);
            int param = 1;
            for (String columnName : tableMetaData.getColumnsNames()) {
                if (dest instanceof OracleConnection) {
                    if (tableMetaData.getColumnsTypes().get(columnName).equalsIgnoreCase("BLOB")) {
                        BLOB blob = new BLOB((OracleConnection) dest, (byte[]) r.getRowData().get(columnName));
                        ((OraclePreparedStatement) ps).setBLOB(param, blob);
                    } else if (tableMetaData.getColumnsTypes().get(columnName).equalsIgnoreCase("CLOB")) {
                        ((OraclePreparedStatement) ps).setStringForClob(param, (String) r.getRowData().get(columnName));
                    } else if (tableMetaData.getColumnsTypes().get(columnName).equalsIgnoreCase("LONG")) {
                        ps.setBytes(param, (byte[]) r.getRowData().get(columnName));
                    }
                } else {
                    ps.setObject(param, r.getRowData().get(columnName));
                }
                param++;
            }
            for (String pkColumnName : tableMetaData.getPkColumns()) {
                ps.setObject(param, r.getRowData().get(pkColumnName));
                param++;
            }
            if (ps.executeUpdate() != 1) {
                dest.rollback();
                throw new Exception("Erro no update");
            }
            ps.clearParameters();
            dest.commit();
            dest.setAutoCommit(true);
        } finally {
            if (ps != null) ps.close();
        }
    }
public static String generateHash(String string, String algoritmo) {
        try {
            MessageDigest md = MessageDigest.getInstance(algoritmo);
            md.update(string.getBytes());
            byte[] result = md.digest();
            int firstPart;
            int lastPart;
            StringBuilder sBuilder = new StringBuilder();
            for (int i = 0; i < result.length; i++) {
                firstPart = ((result[i] >> 4) & 0xf) << 4;
                lastPart = result[i] & 0xf;
                if (firstPart == 0) sBuilder.append("0");
                sBuilder.append(Integer.toHexString(firstPart | lastPart));
            }
            return sBuilder.toString();
        } catch (NoSuchAlgorithmException ex) {
            return null;
        }
    }
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        final FileManager fmanager = FileManager.getFileManager(request, leechget);
        ServletFileUpload upload = new ServletFileUpload();
        FileItemIterator iter;
        try {
            iter = upload.getItemIterator(request);
            while (iter.hasNext()) {
                FileItemStream item = iter.next();
                String name = item.getFieldName();
                InputStream stream = item.openStream();
                if (!item.isFormField()) {
                    final FileObject file = fmanager.getFile(name);
                    if (!file.exists()) {
                        IOUtils.copyLarge(stream, file.getContent().getOutputStream());
                    }
                }
            }
        } catch (FileUploadException e1) {
            e1.printStackTrace();
        }
    }
private void copyFile(URL from, File to) {
        try {
            InputStream is = from.openStream();
            IOUtils.copy(is, new FileOutputStream(to));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
private void copyFile(File file, File dir) throws IOException {
        BufferedReader in = new BufferedReader(new FileReader(file));
        BufferedWriter out = new BufferedWriter(new FileWriter(new File(dir.getAbsolutePath() + File.separator + file.getName())));
        char[] buffer = new char[512];
        int read = -1;
        while ((read = in.read(buffer)) > 0) {
            out.write(buffer, 0, read);
        }
        in.close();
        out.close();
    }
public void testSendMessage() throws ClientProtocolException, IOException {
        String textMessage = "La%20sua%20prenotazione%20e60%20andata%20a%20buon%20fine";
        String customerPhoneNumber = "+393345730726";
        DefaultHttpClient httpclient = new DefaultHttpClient();
        String other = "http://smswizard.globalitalia.it/smsgateway/send.asp";
        String urlProva = other + "?" + "Account=sardricerche" + "&Password=v8LomdZT" + "&PhoneNumbers=+393345730726" + "&SMSData=" + textMessage + "&Recipients=1" + "&Sender=+393337589951" + "&ID=11762";
        HttpPost httpPost = new HttpPost(urlProva);
        HttpResponse response = httpclient.execute(httpPost);
        HttpEntity entity = response.getEntity();
        String txt = EntityUtils.toString(entity);
    }
public static void copy(File sourceFile, File destinationFile) throws IOException {
        FileChannel sourceChannel = new FileInputStream(sourceFile).getChannel();
        FileChannel destinationChannel = new FileOutputStream(destinationFile).getChannel();
        destinationChannel.transferFrom(sourceChannel, 0, sourceChannel.size());
        sourceChannel.close();
        destinationChannel.close();
    }
public static void main(String[] args) throws Exception {
        URL url = new URL("http://www.sohu.com");
        InputStream is = url.openStream();
        InputStreamReader isr = new InputStreamReader(is, Charset.forName("GB18030"));
        FileOutputStream fos = new FileOutputStream("gen/sohu2.html");
        OutputStreamWriter osw = new OutputStreamWriter(fos);
        char[] b = new char[2048];
        int temp;
        while (-1 != (temp = isr.read(b, 0, b.length))) {
            osw.write(b);
        }
        osw.close();
        BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
        String line = null;
    }
public void write(PDDocument doc) throws COSVisitorException {
        document = doc;
        SecurityHandler securityHandler = document.getSecurityHandler();
        if (securityHandler != null) {
            try {
                securityHandler.prepareDocumentForEncryption(document);
                this.willEncrypt = true;
            } catch (IOException e) {
                throw new COSVisitorException(e);
            } catch (CryptographyException e) {
                throw new COSVisitorException(e);
            }
        } else {
            this.willEncrypt = false;
        }
        COSDocument cosDoc = document.getDocument();
        COSDictionary trailer = cosDoc.getTrailer();
        COSArray idArray = (COSArray) trailer.getDictionaryObject("ID");
        if (idArray == null) {
            try {
                MessageDigest md = MessageDigest.getInstance("MD5");
                md.update(Long.toString(System.currentTimeMillis()).getBytes());
                COSDictionary info = (COSDictionary) trailer.getDictionaryObject("Info");
                if (info != null) {
                    Iterator values = info.getValues().iterator();
                    while (values.hasNext()) {
                        md.update(values.next().toString().getBytes());
                    }
                }
                idArray = new COSArray();
                COSString id = new COSString(md.digest());
                idArray.add(id);
                idArray.add(id);
                trailer.setItem("ID", idArray);
            } catch (NoSuchAlgorithmException e) {
                throw new COSVisitorException(e);
            }
        }
        cosDoc.accept(this);
    }
public static String generateHash(String value) {
        MessageDigest md5 = null;
        try {
            md5 = MessageDigest.getInstance("MD5");
            md5.reset();
            md5.update(value.getBytes());
        } catch (NoSuchAlgorithmException e) {
            log.error("Could not find the requested hash method: " + e.getMessage());
        }
        byte[] result = md5.digest();
        StringBuffer hexString = new StringBuffer();
        for (int i = 0; i < result.length; i++) {
            hexString.append(Integer.toHexString(0xFF & result[i]));
        }
        return hexString.toString();
    }
public void setTableBraille(String tableBraille, boolean sys) {
        fiConf.setProperty(OptNames.fi_braille_table, tableBraille);
        fiConf.setProperty(OptNames.fi_is_sys_braille_table, Boolean.toString(sys));
        FileChannel in = null;
        FileChannel out = null;
        try {
            String fichTable;
            if (!(tableBraille.endsWith(".ent"))) {
                tableBraille = tableBraille + ".ent";
            }
            if (sys) {
                fichTable = ConfigNat.getInstallFolder() + "xsl/tablesBraille/" + tableBraille;
            } else {
                fichTable = ConfigNat.getUserBrailleTableFolder() + tableBraille;
            }
            in = new FileInputStream(fichTable).getChannel();
            out = new FileOutputStream(getUserBrailleTableFolder() + "Brltab.ent").getChannel();
            in.transferTo(0, in.size(), out);
            in.close();
            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            String fichTable;
            if (sys) {
                fichTable = ConfigNat.getInstallFolder() + "/xsl/tablesEmbosseuse/" + tableBraille;
            } else {
                fichTable = ConfigNat.getUserEmbossTableFolder() + "/" + tableBraille;
            }
            in = new FileInputStream(fichTable).getChannel();
            out = new FileOutputStream(ConfigNat.getUserTempFolder() + "Table_pour_chaines.ent").getChannel();
            in.transferTo(0, in.size(), out);
            in.close();
            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
public void setTableEmbossage(String te, boolean sys) {
        fiConf.setProperty(OptNames.pr_emboss_table, te);
        fiConf.setProperty(OptNames.fi_is_sys_emboss_table, Boolean.toString(sys));
        FileChannel in = null;
        FileChannel out = null;
        try {
            String fichTable;
            if (!(te.endsWith(".ent"))) {
                te = te + ".ent";
            }
            if (sys) {
                fichTable = ConfigNat.getInstallFolder() + "/xsl/tablesEmbosseuse/" + te;
            } else {
                fichTable = ConfigNat.getUserEmbossTableFolder() + "/" + te;
            }
            in = new FileInputStream(fichTable).getChannel();
            out = new FileOutputStream(ConfigNat.getUserEmbossTableFolder() + "/Embtab.ent").getChannel();
            in.transferTo(0, in.size(), out);
            in.close();
            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
private long getSize(String url) throws ClientProtocolException, IOException {
            url = normalizeUrl(url);
            Log.i(LOG_TAG, "Head " + url);
            HttpHead httpGet = new HttpHead(url);
            HttpResponse response = mHttpClient.execute(httpGet);
            if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
                throw new IOException("Unexpected Http status code " + response.getStatusLine().getStatusCode());
            }
            Header[] clHeaders = response.getHeaders("Content-Length");
            if (clHeaders.length > 0) {
                Header header = clHeaders[0];
                return Long.parseLong(header.getValue());
            }
            return -1;
        }
private InputStream get(String url, long startOffset, long expectedLength) throws ClientProtocolException, IOException {
            url = normalizeUrl(url);
            Log.i(LOG_TAG, "Get " + url);
            mHttpGet = new HttpGet(url);
            int expectedStatusCode = HttpStatus.SC_OK;
            if (startOffset > 0) {
                String range = "bytes=" + startOffset + "-";
                if (expectedLength >= 0) {
                    range += expectedLength - 1;
                }
                Log.i(LOG_TAG, "requesting byte range " + range);
                mHttpGet.addHeader("Range", range);
                expectedStatusCode = HttpStatus.SC_PARTIAL_CONTENT;
            }
            HttpResponse response = mHttpClient.execute(mHttpGet);
            long bytesToSkip = 0;
            int statusCode = response.getStatusLine().getStatusCode();
            if (statusCode != expectedStatusCode) {
                if ((statusCode == HttpStatus.SC_OK) && (expectedStatusCode == HttpStatus.SC_PARTIAL_CONTENT)) {
                    Log.i(LOG_TAG, "Byte range request ignored");
                    bytesToSkip = startOffset;
                } else {
                    throw new IOException("Unexpected Http status code " + statusCode + " expected " + expectedStatusCode);
                }
            }
            HttpEntity entity = response.getEntity();
            InputStream is = entity.getContent();
            if (bytesToSkip > 0) {
                is.skip(bytesToSkip);
            }
            return is;
        }
String extractTiffFile(String path) throws IOException {
        ZipInputStream in = new ZipInputStream(new FileInputStream(path));
        OutputStream out = new FileOutputStream(dir + TEMP_NAME);
        byte[] buf = new byte[1024];
        int len;
        ZipEntry entry = in.getNextEntry();
        if (entry == null) return null;
        String name = entry.getName();
        if (!name.endsWith(".tif")) throw new IOException("This ZIP archive does not appear to contain a TIFF file");
        while ((len = in.read(buf)) > 0) out.write(buf, 0, len);
        out.close();
        in.close();
        return name;
    }
public static String sendPost(String url, String param) {
        String result = "";
        try {
            URL httpurl = new URL(url);
            HttpURLConnection httpConn = (HttpURLConnection) httpurl.openConnection();
            httpConn.setRequestProperty("Accept-Language", "zh-CN");
            httpConn.setDoOutput(true);
            httpConn.setDoInput(true);
            PrintWriter out = new PrintWriter(httpConn.getOutputStream());
            out.print(param);
            out.flush();
            out.close();
            BufferedReader in = new BufferedReader(new InputStreamReader(httpConn.getInputStream(), "UTF-8"));
            String line;
            while ((line = in.readLine()) != null) {
                result += line;
            }
            in.close();
        } catch (Exception e) {
            MsgPrint.showMsg(e.getMessage());
        }
        return result;
    }
public static byte[] sendSmsRequest(String url, String param) {
        byte[] bytes = null;
        try {
            URL httpurl = new URL(url);
            HttpURLConnection httpConn = (HttpURLConnection) httpurl.openConnection();
            httpConn.setRequestProperty("Accept-Language", "zh-CN");
            httpConn.setDoOutput(true);
            httpConn.setDoInput(true);
            PrintWriter out = new PrintWriter(httpConn.getOutputStream());
            out.print(param);
            out.flush();
            out.close();
            InputStream ism = httpConn.getInputStream();
            bytes = new byte[httpConn.getContentLength()];
            ism.read(bytes);
            ism.close();
            MsgPrint.showByteArray("result", bytes);
        } catch (Exception e) {
            return new byte[] { 0, 0, 0, 0 };
        }
        return bytes;
    }