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

  • SEARCH
  • Home
  • 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 8626845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:07:45+00:00 2026-06-12T08:07:45+00:00

I have written a small TCP client to retrieve various data. It works fine

  • 0

I have written a small TCP client to retrieve various data. It works fine for text, but I have no clue how to implement image processing. At the moment, the incoming data is stored in an ArrayList<String>:

public ArrayList<String> sendSelector(String selector, String host, int port) throws IOException {
    socket = new Socket(host, port);
    out = new PrintWriter(socket.getOutputStream(), true);
    in = new BufferedReader(new InputStreamReader(socket.getInputStream()));

    out.println(encodePercent(selector) + CRLF);

    ArrayList<String> lines = new ArrayList();
    String line;

    while ((line = in.readLine()) != null) {
        if (line.equals("."))
            break;

        lines.add(line);
    }

    out.close();
    in.close();
    socket.close();

    return lines;
}

How can I create an Image or BufferedImage out of a GIF or JPEG stored in an ArrayList<String>? (Or am I completely in the dark and have to use different data structures?)

  • 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-06-12T08:07:46+00:00Added an answer on June 12, 2026 at 8:07 am

    Once you open an input stream from the server, create the image using ImageIO.read(InputStream):

    public BufferedImage sendSelector(String selector, String host, int port) throws IOException {
        socket = new Socket(host, port);
        try {
            out = new PrintWriter(socket.getOutputStream(), true);
            out.println(encodePercent(selector) + CRLF);
            in = socket.getInputStream();
            return ImageIO.read(in);
        } finally {
            socket.close(); // closes in and out as well
        }
    }
    

    For better efficiency, you might wrap in in a BufferedInputStream.

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

Sidebar

Related Questions

I have written a small plugin to change the text size but it doesn't
I have written a small HTTP server and everything is working fine locally, but
I have written a small utility to collect system data and output it to
I have written a small function, which uses ElementTree to parse xml file,but it
Here i have written a small code...in this looping is not done..only first image
I have written a small web application but am missing some cool functionality. I
I have written a small code, but found something amazing. I have a class
I'm trying to implement a small chat server-client pair in Python. I have already
I have written a small server application. It stores a lot of data in
I have written this small function to retrieve the tail of a list: let

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.