Package ghidra.framework.protocol.ghidra

# Class GhidraURLConnection

java.lang.Object
java.net.URLConnection
ghidra.framework.protocol.ghidra.GhidraURLConnection

public class GhidraURLConnection extends URLConnection

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static enum`
  `GhidraURLConnection.StatusCode`
  Connection status codes

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final String`
  `GHIDRA_WRAPPED_CONTENT`
  Ghidra content type - domain folder/file wrapped within GhidraURLWrappedContent object.
  `static final String`
  `REPOSITORY_SERVER_CONTENT`
  Ghidra content type - repository server in the form of a RepositoryAdapter

  ### Fields inherited from class java.net.URLConnection

  `allowUserInteraction, connected, doInput, doOutput, ifModifiedSince, url, useCaches`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `GhidraURLConnection(URL ghidraUrl)`
  Construct a Ghidra URL connection which uses the default handler without any extension protocol.
  `GhidraURLConnection(URL url, GhidraProtocolHandler protocolHandler)`
  Construct a Ghidra URL connection which requires an Ghidra protocol extension

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `connect()`
  `Object`
  `getContent()`
  Get content associated with the URL
  `String`
  `getContentType()`
  `String`
  `getFolderItemName()`
  Gets the repository folder item name associated with this connection.
  `String`
  `getFolderPath()`
  Gets the repository folder path associated with this connection.
  `InputStream`
  `getInputStream()`
  `OutputStream`
  `getOutputStream()`
  `ProjectData`
  `getProjectData()`
  If URL connects and corresponds to a valid repository or local project, this method may be used to obtain the associated ProjectData object.
  `String`
  `getRepositoryName()`
  Gets the repository name associated with this `GhidraURLConnection`.
  `GhidraURLConnection.StatusCode`
  `getStatusCode()`
  Gets the status code from a Ghidra URL connect attempt.
  `boolean`
  `isReadOnly()`
  Connection was opened as read-only
  `void`
  `setReadOnly(boolean state)`
  Set the read-only state for this connection prior to connecting or getting content.

  ### Methods inherited from class java.net.URLConnection

  `addRequestProperty, getAllowUserInteraction, getConnectTimeout, getContent, getContentEncoding, getContentLength, getContentLengthLong, getDate, getDefaultAllowUserInteraction, getDefaultRequestProperty, getDefaultUseCaches, getDefaultUseCaches, getDoInput, getDoOutput, getExpiration, getFileNameMap, getHeaderField, getHeaderField, getHeaderFieldDate, getHeaderFieldInt, getHeaderFieldKey, getHeaderFieldLong, getHeaderFields, getIfModifiedSince, getLastModified, getPermission, getReadTimeout, getRequestProperties, getRequestProperty, getURL, getUseCaches, guessContentTypeFromName, guessContentTypeFromStream, setAllowUserInteraction, setConnectTimeout, setContentHandlerFactory, setDefaultAllowUserInteraction, setDefaultRequestProperty, setDefaultUseCaches, setDefaultUseCaches, setDoInput, setDoOutput, setFileNameMap, setIfModifiedSince, setReadTimeout, setRequestProperty, setUseCaches, toString`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Field Details

  - ### GHIDRA_WRAPPED_CONTENT

    public static final String GHIDRA_WRAPPED_CONTENT
    Ghidra content type - domain folder/file wrapped within GhidraURLWrappedContent object.
    See Also:
      - `GhidraURLWrappedContent`
      - Constant Field Values

  - ### REPOSITORY_SERVER_CONTENT

    public static final String REPOSITORY_SERVER_CONTENT
    Ghidra content type - repository server in the form of a RepositoryAdapter
    See Also:
      - `RepositoryAdapter`
      - Constant Field Values

