semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public static void loginLocalhostr() throws IOException {
        HttpParams params = new BasicHttpParams();
        params.setParameter("http.useragent", "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2) Gecko/20100115 Firefox/3.6");
        httpclient = new DefaultHttpClient(params);
        System.out.println("Trying to log in to localhostr");
        HttpPost httppost = new HttpPost("http://localhostr.com/signin");
        httppost.setHeader("Referer", "http://www.localhostr.com/");
        httppost.setHeader("Accept", "application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5");
        List<NameValuePair> formparams = new ArrayList<NameValuePair>();
        formparams.add(new BasicNameValuePair("username", "007007dinesh@gmail.com"));
        formparams.add(new BasicNameValuePair("password", ""));
        UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, "UTF-8");
        httppost.setEntity(entity);
        HttpResponse httpresponse = httpclient.execute(httppost);
        System.out.println("Getting cookies........");
        System.out.println(httpresponse.getStatusLine());
        Iterator<Cookie> it = httpclient.getCookieStore().getCookies().iterator();
        Cookie escookie = null;
        while (it.hasNext()) {
            escookie = it.next();
            if (escookie.getName().contains("session")) {
                sessioncookie = escookie.getName() + " = " + escookie.getValue();
                System.out.println("session cookie : " + sessioncookie);
            }
        }
        if (httpresponse.getStatusLine().getStatusCode() == 302) {
            login = true;
            System.out.println("localhostr Login Success");
        } else {
            System.out.println("localhostr Login failed");
        }
        System.out.println(EntityUtils.toString(httpresponse.getEntity()));
        InputStream is = httpresponse.getEntity().getContent();
        is.close();
    }
public static void fileUpload() throws IOException {
        file = new File("C:\\Documents and Settings\\dinesh\\Desktop\\ImageShackUploaderPlugin.java");
        HttpPost httppost = new HttpPost(localhostrurl);
        MultipartEntity mpEntity = new MultipartEntity();
        ContentBody cbFile = new FileBody(file);
        mpEntity.addPart("name", new StringBody(file.getName()));
        if (login) {
            mpEntity.addPart("session", new StringBody(sessioncookie.substring(sessioncookie.indexOf("=") + 2)));
        }
        mpEntity.addPart("file", cbFile);
        httppost.setEntity(mpEntity);
        System.out.println("Now uploading your file into localhost...........................");
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity resEntity = response.getEntity();
        System.out.println(response.getStatusLine());
        if (resEntity != null) {
            String tmp = EntityUtils.toString(resEntity);
            downloadlink = parseResponse(tmp, "\"url\":\"", "\"");
            System.out.println("download link : " + downloadlink);
        }
    }
public static void main(String args[]) {
        int temp;
        int[] a1 = { 6, 2, -3, 7, -1, 8, 9, 0 };
        for (int j = 0; j < (a1.length * a1.length); j++) {
            for (int i = 0; i < a1.length - 1; i++) {
                if (a1[i] > a1[i + 1]) {
                    temp = a1[i];
                    a1[i] = a1[i + 1];
                    a1[i + 1] = temp;
                }
            }
        }
        for (int i = 0; i < a1.length; i++) {
            System.out.print(" " + a1[i]);
        }
    }
public static void copyFile(String fromFilePath, String toFilePath, boolean overwrite) throws IOException {
        File fromFile = new File(fromFilePath);
        File toFile = new File(toFilePath);
        if (!fromFile.exists()) throw new IOException("FileCopy: " + "no such source file: " + fromFilePath);
        if (!fromFile.isFile()) throw new IOException("FileCopy: " + "can't copy directory: " + fromFilePath);
        if (!fromFile.canRead()) throw new IOException("FileCopy: " + "source file is unreadable: " + fromFilePath);
        if (toFile.isDirectory()) toFile = new File(toFile, fromFile.getName());
        if (toFile.exists()) {
            if (!overwrite) {
                throw new IOException(toFilePath + " already exists!");
            }
            if (!toFile.canWrite()) {
                throw new IOException("FileCopy: destination file is unwriteable: " + toFilePath);
            }
            String parent = toFile.getParent();
            if (parent == null) {
                parent = System.getProperty("user.dir");
            }
            File dir = new File(parent);
            if (!dir.exists()) {
                throw new IOException("FileCopy: destination directory doesn't exist: " + parent);
            }
            if (dir.isFile()) {
                throw new IOException("FileCopy: destination is not a directory: " + parent);
            }
            if (!dir.canWrite()) {
                throw new IOException("FileCopy: destination directory is unwriteable: " + parent);
            }
        }
        FileInputStream from = null;
        FileOutputStream to = null;
        try {
            from = new FileInputStream(fromFile);
            to = new FileOutputStream(toFile);
            byte[] buffer = new byte[4096];
            int bytesRead;
            while ((bytesRead = from.read(buffer)) != -1) to.write(buffer, 0, bytesRead);
        } finally {
            long lastModified = fromFile.lastModified();
            toFile.setLastModified(lastModified);
            if (from != null) {
                try {
                    from.close();
                } catch (IOException e) {
                }
            }
            if (to != null) {
                try {
                    to.close();
                } catch (IOException e) {
                }
            }
        }
    }
