小编Avi*_*Avi的帖子

WebClient与HttpWebRequest/HttpWebResponse

在我看来,大部分可以完成的事情HttpWebRequest/Response也可以在WebClient课堂上完成.我读到的地方WebClient是一个高级包装器WebRequest/Response.
到目前为止,我无法看到任何无法实现的功能HttpWebRequest/Response,也无法看到WebClientHttpWebRequest/Response将为您提供更多"细粒度"控件.

我何时应该使用WebClient HttpWebRequest/Response?何时?(显然,HttpWebRequest/Response是HTTP特定的.)

如果HttpWebRequest/Response是较低级别那么WebClient,HttpWebRequest/Response我能用不能实现的目标完成WebClient什么?

.net webclient httpwebrequest httpwebresponse

132
推荐指数
7
解决办法
5万
查看次数

了解spring @Configuration类

了解了Spring @Autowired用法的问题之后,我想为另一个弹簧布线选项(@Configuration该类)创建一个完整的知识库.

假设我有一个如下所示的spring XML文件:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
  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.0.xsd">

  <import resource="another-application-context.xml"/>

  <bean id="someBean" class="stack.overflow.spring.configuration.SomeClassImpl">
    <constructor-arg value="${some.interesting.property}" />
  </bean>

  <bean id="anotherBean" class="stack.overflow.spring.configuration.AnotherClassImpl">
    <constructor-arg ref="someBean"/>
    <constructor-arg ref="beanFromSomewhereElse"/>
  </bean>
</beans>
Run Code Online (Sandbox Code Playgroud)

我该怎么用@Configuration呢?它对代码本身有什么影响吗?

java configuration spring autowired

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

将毫秒转换为分钟和秒?

我查看过以前的问题,但没有人得到我想要的答案.如何将StopWatch方法的毫秒转换为分钟和秒?我有:

 watch.start();
Run Code Online (Sandbox Code Playgroud)

启动秒表和

  watch.stop();
Run Code Online (Sandbox Code Playgroud)

停下手表 我以后有

  watch.getTime();
Run Code Online (Sandbox Code Playgroud)

返回毫秒.我希望它能在秒和分钟内返回.我该怎么做呢?我正在寻找一种方法来做到这一点,而不是乘以/除以1000,而是一种方法,使整个计算更具可读性,更不容易出错.

java time stopwatch type-conversion watch

65
推荐指数
12
解决办法
18万
查看次数

如何修复错误的URI不是URI

我正在使用ruby版本1.9.3,我喜欢从下面的视频网址获取主机名,

我试过代码

require 'uri'
url = "https://ferrari-view.4me.it/view-share/playerp/?plContext=http://ferrari-%201363948628-stream.4mecloud.it/live/ferrari/ngrp:livegenita/manifest.f4m&cartellaConfig=http://ferrari-4me.weebo.it/static/player/config/&cartellaLingua=http://ferrari-4me.weebo.it/static/player/config/&poster=http://pusher.newvision.it:8080/resources/img1.jpg&urlSkin=http://ferrari-4me.weebo.it/static/player/swf/skin.swf?a=1363014732171&method=GET&target_url=http://ferrari-4me.weebo.it/static/player/swf/player.swf&userLanguage=IT&styleTextColor=#000000&autoPlay=true&bufferTime=2&isLive=true&highlightColor=#eb2323&gaTrackerList=UA-23603234-4"  
puts URI.parse(url).host  
Run Code Online (Sandbox Code Playgroud)

它抛出异常URI :: InvalidURIError:错误的URI(不是URI?):

我尝试使用编码URL然后解析如下

puts URI.parse(URI.parse(url)).host
Run Code Online (Sandbox Code Playgroud)

它抛出异常相同 URI::InvalidURIError: bad URI(is not URI?)

但上面的代码适用于以下URL.

url = http://www.youtube.com/v/GpQDa3PUAbU?version=3&autohide=1&autoplay=1

如何解决这个问题?任何建议请.谢谢

ruby uri ruby-on-rails-3

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

在Java文件中定义包的目的是什么?

我是新手,刚学会了如果我定义说

package my.first.group.here;
...
Run Code Online (Sandbox Code Playgroud)

然后,此包中的Java文件将放在my/first/group/here目录下.

将一些Java文件放入包中的主要目的是什么?另外,如果我选择采用这个,我应该如何分组呢?

谢谢


编辑:对于可能再次遇到相同问题的人,我刚刚 Sun的软件包上找到了这个教程.

java package

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

"this()"方法是什么意思?

我遇到了这段代码,有一条我不放弃了解它的含义或它正在做什么.

public Digraph(In in) {
    this(in.readInt()); 
    int E = in.readInt();
    for (int i = 0; i < E; i++) {
        int v = in.readInt();
        int w = in.readInt();
        addEdge(v, w); 
    }
}
Run Code Online (Sandbox Code Playgroud)

