NumberFormatException当我尝试解析265,858时,我得到了Integer.parseInt().
有没有办法将其解析为整数?
我正在使用kafka将网站用户的页面访问事件流式传输到分析服务.每个事件将包含消费者的以下详细信息:
我需要非常高的吞吐量,所以我决定使用分区键将主题分区为userId-ipAddress
ie
对于userId 1000和ip地址10.0.0.1,该事件的分区键为"1000-10.0.0.1"
在此用例中,分区键是动态的,因此在创建主题时预先指定分区数. 是否可以使用动态分区计数在kafka中创建主题?
使用这种分区是一种好习惯还是有其他方法可以实现这一点?
以下两个代码片段之间有什么区别,
代码1:
<div class={{getClass()}}/>
Run Code Online (Sandbox Code Playgroud)
代码2:
<div ng-class=getClass()/>
Run Code Online (Sandbox Code Playgroud) 这是一个后续问题,为什么不打印此例外?为什么会出现错误?
在下面的代码中为什么没有触发ArithmeticException?
class Exp
{
public static void main(String args[])
{
float d,a=1;
try
{
d=0;
a=44/d; //no exception triggered here.. why?
System.out.print("It's not gonna print: a="+a);
}
catch(ArithmeticException e)
{
System.out.println("Print exception: "+e);
}
}
}
Run Code Online (Sandbox Code Playgroud)
相反,输出如下:
It's not gonna print: a=Infinity
Run Code Online (Sandbox Code Playgroud)
怎么了?
考虑一下BufferedReader,如下所示:
writer = new BufferedWriter(new FileWriter(new File("File.txt"), true));
Run Code Online (Sandbox Code Playgroud)
在这种情况下,在应用程序的结束,我关闭writer与writer.close()
这还够吗?创建的FileWriter new FileWriter(new File("File.txt"), true)不需要关闭吗?
我只是很想知道,在servlet中调用System.out.print()会发生什么?
它在哪里写文字?
或者在servlet中是否有任何重要的System.out用途?
我一直在使用java处理Google OAuth 2.0,并在实现过程中遇到了一些未知错误.
以下用于POST请求的CURL工作正常:
curl -v -k --header "Content-Type: application/x-www-form-urlencoded" --data "code=4%2FnKVGy9V3LfVJF7gRwkuhS3jbte-5.Arzr67Ksf-cSgrKXntQAax0iz1cDegI&client_id=[my_client_id]&client_secret=[my_client_secret]&redirect_uri=[my_redirect_uri]&grant_type=authorization_code" https://accounts.google.com/o/oauth2/token
Run Code Online (Sandbox Code Playgroud)
并产生所需的结果.
但是以下在java中执行上面的POST请求会导致一些错误和响应"invalid_request"
请检查以下代码并指出这里出错:(使用Apache http组件)
HttpPost post = new HttpPost("https://accounts.google.com/o/oauth2/token");
HttpParams params = new BasicHttpParams();
params.setParameter("code", code);
params.setParameter("client_id", client_id);
params.setParameter("client_secret", client_secret);
params.setParameter("redirect_uri", redirect_uri);
params.setParameter("grant_type", grant_type);
post.addHeader("Content-Type", "application/x-www-form-urlencoded");
post.setParams(params);
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpResponse response = httpClient.execute(post);
Run Code Online (Sandbox Code Playgroud)
试过URLEncoder.encode( param , "UTF-8")每个参数,但这也不起作用.
可能是什么原因?
我有一个带有配置文件的spring应用程序,如下所示.所有的配置似乎都是正确的,但在调试时我发现,在初始化期间,spring为FilterSecurityInterceptor创建了两个bean,没有任何拦截 - url规则,另一个有我指定的规则. 当请求到来时,它使用FilterSecurityInterceptor bean而没有intercept-url规则.所以我看到以下日志:
DEBUG FilterSecurityInterceptor:183 - Public object - authentication not attempted
Run Code Online (Sandbox Code Playgroud)
但请求URL属于拦截URL规则.我调试,发现这是因为所使用的豆没有任何拦截规则httpMethodMap的DefaultFilterInvocationSecurityMetadataSource.我不确定这里有什么问题.
以下是applicationContext-security.xml:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:security="http://www.springframework.org/schema/security"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd"
default-init-method="init">
<security:authentication-manager alias="authenticationManager">
<security:authentication-provider
user-service-ref="userDetailService">
</security:authentication-provider>
</security:authentication-manager>
<alias name="filterChainProxy" alias="springSecurityFilterChain" />
<bean id="accessDecisionManager"
class="org.springframework.security.access.vote.AffirmativeBased">
<property name="decisionVoters">
<list>
<bean class="org.springframework.security.access.vote.RoleVoter" />
<bean class="org.springframework.security.access.vote.AuthenticatedVoter" />
</list>
</property>
</bean>
<bean id="consoleAuthenticationSuccessHandler"
class="custom_class">
<property name="defaultTargetUrl" value="/loginSuccess.htm" />
<property name="targetUrlParameter" value="targetURL" />
</bean>
<bean id="consoleAuthenticationFailureHandler"
class="custom_class">
<property name="loginFailureUrl" value="/loginFailure.htm" />
</bean>
<bean id="consoleLogoutSuccessHandler"
class="custom_class"> …Run Code Online (Sandbox Code Playgroud) 在Google App Engine中,GQL(类似SQL的数据存储查询机制)仅适用于Python项目,而不适用于Java项目.为什么会这样?
还有它在那里克服这个并在Java项目中使用GQL也?
java ×7
exception ×2
angularjs ×1
apache-kafka ×1
database ×1
file ×1
filewriter ×1
google-oauth ×1
gql ×1
jsp ×1
mongodb ×1
mongodb-java ×1
ng-class ×1
partitioning ×1
post ×1
python ×1
servlets ×1
spring ×1
spring-mvc ×1
stream ×1
system.out ×1