@Override
    public DownloadingItem download(Playlist playlist, String title, File folder, StopDownloadCondition condition, String uuid) throws IOException, StoreStateException {
        boolean firstIteration = true;
        Iterator<PlaylistEntry> entries = playlist.getEntries().iterator();
        DownloadingItem prevItem = null;
        File[] previousDownloadedFiles = new File[0];
        while (entries.hasNext()) {
            PlaylistEntry entry = entries.next();
            DownloadingItem item = null;
            LOGGER.info("Downloading from '" + entry.getTitle() + "'");
            InputStream is = RESTHelper.inputStream(entry.getUrl());
            boolean stopped = false;
            File nfile = null;
            try {
                nfile = createFileStream(folder, entry);
                item = new DownloadingItem(nfile, uuid.toString(), title, entry, new Date(), getPID(), condition);
                if (previousDownloadedFiles.length > 0) {
                    item.setPreviousFiles(previousDownloadedFiles);
                }
                addItem(item);
                if (prevItem != null) deletePrevItem(prevItem);
                prevItem = item;
                stopped = IOUtils.copyStreams(is, new FileOutputStream(nfile), condition);
            } catch (IOException e) {
                LOGGER.log(Level.SEVERE, e.getMessage(), e);
                radioScheduler.fireException(e);
                if (!condition.isStopped()) {
                    File[] nfiles = new File[previousDownloadedFiles.length + 1];
                    System.arraycopy(previousDownloadedFiles, 0, nfiles, 0, previousDownloadedFiles.length);
                    nfiles[nfiles.length - 1] = item.getFile();
                    previousDownloadedFiles = nfiles;
                    if ((!entries.hasNext()) && (firstIteration)) {
                        firstIteration = false;
                        entries = playlist.getEntries().iterator();
                    }
                    continue;
                }
            }
            if (stopped) {
                item.setState(ProcessStates.STOPPED);
                this.radioScheduler.fireStopDownloading(item);
                return item;
            }
        }
        return null;
    }
public void testPreparedStatement0009() throws Exception {
        Statement stmt = con.createStatement();
        stmt.executeUpdate("create table #t0009 " + "  (i  integer  not null,      " + "   s  char(10) not null)      ");
        con.setAutoCommit(false);
        PreparedStatement pstmt = con.prepareStatement("insert into #t0009 values (?, ?)");
        int rowsToAdd = 8;
        final String theString = "abcdefghijklmnopqrstuvwxyz";
        int count = 0;
        for (int i = 1; i <= rowsToAdd; i++) {
            pstmt.setInt(1, i);
            pstmt.setString(2, theString.substring(0, i));
            count += pstmt.executeUpdate();
        }
        pstmt.close();
        assertEquals(count, rowsToAdd);
        con.rollback();
        ResultSet rs = stmt.executeQuery("select s, i from #t0009");
        assertNotNull(rs);
        count = 0;
        while (rs.next()) {
            count++;
            assertEquals(rs.getString(1).trim().length(), rs.getInt(2));
        }
        assertEquals(count, 0);
        con.commit();
        pstmt = con.prepareStatement("insert into #t0009 values (?, ?)");
        rowsToAdd = 6;
        count = 0;
        for (int i = 1; i <= rowsToAdd; i++) {
            pstmt.setInt(1, i);
            pstmt.setString(2, theString.substring(0, i));
            count += pstmt.executeUpdate();
        }
        assertEquals(count, rowsToAdd);
        con.commit();
        pstmt.close();
        rs = stmt.executeQuery("select s, i from #t0009");
        count = 0;
        while (rs.next()) {
            count++;
            assertEquals(rs.getString(1).trim().length(), rs.getInt(2));
        }
        assertEquals(count, rowsToAdd);
        con.commit();
        stmt.close();
        con.setAutoCommit(true);
    }
