semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
@Override
    public void onSensorChanged(SensorEvent event) {
        float values[] = event.values;
        if (httpRequestRunning) {
            return;
        }
        float x = values[0] / SensorManager.GRAVITY_EARTH;
        float y = values[1] / SensorManager.GRAVITY_EARTH;
        float z = values[2] / SensorManager.GRAVITY_EARTH;
        String ip = edtIpAddress.getText().toString();
        String server = new String("http://" + ip + ":8080/ACC/");
        server += String.valueOf(x);
        server += "/";
        server += String.valueOf(y);
        server += "/";
        server += String.valueOf(z);
        final URL url;
        try {
            url = new URL(server);
        } catch (MalformedURLException e) {
            return;
        }
        httpRequestRunning = true;
        handler.post(new Runnable() {

            public void run() {
                try {
                    URLConnection conn = url.openConnection();
                    conn.getInputStream().close();
                } catch (IOException e) {
                }
                httpRequestRunning = false;
            }
        });
    }
public String uploadFile(String url, int port, String uname, String upass, InputStream input) {
        String serverPath = config.getServerPath() + DateUtil.getSysmonth();
        FTPClient ftp = new FTPClient();
        try {
            int replyCode;
            ftp.connect(url, port);
            ftp.login(uname, upass);
            replyCode = ftp.getReplyCode();
            if (!FTPReply.isPositiveCompletion(replyCode)) {
                ftp.disconnect();
                return config.getServerPath();
            }
            if (!ftp.changeWorkingDirectory(serverPath)) {
                ftp.makeDirectory(DateUtil.getSysmonth());
                ftp.changeWorkingDirectory(serverPath);
            }
            ftp.storeFile(getFileName(), input);
            input.close();
            ftp.logout();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return serverPath;
    }
private static void copyFile(File sourceFile, File destFile) throws IOException {
        System.out.println(sourceFile.getAbsolutePath());
        System.out.println(destFile.getAbsolutePath());
        FileChannel source = new FileInputStream(sourceFile).getChannel();
        try {
            FileChannel destination = new FileOutputStream(destFile).getChannel();
            try {
                destination.transferFrom(source, 0, source.size());
            } finally {
                if (destination != null) {
                    destination.close();
                }
            }
        } finally {
            source.close();
        }
    }
public static void copyFile(File src, File dst) {
        try {
            FileInputStream fis = new FileInputStream(src);
            FileOutputStream fos = new FileOutputStream(dst);
            try {
                byte[] buf = new byte[1024];
                int i = 0;
                while ((i = fis.read(buf)) != -1) fos.write(buf, 0, i);
            } catch (IOException e) {
                throw e;
            } finally {
                if (fis != null) fis.close();
                if (fos != null) fos.close();
            }
        } catch (IOException e) {
            logger.error("Error coping file from " + src + " to " + dst, e);
        }
    }
public static void init() {
        if (init_) return;
        init_ = true;
        URLStreamHandler h = new URLStreamHandler() {

            protected URLConnection openConnection(URL _url) throws IOException {
                return new Connection(_url);
            }
        };
        FuLib.setUrlHandler("data", h);
    }
private static long copy(InputStream source, OutputStream sink) {
        try {
            return IOUtils.copyLarge(source, sink);
        } catch (IOException e) {
            throw new FaultException("System error copying stream", e);
        } finally {
            IOUtils.closeQuietly(source);
            IOUtils.closeQuietly(sink);
        }
    }
static void test() throws SQLException {
        Connection conn = null;
        Statement st = null;
        ResultSet rs = null;
        try {
            conn = JdbcUtils.getConnection();
            conn.setAutoCommit(false);
            st = conn.createStatement();
            String sql = "update user set money=money-10 where id=15";
            st.executeUpdate(sql);
            sql = "select money from user where id=13";
            rs = st.executeQuery(sql);
            float money = 0.0f;
            while (rs.next()) {
                money = rs.getFloat("money");
            }
            if (money > 1000) throw new RuntimeException("�Ѿ��������ֵ��");
            sql = "update user set money=money+10 where id=13";
            st.executeUpdate(sql);
            conn.commit();
        } catch (SQLException e) {
            if (conn != null) conn.rollback();
            throw e;
        } finally {
            JdbcUtils.free(rs, st, conn);
        }
    }
private boolean copy(File in, File out) {
        try {
            FileInputStream fis = new FileInputStream(in);
            FileOutputStream fos = new FileOutputStream(out);
            FileChannel readableChannel = fis.getChannel();
            FileChannel writableChannel = fos.getChannel();
            writableChannel.truncate(0);
            writableChannel.transferFrom(readableChannel, 0, readableChannel.size());
            fis.close();
            fos.close();
            return true;
        } catch (IOException ioe) {
            guiBuilder.showError("Copy Error", "IOException during copy", ioe.getMessage());
            return false;
        }
    }
public static void main(String[] args) throws Exception {
        URI uri = new URI("file:/c:/foo.xyz");
        System.err.println(uri);
        uri = new URI("bin.file:/c:/foo.xyz");
        System.err.println(uri);
        uri = new URI("bin.http://c:/foo.xyz");
        System.err.println(uri);
        uri = new URI("bin.http://c:/foo.xyz?x[3:5]");
        System.err.println(uri);
        uri = new File("C:\\Documents and Settings\\jbf\\My Documents\\foo.jy").toURI();
        System.err.println(uri);
        uri = new File("/home/jbf/my%file.txt").toURI();
        System.err.println(uri);
        System.err.println(uri.toURL());
        URL url = uri.toURL();
        InputStream in = url.openStream();
        int ch = in.read();
        while (ch != -1) {
            System.err.print((char) ch);
            ch = in.read();
        }
    }
private static void zip(File d) throws FileNotFoundException, IOException {
        String[] entries = d.list();
        byte[] buffer = new byte[4096];
        int bytesRead;
        ZipOutputStream out = new ZipOutputStream(new FileOutputStream(new File(d.getParent() + File.separator + "dist.zip")));
        for (int i = 0; i < entries.length; i++) {
            File f = new File(d, entries[i]);
            if (f.isDirectory()) continue;
            FileInputStream in = new FileInputStream(f);
            int skipl = d.getCanonicalPath().length();
            ZipEntry entry = new ZipEntry(f.getPath().substring(skipl));
            out.putNextEntry(entry);
            while ((bytesRead = in.read(buffer)) != -1) out.write(buffer, 0, bytesRead);
            in.close();
        }
        out.close();
        FileUtils.moveFile(new File(d.getParent() + File.separator + "dist.zip"), new File(d + File.separator + "dist.zip"));
    }
public static void main(String[] args) {
        String url = "jdbc:mysql://localhost/test";
        String user = "root";
        String password = "password";
        String imageLocation = "C:\\Documents and Settings\\EddyM\\Desktop\\Nick\\01100002.tif";
        String imageLocation2 = "C:\\Documents and Settings\\EddyM\\Desktop\\Nick\\011000022.tif";
        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException ex) {
            ex.printStackTrace();
        }
        try {
            File f = new File(imageLocation);
            InputStream fis = new FileInputStream(f);
            Connection c = DriverManager.getConnection(url, user, password);
            ResultSet rs = c.createStatement().executeQuery("SELECT Image FROM ImageTable WHERE ImageID=12345678");
            new File(imageLocation2).createNewFile();
            rs.first();
            System.out.println("GotFirst");
            InputStream is = rs.getAsciiStream("Image");
            System.out.println("gotStream");
            FileOutputStream fos = new FileOutputStream(new File(imageLocation2));
            int readInt;
            int i = 0;
            while (true) {
                readInt = is.read();
                if (readInt == -1) {
                    System.out.println("ReadInt == -1");
                    break;
                }
                i++;
                if (i % 1000000 == 0) System.out.println(i + " / " + is.available());
                fos.write(readInt);
            }
            c.close();
        } catch (SQLException ex) {
            ex.printStackTrace();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
public static String[] listFilesInJar(String resourcesLstName, String dirPath, String ext) {
        try {
            dirPath = Tools.subString(dirPath, "\\", "/");
            if (!dirPath.endsWith("/")) {
                dirPath = dirPath + "/";
            }
            if (dirPath.startsWith("/")) {
                dirPath = dirPath.substring(1, dirPath.length());
            }
            URL url = ResourceLookup.getClassResourceUrl(Tools.class, resourcesLstName);
            if (url == null) {
                String msg = "File not found " + resourcesLstName;
                Debug.signal(Debug.ERROR, null, msg);
                return new String[0];
            }
            InputStream is = url.openStream();
            BufferedReader in = new BufferedReader(new InputStreamReader(is));
            String name = in.readLine();
            HashSet<String> list = new HashSet<String>(10);
            while (name != null) {
                name = in.readLine();
                if (name == null) {
                    continue;
                }
                if (ext != null && !name.endsWith(ext)) {
                    continue;
                }
                if (name.indexOf('.') == -1 && !name.endsWith("/")) {
                    name = name + "/";
                }
                int index = name.indexOf(dirPath);
                if (index < 0) {
                    continue;
                }
                index += dirPath.length();
                if (index >= name.length() - 1) {
                    continue;
                }
                index = name.indexOf("/", index);
                if (ext != null && (name.endsWith("/") || index >= 0)) {
                    continue;
                } else if (ext == null && (index < 0 || index < name.length() - 1)) {
                    continue;
                }
                list.add("/" + name);
            }
            is.close();
            String[] toReturn = {};
            return list.toArray(toReturn);
        } catch (IOException ioe) {
            String msg = "Error reading file " + resourcesLstName + " caused by " + ioe;
            Debug.signal(Debug.ERROR, null, msg);
            return new String[0];
        }
    }
public void doDelete(Role role) throws Exception {
        Connection con = null;
        PreparedStatement ps = null;
        ResultSet result = null;
        String strEdQuery = "SELECT authority_id from " + Common.ROLE_AUTHORITY_TABLE + " WHERE role_id = ?";
        String strQuery = "DELETE FROM " + Common.ROLE_AUTHORITY_TABLE + " WHERE role_id = ?";
        DBOperation dbo = factory.createDBOperation(POOL_NAME);
        try {
            try {
                con = dbo.getConnection();
                con.setAutoCommit(false);
                ps = con.prepareStatement(strEdQuery);
                ps.setInt(1, role.getRoleID());
                result = ps.executeQuery();
                while (result.next()) {
                    int authID = result.getInt("authority_id");
                    Authority auth = new Authority(authID);
                    auth.load();
                    AssignLog aLog = new AssignLog();
                    aLog.setLogNO(aLog.getNewLogNo());
                    aLog.setID(authID);
                    aLog.setName(auth.getAuthorityName());
                    aLog.setAssignType(AssignLog.ASSIGN_AUTHORITY);
                    aLog.setAssignDate(Translate.getSysTime());
                    aLog.setAssignFrom(this.provider.getUserID());
                    aLog.setAssignFromName(this.provider.getUserName());
                    aLog.setAssignTo(role.getRoleID());
                    aLog.setAssignToName(role.getRoleName());
                    aLog.setReceiverType(AssignLog.RECEIVER_ROLE);
                    aLog.setInfo("ɾ���ɫ�е�Ȩ��");
                    aLog.setPath("");
                    aLog.setPathName("");
                    aLog.doUpdateOrNew(con);
                }
                ps = con.prepareStatement(strQuery);
                ps.setInt(1, role.getRoleID());
                int resultCount = ps.executeUpdate();
                if (resultCount < 0) {
                    con.rollback();
                    throw new CesSystemException("RoleAuthority.doDelete(role): ERROR deleting data in T_SYS_ROLE_AUTHORITY!! " + "resultCount = " + resultCount);
                }
                con.commit();
            } catch (SQLException se) {
                con.rollback();
                throw new CesSystemException("RoleAuthority.doDelete(role): SQLException while deleting Role_authority; " + " role_id = " + role.getRoleID() + " :\n\t" + se);
            } finally {
                con.setAutoCommit(true);
                close(dbo, ps, result);
            }
        } catch (SQLException sqle) {
            throw new CesSystemException("RoleAuthority.doDelete(role): SQLException while committing or rollback");
        }
    }
public void copyFile(File in, File out) throws Exception {
        FileChannel sourceChannel = new FileInputStream(in).getChannel();
        FileChannel destinationChannel = new FileOutputStream(out).getChannel();
        sourceChannel.transferTo(0, sourceChannel.size(), destinationChannel);
        sourceChannel.close();
        destinationChannel.close();
    }
private int resourceToString(String aFile, StringBuffer aBuffer) {
        int cols = 0;
        URL url = getClass().getResource(aFile);
        try {
            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
            String line = "";
            do {
                line = in.readLine();
                if (line != null) {
                    if (line.length() > cols) cols = line.length();
                    aBuffer.append(line);
                    aBuffer.append('\n');
                }
            } while (line != null);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return cols;
    }
public static void copyFile(File in, File out) {
        try {
            FileChannel inChannel = null, outChannel = null;
            try {
                out.getParentFile().mkdirs();
                inChannel = new FileInputStream(in).getChannel();
                outChannel = new FileOutputStream(out).getChannel();
                outChannel.transferFrom(inChannel, 0, inChannel.size());
            } finally {
                if (inChannel != null) {
                    inChannel.close();
                }
                if (outChannel != null) {
                    outChannel.close();
                }
            }
        } catch (Exception e) {
            ObjectUtils.throwAsError(e);
        }
    }
private InputStream openStreamRaw(String filename) {
        InputStream stream = null;
        if (filename == null) return null;
        if (filename.length() == 0) {
            return null;
        }
        try {
            URL url = new URL(filename);
            stream = url.openStream();
            return stream;
        } catch (MalformedURLException mfue) {
        } catch (FileNotFoundException fnfe) {
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
        ClassLoader cl = getClass().getClassLoader();
        stream = cl.getResourceAsStream("data/" + filename);
        if (stream != null) {
            String cn = stream.getClass().getName();
            if (!cn.equals("sun.plugin.cache.EmptyInputStream")) {
                return stream;
            }
        }
        stream = cl.getResourceAsStream(filename);
        if (stream != null) {
            String cn = stream.getClass().getName();
            if (!cn.equals("sun.plugin.cache.EmptyInputStream")) {
                return stream;
            }
        }
        return stream;
    }
private void copyIconFiles(UmlClass clazz) {
        if (clazz.hasAnnotation("icon16")) {
            String i16 = clazz.annotationValue("icon16");
            String fileType = ".png";
            if (i16.endsWith(".jpg")) fileType = ".jpg";
            if (i16.endsWith(".gif")) fileType = ".gif";
            String desti16 = output_dir + "/../resources/images/" + clazz.getName() + "16" + fileType;
            try {
                FileChannel src = new FileInputStream(i16).getChannel();
                FileChannel dst = new FileOutputStream(desti16).getChannel();
                dst.transferFrom(src, 0, src.size());
                src.close();
                dst.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if (clazz.hasAnnotation("icon32")) {
            String i32 = clazz.annotationValue("icon32");
            String fileType = ".png";
            if (i32.endsWith(".jpg")) fileType = ".jpg";
            if (i32.endsWith(".gif")) fileType = ".gif";
            String desti32 = output_dir + "/../resources/images/" + clazz.getName() + "32" + fileType;
            try {
                FileChannel src = new FileInputStream(i32).getChannel();
                FileChannel dst = new FileOutputStream(desti32).getChannel();
                dst.transferFrom(src, 0, src.size());
                src.close();
                dst.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
public static String downloadWebpage1(String address) throws MalformedURLException, IOException {
		URL url = new URL(address);
		BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
		String line;
		String page = "";
		while((line = br.readLine()) != null) {
			page += line + "\n";
		}
		br.close();
		return page;
	}
public static String downloadWebpage2(String address) throws MalformedURLException, IOException {
		URL url = new URL(address);
		HttpURLConnection conn = (HttpURLConnection) url.openConnection();
		HttpURLConnection.setFollowRedirects(true);
		String encoding = conn.getContentEncoding();
		InputStream is = null;
		if(encoding != null && encoding.equalsIgnoreCase("gzip")) {
			is = new GZIPInputStream(conn.getInputStream());
		} else if (encoding != null && encoding.equalsIgnoreCase("deflate")) {
			is = new InflaterInputStream(conn.getInputStream());
		} else {
			is = conn.getInputStream();
		}
		BufferedReader br = new BufferedReader(new InputStreamReader(is));
		String line;
		String page = "";
		while((line = br.readLine()) != null) {
			page += line + "\n";
		}
		br.close();
		return page;
	}
public static String downloadWebpage3(String address) throws ClientProtocolException, IOException {
		HttpClient client = HttpClientBuilder.create().build();
		HttpGet request = new HttpGet(address);
		HttpResponse response = client.execute(request);
		BufferedReader br = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
		String line;
		String page = "";
		while((line = br.readLine()) != null) {
			page += line + "\n";
		}
		br.close();
		return page;
	}
public static void copyFile1(File srcFile, File destFile) throws IOException {
		if(!destFile.exists()) {
			destFile.createNewFile();
		}
		
		FileInputStream fis = new FileInputStream(srcFile);
		FileOutputStream fos = new FileOutputStream(destFile);
		
		FileChannel source = fis.getChannel();
		FileChannel destination = fos.getChannel();
		
		destination.transferFrom(source, 0, source.size());
		
		source.close();
		destination.close();
		
		fis.close();
		fos.close();
	}
public static void copyFile3(File srcFile, File destFile) throws IOException {
		InputStream in = new FileInputStream(srcFile);
		OutputStream out = new FileOutputStream(destFile);
		
		byte[] buf = new byte[1024];
		int len;
		while((len = in.read(buf)) > 0) {
			out.write(buf, 0, len);
		}
		in.close();
		out.close();
	}
public static void copyFile4(File srcFile, File destFile) throws IOException {
		InputStream in = new FileInputStream(srcFile);
		OutputStream out = new FileOutputStream(destFile);
		IOUtils.copy(in, out);
		in.close();
		out.close();
	}
public static void copyFile5(File srcFile, File destFile) throws IOException {
		InputStream in = new FileInputStream(srcFile);
		OutputStream out = new FileOutputStream(destFile);
		IOUtils.copyLarge(in, out);
		in.close();
		out.close();
	}
public static void copyFile6(File srcFile, File destFile) throws FileNotFoundException {
		Scanner s = new Scanner(srcFile);
		PrintWriter pw = new PrintWriter(destFile);
		while(s.hasNextLine()) {
			pw.println(s.nextLine());
		}
		pw.close();
		s.close();
	}
public static void unzip1(File zipfile, File outputdir) throws IOException {
		//Buffer for copying the files out of the zip input stream
		byte[] buffer = new byte[1024];
				
		//Create parent output directory if it doesn't exist
		if(!outputdir.exists()) {
			outputdir.mkdirs();
		}
				
		//Create the zip input stream
		//OR ArchiveInputStream zis = new ArchiveStreamFactory().createArchiveInputStream(ArchiveStreamFactory.ZIP, new FileInputStream(zipfile));
		ArchiveInputStream zis = new ZipArchiveInputStream(new FileInputStream(zipfile));
		
		//Iterate through the entries of the zip file, and extract them to the output directory
		ArchiveEntry ae = zis.getNextEntry(); // OR zis.getNextZipEntry()
		while(ae != null) {
			//Resolve new file
			File newFile = new File(outputdir + File.separator + ae.getName());
			
			//Create parent directories if not exists
			if(!newFile.getParentFile().exists())
				newFile.getParentFile().mkdirs();
			
			if(ae.isDirectory()) { //If directory, create if not exists
				if(!newFile.exists())
					newFile.mkdir();
			} else { //If file, write file
				FileOutputStream fos = new FileOutputStream(newFile);
				int len;
				while((len = zis.read(buffer)) > 0) {
					fos.write(buffer, 0, len);
				}
				fos.close();
			}
			
			//Proceed to the next entry in the zip file
			ae = zis.getNextEntry();
		}
		
		//Cleanup
		zis.close();
	}
public static void unzip2(File zipfile, File outputdir) throws IOException {
		//Buffer for extracting files
		byte[] buffer = new byte[1024];
				
		//Zip file
		ZipFile zip = new ZipFile(zipfile);
				
		//Get entries
		Enumeration<ZipArchiveEntry> files = zip.getEntries();
				
		//Iterate through the entries
		while(files.hasMoreElements()) {
			//Get entry
			ZipArchiveEntry ze = files.nextElement();
					
			//Resolve entry file
			File newFile = new File(outputdir + File.separator + ze.getName());
					
			//Make parent directories
			newFile.getParentFile().mkdirs();
					
			if(ze.isDirectory()) { //If directory, create it
				newFile.mkdir();
			} else { //If file, extract it
				InputStream is = zip.getInputStream(ze);
				FileOutputStream fos = new FileOutputStream(newFile);
				int len;
				while((len = is.read(buffer)) > 0) {
					fos.write(buffer, 0, len);
				}
				fos.close();
				is.close();
			}	
		}
				
		//Cleanup
		zip.close();
	}
public FTPClient sample1a(String server, int port, String username, String password) throws SocketException, IOException {
		FTPClient ftpClient = new FTPClient();
		ftpClient.connect(server, port);
		ftpClient.login(username, password);
		return ftpClient;
	}