Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3438046
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:08:22+00:00 2026-05-18T08:08:22+00:00

I have written some code in Java that will decode a SHOUTcast stream and

  • 0

I have written some code in Java that will decode a SHOUTcast stream and return metadata. This code works as intended, but when I port it to Android the same code does not work. Specifically, I can’t seem to parse the HTTP response header from the SHOUTcast server. Where I can parse it just fine outside Android, I seem to get nothing but garbage back when the request is made via Android.

The relevant code follows.

        URL u = new URL("http://scfire-mtc-aa01.stream.aol.com:80/stream/1074");
        URLConnection uc = u.openConnection();
        uc.addRequestProperty("Icy-MetaData", "1");

        InputStream in       = uc.getInputStream();
        byte[] byteheader    = new byte[512];

        int c = 0;
        int i = 0;
        int metaint = 0;

        while ((c = in.read()) != -1){
            byteheader[i] = (byte)c;
            if (i > 4){
                if (byteheader[i - 3] == '\r' &&
                    byteheader[i - 2] == '\n' &&
                    byteheader[i - 1] == '\r' &&
                    byteheader[i] == '\n')
                    break;   
            }
            i++;
        }

When run in Android, this code overflows the “byteheader” buffer. When run outside Android, it functions properly. To make matters stranger, I have sniffed on the conversation via Wireshark and echoed the header sent by Android to a file. When using netcat to make a request with the same header, I get the appropriate response back. When I look at the logcat output of Android, “byteheader” contains only garbage.

My only idea is that this is something environmental that I’m overlooking. Or, I’m missing something massively obvious.

Any ideas?

As an edit, I’ve further isolated the problem by creating a dummy app and putting only the offending code in it. The problem persists, with Android returning garbage, and my identical external code working as expected. I thought this could be somehow related to character encodings, but it appears both environments are defaulting to UTF8.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T08:08:23+00:00Added an answer on May 18, 2026 at 8:08 am

    I have finally tracked the problem down to URLConnection. Apparently the class operates differently on my local JVM than it does on Android. Outside Android, URLConnection leaves the response header intact. Within Android, the response header is consumed, and the input stream begins at the first byte of data. The header information is available via getHeaderField.

    I’m not sure I understand this behavioral difference, and I can chalk it up only to a difference in Java versions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a java program named Automate.java, in which the another java program
I have a Java web application that has a 'disconnected' Java Swing desktop app.
I have written an application in C, which runs as a Windows service. Most
I am currently involved in some interesting programming language research which has, up until
I have a feeling my problem is a bit strange, but here goes... I
I am using java.util logging classes to create a rolling file appender. I want
i'm supposed to write code which when given a text file (source code) as
I'm attempting to create my own custom ToolTip for a program I've ported to
I am attempting to detect the file type of a library of files on
OK, first, I dont want any kind of flamewar here or anything like it.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.