public void testTransactions0010() throws Exception {
        Statement stmt = con.createStatement();
        stmt.executeUpdate("create table #t0010 " + "  (i  integer  not null,      " + "   s  char(10) not null)      ");
        con.setAutoCommit(false);
        PreparedStatement pstmt = con.prepareStatement("insert into #t0010 values (?, ?)");
        int rowsToAdd = 8;
        final String theString = "abcdefghijklmnopqrstuvwxyz";
        int count = 0;
        for (int i = 1; i <= rowsToAdd; i++) {
            pstmt.setInt(1, i);
            pstmt.setString(2, theString.substring(0, i));
            count += pstmt.executeUpdate();
        }
        assertEquals(count, rowsToAdd);
        con.rollback();
        ResultSet rs = stmt.executeQuery("select s, i from #t0010");
        assertNotNull(rs);
        count = 0;
        while (rs.next()) {
            count++;
            assertEquals(rs.getString(1).trim().length(), rs.getInt(2));
        }
        assertEquals(count, 0);
        rowsToAdd = 6;
        for (int j = 1; j <= 2; j++) {
            count = 0;
            for (int i = 1; i <= rowsToAdd; i++) {
                pstmt.setInt(1, i + ((j - 1) * rowsToAdd));
                pstmt.setString(2, theString.substring(0, i));
                count += pstmt.executeUpdate();
            }
            assertEquals(count, rowsToAdd);
            con.commit();
        }
        rs = stmt.executeQuery("select s, i from #t0010");
        count = 0;
        while (rs.next()) {
            count++;
            int i = rs.getInt(2);
            if (i > rowsToAdd) {
                i -= rowsToAdd;
            }
            assertEquals(rs.getString(1).trim().length(), i);
        }
        assertEquals(count, (2 * rowsToAdd));
        stmt.close();
        pstmt.close();
        con.setAutoCommit(true);
    }
public static void copy(File source, File dest) throws FileNotFoundException, IOException {
        FileInputStream input = new FileInputStream(source);
        FileOutputStream output = new FileOutputStream(dest);
        System.out.println("Copying " + source + " to " + dest);
        IOUtils.copy(input, output);
        output.close();
        input.close();
        dest.setLastModified(source.lastModified());
    }
private void auth() throws IOException {
        authorized = false;
        seqNumber = 0;
        DatagramSocket ds = new DatagramSocket();
        ds.setSoTimeout(UDPHID_DEFAULT_TIMEOUT);
        ds.connect(addr, port);
        DatagramPacket p = new DatagramPacket(buffer.array(), buffer.capacity());
        for (int i = 0; i < UDPHID_DEFAULT_ATTEMPTS; i++) {
            buffer.clear();
            buffer.put((byte) REQ_CHALLENGE);
            buffer.put(htons((short) UDPHID_PROTO));
            buffer.put(name.getBytes());
            ds.send(new DatagramPacket(buffer.array(), buffer.position()));
            buffer.clear();
            try {
                ds.receive(p);
            } catch (SocketTimeoutException e) {
                continue;
            }
            switch(buffer.get()) {
                case ANS_CHALLENGE:
                    break;
                case ANS_FAILURE:
                    throw new IOException("REQ_FAILURE");
                default:
                    throw new IOException("invalid packet");
            }
            byte challenge_id = buffer.get();
            int challenge_len = (int) buffer.get();
            byte[] challenge = new byte[challenge_len];
            buffer.get(challenge, 0, p.getLength() - buffer.position());
            byte[] response;
            try {
                MessageDigest md = MessageDigest.getInstance("MD5");
                md.update(challenge_id);
                md.update(password.getBytes(), 0, password.length());
                md.update(challenge, 0, challenge.length);
                response = md.digest();
            } catch (NoSuchAlgorithmException e) {
                throw new IOException("NoSuchAlgorithmException: " + e.toString());
            }
            buffer.clear();
            buffer.put((byte) REQ_RESPONSE);
            buffer.put(challenge_id);
            buffer.put((byte) response.length);
            buffer.put(response);
            buffer.put(login.getBytes());
            ds.send(new DatagramPacket(buffer.array(), buffer.position()));
            buffer.clear();
            try {
                ds.receive(p);
            } catch (SocketTimeoutException e) {
                continue;
            }
            switch(buffer.get()) {
                case ANS_SUCCESS:
                    int sidLength = buffer.get();
                    sid = new byte[sidLength];
                    buffer.get(sid, 0, sidLength);
                    authorized = true;
                    return;
                case ANS_FAILURE:
                    throw new IOException("access deny");
                default:
                    throw new IOException("invalid packet");
            }
        }
        throw new IOException("operation time out");
    }
