Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
Y
yzg-util
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
YZG
yzg-util
Commits
a6b4d3a6
Commit
a6b4d3a6
authored
Apr 15, 2019
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
消费者自动创建
parent
f6fdb0b5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
60 additions
and
13 deletions
+60
-13
UrlHelper.java
.../src/main/java/com/yanzuoguang/util/helper/UrlHelper.java
+60
-13
No files found.
yzg-util-base/src/main/java/com/yanzuoguang/util/helper/UrlHelper.java
View file @
a6b4d3a6
...
...
@@ -2,8 +2,10 @@ package com.yanzuoguang.util.helper;
import
com.yanzuoguang.util.exception.CodeException
;
import
java.net.URLDecoder
;
import
java.net.URLEncoder
;
import
java.net.*
;
import
java.util.ArrayList
;
import
java.util.Enumeration
;
import
java.util.List
;
/**
* 地址字符串处理
...
...
@@ -12,15 +14,15 @@ public class UrlHelper {
/**
* 转换为%E4%BD%A0形式
*
* @param
s
* @param encoding
* @return
* @param
from 来源字符串
* @param encoding
编码方式
* @return
转换后的结果
*/
public
static
String
encoding
(
String
s
,
String
encoding
)
{
public
static
String
encoding
(
String
from
,
String
encoding
)
{
try
{
StringBuffer
sb
=
new
StringBuffer
();
for
(
int
i
=
0
;
i
<
s
.
length
();
i
++)
{
char
c
=
s
.
charAt
(
i
);
for
(
int
i
=
0
;
i
<
from
.
length
();
i
++)
{
char
c
=
from
.
charAt
(
i
);
if
(
c
>=
0
&&
c
<=
255
)
{
sb
.
append
(
c
);
}
else
{
...
...
@@ -37,15 +39,60 @@ public class UrlHelper {
/**
* 将%E4%BD%A0转换为汉字
*
* @param
s
* @param encoding
* @return
* @param
from 来源字符串
* @param encoding
编码方式
* @return
转换后的结果
*/
public
static
String
decoding
(
String
s
,
String
encoding
)
{
public
static
String
decoding
(
String
from
,
String
encoding
)
{
try
{
return
URLDecoder
.
decode
(
s
,
encoding
);
return
URLDecoder
.
decode
(
from
,
encoding
);
}
catch
(
Exception
ex
)
{
throw
new
CodeException
(
ex
);
}
}
/**
* 获取IP
*
* @return 获取到的IP
*/
public
static
String
getIp
()
{
List
<
String
>
ips
=
getIps
();
if
(
ips
.
size
()
==
1
)
{
return
ips
.
get
(
0
);
}
for
(
String
ip
:
ips
)
{
if
(
ip
.
equals
(
"127.0.0.1"
)
||
ip
.
equals
(
"0.0.0.0"
))
{
continue
;
}
return
ip
;
}
return
StringHelper
.
EMPTY
;
}
/**
* 获取IP列表
*
* @return IP结果
*/
public
static
List
<
String
>
getIps
()
{
List
<
String
>
ipList
=
new
ArrayList
<
String
>();
try
{
Enumeration
<
NetworkInterface
>
networkInterfaces
=
NetworkInterface
.
getNetworkInterfaces
();
while
(
networkInterfaces
.
hasMoreElements
())
{
NetworkInterface
networkInterface
=
networkInterfaces
.
nextElement
();
Enumeration
<
InetAddress
>
inetAddresses
=
networkInterface
.
getInetAddresses
();
while
(
inetAddresses
.
hasMoreElements
())
{
InetAddress
inetAddress
=
inetAddresses
.
nextElement
();
if
(
inetAddress
!=
null
&&
inetAddress
instanceof
Inet4Address
)
{
// IPV4
String
ip
=
inetAddress
.
getHostAddress
();
ipList
.
add
(
ip
);
}
}
}
}
catch
(
SocketException
e
)
{
e
.
printStackTrace
();
}
return
ipList
;
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment