小编Ash*_*win的帖子

使用安全随机生成一个长号

我用长数字播种了我的安全随机对象.现在我想提取另一个长数字.但是只有一个叫做nextBytes(byte[] b)随机的函数byte[].

有没有办法得到一个长号?

SecureRandom ranGen1 = new SecureRandom();
   ranGen1.setSeed(1000);
   SecureRandom ranGen2 = new SecureRandom();
   ranGen2.setSeed(1000);
   byte[] b1= new byte[3];
   byte[] b2=new byte[3];
   ranGen1.nextBytes(b1);
   ranGen2.nextBytes(b2);
   int a1=b1[0];
   int a2=b1[1];
   int a3=b1[2];

   int c1=b2[0];
   int c2=b2[1];
   int c3=b2[2];

   System.out.println(a1+", "+a2+", "+a3);//genearated by ranGen1
   System.out.println(c1+", "+c2+", "+c3);//generated by ranGen2

   System.out.println(ranGen1.nextLong());//genearated by ranGen1
Run Code Online (Sandbox Code Playgroud)

System.out.println(ranGen2.nextLong()); //由ranGen2生成

结果:

4, -67, 69
4, -67, 69

   -3292989024239613972  //this is using nextLong()
-3292989024239613972 
Run Code Online (Sandbox Code Playgroud)

Peter Lawrey的代码输出:(使用安全随机)

-7580880967916090810 -7580880967916090810
7364820596437092015 7364820596437092015
6152225453014145174 6152225453014145174
6933818190189005053 6933818190189005053
-2602185131584800869 -2602185131584800869 …
Run Code Online (Sandbox Code Playgroud)

java random

4
推荐指数
1
解决办法
1万
查看次数

在 android 和 windows 中使用 sha1prng 给出不同的序列

我在我的 android 程序和 java 程序中都使用了 sha1prng 作为伪随机数生成器算法。我用相同的值播种了它们。

但是android生成的sequesnce和java生成的不一样。为什么会发生这种情况以及解决此问题的方法是什么?

java android

3
推荐指数
1
解决办法
655
查看次数

int中没有返回PostgreSQL错误代码?

我把我的java程序连接到postgresql.我想检索sqlexception的错误代码.我在这里找到了postgresql的错误代码 .

但是Java SQLException只包含以int形式返回的错误代码的方法getErrorCode()

但链接中的错误代码不是int类型.我在哪里可以获得postgresql的int错误代码?`

postgresql jdbc

3
推荐指数
1
解决办法
1949
查看次数

如何将CSS中的span元素居中?

我有三个<span>元素,我想一个接一个地水平放置.我还需要将中间元素放在页面的中心(水平),但margin:auto; width: 100px由于它是a ,因此不能正常工作<span>.如果我这样做<div>,就会有一个换行符.

我该如何解决这个问题?

html css

3
推荐指数
1
解决办法
3万
查看次数

如何更新通知而不影响待处理的意图及其有效负载?

我正在使用以下代码创建通知:

Intent intent = new Intent(this, GetStockQuote.class);
            intent.putExtra("abc", abcObject);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);

            /* Build the notification */
            Notification notification = new Notification.Builder(this)
                                     .setContentTitle(abcObject.getCode())
                                     .setContentText(abcObject.getText())
                                     .setAutoCancel(false)
                                     .setSmallIcon(R.drawable.ic_launcher)
                                     .setContentIntent(pIntent).build();
 NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
            notificationManager.notify(notificationID,notification);
            Log.i(TAG,"notification.notified");
Run Code Online (Sandbox Code Playgroud)

如您所见,PendingIntent附加到通知的有效载荷.它是自定义类的对象.

现在我更新服务中的通知.我知道如果你必须更新通知(不创建新通知),你必须指定notificationID我正在做的相同.

这是用于更新上面创建的通知的服务中的代码:

Intent intent = new Intent(this, GetStockQuote.class);
                PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);   
 Notification notification=new Notification.Builder(this)
                                .setContentTitle(newTitle)
                                .setContentText(newBody)
                                .setSmallIcon(R.drawable.ic_launcher)
                                .setContentIntent(pIntent)
                                .build();

                /*Get instance of Notification Manager and show the notification*/
                        NotificationManager notificationManager = (NotificationManager) …
Run Code Online (Sandbox Code Playgroud)

android android-pendingintent

3
推荐指数
1
解决办法
998
查看次数

无法减少kotlin中的布尔值列表

我试图映射到布尔值并减少kotlin.这是我的代码

class Model{
 fun isEmpty() : Boolean
}


list.asSequence().map { model ->
      {
        model.isEmpty()
      }
     }.reduce { acc, next -> (acc && next)}
Run Code Online (Sandbox Code Playgroud)

但编译器给我一个错误的告诉

Type mismatch required () Boolean? but found Boolean
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?我希望我没有做任何概念错误的事情

android kotlin kotlin-android-extensions

3
推荐指数
1
解决办法
804
查看次数

子组件(无作用域)不能引用作用域绑定:@Singleton @Provides @org.jetbrains.annotations.NotNull

我正在使用匕首 2.11

模块

@Module
class MyModule {
    @Provides
    fun provideString() : String = "yo"
    @Provides @Named("injector")
    fun provideInzectorString() : String = "named_injection"

    @Singleton @Provides //The error goes away if I remove @Singleton
    fun provideRepository() = Repository(Interceptor(),"")
}
Run Code Online (Sandbox Code Playgroud)

活动绑定模块

@Module
abstract class ActivityBindingModule {
    @ContributesAndroidInjector(modules = [MyModule::class])
     abstract fun suggestionActivity() : SuggestionsActivity

    @ContributesAndroidInjector(modules = [MyModule::class])
    abstract fun editSubscriptionActivity() : SubscribeActivity
}
Run Code Online (Sandbox Code Playgroud)

应用组件

@Singleton
@Component(modules = {
        AndroidInjectionModule.class,
        MyModule.class
})
interface AppComponent {
    @Component.Builder
    interface Builder {
        @BindsInstance
        Builder application(MyApplication application);

        AppComponent …
Run Code Online (Sandbox Code Playgroud)

singleton android dagger dagger-2

3
推荐指数
1
解决办法
2699
查看次数

什么是xml签名中的规范化?

什么是xml签名中使用的规范化标记.它存在于<signed info>元素中.我通过网络浏览了各种文件.但是所有这些都太抽象了,我无法理解.如果有人可以解释规范化标签中应该包含哪些内容以及应该如何使用它将会有所帮助?
我对<signature value>元素也有疑问.它包含什么签名?

xml xml-signature

2
推荐指数
1
解决办法
2048
查看次数

初始化一次数据库连接对象并重用它 - jboss

我使用jboss服务器和postgresql作为数据库.现在我每次都在servlet中连接到数据库,如下所示:

public void doPost(HttpServletRequest req, HttpServletResponse resp)
{
Connection conn =null; // Create connection object
             String database = "jbossdb"; // Name of database
             String user = "qwerty"; //
             String password = "qwerty";
             String url = "jdbc:postgresql://localhost:5432/" + database;
             ResultSet rs = null;
             ResultSetMetaData rsm = null;
             ObjectInputStream in=new ObjectInputStream(req.getInputStream());
             String input=(String) in.readObject();
             String[] s_input=input.split(",");

              try{
                    Class.forName("org.postgresql.Driver").newInstance();
                    //.newInstance()
                 } catch(Exception e) 
                    {
                    System.err.println(e);
                    }

            try{
                conn = DriverManager.getConnection(url, user, password);

                }catch(SQLException se) 
                 {
                        System.err.println(se);
                 }
Run Code Online (Sandbox Code Playgroud)

这个代码存在于我的每个服务中.对于每个请求,都会创建一个新的连接对象.这会影响性能吗?在jboss中是否有任何方法只能初始化连接(可能在启动时),然后在需要时传递给servlet?我应该把它放在init()servlet 的方法中吗?

java jboss servlets

2
推荐指数
2
解决办法
1万
查看次数

Clojure中#的含义

在clojure中,您可以使用以下命令创建匿名函数 #

例如

#(+ % 1) 
Run Code Online (Sandbox Code Playgroud)

是一个接受参数并将其加1的函数。

但是我们也必须使用#正则表达式,例如

(clojure.string/split "hi, buddy" #",")
Run Code Online (Sandbox Code Playgroud)

这两个有#关系吗?

clojure

2
推荐指数
1
解决办法
164
查看次数