Last active
May 10, 2022 04:56
-
-
Save kopstill/59d70d8194455d51d7dfddc9e95f61c5 to your computer and use it in GitHub Desktop.
demo java code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static boolean isOdd(int val) { | |
return (val & 1) != 0; | |
} | |
public static boolean isEven(int val) { | |
return !isOdd(val); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static boolean isSameDate(String date) throws ParseException { | |
Date today = new Date(); | |
Date target = DateFormat.getDateInstance().parse(date); | |
Calendar todayCalendar = Calendar.getInstance(); | |
todayCalendar.setTime(today); | |
Calendar targetCalendar = Calendar.getInstance(); | |
targetCalendar.setTime(target); | |
boolean isSameYear = todayCalendar.get(Calendar.YEAR) == targetCalendar.get(Calendar.YEAR); | |
boolean isSameMonth = isSameYear && todayCalendar.get(Calendar.MONTH) == targetCalendar.get(Calendar.MONTH); | |
boolean isSameDate = isSameMonth && todayCalendar.get(Calendar.DAY_OF_MONTH) == targetCalendar.get(Calendar.DAY_OF_MONTH); | |
return isSameDate; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void proxy() throws IOException { | |
URL url = new URL("http://www.test.com/"); | |
InetSocketAddress address = new InetSocketAddress("127.0.0.1", 8080); | |
Proxy proxy = new Proxy(Proxy.Type.HTTP, address); | |
Authenticator.setDefault(new MyAuthenticator(new String("root".getBytes("UTF-8")), new String("password".getBytes("UTF-8")))); | |
HttpURLConnection connection = (HttpURLConnection) url.openConnection(proxy); | |
InputStreamReader in = null; | |
BufferedReader reader = null; | |
try { | |
in = new InputStreamReader(connection.getInputStream()); | |
reader = new BufferedReader(in); | |
StringBuffer buffer = new StringBuffer(); | |
String line; | |
while ((line = reader.readLine()) != null) { | |
buffer.append(line); | |
} | |
System.out.println(buffer); | |
} finally { | |
if (in != null) { | |
in.close(); | |
} | |
if (reader != null) { | |
reader.close(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment