小编t0m*_*13b的帖子

为什么不能在迭代器上下文中使用unsafe关键字?

在看这个问题时,Jon在回答问题方面做得很好......" 如何用迭代器反向读取文本文件 ".并且有一个类似的问题,我回答使用指针hocus pocus ..'.net有一种方法从它自己关闭之前从下到上读取文本文件 ....

现在我开始尝试使用指针来解决这个问题,好吧,它看起来很粗糙和边缘粗糙......

public class ReadChar : IEnumerable<char>
{
    private Stream _strm = null;
    private string _str = string.Empty;
    public ReadChar(string s)
    {
        this._str = s;
    }
    public ReadChar(Stream strm)
    {
        this._strm = strm;
    }
    public IEnumerator<char> GetEnumerator()
    {
        if (this._strm != null && this._strm.CanRead && this._strm.CanSeek)
        {
            return ReverseReadStream();
        }
        if (this._str.Length > 0)
        {
            return ReverseRead();
        }
        return null;
    }

    private IEnumerator<char> ReverseReadStream()
    {
        long lIndex = this._strm.Length;
        while (lIndex != …

c# iterator unsafe

6
推荐指数
2
解决办法
3068
查看次数

需要以编程方式打开蓝牙并在Android中发现设备

我需要通过我的代码打开蓝牙而不要求用户启用它,然后发现范围内的所有设备并返回这些设备,然后关闭蓝牙连接.

怎么做?

android bluetooth

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

Android没有代理无法正常工作?

我需要在我的应用程序中设置无代理的条件; 为此,我使用以下代码:

URL url = null;

try {
    url = new URL(uri.toURL().toString());
} catch (MalformedURLException e3) {
    e3.printStackTrace();
}

try {
    //client = (HttpURLConnection) url.openConnection(java.net.Proxy.NO_PROXY);
    Properties systemProperties = System.getProperties();

    systemProperties.setProperty("http.nonProxyHosts",ServerIP);
    systemProperties.setProperty( "proxySet", "false" );
    systemProperties.setProperty("http.proxyHost","");
    systemProperties.setProperty("http.proxyPort","");
    URLConnection conn = url.openConnection(Proxy.NO_PROXY);


    conn.connect();
} catch (IOException e3) {
    e3.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)

但我得到了网络无法访问的异常!!

任何帮助!!

proxy android httpurlconnection

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

Common data types: How much bytes are they?

I'd like to know how much bytes a

  • 32-bit integer

  • ASCII character (char in C++?)

  • Pointer (4 bytes?)

  • Short

  • Float

Takes up in Delphi, and if it is generally the same in most languages

另外,上面提到的数据类型是否具有恒定的大小?我的意思是整数0,4,123和32231都是相同的大小?

memory delphi

5
推荐指数
2
解决办法
4400
查看次数

LightSwitch - 无法确定目标数据库架构提供程序

在Visual Studio 2010中,我创建了一个新的LightSwitch项目.

在"从数据开始"屏幕上,单击"创建新表"链接.

我命名并添加几列,我添加一个表单,然后运行该项目,我得到这个例外:

为应用程序构建数据库时发生异常.无法确定目标数据库架构提供程序.部署无法继续.

C:\ Program Files(x86)\ MSBuild\Microsoft\VisualStudio\LightSwitch\v1.0\Microsoft.LightSwitch.targets

看似简单但它不起作用.

如何指定目标数据库架构或绕过此错误?

c# visual-studio-lightswitch

5
推荐指数
1
解决办法
3109
查看次数

如何在Java线程上使用共享内存?

我正在用Java实现一个多线程程序,每个程序thread都是一个type class Node extends Thread

所有这些类都会生成某些值,这些值将由其他类使用。

因为main很容易从生成的值中获取值threads,但是从threads自身内部获取值,我又该如何获取其他值threads

//Start the threads from a list of objects
for (int i = 0; i < lnode.size(); i++) { 
    lnode.get(i).start();
}
Run Code Online (Sandbox Code Playgroud)

谢谢

java multithreading class shared-memory multiprocessing

5
推荐指数
1
解决办法
8128
查看次数

Android - 用于在智能手机和蓝牙模块之间路由音频的功能

这是我在Stackoverflow上的第一篇文章.我尝试在过去几天在Android智能手机上路由音频,但我找不到正确的功能.

它用于制作蓝牙Babyphone.

我需要在智能手机和蓝牙模块之间进行路由.蓝牙模块最初用于制作手机,汽车免提,无线扬声器......

我与项目的音频端的A2DP和HFP(免提)配置文件进行通信.

我可以在设备之间建立"sco"连接(与音频蓝牙交换机连接使用),并从蓝牙模块获取音频.但是当连接"sco"正在工作时,我就不能再使用智能手机上的扬声器和麦克风了.

我希望找到一个解决方案,在我的智能手机上使用音频,同时在我的蓝牙模块上使用音频.

我在http://developer.android.com/index.html上搜索了一个路由音频的功能.

AudioManager类有一些函数来路由音频,如setRouting或setParameters,但我还有任何结果. http://developer.android.com/reference/android/media/AudioManager.html

您可以在下面看到我用来从babyphone侧(蓝牙模块侧)获取音频的代码:

boolean isRecording=true;
int buffersize = 8000;
byte[] buffer = new byte[buffersize];

//audio configuration and SCO Bluetooth connection. 
AudioManager aManager = (AudioManager) getSystemService(AUDIO_SERVICE);
android.os.Process.setThreadPriority(
            android.os.Process.THREAD_PRIORITY_URGENT_AUDIO);
aManager.startBluetoothSco();
aManager.setBluetoothScoOn(true);
aManager.setMode(AudioManager.MODE_IN_COMMUNICATION);

//AudioRecord configuation for recording audio from babyphone.
AudioRecord  arec = new AudioRecord(
            MediaRecorder.AudioSource.VOICE_COMMUNICATION,
            8000,
            AudioFormat.CHANNEL_IN_MONO,
            AudioFormat.ENCODING_PCM_16BIT,
            buffersize); 

//AudioTrack configuation for sending audio to smartphone speaker.                
AudioTrack  atrack = new AudioTrack(AudioManager.STREAM_VOICE_CALL,
                8000,
                AudioFormat.CHANNEL_OUT_MONO,
                AudioFormat.ENCODING_PCM_16BIT,
                buffersize,
                AudioTrack.MODE_STREAM);

atrack.setPlaybackRate(8000);

//start audio recording and playing. …
Run Code Online (Sandbox Code Playgroud)

audio routing android bluetooth

5
推荐指数
1
解决办法
7340
查看次数

相当于ios的spongycastle加密

这让我很难过 - 以下代码使用SpongyCastle的Android加密/解密 - 我正在尝试为iOS实现跨平台加密/解密.

下面的代码(来自Android)使用PKCS7Padding处理AES 128bit CBC,使用提供的salt和密码,salt存储在mysql数据库中,密码由最终用户提供,以下代码改编自此kelhoer回答.

我之所以使用AES128bit是因为AES256在iOS 4+中不可用,它是在iOS5 +中引入的,并且不得不使用脚趾openssl来生成派生密钥和初始化矢量(iv),因为学到苹果公司拒绝它是很冒险的与openssl库静态链接的应用程序.

由于该平台基于iOS 4.2+,因此使用捆绑和静态链接openssl库似乎过度杀死并且最好使用CommonCryptor库.

这是使用Spongycastle代码的Android版本:

private static void encrypt(InputStream fin, 
    OutputStream fout, 
    String password, 
    byte[] bSalt) {
    try {
        PKCS12ParametersGenerator pGen = new PKCS12ParametersGenerator(
            new SHA256Digest()
            );
        char[] passwordChars = password.toCharArray();
        final byte[] pkcs12PasswordBytes = 
            PBEParametersGenerator.PKCS12PasswordToBytes(passwordChars);
        pGen.init(pkcs12PasswordBytes, bSalt, ITERATIONS);
        CBCBlockCipher aesCBC = new CBCBlockCipher(new AESEngine());
        ParametersWithIV aesCBCParams = 
            (ParametersWithIV) pGen.generateDerivedParameters(128, 128);
        aesCBC.init(true, aesCBCParams);
        PaddedBufferedBlockCipher aesCipher = 
            new PaddedBufferedBlockCipher(aesCBC, new PKCS7Padding());
        aesCipher.init(true, aesCBCParams);
        byte[] buf = …
Run Code Online (Sandbox Code Playgroud)

android ios commoncrypto spongycastle

5
推荐指数
1
解决办法
1554
查看次数

Windows窗体 - Tab键在子面板中不起作用

我有一个包含一些文本框和按钮的表单中的子面板.我尝试为这些控件设置tabstop和tabindex属性,以便用户可以从一个控件切换到下一个控件.但由于某种原因,标签不起作用,当按下标签键时,弯曲停留在同一个具有焦点的区域.我正在使用C#和.Net 3.5框架.以下是我的代码的样子 -

  rightPanel.Controls.Clear();
        marketMessageLabel = new Label();
        marketMessageLabel.Location = new Point(0, 20);            
        marketMessageLabel.AutoSize = false;
        marketMessageLabel.Size = new Size(rightPanel.Width, 42);
        marketMessageLabel.BackColor = Color.White;            
        marketMessageLabel.Font = new System.Drawing.Font("Verdana", 8.00F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
        rightPanel.Controls.Add(marketMessageLabel);                        

        signinUserNameLabel = new Label();
        signinUserNameLabel.Location = new Point(0, 150);
        signinUserNameLabel.Size = new Size(60, 14);
        signinUserNameLabel.BackColor = Color.White;
        signinUserNameLabel.Text = "User Name";            
        signinUserNameLabel.Font = new System.Drawing.Font("Verdana", 9.00F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
        rightPanel.Controls.Add(signinUserNameLabel);

        signinUserNameTextBox = new TextBox();
        signinUserNameTextBox.Location = new Point(0, 170);
        signinUserNameTextBox.Width = this.Width - 80;
        signinUserNameTextBox.Font = new …
Run Code Online (Sandbox Code Playgroud)

c# tabbing winforms

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

BroadcastReceiver ClassNotFound异常

我有一个应用程序,它使用AlarmManager来安排用户通知的警报.我将Alarm对象的实例传递给AlarmManager使用的PendingIntent:

public void scheduleAlarms(List<Alarm> alarms)
{
    for (Alarm alarm : alarms)
    {           
        Log.d(Constants.EVERY_OTHER_ALARM_APP_LOG_TAG, 
                "Setting alarm for: " + new Date(alarm.getTime()).toString() + 
                " with an interval of " + 
                IntervalEnumStringProvider.getIntervalStringInGivenFormat(
                        alarm.getInterval(), 
                        true));
        PendingIntent alarmScheduledPending = createPendingIntent(alarm);
        alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, 
                alarm.getTime(), 
                (alarm.getInterval() * Constants.ONE_SECOND_IN_MILLIS), 
                alarmScheduledPending);
    }
}

private PendingIntent createPendingIntent(Alarm alarm)
{
    alarmBroadcastReceiverIntent = new Intent(context, AlarmBroadcastReceiver.class);
    alarmBroadcastReceiverIntent.putExtra(Constants.SCHEDULED_ALARM_TAG, alarm);
    return PendingIntent.getBroadcast(context, 
                alarm.getIdForPendingIntent(), 
                alarmBroadcastReceiverIntent, 
                PendingIntent.FLAG_UPDATE_CURRENT);
}
Run Code Online (Sandbox Code Playgroud)

当闹钟时间发生时,我的AlarmBroadcastReceiver班级正确接收广播,但LogCat警告未找到Alarm类:

06-29 08:30:00.084: W/Intent(66): Failure filling in extras
06-29 08:30:00.084: W/Intent(66): java.lang.RuntimeException: Parcelable encounteredClassNotFoundException reading a Serializable …
Run Code Online (Sandbox Code Playgroud)

serialization android broadcastreceiver alarmmanager android-intent

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