- ## Constructor Details

  - ### GhidraURLConnection

    public GhidraURLConnection(URL ghidraUrl) throws MalformedURLException
    Construct a Ghidra URL connection which uses the default handler without any extension protocol.
    Parameters:
      `ghidraUrl` - ghidra protocol URL (e.g., ghidra://server/repo)
    Throws:
      `MalformedURLException` - if URL is invalid

  - ### GhidraURLConnection

    public GhidraURLConnection(URL url, GhidraProtocolHandler protocolHandler) throws MalformedURLException
    Construct a Ghidra URL connection which requires an Ghidra protocol extension
    Parameters:
      `url` - extension URL without the ghidra protocol prefix (e.g., http://server/repo)
      `protocolHandler` - Ghidra protocol extension handler
    Throws:
      `MalformedURLException` - if URL is invalid

- ## Method Details

  - ### isReadOnly

    public boolean isReadOnly()
    Connection was opened as read-only
    Returns:
      true if read-only connection

  - ### setReadOnly

    public void setReadOnly(boolean state)
    Set the read-only state for this connection prior to connecting or getting content. The default access is read-only. Extreme care must be taken when setting the state to false for local projects without the use of a ProjectLock.

    NOTE: Local project URL connections only support read-only access.

    Parameters:
      `state` - read-only if true, otherwise read-write
    Throws:
      `UnsupportedOperationException` - if an attempt is made to enable write access for a local project URL.
      `IllegalStateException` - if already connected

  - ### getRepositoryName

    public String getRepositoryName()
    Gets the repository name associated with this `GhidraURLConnection`.
    Returns:
      the repository name or null if URL does not identify a specific repository

  - ### getFolderPath

    public String getFolderPath()
    Gets the repository folder path associated with this connection. If an ambiguous path has been specified, the folder path may change after a connection is established (e.g., folder item name will be appended to folder path and item name will become null if item turns out to be a folder).
    Returns:
      repository folder path or null

  - ### getFolderItemName

    public String getFolderItemName()
    Gets the repository folder item name associated with this connection. If an ambiguous path has been specified, the folder item name may become null after a connection is established (e.g., folder item name will be appended to folder path and item name will become null if item turns out to be a folder).
    Returns:
      folder item name or null

  - ### getStatusCode

    public GhidraURLConnection.StatusCode getStatusCode() throws IOException
    Gets the status code from a Ghidra URL connect attempt.
    Returns:
      the Ghidra connection status code or null
    Throws:
      `IOException` - if an error occurred connecting to the server.

  - ### getContentType

    public String getContentType()
    Overrides:
      `getContentType` in class `URLConnection`

  - ### getContent

    public Object getContent() throws IOException
    Get content associated with the URL
    Overrides:
      `getContent` in class `URLConnection`
    Returns:
      URL content generally in the form of GhidraURLWrappedContent, although other special cases may result in different content (Example: a server-only URL could result in content class of RepositoryServerAdapter).
    Throws:
      `IOException` - if an IO error occurs

  - ### getProjectData

    public ProjectData getProjectData() throws IOException
    If URL connects and corresponds to a valid repository or local project, this method may be used to obtain the associated ProjectData object. The caller is responsible for properly `closing` the returned project data instance when no longer in-use, failure to do so may prevent release of repository handle to server until process exits. It is important that `ProjectData.close()` is invoked once, and only once, per call to this method to ensure project "use" tracking is properly maintained. Improperly invoking the close method on a shared transient `ProjectData` instance may cause the underlying storage to be prematurely disposed.
    Returns:
      project data which corresponds to this connection or null if unavailable
    Throws:
      `IOException` - if an IO error occurs

  - ### connect

    public void connect() throws IOException
    Specified by:
      `connect` in class `URLConnection`
    Throws:
      `IOException`

  - ### getInputStream

    public InputStream getInputStream() throws IOException
    Overrides:
      `getInputStream` in class `URLConnection`
    Throws:
      `IOException`

  - ### getOutputStream

    public OutputStream getOutputStream() throws IOException
    Overrides:
      `getOutputStream` in class `URLConnection`
    Throws:
      `IOException`