public void readData(RowSetInternal caller) throws SQLException {
        Connection con = null;
        try {
            CachedRowSet crs = (CachedRowSet) caller;
            if (crs.getPageSize() == 0 && crs.size() > 0) {
                crs.close();
            }
            writerCalls = 0;
            userCon = false;
            con = this.connect(caller);
            if (con == null || crs.getCommand() == null) throw new SQLException(resBundle.handleGetObject("crsreader.connecterr").toString());
            try {
                con.setTransactionIsolation(crs.getTransactionIsolation());
            } catch (Exception ex) {
                ;
            }
            PreparedStatement pstmt = con.prepareStatement(crs.getCommand());
            decodeParams(caller.getParams(), pstmt);
            try {
                pstmt.setMaxRows(crs.getMaxRows());
                pstmt.setMaxFieldSize(crs.getMaxFieldSize());
                pstmt.setEscapeProcessing(crs.getEscapeProcessing());
                pstmt.setQueryTimeout(crs.getQueryTimeout());
            } catch (Exception ex) {
                throw new SQLException(ex.getMessage());
            }
            if (crs.getCommand().toLowerCase().indexOf("select") != -1) {
                ResultSet rs = pstmt.executeQuery();
                if (crs.getPageSize() == 0) {
                    crs.populate(rs);
                } else {
                    pstmt = con.prepareStatement(crs.getCommand(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
                    decodeParams(caller.getParams(), pstmt);
                    try {
                        pstmt.setMaxRows(crs.getMaxRows());
                        pstmt.setMaxFieldSize(crs.getMaxFieldSize());
                        pstmt.setEscapeProcessing(crs.getEscapeProcessing());
                        pstmt.setQueryTimeout(crs.getQueryTimeout());
                    } catch (Exception ex) {
                        throw new SQLException(ex.getMessage());
                    }
                    rs = pstmt.executeQuery();
                    crs.populate(rs, startPosition);
                }
                rs.close();
            } else {
                pstmt.executeUpdate();
            }
            pstmt.close();
            try {
                con.commit();
            } catch (SQLException ex) {
                ;
            }
            if (getCloseConnection() == true) con.close();
        } catch (SQLException ex) {
            throw ex;
        } finally {
            try {
                if (con != null && getCloseConnection() == true) {
                    try {
                        if (!con.getAutoCommit()) {
                            con.rollback();
                        }
                    } catch (Exception dummy) {
                    }
                    con.close();
                    con = null;
                }
            } catch (SQLException e) {
            }
        }
    }
public Object getContent(ContentProducerContext context, String ctxAttrName, Object ctxAttrValue) {
        try {
            URL url = (getURL() != null) ? new URL(getURL().toExternalForm()) : new URL(((URL) ctxAttrValue).toExternalForm());
            InputStream reader = url.openStream();
            int available = reader.available();
            byte contents[] = new byte[available];
            reader.read(contents, 0, available);
            reader.close();
            return new String(contents);
        } catch (Exception ex) {
            ex.printStackTrace();
            return ex.toString();
        }
    }
protected byte[] bytesFromJar(String path) throws IOException {
        URL url = new URL(path);
        InputStream is = url.openStream();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        byte[] buffer = new byte[2048];
        int n;
        while ((n = is.read(buffer)) >= 0) baos.write(buffer, 0, n);
        is.close();
        return baos.toByteArray();
    }
protected void sort(int a) {
        int[] masiv = new int[a + 1];
        Random fff = new Random();
        for (int i = 0; i <= a; i++) {
            masiv[i] = fff.nextInt(9);
        }
        int d;
        for (int j = 0; j < a; j++) {
            for (int i = 0; i < a; i++) {
                if (masiv[i] < masiv[i + 1]) {
                } else {
                    d = masiv[i];
                    masiv[i] = masiv[i + 1];
                    masiv[i + 1] = d;
                }
            }
        }
        while (a != 0) {
            System.out.println("sort: " + masiv[a]);
            a--;
        }
    }
public void testIsVersioned() throws ServiceException, IOException {
        JCRNodeSource emptySource = loadTestSource();
        assertTrue(emptySource.isVersioned());
        OutputStream sourceOut = emptySource.getOutputStream();
        assertNotNull(sourceOut);
        InputStream contentIn = getClass().getResourceAsStream(CONTENT_FILE);
        try {
            IOUtils.copy(contentIn, sourceOut);
            sourceOut.flush();
        } finally {
            sourceOut.close();
            contentIn.close();
        }
        assertTrue(emptySource.isVersioned());
    }
public void testRevcounter() throws ServiceException, IOException {
        JCRNodeSource emptySource = loadTestSource();
        for (int i = 0; i < 3; i++) {
            OutputStream sourceOut = emptySource.getOutputStream();
            InputStream contentIn = getClass().getResourceAsStream(CONTENT_FILE);
            try {
                IOUtils.copy(contentIn, sourceOut);
                sourceOut.flush();
            } finally {
                sourceOut.close();
                contentIn.close();
            }
            System.out.println(emptySource.getLatestSourceRevision());
        }
        String testSourceUri = BASE_URL + "users/lars.trieloff?revision=1.1";
        JCRNodeSource secondSource = (JCRNodeSource) resolveSource(testSourceUri);
        System.out.println("Created at: " + secondSource.getSourceRevision());
        for (int i = 0; i < 3; i++) {
            OutputStream sourceOut = emptySource.getOutputStream();
            InputStream contentIn = getClass().getResourceAsStream(CONTENT_FILE);
            try {
                IOUtils.copy(contentIn, sourceOut);
                sourceOut.flush();
            } finally {
                sourceOut.close();
                contentIn.close();
            }
            System.out.println(emptySource.getLatestSourceRevision());
        }
        System.out.println("Read again at:" + secondSource.getSourceRevision());
        assertNotNull(emptySource.getSourceRevision());
    }
public void testGetOldVersion() throws ServiceException, IOException, SAXException, ParserConfigurationException {
        JCRNodeSource emptySource = loadTestSource();
        for (int i = 0; i < 3; i++) {
            OutputStream sourceOut = emptySource.getOutputStream();
            InputStream contentIn = getClass().getResourceAsStream(CONTENT_FILE);
            try {
                IOUtils.copy(contentIn, sourceOut);
                sourceOut.flush();
            } finally {
                sourceOut.close();
                contentIn.close();
            }
        }
        String testSourceUri = BASE_URL + "users/lars.trieloff?revision=1.1";
        JCRNodeSource secondSource = (JCRNodeSource) resolveSource(testSourceUri);
        System.out.println("Read again at:" + secondSource.getSourceRevision());
        InputStream expected = emptySource.getInputStream();
        InputStream actual = secondSource.getInputStream();
        assertTrue(isXmlEqual(expected, actual));
    }
public void testCreateNewXMLFile() throws InvalidNodeTypeDefException, ParseException, Exception {
        JCRNodeSource emptySource = loadTestSource();
        assertEquals(false, emptySource.exists());
        OutputStream sourceOut = emptySource.getOutputStream();
        assertNotNull(sourceOut);
        InputStream contentIn = getClass().getResourceAsStream(CONTENT_FILE);
        try {
            IOUtils.copy(contentIn, sourceOut);
            sourceOut.flush();
        } finally {
            sourceOut.close();
            contentIn.close();
        }
        InputStream contentIn2 = getClass().getResourceAsStream(CONTENT2_FILE);
        sourceOut = emptySource.getOutputStream();
        try {
            IOUtils.copy(contentIn2, sourceOut);
            sourceOut.flush();
        } finally {
            sourceOut.close();
            contentIn2.close();
        }
        InputStream expected = getClass().getResourceAsStream(CONTENT2_FILE);
        JCRNodeSource persistentSource = loadTestSource();
        assertEquals(true, persistentSource.exists());
        InputStream actual = persistentSource.getInputStream();
        try {
            assertTrue(isXmlEqual(expected, actual));
        } finally {
            expected.close();
            actual.close();
        }
        JCRNodeSource tmpSrc = (JCRNodeSource) resolveSource(BASE_URL + "users/alexander.saar");
        persistentSource.delete();
        tmpSrc.delete();
    }