我明白了什么this.method()this.variable有,但什么是this()

java constructor this constructor-overloading

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

UILocalNotification自定义声音不在iOS7中播放

我正在UILocalNotification申请中使用.

在应用程序中有两种声音有条件地播放 - 我已经为它们应用了适当的条件.

但是当我安装应用程序并在iOS 7设备上运行它时,它会触发本地通知,但声音不会在应用程序中播放.

下面给出了代码来设置通知:

    UILocalNotification *localNotification = [[UILocalNotification alloc] init];
    if (localNotification == nil)
        return;
    localNotification.fireDate = [pickerView date];

    localNotification.timeZone = [NSTimeZone defaultTimeZone];

    if (alarm_number == 1) {
        localNotification.alertBody = [NSString stringWithFormat:@"First Alarm"];
    }
    else
    {
        localNotification.alertBody = [NSString stringWithFormat:@"Second Alarm"];
    }

    localNotification.alertAction =@"Ok";

    NSString *message = [[NSString alloc]initWithString:@""];

    if(alarm_number == 1)
    {
        localNotification.soundName=@"Alarm_1.mp3";
        message = @"First Alarm Scheduled";
    }
    else
    {
        localNotification.soundName=@"Alarm_2.mp3";
        message = @"Second Alarm Scheduled";
    }

    localNotification.applicationIconBadgeNumber = 1;

    // …
Run Code Online (Sandbox Code Playgroud)

iphone audio ios uilocalnotification ios7

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

请求中包含的安全令牌已过期

我有一个脚本可以从 Cloudwatch 中提取大量指标用于我们自己的内部报告。

该脚本迭代特定区域中的所有 EC2 实例,并要求提供过去 2 周的 5 个 cloudwatch 指标(所有可用统计数据)(每 5 天间隔 5 分钟,正好是 1440 配额)。我正在使用一个假设的会话:

session = Session(aws_access_key_id=AWS_ACCESS_KEY_ID, aws_secret_access_key=AWS_SECRET_ACCESS_KEY, region_name=regionName)
sts = session.client('sts')
response = sts.assume_role(
    RoleArn=arn, # External role arn
    RoleSessionName='role-name',
    ExternalId='<some-id-here>',
)
tempAccessKeyId = response['Credentials']['AccessKeyId']
tempSecretAccessKey = response['Credentials']['SecretAccessKey']
tempSessionToken = response['Credentials']['SessionToken']
assumedSession = Session(
    aws_access_key_id=tempAccessKeyId,
    aws_secret_access_key=tempSecretAccessKey,
    aws_session_token=tempSessionToken,
    region_name=regionName)
Run Code Online (Sandbox Code Playgroud)

在运行脚本时,我遇到了这个异常:

botocore.exceptions.ClientError: An error occurred (ExpiredToken) when calling the GetMetricStatistics operation: The security token included in the request is expired
Run Code Online (Sandbox Code Playgroud)

有没有办法确保令牌在运行脚本时不会过期?我正在使用 boto3。

amazon-web-services boto3

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

使用某个接口注入所有bean的列表

我有一个@Component看起来像这样的类(bean):

@Component
public class EntityCleaner {

    @Autowired
    private List<Cleaner> cleaners;

    public void clean(Entity entity) {
         for (Cleaner cleaner: cleaners) {
             cleaner.clean(entity);
         }
    }
}
Run Code Online (Sandbox Code Playgroud)

Cleaner 是一个界面,我有一些清洁器,我希望它们都能运行(不介意顺序)。今天我做这样的事情:

 @Configuration
 public class MyConfiguration {
     @Bean
     public List<Cleaner> businessEntityCleaner() {
         List<Cleaner> cleaners = new ArrayList<>();
         cleaners.add(new Cleaner1());
         cleaners.add(new Cleaner2());
         cleaners.add(new Cleaner3());
         // ... More cleaners here

         return cleaners;
     }
 }
Run Code Online (Sandbox Code Playgroud)

有没有办法在不定义配置中的特殊方法的情况下构建这个列表?只是那个 spring 自动神奇地找到所有实现Cleaner接口的类,创建列表并将其注入EntityCleaner

java spring dependency-injection

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

为Factory类创建的对象注入Mocks

我有以下课程:

public class MyClass {        
    private Apple apple;

    public void myMethod() {
       apple = AppleFactory.createInstance(someStringVariable);
       ....
       ....
       ....
    }
}
Run Code Online (Sandbox Code Playgroud)

和测试类:

@RunWith(MockitoJUnitRunner.class)
public class MyClassTest {

        @InjectMocks 
        MyClass myClass;

        @Test
        public void myMethod(){
         ...
         ...
         ...
        }
    }
Run Code Online (Sandbox Code Playgroud)

我如何在MyClass中注入Apple实例作为模拟?

java junit spring mockito

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